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/04/13 03:12:18 UTC
[1/2] incubator-commonsrdf git commit: Remove GraphOrDataset
Repository: incubator-commonsrdf
Updated Branches:
refs/heads/quad 084a4adee -> 839a6425f
Remove GraphOrDataset
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/bfa15b89
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/bfa15b89
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/bfa15b89
Branch: refs/heads/quad
Commit: bfa15b89dad8ea6b9db3d4fbd942966b971ebd96
Parents: 084a4ad
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Apr 13 01:07:15 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Apr 13 01:07:15 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/Dataset.java | 2 +-
.../java/org/apache/commons/rdf/api/Graph.java | 2 +-
.../apache/commons/rdf/api/GraphOrDataset.java | 114 -------------------
3 files changed, 2 insertions(+), 116 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/bfa15b89/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 04d0030..3d24022 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
@@ -28,7 +28,7 @@ import java.util.stream.Stream;
* <a href="http://www.w3.org/TR/rdf11-concepts/" >RDF-1.1 Concepts and Abstract
* Syntax</a>, a W3C Recommendation published on 25 February 2014.
*/
-public interface Dataset extends AutoCloseable, GraphOrDataset<Quad> {
+public interface Dataset extends AutoCloseable {
/**
* Add a quad to the dataset, possibly mapping any of the components of the
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/bfa15b89/api/src/main/java/org/apache/commons/rdf/api/Graph.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Graph.java b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
index 019a713..c421226 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Graph.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
@@ -27,7 +27,7 @@ import java.util.stream.Stream;
* href="http://www.w3.org/TR/rdf11-concepts/" >RDF-1.1 Concepts and Abstract
* Syntax</a>, a W3C Recommendation published on 25 February 2014.
*/
-public interface Graph extends AutoCloseable, GraphOrDataset<Triple> {
+public interface Graph extends AutoCloseable {
/**
* Add a triple to the graph, possibly mapping any of the components of the
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/bfa15b89/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
deleted file mode 100644
index 87a1137..0000000
--- a/api/src/main/java/org/apache/commons/rdf/api/GraphOrDataset.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.rdf.api;
-
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-
-/**
- * Common interface for {@link Graph} and {@link Dataset}
- * <p>
- *
- */
-public interface GraphOrDataset<T extends TripleOrQuad> extends AutoCloseable {
-
- /**
- * Add a triple/quad to the graph, possibly mapping any of the components of the
- * TripleOrQuad to those supported by this Graph.
- *
- * @param tripleOrQuad The triple or quad to add
- */
- void add(T tripleOrQuad);
-
- /**
- * Check if graph/dataset contains triple/quad.
- *
- * @param tripleOrQuad The triple/quad to check.
- * @return True if this graph/dataset contains the given Triple.
- */
- boolean contains(T tripleOrQuad);
-
- /**
- * Close the graph/dataset, relinquishing any underlying resources.
- * <p>
- * For example, this would close any open file and network streams and free
- * database locks held by the Graph implementation.
- * <p>
- * The behaviour of the other Graph methods are undefined after closing the
- * graph.
- * <p>
- * Implementations might not need {@link #close()}, hence the default
- * implementation does nothing.
- */
- @Override
- default void close() throws Exception {
- }
-
- /**
- * Remove a concrete triple/quad from the graph.
- *
- * @param tripleOrQuad triple/quad to remove
- */
- void remove(T tripleOrQuad);
-
- /**
- * Clear the graph/dataset, removing all triples/quads.
- */
- void clear();
-
- /**
- * Number of triples/quads contained by the graph/dataset.
- *
- * @return The number of triples/quads in the graph/dataset
- */
- long size();
-
- /**
- * 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>
- * for (TripleOrQuad t : graphOrDataset.iterate()) {
- * System.out.println(t);
- * }
- * </pre>
- * 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.
- *
- * @return A {@link Iterable} that returns {@link Iterator} over all of the
- * 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.
- */
- Iterable<T> iterate()
- throws ConcurrentModificationException, IllegalStateException;
-
-}
[2/2] incubator-commonsrdf git commit: add getGraph(),
getGraph(graphName), getGraphNames()
Posted by st...@apache.org.
add getGraph(), getGraph(graphName), getGraphNames()
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/839a6425
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/839a6425
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/839a6425
Branch: refs/heads/quad
Commit: 839a6425fdb4985ef1594af87c6e12dcef8ec519
Parents: bfa15b8
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Apr 13 02:11:36 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Apr 13 02:11:36 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/Dataset.java | 65 ++++++++++++++++++++
.../apache/commons/rdf/simple/DatasetImpl.java | 30 +++++++++
2 files changed, 95 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/839a6425/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 3d24022..706366c 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
@@ -99,6 +99,71 @@ public interface Dataset extends AutoCloseable {
}
/**
+ * Get the default graph of this dataset.
+ * <p>
+ * The {@link Triple}s of the default graph are equivalent to the
+ * {@link Quad}s in this Dataset which has the {@link Quad#getGraphName()}
+ * set to {@link Optional#empty()}.
+ * <p>
+ * It is unspecified if modifications to the returned Graph are reflected in
+ * this Dataset.
+ * <p>
+ * The returned graph MAY be empty.
+ *
+ * @see #getGraph(BlankNodeOrIRI)
+ * @return The default graph of this Dataset
+ */
+ Graph getGraph();
+
+ /**
+ * Get a named graph in this dataset.
+ * <p>
+ * The {@link Triple}s of the named graph are equivalent to the
+ * the Quads of this Dataset which has the
+ * {@link Quad#getGraphName()} equal to the provided <code>graphName</code>, or
+ * equal to {@link Optional#empty()} if the provided <code>graphName</code> is
+ * <code>null</code>.
+ * <p>
+ * It is unspecified if modifications to the returned Graph are reflected in
+ * this Dataset.
+ * <p>
+ * It is unspecified if requesting an unknown or empty graph will return
+ * {@link Optional#empty()} or create a new empty {@link Graph}.
+ *
+ * @see #getGraph()
+ * @see #getGraphNames()
+ * @param graphName
+ * The name of the graph, or <code>null</code> for the default
+ * graph.
+ * @return The named Graph, or {@link Optional#empty()} if the dataset do
+ * not contain the named graph.
+ */
+ Optional<Graph> getGraph(BlankNodeOrIRI graphName);
+
+ /**
+ * Get the graph names in this Dataset.
+ * <p>
+ * The set of returned graph names is equivalent to the set of unique
+ * {@link Quad#getGraphName()} of all the {@link #getQuads()} of this
+ * dataset (excluding the default graph).
+ * <p>
+ * The returned {@link Stream} SHOULD NOT contain duplicate graph names.
+ * <p>
+ * The graph names can be used with {@link #getGraph(BlankNodeOrIRI)} to
+ * retrieve the corresponding {@link Graph}, however callers should be aware
+ * of any concurrent modifications to the Dataset may cause such calls to
+ * return {@link Optional#empty()}.
+ * <p>
+ * Note that a Dataset always contains a <strong>default graph</strong>
+ * which is not named, and thus is not represented in the returned Stream.
+ * The default graph is accessible via {@link #getGraph()} or by using
+ * {@link Optional#empty()} in the Quad access methods).
+ *
+ * @return A {@link Stream} of the graph names of this Dataset.
+ */
+ Stream<BlankNodeOrIRI> getGraphNames();
+
+ /**
* Remove a concrete quad from the dataset.
*
* @param quad
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/839a6425/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 63d4025..af9b01d 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
@@ -28,6 +28,7 @@ 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.Graph;
import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.Literal;
import org.apache.commons.rdf.api.Quad;
@@ -192,5 +193,34 @@ final class DatasetImpl implements Dataset {
}
}
+ @Override
+ public void close() {
+ }
+
+ @Override
+ public Graph getGraph() {
+ return getGraph(null).get();
+ }
+
+ @Override
+ public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
+ // NOTE: Always returns a new copy
+ Graph g = new GraphImpl(factory);
+ getQuads(Optional.ofNullable(graphName), null, null, null)
+ .map(Quad::asTriple)
+ .sequential()
+ .forEach(g::add);
+ return Optional.of(g);
+ }
+
+ @Override
+ public Stream<BlankNodeOrIRI> getGraphNames() {
+ // Not very efficient..
+ return getQuads()
+ .map(Quad::getGraphName)
+ .filter(Optional::isPresent).map(Optional::get)
+ .distinct();
+ }
+
}