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 TypeMethodDescriptionvoid
add
(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Adds a triple to the graph, possibly mapping any of the components to those supported by this Graph.void
Adds a triple to the graph, possibly mapping any of the components of the Triple to those supported by this Graph.void
clear()
Clears the graph, removing all triples.default void
close()
Closes the graph, relinquishing any underlying resources.boolean
contains
(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Checks if graph contains a pattern of triples.boolean
Checks 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.void
remove
(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) Removes a concrete pattern of triples from the graph.void
Removes a concrete triple from the graph.long
size()
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
Adds a triple to the graph, possibly mapping any of the components of the Triple to those supported by this Graph. -
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
Checks if graph contains triple. -
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:
close
in interfaceAutoCloseable
- Throws:
Exception
-
remove
Removes a concrete triple from the graph. -
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
void clear()Clears the graph, removing all triples. -
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
Stream
is not specified ifadd(Triple)
,remove(Triple)
orclear()
are called on theGraph
before it terminates.Implementations may throw
ConcurrentModificationException
from 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
Stream
is not specified ifadd(Triple)
,remove(Triple)
orclear()
are called on theGraph
before it terminates.Implementations may throw
ConcurrentModificationException
from 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
Stream
over the matched triples. - Since:
- 0.3.0-incubating
-
getTriples
Deprecated.This method is deprecated, use the equivalent methodstream()
instead.- Returns:
- A
Stream
over all triples.
-
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
Stream
over 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 theGraph
before it terminates. It is undefined if the returnedIterator
supports theIterator.remove()
method.Implementations may throw
ConcurrentModificationException
from 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. AIllegalStateException
may be thrown on attempt to reuse the Iterable.The default implementation of this method will call
stream()
to return itsBaseStream.iterator()
.- Specified by:
iterate
in interfaceGraphLike<Triple>
- Returns:
- A
Iterable
that returnsIterator
over all of the triples in the graph - Throws:
IllegalStateException
- if theIterable
has 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 theGraph
before it terminates. It is undefined if the returnedIterator
supports theIterator.remove()
method.Implementations may throw
ConcurrentModificationException
from 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. AIllegalStateException
may 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
Iterable
that returnsIterator
over the matching triples in the graph - Throws:
IllegalStateException
- if theIterable
has been reusedConcurrentModificationException
- if a concurrency conflict occurs while the Iterator is active.
-