You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commonsrdf.apache.org by st...@apache.org on 2016/09/05 15:53:52 UTC
[08/19] incubator-commonsrdf git commit: Dataset does not do
Triple-stuff
Dataset does not do Triple-stuff
.. to avoid making assumptions about the default graph
See https://github.com/apache/incubator-commonsrdf/pull/19#issuecomment-208365206
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/084a4ade
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/084a4ade
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/084a4ade
Branch: refs/heads/master
Commit: 084a4adee2f286f1babec035382fae36812ec3c9
Parents: 683a2bb
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Apr 11 15:17:11 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Mon Apr 11 15:17:11 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/Dataset.java | 49 +------
.../apache/commons/rdf/api/GraphOrDataset.java | 135 +------------------
.../apache/commons/rdf/simple/DatasetImpl.java | 47 ++-----
3 files changed, 14 insertions(+), 217 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/084a4ade/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
index fca9810..04d0030 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Dataset.java
@@ -40,23 +40,6 @@ public interface Dataset extends AutoCloseable, GraphOrDataset<Quad> {
void add(Quad quad);
/**
- * Add a triple to the default graph of this dataset, possibly mapping any
- * of the components to those supported by this dataset.
- * <p>
- * This method is equivalent to
- * {@link #add(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)} with
- * <code>graphName</code> set as <code>null</code>.
- *
- * @param subject
- * The quad subject
- * @param predicate
- * The quad predicate
- * @param object
- * The quad object
- */
- void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
- /**
* Add a quad to the dataset, possibly mapping any of the components to
* those supported by this dataset.
*
@@ -82,24 +65,6 @@ public interface Dataset extends AutoCloseable, GraphOrDataset<Quad> {
boolean contains(Quad quad);
/**
- * Check if the default graph in the dataset contains a triple pattern.
- * <p>
- * This method is equivalent to
- * {@link #contains(Optional, BlankNodeOrIRI, IRI, RDFTerm)} with a
- * <code>graphName</code> set to <code>null</code>
- *
- * @param subject
- * The quad subject (<code>null</code> is a wildcard)
- * @param predicate
- * The quad predicate (<code>null</code> is a wildcard)
- * @param object
- * The quad object (<code>null</code> is a wildcard)
- * @return True if the default graph in the dataset contains any quads that
- * match the given pattern.
- */
- boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
- /**
* Check if dataset contains a pattern of quads.
*
* @param graphName
@@ -144,18 +109,6 @@ public interface Dataset extends AutoCloseable, GraphOrDataset<Quad> {
/**
* Remove a concrete pattern of quads from the default graph of the dataset.
*
- * @param subject
- * The quad subject (<code>null</code> is a wildcard)
- * @param predicate
- * The quad predicate (<code>null</code> is a wildcard)
- * @param object
- * The quad object (<code>null</code> is a wildcard)
- */
- void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
- /**
- * Remove a concrete pattern of quads from the default graph of the dataset.
- *
* @param graphName
* The graph the quad belongs to, wrapped as an {@link Optional}
* (<code>null</code> is a wildcard, {@link Optional#empty()} is
@@ -315,6 +268,6 @@ public interface Dataset extends AutoCloseable, GraphOrDataset<Quad> {
@SuppressWarnings("unchecked")
default Iterable<Quad> iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
RDFTerm object) throws ConcurrentModificationException, IllegalStateException {
- return ((Stream<Quad>) getQuads(null, subject, predicate, object))::iterator;
+ return ((Stream<Quad>) getQuads(graphName, subject, predicate, object))::iterator;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/084a4ade/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java b/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
index f41463a..87a1137 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
@@ -19,7 +19,6 @@ package org.apache.commons.rdf.api;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
-import java.util.stream.Stream;
/**
* Common interface for {@link Graph} and {@link Dataset}
@@ -37,17 +36,6 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
void add(T tripleOrQuad);
/**
- * Add a triple to the Graph, (or the default graph of a Dataset),
- * possibly mapping any of the components to
- * those supported by this graph/dataset.
- *
- * @param subject The triple subject
- * @param predicate The triple predicate
- * @param object The triple object
- */
- void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
- /**
* Check if graph/dataset contains triple/quad.
*
* @param tripleOrQuad The triple/quad to check.
@@ -56,21 +44,6 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
boolean contains(T tripleOrQuad);
/**
- * Check if graph/dataset contains a pattern of triples or quads in the
- * default graph of a dataset.
- *
- * @param subject
- * The triple subject (null is a wildcard)
- * @param predicate
- * The triple predicate (null is a wildcard)
- * @param object
- * The triple object (null is a wildcard)
- * @return True if this graph/dataset contains any triples/quads
- * that match the given pattern.
- */
- boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
- /**
* Close the graph/dataset, relinquishing any underlying resources.
* <p>
* For example, this would close any open file and network streams and free
@@ -94,16 +67,6 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
void remove(T tripleOrQuad);
/**
- * Remove a concrete pattern of triples from the graph, or
- * quads from the default graph of a dataset.
- *
- * @param subject The triple subject (null is a wildcard)
- * @param predicate The triple predicate (null is a wildcard)
- * @param object The triple object (null is a wildcard)
- */
- void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
- /**
* Clear the graph/dataset, removing all triples/quads.
*/
void clear();
@@ -116,49 +79,7 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
long size();
/**
- * Get all triples contained by the graph, or
- * the equivalent of {@link Quad#asTriple()}
- * for all quads of the default graph of a dataset.
- * <p>
- * The iteration does not contain any duplicate triples, as determined by
- * the {@link Triple#equals(Object)} method for each {@link Triple}.
- * <p>
- * The behaviour of the {@link Stream} is not specified if {@link #add(TripleOrQuad)},
- * {@link #remove(TripleOrQuad)} or {@link #clear()} are called on the
- * {@link GraphOrDataset} before it terminates.
- * <p>
- * Implementations may throw {@link ConcurrentModificationException} from Stream
- * methods if they detect a conflict while the Stream is active.
- *
- * @return A {@link Stream} over all of the triples in the graph
- */
- Stream<? extends Triple> getTriples();
-
- /**
- * Get all triples contained by the graph matched with the pattern, or
- * the equivalent of {@link Quad#asTriple()}
- * for all quads of the default graph of a dataset that match the pattern.
- * <p>
- * The iteration does not contain any duplicate triples, as determined by
- * the {@link Triple#equals(Object)} method for each {@link Triple}.
- * <p>
- * The behaviour of the {@link Stream} is not specified if {@link #add(TripleOrQuad)},
- * {@link #remove(TripleOrQuad)} or {@link #clear()} are called on the
- * {@link GraphOrDataset} before it terminates.
- * <p>
- * Implementations may throw {@link ConcurrentModificationException} from Stream
- * methods if they detect a conflict while the Stream is active.
- *
- * @param subject The triple subject (null is a wildcard)
- * @param predicate The triple predicate (null is a wildcard)
- * @param object The triple object (null is a wildcard)
- * @return A {@link Stream} over the matched triples.
- */
- Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object);
-
- /**
- * Get an Iterable for iterating over all triples in the graph.
+ * Get an Iterable for iterating over all triples/quads in the graph/dataset.
* <p>
* This method is meant to be used with a Java for-each loop, e.g.:
* <pre>
@@ -187,57 +108,7 @@ public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
* if a concurrency conflict occurs while the Iterator is
* active.
*/
- @SuppressWarnings("unchecked")
- default Iterable<T> iterate()
- throws ConcurrentModificationException, IllegalStateException {
- return ((Stream<T>)getTriples())::iterator;
- }
+ Iterable<T> iterate()
+ throws ConcurrentModificationException, IllegalStateException;
- /**
- * Get an Iterable for iterating over the triples in the graph
- * or quads in the default graph of a dataset that
- * match the pattern.
- * <p>
- * This method is meant to be used with a Java for-each loop, e.g.:
- * <pre>
- * IRI alice = factory.createIRI("http://example.com/alice");
- * IRI knows = factory.createIRI("http://xmlns.com/foaf/0.1/");
- * for (Triple t : graphOrDataset.iterate(alice, knows, null)) {
- * System.out.println(t.getObject());
- * }
- * </pre>
- * <p>
- * The behaviour of the iterator is not specified if
- * {@link #add(TripleOrQuad)}, {@link #remove(TripleOrQuad)} or {@link #clear()}, are
- * called on the {@link GraphOrDataset} before it terminates. It is undefined if the
- * returned {@link Iterator} supports the {@link Iterator#remove()} method.
- * <p>
- * Implementations may throw {@link ConcurrentModificationException} from
- * Iterator methods if they detect a concurrency conflict while the Iterator
- * is active.
- * <p>
- * The {@link Iterable#iterator()} must only be called once, that is the
- * Iterable must only be iterated over once. A {@link IllegalStateException}
- * may be thrown on attempt to reuse the Iterable.
- *
- * @param subject
- * The triple subject (null is a wildcard)
- * @param predicate
- * The triple predicate (null is a wildcard)
- * @param object
- * The triple object (null is a wildcard)
- * @return A {@link Iterable} that returns {@link Iterator} over the
- * matching triples in the graph
- * @throws IllegalStateException
- * if the {@link Iterable} has been reused
- * @throws ConcurrentModificationException
- * if a concurrency conflict occurs while the Iterator is
- * active.
- */
- @SuppressWarnings("unchecked")
- default Iterable<T> iterate(
- BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
- throws ConcurrentModificationException, IllegalStateException {
- return ((Stream<T>) getTriples(subject, predicate, object))::iterator;
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/084a4ade/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
index 64cf57d..63d4025 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetImpl.java
@@ -17,9 +17,6 @@
*/
package org.apache.commons.rdf.simple;
-import org.apache.commons.rdf.api.*;
-import org.apache.commons.rdf.simple.SimpleRDFTermFactory.SimpleRDFTerm;
-
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
@@ -28,6 +25,15 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.apache.commons.rdf.api.BlankNode;
+import org.apache.commons.rdf.api.BlankNodeOrIRI;
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.Literal;
+import org.apache.commons.rdf.api.Quad;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.simple.SimpleRDFTermFactory.SimpleRDFTerm;
+
/**
* A simple, memory-based implementation of Dataset.
* <p>
@@ -44,12 +50,6 @@ final class DatasetImpl implements Dataset {
DatasetImpl(SimpleRDFTermFactory simpleRDFTermFactory) {
this.factory = simpleRDFTermFactory;
}
-
- @Override
- public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- // TODO: Should this method be promoted as a default method in Dataset?
- add(null, subject, predicate, object);
- }
@Override
public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
@@ -117,13 +117,6 @@ final class DatasetImpl implements Dataset {
quads.clear();
}
- @Override
- public boolean contains(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) {
- // TODO: Should this method be promoted as a default method in Dataset?
- return getQuads(Optional.empty(), subject, predicate, object).findAny().isPresent();
- }
-
@Override
public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
return getQuads(graphName, subject, predicate, object).findAny().isPresent();
@@ -165,29 +158,10 @@ final class DatasetImpl implements Dataset {
});
}
- @Override
- public Stream<Triple> getTriples() {
- // TODO: Should this method be promoted as a default method in Dataset?
- return getQuads(Optional.empty(), null, null, null).map(Quad::asTriple);
- }
-
- @Override
- public Stream<Triple> getTriples(final BlankNodeOrIRI subject,
- final IRI predicate, final RDFTerm object) {
- // TODO: Should this method be promoted as a default method in Dataset?
- return getQuads(Optional.empty(), subject, predicate, object).map(Quad::asTriple);
- }
-
private Stream<Quad> getQuads(final Predicate<Quad> filter) {
return getQuads().filter(filter);
}
- @Override
- public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- // TODO: Should this method be promoted as a default method in Dataset?
- remove(Optional.empty(), subject, predicate, object);
- }
-
@Override
public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
Stream<Quad> toRemove = getQuads(graphName, subject, predicate, object);
@@ -197,7 +171,6 @@ final class DatasetImpl implements Dataset {
}
}
-
@Override
public void remove(Quad quad) {
quads.remove(Objects.requireNonNull(quad));
@@ -210,7 +183,7 @@ final class DatasetImpl implements Dataset {
@Override
public String toString() {
- String s = getTriples().limit(TO_STRING_MAX).map(Object::toString)
+ String s = getQuads().limit(TO_STRING_MAX).map(Object::toString)
.collect(Collectors.joining("\n"));
if (size() > TO_STRING_MAX) {
return s + "\n# ... +" + (size() - TO_STRING_MAX) + " more";