org.jrdf.graph.local.mem
Class GraphImpl

java.lang.Object
  extended by org.jrdf.graph.local.mem.GraphImpl
All Implemented Interfaces:
Serializable, Graph

public class GraphImpl
extends Object
implements Graph, Serializable

A memory based RDF Graph.

Version:
$Revision: 1842 $
Author:
Paul Gearon, Andrew Newman
See Also:
Serialized Form

Field Summary
protected  BlankNodeRegistry bNodeRegistry
          Registry used for the toString method.
protected  RdfNamespaceMap nameSpace
          Namespace map used for toString method.
 
Constructor Summary
GraphImpl(LongIndex[] longIndexes, NodePool newNodePool, IteratorFactory newIteratorFactory, ReadWriteGraph newWritableGraph, ResourceFactory newResourceFactory)
          Default constructor.
 
Method Summary
 void add(Iterator<Triple> triples)
          Adds all the triples contained in an iterator into the graph.
 void add(SubjectNode subject, PredicateNode predicate, ObjectNode object)
          Adds a triple to the graph.
 void add(Triple... triples)
          Adds all the triples into the graph.
 void add(Triple triple)
          Adds a triple to the graph.
 void clear()
          Removes all statements and resource related to those statements from the graph.
 void close()
          Closes any resources associated with this graph.
 boolean contains(SubjectNode subject, PredicateNode predicate, ObjectNode object)
          Test the graph for the occurrence of a statement.
 boolean contains(Triple triple)
          Test the graph for the occurrence of the triple.
 ClosableIterator<Triple> find(SubjectNode subject, PredicateNode predicate, ObjectNode object)
          Returns an iterator of Triples to a set of statements that match a given subject, predicate and object.
 ClosableIterator<Triple> find(Triple triple)
          Returns an iterator of Triples to a set of statements that match a given subject, predicate and object.
 ClosableIterator<? extends Node> findNodes(NodeType type)
          Returns all unique values of a given type.
 ClosableIterator<PredicateNode> findPredicates(Resource resource)
          Return predicates that are part of an RDF triple where resource is either a subject or object.
 ClosableIterator<? super Resource> findResources(ValueNodeType type)
          Returns all unique resources for a given ValueNodeType (BNode or URIReference is currently supported).
 GraphElementFactory getElementFactory()
          Returns the node factory for the graph, or creates one.
 long getNumberOfTriples()
          Returns the number of triples in the graph.
 TripleFactory getTripleFactory()
          Returns the triple factory for the graph, or creates one.
 boolean isEmpty()
          Returns true if the graph is empty i.e. the number of triples is 0.
 void remove(Iterator<Triple> triples)
          Removes all the triples contained in an iterator from the graph.
 void remove(SubjectNode subject, PredicateNode predicate, ObjectNode object)
          Removes a triple from the graph.
 void remove(Triple... triples)
          Removes all the triples into the graph.
 void remove(Triple triple)
          Removes a triple from the graph.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

bNodeRegistry

protected transient BlankNodeRegistry bNodeRegistry
Registry used for the toString method.


nameSpace

protected transient RdfNamespaceMap nameSpace
Namespace map used for toString method.

Constructor Detail

GraphImpl

public GraphImpl(LongIndex[] longIndexes,
                 NodePool newNodePool,
                 IteratorFactory newIteratorFactory,
                 ReadWriteGraph newWritableGraph,
                 ResourceFactory newResourceFactory)
Default constructor.

Method Detail

contains

public boolean contains(Triple triple)
                 throws GraphException
Description copied from interface: Graph
Test the graph for the occurrence of the triple. An AnyNode value for any of the parts of a triple are treated as unconstrained, any values will be returned.

Specified by:
contains in interface Graph
Parameters:
triple - The triple to find.
Returns:
True if the triple is found in the graph, otherwise false.
Throws:
GraphException - If there was an error accessing the graph.

contains

public boolean contains(SubjectNode subject,
                        PredicateNode predicate,
                        ObjectNode object)
                 throws GraphException
Description copied from interface: Graph
Test the graph for the occurrence of a statement. An AnyNode value for any of the parts of a triple are treated as unconstrained, any values will be returned.

Specified by:
contains in interface Graph
Parameters:
subject - The subject to find or AnySubjectNode to indicate any subject.
predicate - The predicate to find or AnyPredicateNode to indicate any predicate.
object - The object to find or AnyObjectNode to indicate any object.
Returns:
True if the statement is found in the model, otherwise false.
Throws:
GraphException - If there was an error accessing the graph.

find

public ClosableIterator<Triple> find(Triple triple)
                              throws GraphException
Description copied from interface: Graph
Returns an iterator of Triples to a set of statements that match a given subject, predicate and object. An AnyNode value for any of the parts of a triple are treated as unconstrained, any values will be returned.

Specified by:
find in interface Graph
Parameters:
triple - The triple to find.
Returns:
an iterator containing the matching statements.
Throws:
GraphException - If there was an error accessing the graph.

find

public ClosableIterator<Triple> find(SubjectNode subject,
                                     PredicateNode predicate,
                                     ObjectNode object)
                              throws GraphException
Description copied from interface: Graph
Returns an iterator of Triples to a set of statements that match a given subject, predicate and object. An AnyNode value for any of the parts of a triple are treated as unconstrained, any values will be returned.

