de.fuberlin.wiwiss.ng4j.impl
Class NamedGraphSetImpl

java.lang.Object
  extended by de.fuberlin.wiwiss.ng4j.impl.NamedGraphSetIO
      extended by de.fuberlin.wiwiss.ng4j.impl.NamedGraphSetImpl
All Implemented Interfaces:
NamedGraphSet
Direct Known Subclasses:
SemanticWebClient, SWPNamedGraphSetImpl

public class NamedGraphSetImpl
extends NamedGraphSetIO
implements NamedGraphSet

Implementation of the NamedGraphSet interface based on a set of in-memory NamedGraphs. For details about Named Graphs see http://www.w3.org/2004/03/trix/.

Author:
Chris Bizer, Richard Cyganiak (richard@cyganiak.de)

Constructor Summary
NamedGraphSetImpl()
           
 
Method Summary
 void addGraph(NamedGraph graph)
          Adds a NamedGraph to the set.
 void addQuad(Quad quad)
          Adds a quad to the NamedGraphSet.
 Graph asJenaGraph(Node defaultGraphForAdding)
          Returns the union graph of the NamedGraphSet.
 NamedGraphModel asJenaModel(String defaultGraphForAdding)
          Returns a Jena Model view on the NamedGraphSet, equivalent to the union graph of all graphs in the graph set.
 void clear()
          Deletes all NamedGraphs from the set.
 void close()
          Closes the NamedGraphSet and frees up resources held.
 boolean containsGraph(Node graphName)
          Tells wether the NamedGraphSet contains a NamedGraph.
 boolean containsGraph(String graphNameURI)
          Tells wether the NamedGraphSet contains a NamedGraph.
 boolean containsQuad(Quad pattern)
          Tells wether the NamedGraphSet contains a quad or quads matching a pattern.
 long countGraphs()
          Returns the number of NamedGraphs in the set.
 int countQuads()
          Counts the Quads in the NamedGraphSet.
 NamedGraph createGraph(Node graphName)
          Creates a new NamedGraph and adds it to the set.
 NamedGraph createGraph(String graphNameURI)
          Creates a new NamedGraph and adds it to the set.
protected  NamedGraph createNamedGraphInstance(Node graphName)
           
 Iterator findQuads(Node graphName, Node subject, Node predicate, Node object)
          Finds Quads that match a pattern.
 Iterator findQuads(Quad pattern)
          Finds Quads that match a quad pattern.
 NamedGraph getGraph(Node graphName)
          Returns the NamedGraph with a specific name from the GraphSet.
 NamedGraph getGraph(String graphNameURI)
          Returns the NamedGraph with a specific name from the GraphSet.
 boolean isEmpty()
          Tells wether the set contains any NamedGraphs.
 Iterator listGraphs()
          Returns an iterator over all NamedGraphs in the set.
 void removeGraph(Node graphName)
          Removes a NamedGraph from the set.
 void removeGraph(String graphNameURI)
          Removes the NamedGraph with a specific name.
 void removeQuad(Quad pattern)
          Deletes Quads from the NamedGraphSet.
 
Methods inherited from class de.fuberlin.wiwiss.ng4j.impl.NamedGraphSetIO
read, read, read, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.fuberlin.wiwiss.ng4j.NamedGraphSet
read, read, read, write, write
 

Constructor Detail

NamedGraphSetImpl

public NamedGraphSetImpl()
Method Detail

addGraph

public void addGraph(NamedGraph graph)
Description copied from interface: NamedGraphSet
Adds a NamedGraph to the set. Will replace a NamedGraph with the same name that is already in the set.

Specified by:
addGraph in interface NamedGraphSet
Parameters:
graph - The NamedGraph to be added

containsGraph

public boolean containsGraph(Node graphName)
Description copied from interface: NamedGraphSet
Tells wether the NamedGraphSet contains a NamedGraph.

Specified by:
containsGraph in interface NamedGraphSet
Parameters:
graphName - The name of a NamedGraph
Returns:
True if the set contains a graph with that name, false otherwise.

containsGraph

public boolean containsGraph(String graphNameURI)
Description copied from interface: NamedGraphSet
Tells wether the NamedGraphSet contains a NamedGraph.

Specified by:
containsGraph in interface NamedGraphSet
Parameters:
graphNameURI - The name of a NamedGraph
Returns:
True if the set contains a graph with that name, false otherwise.

countGraphs

public long countGraphs()
Description copied from interface: NamedGraphSet
Returns the number of NamedGraphs in the set. Empty graphs are counted.

Specified by:
countGraphs in interface NamedGraphSet
Returns:
The number of NamedGraphs in the set.

createGraph

public NamedGraph createGraph(Node graphName)
Description copied from interface: NamedGraphSet
Creates a new NamedGraph and adds it to the set. An existing graph with the same name will be replaced.

Specified by:
createGraph in interface NamedGraphSet
Parameters:
graphName - The name of the NamedGraph to be created; must be an URI node
Returns:
The newly created NamedGraph instance

createGraph

public NamedGraph createGraph(String graphNameURI)
Description copied from interface: NamedGraphSet
Creates a new NamedGraph and adds it to the set. An existing graph with the same name will be replaced.

Specified by:
createGraph in interface NamedGraphSet
Parameters:
graphNameURI - The name of the NamedGraph to be created; must be an URI
Returns:
The newly created NamedGraph instance

getGraph

public NamedGraph getGraph(Node graphName)
Description copied from interface: NamedGraphSet
Returns the NamedGraph with a specific name from the GraphSet. Changes to the graph will be reflected in the set.

Specified by:
getGraph in interface NamedGraphSet
Parameters:
graphName - The name of the NamedGraph to be returned
Returns:
The graph with that name, or null if no graph with that name is contained in the set

