Interface Graph
- All Superinterfaces:
AutoCloseable, GraphLike<Triple>
- All Known Subinterfaces:
JsonLdGraph, JsonLdUnionGraph, RDF4JGraph
- All Known Implementing Classes:
DatasetGraphView, GraphImpl, JsonLdGraphImpl, JsonLdUnionGraphImpl, ModelGraphImpl, RepositoryGraphImpl
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidadd(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Adds a triple to the graph, possibly mapping any of the components to those supported by this Graph.voidAdds a triple to the graph, possibly mapping any of the components of the Triple to those supported by this Graph.voidclear()Clears the graph, removing all triples.default voidclose()Closes the graph, relinquishing any underlying resources.booleancontains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Checks if graph contains a pattern of triples.booleanChecks if graph contains triple.Deprecated.getTriples(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Deprecated.iterate()Gets an Iterable for iterating over all triples in the graph.iterate(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Gets an Iterable for iterating over the triples in the graph that match the pattern.voidremove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Removes a concrete pattern of triples from the graph.voidRemoves a concrete triple from the graph.longsize()Number of triples contained by the graph.stream()Gets all triples contained by the graph.stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Gets all triples contained by the graph matched with the pattern.
-
Method Details
-
add
-
add
Adds a triple to the graph, possibly mapping any of the components to those supported by this Graph.- Parameters:
subject- The triple subjectpredicate- The triple predicateobject- The triple object
-
contains
-
contains
Checks if graph contains a pattern of triples.- Parameters:
subject- The triple subject (null is a wildcard)predicate- The triple predicate (null is a wildcard)object- The triple object (null is a wildcard)- Returns:
- True if the Graph contains any Triples that match the given pattern.
-
close
Closes the graph, relinquishing any underlying resources.For example, this would close any open file and network streams and free database locks held by the Graph implementation.
The behaviour of the other Graph methods are undefined after closing the graph.
Implementations might not need
close(), hence the default implementation does nothing.- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
remove
-
remove
Removes a concrete pattern of triples from the graph.- Parameters:
subject- The triple subject (null is a wildcard)predicate- The triple predicate (null is a wildcard)object- The triple object (null is a wildcard)
-
clear
-
size
long size()Number of triples contained by the graph.The count of a set does not include duplicates, consistent with the
Triple.equals(Object)equals method for eachTriple. -
stream
Gets all triples contained by the graph.
The iteration does not contain any duplicate triples, as determined by the
Triple.equals(Object)method for eachTriple.The behaviour of the
Streamis not specified ifadd(Triple),remove(Triple)orclear()are called on theGraphbefore it terminates.Implementations may throw
ConcurrentModificationExceptionfrom Stream methods if they detect a conflict while the Stream is active. -
stream
Gets all triples contained by the graph matched with the pattern.The iteration does not contain any duplicate triples, as determined by the
Triple.equals(Object)method for eachTriple.The behaviour of the
Streamis not specified ifadd(Triple),remove(Triple)orclear()are called on theGraphbefore it terminates.Implementations may throw
ConcurrentModificationExceptionfrom Stream methods if they detect a conflict while the Stream is active.- Parameters:
subject- The triple subject (null is a wildcard)predicate- The triple predicate (null is a wildcard)object- The triple object (null is a wildcard)- Returns:
- A
Streamover the matched triples. - Since:
- 0.3.0-incubating
-
getTriples
-
getTriples
@Deprecated default Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Deprecated.This method is deprecated, use the equivalent methodstream(BlankNodeOrIRI, IRI, RDFTerm)instead.- Parameters:
subject- The triple subject (null is a wildcard)predicate- The triple predicate (null is a wildcard)object- The triple object (null is a wildcard)- Returns:
- A
Streamover the matched triples.
-
iterate
Gets an Iterable for iterating over all triples in the graph.This method is meant to be used with a Java for-each loop, e.g.:
for (Triple t : graph.iterate()) { System.out.println(t); }The behaviour of the iterator is not specified ifadd(Triple),remove(Triple)orclear(), are called on theGraphbefore it terminates. It is undefined if the returnedIteratorsupports theIterator.remove()method.Implementations may throw
ConcurrentModificationExceptionfrom Iterator methods if they detect a concurrency conflict while the Iterator is active.The
Iterable.iterator()must only be called once, that is the Iterable must only be iterated over once. AIllegalStateExceptionmay be thrown on attempt to reuse the Iterable.The default implementation of this method will call
stream()to return itsBaseStream.iterator().- Specified by:
iteratein interfaceGraphLike<Triple>- Returns:
- A
Iterablethat returnsIteratorover all of the triples in the graph - Throws:
IllegalStateException- if theIterablehas been reusedConcurrentModificationException- if a concurrency conflict occurs while the Iterator is active.
-
iterate
default Iterable<Triple> iterate(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws ConcurrentModificationException, IllegalStateException Gets an Iterable for iterating over the triples in the graph that match the pattern.This method is meant to be used with a Java for-each loop, e.g.:
IRI alice = factory.createIRI("http://example.com/alice"); IRI knows = factory.createIRI("http://xmlns.com/foaf/0.1/"); for (Triple t : graph.iterate(alice, knows, null)) { System.out.println(t.getObject()); }The behaviour of the iterator is not specified if
add(Triple),remove(Triple)orclear(), are called on theGraphbefore it terminates. It is undefined if the returnedIteratorsupports theIterator.remove()method.Implementations may throw
ConcurrentModificationExceptionfrom Iterator methods if they detect a concurrency conflict while the Iterator is active.The
Iterable.iterator()must only be called once, that is the Iterable must only be iterated over once. AIllegalStateExceptionmay be thrown on attempt to reuse the Iterable.The default implementation of this method will call
stream(BlankNodeOrIRI, IRI, RDFTerm)to return itsBaseStream.iterator().- Parameters:
subject- The triple subject (null is a wildcard)predicate- The triple predicate (null is a wildcard)object- The triple object (null is a wildcard)- Returns:
- A
Iterablethat returnsIteratorover the matching triples in the graph - Throws:
IllegalStateException- if theIterablehas been reusedConcurrentModificationException- if a concurrency conflict occurs while the Iterator is active.
-