Specified by:
find in interface Graph
Parameters:
subject - The subject to find or AnySubjectNode to indicate any subject.
predicate - The predicate to find or AnyPredicateNode to indicate any predicate.
object - The object to find or AnyObjectNode to indicate any object.
Returns:
an iterator containing the matching statements.
Throws:
GraphException - If there was an error accessing the graph.

findNodes

public ClosableIterator<? extends Node> findNodes(NodeType type)
Description copied from interface: Graph
Returns all unique values of a given type.

Specified by:
findNodes in interface Graph
Parameters:
type - the node type can be positional (SPO) or node type (URIReference, Literal or BNode).
Returns:
all unique values of a given type.

findPredicates

public ClosableIterator<PredicateNode> findPredicates(Resource resource)
                                               throws GraphException
Description copied from interface: Graph
Return predicates that are part of an RDF triple where resource is either a subject or object.

Specified by:
findPredicates in interface Graph
Parameters:
resource - the resource that is either a subject or object in a triple.
Returns:
the unique predicates associated with the resource.
Throws:
GraphException - If there was an error accessing the graph.

findResources

public ClosableIterator<? super Resource> findResources(ValueNodeType type)
Description copied from interface: Graph
Returns all unique resources for a given ValueNodeType (BNode or URIReference is currently supported).

Specified by:
findResources in interface Graph
Parameters:
type - either BlankNodeType or URIReferenceNodeType.
Returns:
all unique resources.

add

public void add(Iterator<Triple> triples)
         throws GraphException
Description copied from interface: Graph
Adds all the triples contained in an iterator into the graph. The nodes must have already been created using GraphElementFactory.

Specified by:
add in interface Graph
Parameters:
triples - The triple iterator.
Throws:
GraphException - If the statements can't be made.

add

public void add(Triple... triples)
         throws GraphException
Description copied from interface: Graph
Adds all the triples into the graph. The nodes must have already been created using GraphElementFactory.

Specified by:
add in interface Graph
Parameters:
triples - the triples to add.
Throws:
GraphException - If the statements can't be made.

add

public void add(Triple triple)
         throws GraphException
Description copied from interface: Graph
Adds a triple to the graph. The nodes must have already been created using GraphElementFactory.

Specified by:
add in interface Graph
Parameters:
triple - The triple.
Throws:
GraphException - If the statement can't be made.

add

public void add(SubjectNode subject,
                PredicateNode predicate,
                ObjectNode object)
         throws GraphException
Description copied from interface: Graph
Adds a triple to the graph. The nodes must have already been created using GraphElementFactory.

Specified by:
add in interface Graph
Parameters:
subject - The subject.
predicate - The predicate.
object - The object.
Throws:
GraphException - If the statement can't be made.

remove

public void remove(Iterator<Triple> triples)
            throws GraphException
Description copied from interface: Graph
Removes all the triples contained in an iterator from the graph. The nodes must have already been created using GraphElementFactory.

Specified by:
remove in interface Graph
Parameters:
triples - The triple iterator.
Throws:
GraphException - If the statements can't be revoked.

remove

public void remove(Triple... triples)
            throws GraphException
Description copied from interface: Graph
Removes all the triples into the graph. The nodes must have already been created using GraphElementFactory.

Specified by:
remove in interface Graph
Parameters:
triples - the triples to remove.
Throws:
GraphException - If the statements can't be revoked.

remove

public void remove(Triple triple)
            throws GraphException
Description copied from interface: Graph
Removes a triple from the graph. The nodes must have already been created using GraphElementFactory.

Specified by:
remove in interface Graph
Parameters:
triple - The triple.
Throws:
GraphException - If there was an error revoking the statement, For example if it didn't exist.

remove

public void remove(SubjectNode subject,
                   PredicateNode predicate,
                   ObjectNode object)
            throws GraphException
Description copied from interface: Graph
Removes a triple from the graph. The nodes must have already been created using GraphElementFactory.

Specified by:
remove in interface Graph
Parameters:
subject - The subject.
predicate - The predicate.
object - The object.
Throws:
GraphException - If there was an error revoking the statement, For example if it didn't exist.

getElementFactory

public GraphElementFactory getElementFactory()
Description copied from interface: Graph
Returns the node factory for the graph, or creates one.

Specified by:
getElementFactory in interface Graph
Returns:
the node factory for the graph, or creates one.

getTripleFactory

public TripleFactory getTripleFactory()
Description copied from interface: Graph
Returns the triple factory for the graph, or creates one.

Specified by:
getTripleFactory in interface Graph
Returns:
the triple factory for the graph, or creates one.

getNumberOfTriples

public long getNumberOfTriples()
                        throws GraphException
Description copied from interface: Graph
Returns the number of triples in the graph.

Specified by:
getNumberOfTriples in interface Graph
Returns:
the number of triples in the graph.
Throws:
GraphException - If the statements number of statements in the graph fails to be found.

isEmpty

public boolean isEmpty()
                throws GraphException
Description copied from interface: Graph
Returns true if the graph is empty i.e. the number of triples is 0.

Specified by:
isEmpty in interface Graph
Returns:
true if the graph is empty i.e. the number of triples is 0.
Throws:
GraphException - If the statements number of statements in the graph fails to be found.

clear

public void clear()
Description copied from interface: Graph
Removes all statements and resource related to those statements from the graph.

Specified by:
clear in interface Graph

close

public void close()
Description copied from interface: Graph
Closes any resources associated with this graph.

Specified by:
close in interface Graph

toString

public String toString()
Overrides:
toString in class Object