getGraph

public NamedGraph getGraph(String graphNameURI)
Description copied from interface: NamedGraphSet
Returns the NamedGraph with a specific name from the GraphSet. Changes to the graph will be reflected in the set.

Specified by:
getGraph in interface NamedGraphSet
Parameters:
graphNameURI - The name of the NamedGraph to be returned
Returns:
The graph with that name, or null if no graph with that name is contained in the set

isEmpty

public boolean isEmpty()
Description copied from interface: NamedGraphSet
Tells wether the set contains any NamedGraphs.

Specified by:
isEmpty in interface NamedGraphSet
Returns:
True if the set contains any NamedGraphs, false otherwise

listGraphs

public Iterator listGraphs()
Description copied from interface: NamedGraphSet
Returns an iterator over all NamedGraphs in the set.

Specified by:
listGraphs in interface NamedGraphSet
Returns:
An iterator over all NamedGraphs in the set

removeGraph

public void removeGraph(Node graphName)
Description copied from interface: NamedGraphSet
Removes a NamedGraph from the set. Nothing happens if no graph with that name is contained in the set. Node.ANY will remove all graphs from the set.

Specified by:
removeGraph in interface NamedGraphSet
Parameters:
graphName - The name of the NamedGraph to be removed

removeGraph

public void removeGraph(String graphNameURI)
Description copied from interface: NamedGraphSet
Removes the NamedGraph with a specific name. Nothing happens if no graph with that name is contained in the set. Node.ANY will remove all graphs from the set.

Specified by:
removeGraph in interface NamedGraphSet
Parameters:
graphNameURI - The name of the NamedGraph to be removed

clear

public void clear()
Description copied from interface: NamedGraphSet
Deletes all NamedGraphs from the set.

Specified by:
clear in interface NamedGraphSet

addQuad

public void addQuad(Quad quad)
Description copied from interface: NamedGraphSet
Adds a quad to the NamedGraphSet. The argument must not contain any wildcards. If the quad is already present, nothing happens. A new named graph will automatically be created if necessary.

Specified by:
addQuad in interface NamedGraphSet
Parameters:
quad - A quad to be added to the NamedGraphSet

containsQuad

public boolean containsQuad(Quad pattern)
Description copied from interface: NamedGraphSet
Tells wether the NamedGraphSet contains a quad or quads matching a pattern. Quad patterns are Quad instances with Node.ANY in one or more positions.

Specified by:
containsQuad in interface NamedGraphSet
Parameters:
pattern - A quad or quad pattern
Returns:
True if The NamedGraphSet contains matching quads, false otherwise

countQuads

public int countQuads()
Description copied from interface: NamedGraphSet
Counts the Quads in the NamedGraphSet. Identical Triples in different NamedGraphs are counted individually.

Specified by:
countQuads in interface NamedGraphSet
Returns:
The number of Quads in the set

findQuads

public Iterator findQuads(Node graphName,
                          Node subject,
                          Node predicate,
                          Node object)
Description copied from interface: NamedGraphSet
Finds Quads that match a pattern. All arguments may be Node.ANY to match everything in that position.

Specified by:
findQuads in interface NamedGraphSet
Parameters:
graphName - The graph to find triples from
subject - The subject to be matched
predicate - The predicate to be matched
object - The object to be matched
Returns:
An iterator over all Quads that match the pattern

findQuads

public Iterator findQuads(Quad pattern)
Description copied from interface: NamedGraphSet
Finds Quads that match a quad pattern. The argument may contain wildcards (Node.ANY).

Specified by:
findQuads in interface NamedGraphSet
Parameters:
pattern - A quad or quad pattern
Returns:
An iterator over all Quads that match the pattern

removeQuad

public void removeQuad(Quad pattern)
Description copied from interface: NamedGraphSet
Deletes Quads from the NamedGraphSet. The argument may contain wildcards (Node.ANY). All matching Quads will be deleted. If no Quads match, nothing happens. This operation will not delete any NamedGraphs from the set. Empty NamedGraphs will be retained.

Specified by:
removeQuad in interface NamedGraphSet
Parameters:
pattern - A quad or quad pattern to be deleted

asJenaGraph

public Graph asJenaGraph(Node defaultGraphForAdding)
Description copied from interface: NamedGraphSet
Returns the union graph of the NamedGraphSet. The graph is backed by the NamedGraphSet: Subsequent changes to one are reflected in the other.

Add operations to the union graph are all written to the default graph specified as the argument.

Delete operations remove the triple from all NamedGraphs.

Specified by:
asJenaGraph in interface NamedGraphSet
Parameters:
defaultGraphForAdding - The name of the default graph used for adding triples; must be an URI
Returns:
A Graph view on the NamedGraphSet

asJenaModel

public NamedGraphModel asJenaModel(String defaultGraphForAdding)
Description copied from interface: NamedGraphSet
Returns a Jena Model view on the NamedGraphSet, equivalent to the union graph of all graphs in the graph set.

Add operations on the returned model are all written to the default graph.

Read and write operations one the returned model have the behaviour of NamedGraphSet.read(String, String) and NamedGraphSet.write(OutputStream, String, String).

All Statements returned by the NamedGraphModel can be casted to NamedGraphStatement to access information about the graphs they are contained in.

Specified by:
asJenaModel in interface NamedGraphSet
Parameters:
defaultGraphForAdding - The name of the default graph used for adding triples; must be an URI
Returns:
A Model view on the NamedGraphSet

close

public void close()
Description copied from interface: NamedGraphSet
Closes the NamedGraphSet and frees up resources held. Any subsequent calls to methods of the object have undefined results.

Specified by:
close in interface NamedGraphSet

createNamedGraphInstance

protected NamedGraph createNamedGraphInstance(Node graphName)