public interface Dataset extends AutoCloseable, GraphLike<Quad>
RDF.createDataset()
Modifier and Type | Method and Description |
---|---|
void |
add(BlankNodeOrIRI graphName,
BlankNodeOrIRI subject,
IRI predicate,
RDFTerm object)
Add a quad to the dataset, possibly mapping any of the components to
those supported by this dataset.
|
void |
add(Quad quad)
Add a quad to the dataset, possibly mapping any of the components of the
Quad to those supported by this dataset.
|
void |
clear()
Clear the dataset, removing all quads.
|
default void |
close()
Close the dataset, relinquishing any underlying resources.
|
boolean |
contains(Optional<BlankNodeOrIRI> graphName,
BlankNodeOrIRI subject,
IRI predicate,
RDFTerm object)
Check if dataset contains a pattern of quads.
|
boolean |
contains(Quad quad)
Check if dataset contains quad.
|
Graph |
getGraph()
Get the default graph of this dataset.
|
Optional<Graph> |
getGraph(BlankNodeOrIRI graphName)
Get a named graph in this dataset.
|
Stream<BlankNodeOrIRI> |
getGraphNames()
Get the graph names in this Dataset.
|
default Iterable<Quad> |
iterate()
Get an Iterable for iterating over all quads in the dataset.
|
default Iterable<Quad> |
iterate(Optional<BlankNodeOrIRI> graphName,
BlankNodeOrIRI subject,
IRI predicate,
RDFTerm object)
Get an Iterable for iterating over the quads in the dataset that match
the pattern.
|
void |
remove(Optional<BlankNodeOrIRI> graphName,
BlankNodeOrIRI subject,
IRI predicate,
RDFTerm object)
Remove a concrete pattern of quads from the default graph of the dataset.
|
void |
remove(Quad quad)
Remove a concrete quad from the dataset.
|
long |
size()
Number of quads contained by the dataset.
|
Stream<? extends Quad> |
stream()
Get all quads contained by the dataset.
|
Stream<? extends Quad> |
stream(Optional<BlankNodeOrIRI> graphName,
BlankNodeOrIRI subject,
IRI predicate,
RDFTerm object)
Get all quads contained by the dataset matched with the pattern.
|
void add(Quad quad)
void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
graphName
- The graph the quad belongs to, or null
for the
default graphsubject
- The quad subjectpredicate
- The quad predicateobject
- The quad objectboolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
graphName
- The graph the quad belongs to, wrapped as an Optional
(null
is a wildcard, Optional.empty()
is
the default graph)subject
- The quad subject (null
is a wildcard)predicate
- The quad predicate (null
is a wildcard)object
- The quad 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 dataset implementation.
The behaviour of the other dataset methods are undefined after closing the dataset.
Implementations might not need close()
, hence the default
implementation does nothing.
close
in interface AutoCloseable
Exception
Graph getGraph()
The Triple
s of the default graph are equivalent to the
Quad
s in this Dataset which has the Quad.getGraphName()
set to Optional.empty()
.
It is unspecified if modifications to the returned Graph are reflected in this Dataset.
The returned graph MAY be empty.
getGraph(BlankNodeOrIRI)
Optional<Graph> getGraph(BlankNodeOrIRI graphName)
The Triple
s of the named graph are equivalent to the the Quads of
this Dataset which has the Quad.getGraphName()
equal to the
provided graphName
, or equal to Optional.empty()
if
the provided graphName
is null
.
It is unspecified if modifications to the returned Graph are reflected in this Dataset.
It is unspecified if requesting an unknown or empty graph will return
Optional.empty()
or create a new empty Graph
.
graphName
- The name of the graph, or null
for the default
graph.Optional.empty()
if the dataset do
not contain the named graph.getGraph()
,
getGraphNames()
Stream<BlankNodeOrIRI> getGraphNames()
The set of returned graph names is equivalent to the set of unique
Quad.getGraphName()
of all the stream()
of this dataset
(excluding the default graph).
The returned Stream
SHOULD NOT contain duplicate graph names.
The graph names can be used with getGraph(BlankNodeOrIRI)
to
retrieve the corresponding Graph
, however callers should be aware
of any concurrent modifications to the Dataset may cause such calls to
return Optional.empty()
.
Note that a Dataset always contains a default graph
which is not named, and thus is not represented in the returned Stream.
The default graph is accessible via getGraph()
or by using
Optional.empty()
in the Quad access methods).
Stream
of the graph names of this Dataset.void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
graphName
- The graph the quad belongs to, wrapped as an Optional
(null
is a wildcard, Optional.empty()
is
the default graph)subject
- The quad subject (null
is a wildcard)predicate
- The quad predicate (null
is a wildcard)object
- The quad object (null
is a wildcard)void clear()
long size()
The count of a set does not include duplicates, consistent with the
Quad.equals(Object)
equals method for each Quad
.
Stream<? extends Quad> stream()
The iteration does not contain any duplicate quads, as determined by the
Quad.equals(Object)
method for each Quad
.
The behaviour of the Stream
is not specified if
add(Quad)
, remove(Quad)
or clear()
are called
on the Dataset
before it terminates.
Implementations may throw ConcurrentModificationException
from
Stream methods if they detect a conflict while the Stream is active.
Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
The iteration does not contain any duplicate quads, as determined by the
Quad.equals(Object)
method for each Quad
.
The behaviour of the Stream
is not specified if
add(Quad)
, remove(Quad)
or clear()
are called
on the Dataset
before it terminates.
Implementations may throw ConcurrentModificationException
from
Stream methods if they detect a conflict while the Stream is active.
graphName
- The graph the quad belongs to, wrapped as an Optional
(null
is a wildcard, Optional.empty()
is
the default graph)subject
- The quad subject (null
is a wildcard)predicate
- The quad predicate (null
is a wildcard)object
- The quad object (null
is a wildcard)Stream
over the matched quads.default Iterable<Quad> iterate() throws ConcurrentModificationException, IllegalStateException
This method is meant to be used with a Java for-each loop, e.g.:
for (Quad t : dataset.iterate()) { System.out.println(t); }The behaviour of the iterator is not specified if
add(Quad)
,
remove(Quad)
or clear()
, are called on the
Dataset
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<Quad>
Iterable
that returns Iterator
over all of the
quads in the datasetIllegalStateException
- if the Iterable
has been reusedConcurrentModificationException
- if a concurrency conflict occurs while the Iterator is
active.default Iterable<Quad> iterate(Optional<BlankNodeOrIRI> graphName, 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 (Quad t : dataset.iterate(null, alice, knows, null)) { System.out.println(t.getGraphName()); System.out.println(t.getObject()); }
The behaviour of the iterator is not specified if add(Quad)
,
remove(Quad)
or clear()
, are called on the
Dataset
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(Optional, BlankNodeOrIRI, IRI, RDFTerm)
to return its
BaseStream.iterator()
.
graphName
- The graph the quad belongs to, wrapped as an Optional
(null
is a wildcard, Optional.empty()
is
the default graph)subject
- The quad subject (null
is a wildcard)predicate
- The quad predicate (null
is a wildcard)object
- The quad object (null
is a wildcard)Iterable
that returns Iterator
over the
matching quads in the datasetIllegalStateException
- 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.