public interface Graph extends AutoCloseable, GraphLike<Triple>
RDF.createGraph()
Modifier and Type | Method and Description |
---|---|
void |
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 |
add(Triple triple)
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 |
contains(Triple triple)
Checks if graph contains triple.
|
default Stream<? extends Triple> |
getTriples()
Deprecated.
|
default Stream<? extends Triple> |
getTriples(BlankNodeOrIRI subject,
IRI predicate,
RDFTerm object)
Deprecated.
|
default Iterable<Triple> |
iterate()
Gets an Iterable for iterating over all triples in the graph.
|
default Iterable<Triple> |
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 |
remove(Triple triple)
Removes a concrete triple from the graph.
|
long |
size()
Number of triples contained by the graph.
|
Stream<? extends Triple> |
stream()
Gets all triples contained by the graph.
|
Stream<? extends Triple> |
stream(BlankNodeOrIRI subject,
IRI predicate,
RDFTerm object)
Gets all triples contained by the graph matched with the pattern.
|
void add(Triple triple)
void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
subject
- The triple subjectpredicate
- The triple predicateobject
- The triple objectboolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
subject
- The triple subject (null is a wildcard)predicate
- The triple predicate (null is a wildcard)object
- The triple object (null is a wildcard)default void close() throws Exception
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.
close
in interface AutoCloseable
Exception
void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
subject
- The triple subject (null is a wildcard)predicate
- The triple predicate (null is a wildcard)object
- The triple object (null is a wildcard)void clear()
long size()
The count of a set does not include duplicates, consistent with the
Triple.equals(Object)
equals method for each Triple
.
Stream<? extends Triple> stream()
The iteration does not contain any duplicate triples, as determined by
the Triple.equals(Object)
method for each Triple
.
The behaviour of the Stream
is not specified if
add(Triple)
, remove(Triple)
or clear()
are
called on the Graph
before it terminates.
Implementations may throw ConcurrentModificationException
from
Stream methods if they detect a conflict while the Stream is active.
Stream<? extends Triple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
The iteration does not contain any duplicate triples, as determined by
the Triple.equals(Object)
method for each Triple
.
The behaviour of the Stream
is not specified if
add(Triple)
, remove(Triple)
or clear()
are
called on the Graph
before it terminates.
Implementations may throw ConcurrentModificationException
from
Stream methods if they detect a conflict while the Stream is active.
subject
- The triple subject (null is a wildcard)predicate
- The triple predicate (null is a wildcard)object
- The triple object (null is a wildcard)Stream
over the matched triples.@Deprecated default Stream<? extends Triple> getTriples()
stream()
instead.Stream
over all triples.@Deprecated default Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
stream(BlankNodeOrIRI, IRI, RDFTerm)
instead.subject
- The triple subject (null is a wildcard)predicate
- The triple predicate (null is a wildcard)object
- The triple object (null is a wildcard)Stream
over the matched triples.default Iterable<Triple> iterate() throws ConcurrentModificationException, IllegalStateException
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 if
add(Triple)
,
remove(Triple)
or clear()
, are called on the
Graph
before it terminates. It is undefined if the returned
Iterator
supports the Iterator.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. A IllegalStateException
may be thrown on attempt to reuse the Iterable.
The default implementation of this method will call stream()
to return
its BaseStream.iterator()
.
iterate
in interface GraphLike<Triple>
Iterable
that returns Iterator
over all of the
triples in the graphIllegalStateException
- if the Iterable
has been reusedConcurrentModificationException
- if a concurrency conflict occurs while the Iterator is
active.default Iterable<Triple> iterate(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws ConcurrentModificationException, IllegalStateException
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)
or clear()
, are called on the
Graph
before it terminates. It is undefined if the returned
Iterator
supports the Iterator.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. A IllegalStateException
may be thrown on attempt to reuse the Iterable.
The default implementation of this method will call
stream(BlankNodeOrIRI, IRI, RDFTerm)
to return its
BaseStream.iterator()
.
subject
- The triple subject (null is a wildcard)predicate
- The triple predicate (null is a wildcard)object
- The triple object (null is a wildcard)Iterable
that returns Iterator
over the
matching triples in the graphIllegalStateException
- if the Iterable
has been reusedConcurrentModificationException
- if a concurrency conflict occurs while the Iterator is
active.Copyright © 2015–2018 The Apache Software Foundation. All rights reserved.