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/10/28 13:07:39 UTC
[01/50] [abbrv] incubator-commonsrdf git commit: SimpleRDFTermFactory
-> SimpleRDFFactory [Forced Update!]
Repository: incubator-commonsrdf
Updated Branches:
refs/heads/COMMONSRDF-7 cdc76af17 -> 797a4cd53 (forced update)
SimpleRDFTermFactory -> SimpleRDFFactory
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/08fbb929
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/08fbb929
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/08fbb929
Branch: refs/heads/COMMONSRDF-7
Commit: 08fbb929286d96adb52dfa1946e346900d1f06c5
Parents: 2f4a276
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 19 17:37:56 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 19 17:37:56 2016 +0100
----------------------------------------------------------------------
examples/src/example/UserGuideTest.java | 6 +-
.../commons/rdf/simple/BlankNodeImpl.java | 2 +-
.../apache/commons/rdf/simple/DatasetImpl.java | 8 +-
.../apache/commons/rdf/simple/GraphImpl.java | 8 +-
.../org/apache/commons/rdf/simple/IRIImpl.java | 2 +-
.../apache/commons/rdf/simple/LiteralImpl.java | 2 +-
.../org/apache/commons/rdf/simple/QuadImpl.java | 2 +-
.../commons/rdf/simple/SimpleRDFFactory.java | 114 +++++++++++++++++++
.../rdf/simple/SimpleRDFTermFactory.java | 113 ------------------
.../apache/commons/rdf/simple/TripleImpl.java | 2 +-
.../org/apache/commons/rdf/simple/Types.java | 2 +-
.../simple/experimental/AbstractRDFParser.java | 8 +-
.../apache/commons/rdf/simple/package-info.java | 6 +-
.../org.apache.commons.rdf.api.RDFTermFactory | 2 +-
.../commons/rdf/simple/DefaultGraphTest.java | 2 +-
.../commons/rdf/simple/SimpleGraphTest.java | 4 +-
.../SimpleNoRelativeIRIRDFTermFactoryTest.java | 2 +-
.../simple/SimpleRDFTermFactoryLookupTest.java | 2 +-
.../rdf/simple/SimpleRDFTermFactoryTest.java | 2 +-
.../commons/rdf/simple/TestWritingGraph.java | 2 +-
.../experimental/AbstractRDFParserTest.java | 4 +-
21 files changed, 148 insertions(+), 147 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/examples/src/example/UserGuideTest.java
----------------------------------------------------------------------
diff --git a/examples/src/example/UserGuideTest.java b/examples/src/example/UserGuideTest.java
index 44623b3..c9487e3 100644
--- a/examples/src/example/UserGuideTest.java
+++ b/examples/src/example/UserGuideTest.java
@@ -35,7 +35,7 @@ import org.apache.commons.rdf.api.RDFTerm;
import org.apache.commons.rdf.api.RDFFactory;
import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.api.TripleLike;
-import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
+import org.apache.commons.rdf.simple.SimpleRDFFactory;
import org.apache.commons.rdf.simple.Types;
import org.junit.Before;
import org.junit.Test;
@@ -46,7 +46,7 @@ public class UserGuideTest {
@Before
public void factory() {
- factory = new SimpleRDFTermFactory();
+ factory = new SimpleRDFFactory();
}
@Test
@@ -89,7 +89,7 @@ public class UserGuideTest {
System.out.println(b1.ntriplesString());
System.out.println(b1.equals(factory.createBlankNode("b1")));
- System.out.println(b1.equals(new SimpleRDFTermFactory().createBlankNode("b1")));
+ System.out.println(b1.equals(new SimpleRDFFactory().createBlankNode("b1")));
System.out.println(bnode.uniqueReference());
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
index dab2f12..fbbdb26 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
@@ -23,7 +23,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.rdf.api.BlankNode;
-import org.apache.commons.rdf.simple.SimpleRDFTermFactory.SimpleRDFTerm;
+import org.apache.commons.rdf.simple.SimpleRDFFactory.SimpleRDFTerm;
/**
* A simple implementation of BlankNode.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/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 c372012..78f1981 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
@@ -33,7 +33,7 @@ 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;
+import org.apache.commons.rdf.simple.SimpleRDFFactory.SimpleRDFTerm;
/**
* A simple, memory-based implementation of Dataset.
@@ -46,10 +46,10 @@ final class DatasetImpl implements Dataset {
private static final int TO_STRING_MAX = 10;
private final Set<Quad> quads = new HashSet<Quad>();
- private final SimpleRDFTermFactory factory;
+ private final SimpleRDFFactory factory;
- DatasetImpl(SimpleRDFTermFactory simpleRDFTermFactory) {
- this.factory = simpleRDFTermFactory;
+ DatasetImpl(SimpleRDFFactory simpleRDFFactory) {
+ this.factory = simpleRDFFactory;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index 779b1ad..1173d53 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -18,7 +18,7 @@
package org.apache.commons.rdf.simple;
import org.apache.commons.rdf.api.*;
-import org.apache.commons.rdf.simple.SimpleRDFTermFactory.SimpleRDFTerm;
+import org.apache.commons.rdf.simple.SimpleRDFFactory.SimpleRDFTerm;
import java.util.HashSet;
import java.util.Objects;
@@ -38,10 +38,10 @@ final class GraphImpl implements Graph {
private static final int TO_STRING_MAX = 10;
private final Set<Triple> triples = new HashSet<Triple>();
- private final SimpleRDFTermFactory factory;
+ private final SimpleRDFFactory factory;
- GraphImpl(SimpleRDFTermFactory simpleRDFTermFactory) {
- this.factory = simpleRDFTermFactory;
+ GraphImpl(SimpleRDFFactory simpleRDFFactory) {
+ this.factory = simpleRDFFactory;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
index fdec0ac..c3ef547 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
@@ -24,7 +24,7 @@ import java.net.URI;
/**
* A simple implementation of IRI.
*/
-final class IRIImpl implements IRI, SimpleRDFTermFactory.SimpleRDFTerm {
+final class IRIImpl implements IRI, SimpleRDFFactory.SimpleRDFTerm {
private final String iri;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
index 3d6874a..b3f7042 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
@@ -28,7 +28,7 @@ import org.apache.commons.rdf.api.Literal;
/**
* A simple implementation of Literal.
*/
-final class LiteralImpl implements Literal, SimpleRDFTermFactory.SimpleRDFTerm {
+final class LiteralImpl implements Literal, SimpleRDFFactory.SimpleRDFTerm {
private static final String QUOTE = "\"";
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
index 54921bb..54c5fc1 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
@@ -40,7 +40,7 @@ final class QuadImpl implements Quad {
* Construct Quad from its constituent parts.
* <p>
* The objects are not changed. All mapping of BNode objects is done in
- * {@link SimpleRDFTermFactory#createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)}.
+ * {@link SimpleRDFFactory#createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)}.
*
* @param graphName graphName of triple
* @param subject subject of triple
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFFactory.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFFactory.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFFactory.java
new file mode 100644
index 0000000..4b89603
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFFactory.java
@@ -0,0 +1,114 @@
+/**
+ * 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.simple;
+
+import java.util.UUID;
+
+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;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.Triple;
+
+/**
+ * A simple implementation of RDFFactory.
+ * <p>
+ * The {@link RDFTerm}, {@link Triple}, {@link Quad}, {@link Graph}
+ * and {@link Dataset} instances created by this factory are
+ * simple in-memory Implementations that are not thread-safe or efficient, but
+ * which may be useful for testing and prototyping purposes.
+ */
+public class SimpleRDFFactory implements RDFFactory {
+
+ /**
+ * Marker interface to say that this RDFTerm is part of the
+ * Simple implementation. Used by {@link GraphImpl} to avoid
+ * double remapping.
+ * <p>
+ * This method is package protected to avoid any third-party
+ * subclasses.
+ *
+ */
+ static interface SimpleRDFTerm extends RDFTerm {
+ }
+
+ /** Unique salt per instance, for {@link #createBlankNode(String)}
+ */
+ private final UUID SALT = UUID.randomUUID();
+
+ @Override
+ public BlankNode createBlankNode() {
+ return new BlankNodeImpl();
+ }
+
+ @Override
+ public BlankNode createBlankNode(String name) {
+ return new BlankNodeImpl(SALT, name);
+ }
+
+ @Override
+ public Graph createGraph() {
+ // Creates a GraphImpl object using this object as the factory for
+ // delegating all object creation to
+ return new GraphImpl(this);
+ }
+
+ @Override
+ public Dataset createDataset() throws UnsupportedOperationException {
+ return new DatasetImpl(this);
+ }
+
+ @Override
+ public IRI createIRI(String iri) {
+ IRI result = new IRIImpl(iri);
+ // Reuse any IRI objects already created in Types
+ return Types.get(result).orElse(result);
+ }
+
+ @Override
+ public Literal createLiteral(String literal) {
+ return new LiteralImpl(literal);
+ }
+
+ @Override
+ public Literal createLiteral(String literal, IRI dataType) {
+ return new LiteralImpl(literal, dataType);
+ }
+
+ @Override
+ public Literal createLiteral(String literal, String language) {
+ return new LiteralImpl(literal, language);
+ }
+
+ @Override
+ public Triple createTriple(BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) {
+ return new TripleImpl(subject, predicate, object);
+ }
+
+ @Override
+ public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws IllegalArgumentException {
+ return new QuadImpl(graphName, subject, predicate, object);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
deleted file mode 100644
index 4aee07a..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
+++ /dev/null
@@ -1,113 +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.simple;
-
-import java.util.UUID;
-
-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;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDFFactory;
-import org.apache.commons.rdf.api.Triple;
-
-/**
- * A simple implementation of RDFFactory.
- * <p>
- * The {@link RDFTerm} and {@link Graph} instances created by this factory are
- * simple in-memory Implementations that are not thread-safe or efficient, but
- * which may be useful for testing and prototyping purposes.
- */
-public class SimpleRDFTermFactory implements RDFFactory {
-
- /**
- * Marker interface to say that this RDFTerm is part of the
- * Simple implementation. Used by {@link GraphImpl} to avoid
- * double remapping.
- * <p>
- * This method is package protected to avoid any third-party
- * subclasses.
- *
- */
- static interface SimpleRDFTerm extends RDFTerm {
- }
-
- /** Unique salt per instance, for {@link #createBlankNode(String)}
- */
- private final UUID SALT = UUID.randomUUID();
-
- @Override
- public BlankNode createBlankNode() {
- return new BlankNodeImpl();
- }
-
- @Override
- public BlankNode createBlankNode(String name) {
- return new BlankNodeImpl(SALT, name);
- }
-
- @Override
- public Graph createGraph() {
- // Creates a GraphImpl object using this object as the factory for
- // delegating all object creation to
- return new GraphImpl(this);
- }
-
- @Override
- public Dataset createDataset() throws UnsupportedOperationException {
- return new DatasetImpl(this);
- }
-
- @Override
- public IRI createIRI(String iri) {
- IRI result = new IRIImpl(iri);
- // Reuse any IRI objects already created in Types
- return Types.get(result).orElse(result);
- }
-
- @Override
- public Literal createLiteral(String literal) {
- return new LiteralImpl(literal);
- }
-
- @Override
- public Literal createLiteral(String literal, IRI dataType) {
- return new LiteralImpl(literal, dataType);
- }
-
- @Override
- public Literal createLiteral(String literal, String language) {
- return new LiteralImpl(literal, language);
- }
-
- @Override
- public Triple createTriple(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) {
- return new TripleImpl(subject, predicate, object);
- }
-
- @Override
- public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
- throws IllegalArgumentException, UnsupportedOperationException {
- return new QuadImpl(graphName, subject, predicate, object);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
index 9da2bed..bc7f103 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
@@ -37,7 +37,7 @@ final class TripleImpl implements Triple {
* Construct Triple from its constituent parts.
* <p>
* The objects are not changed. All mapping of BNode objects is done in
- * {@link SimpleRDFTermFactory#createTriple(BlankNodeOrIRI, IRI, RDFTerm)}.
+ * {@link SimpleRDFFactory#createTriple(BlankNodeOrIRI, IRI, RDFTerm)}.
*
* @param subject subject of triple
* @param predicate predicate of triple
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
index 3e3f640..8ad6df8 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
@@ -27,7 +27,7 @@ import java.util.Set;
/**
* Types from the RDF and XML Schema vocabularies.
*/
-public final class Types implements IRI, SimpleRDFTermFactory.SimpleRDFTerm {
+public final class Types implements IRI, SimpleRDFFactory.SimpleRDFTerm {
/**
* <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML</tt>
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
index ef93136..a37a3c4 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
@@ -35,7 +35,7 @@ import org.apache.commons.rdf.api.Quad;
import org.apache.commons.rdf.api.RDFSyntax;
import org.apache.commons.rdf.api.RDFFactory;
import org.apache.commons.rdf.experimental.RDFParser;
-import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
+import org.apache.commons.rdf.simple.SimpleRDFFactory;
/**
* Abstract RDFParser
@@ -63,7 +63,7 @@ public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>>
private static final ExecutorService threadpool = Executors.newCachedThreadPool(r -> new Thread(threadGroup, r));
// Basically only used for creating IRIs
- private static RDFFactory internalRdfTermFactory = new SimpleRDFTermFactory();
+ private static RDFFactory internalRdfTermFactory = new SimpleRDFFactory();
/**
* Get the set {@link RDFFactory}, if any.
@@ -418,7 +418,7 @@ public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>>
// parseSynchronously()
AbstractRDFParser<T> c = clone();
- // Use a fresh SimpleRDFTermFactory for each parse
+ // Use a fresh SimpleRDFFactory for each parse
if (!c.rdfTermFactory.isPresent()) {
c.rdfTermFactory = Optional.of(createRDFTermFactory());
}
@@ -515,7 +515,7 @@ public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>>
* @return A new {@link RDFFactory}
*/
protected RDFFactory createRDFTermFactory() {
- return new SimpleRDFTermFactory();
+ return new SimpleRDFFactory();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java b/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java
index 626154f..5405cef 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java
@@ -28,10 +28,10 @@
* testing and simple usage (e.g. prototyping).
* <p>
* To use this implementation, create an instance of
- * {@link org.apache.commons.rdf.simple.SimpleRDFTermFactory}
+ * {@link org.apache.commons.rdf.simple.SimpleRDFFactory}
* and use methods like
- * {@link org.apache.commons.rdf.simple.SimpleRDFTermFactory#createGraph} and
- * {@link org.apache.commons.rdf.simple.SimpleRDFTermFactory#createIRI(String)}.
+ * {@link org.apache.commons.rdf.simple.SimpleRDFFactory#createGraph} and
+ * {@link org.apache.commons.rdf.simple.SimpleRDFFactory#createIRI(String)}.
* <p>
* The {@link org.apache.commons.rdf.simple.Types} class provide constant
* {@link org.apache.commons.rdf.api.IRI}s of the common RDF XML datatypes.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
----------------------------------------------------------------------
diff --git a/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
index cc53468..17d9680 100644
--- a/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
+++ b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
@@ -1 +1 @@
-org.apache.commons.rdf.simple.SimpleRDFTermFactory
\ No newline at end of file
+org.apache.commons.rdf.simple.SimpleRDFFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
index 4b100b3..ab2cf50 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
@@ -36,7 +36,7 @@ public class DefaultGraphTest extends AbstractGraphTest {
return new RDFFactory() {
@Override
public Graph createGraph() throws UnsupportedOperationException {
- return new GraphImpl(new SimpleRDFTermFactory());
+ return new GraphImpl(new SimpleRDFFactory());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
index e5de520..3872f11 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
@@ -25,13 +25,13 @@ import org.junit.Assume;
import org.junit.Test;
/**
- * Test SimpleRDFTermFactory with AbstractGraphTest
+ * Test SimpleRDFFactory with AbstractGraphTest
*/
public class SimpleGraphTest extends AbstractGraphTest {
@Override
public RDFFactory createFactory() {
- return new SimpleRDFTermFactory();
+ return new SimpleRDFFactory();
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
index 5c35de6..752c465 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
@@ -33,7 +33,7 @@ public class SimpleNoRelativeIRIRDFTermFactoryTest extends
AbstractRDFTermFactoryTest {
@Override
public RDFFactory createFactory() {
- return new SimpleRDFTermFactory() {
+ return new SimpleRDFFactory() {
@Override
public IRI createIRI(String iri) {
if (!URI.create(iri).isAbsolute()) {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryLookupTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryLookupTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryLookupTest.java
index 96f64ca..179b7ef 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryLookupTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryLookupTest.java
@@ -36,7 +36,7 @@ public class SimpleRDFTermFactoryLookupTest {
Iterator<RDFFactory> iterator = loader.iterator();
RDFFactory factory = iterator.next();
- assertTrue(factory instanceof SimpleRDFTermFactory);
+ assertTrue(factory instanceof SimpleRDFFactory);
assertFalse(iterator.hasNext());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
index 0cfabb4..bd3b5ad 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
@@ -27,7 +27,7 @@ public class SimpleRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
@Override
public RDFFactory createFactory() {
- return new SimpleRDFTermFactory();
+ return new SimpleRDFFactory();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
index 1ed2e8f..57ee24a 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
@@ -57,7 +57,7 @@ public class TestWritingGraph {
@BeforeClass
public static void createGraph() throws Exception {
- factory = new SimpleRDFTermFactory();
+ factory = new SimpleRDFFactory();
graph = factory.createGraph();
IRI subject = factory.createIRI("subj");
IRI predicate = factory.createIRI("pred");
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/08fbb929/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
index f003c09..ee26a2c 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
@@ -38,7 +38,7 @@ import org.apache.commons.rdf.api.RDFFactory;
import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.experimental.RDFParser;
import org.apache.commons.rdf.simple.DummyRDFParserBuilder;
-import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
+import org.apache.commons.rdf.simple.SimpleRDFFactory;
import org.apache.commons.rdf.simple.Types;
import org.junit.After;
import org.junit.Before;
@@ -48,7 +48,7 @@ import org.junit.rules.ExpectedException;
public class AbstractRDFParserTest {
- private RDFFactory factory = new SimpleRDFTermFactory();
+ private RDFFactory factory = new SimpleRDFFactory();
private DummyRDFParserBuilder dummyParser = new DummyRDFParserBuilder();
private Path testNt;
[03/50] [abbrv] incubator-commonsrdf git commit: Updated
META-INF/services
Posted by st...@apache.org.
Updated META-INF/services
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/2c62adad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/2c62adad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/2c62adad
Branch: refs/heads/COMMONSRDF-7
Commit: 2c62adad2f6e5a055e208345c0aa7f42ba8ebcc6
Parents: 374bb0f
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 19 17:48:19 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 19 17:48:19 2016 +0100
----------------------------------------------------------------------
.../META-INF/services/org.apache.commons.rdf.api.RDFFactory | 1 +
.../META-INF/services/org.apache.commons.rdf.api.RDFTermFactory | 1 -
.../META-INF/services/org.apache.commons.rdf.api.RDFFactory | 1 +
.../META-INF/services/org.apache.commons.rdf.api.RDFTermFactory | 1 -
.../META-INF/services/org.apache.commons.rdf.api.RDFFactory | 1 +
.../META-INF/services/org.apache.commons.rdf.api.RDFFactory | 2 +-
.../META-INF/services/org.apache.commons.rdf.api.RDFTermFactory | 2 +-
7 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2c62adad/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
----------------------------------------------------------------------
diff --git a/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory b/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
new file mode 100644
index 0000000..f39e71d
--- /dev/null
+++ b/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
@@ -0,0 +1 @@
+org.apache.commons.rdf.jena.JenaFactory
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2c62adad/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
----------------------------------------------------------------------
diff --git a/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory b/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
deleted file mode 100644
index 50e08bb..0000000
--- a/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.commons.rdf.jena.RDFTermFactoryJena
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2c62adad/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory b/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
new file mode 100644
index 0000000..ecb7535
--- /dev/null
+++ b/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
@@ -0,0 +1 @@
+org.apache.commons.rdf.jsonldjava.JsonLdFactory
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2c62adad/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory b/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
deleted file mode 100644
index 9bf95f8..0000000
--- a/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.commons.rdf.jsonldjava.JsonLdFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2c62adad/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory b/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
new file mode 100644
index 0000000..bfcdc12
--- /dev/null
+++ b/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
@@ -0,0 +1 @@
+org.apache.commons.rdf.rdf4j.RDF4JFactory
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2c62adad/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
----------------------------------------------------------------------
diff --git a/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
index 17d9680..67557cf 100644
--- a/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
+++ b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
@@ -1 +1 @@
-org.apache.commons.rdf.simple.SimpleRDFFactory
\ No newline at end of file
+org.apache.commons.rdf.simple.SimpleRDFFactory
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2c62adad/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
----------------------------------------------------------------------
diff --git a/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
index cc53468..5a56ae6 100644
--- a/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
+++ b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
@@ -1 +1 @@
-org.apache.commons.rdf.simple.SimpleRDFTermFactory
\ No newline at end of file
+org.apache.commons.rdf.simple.SimpleRDFTermFactory
[07/50] [abbrv] incubator-commonsrdf git commit: RDFFactory -> RDF
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
index ee26a2c..732df71 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
@@ -34,7 +34,7 @@ import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.Literal;
import org.apache.commons.rdf.api.RDFSyntax;
import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.experimental.RDFParser;
import org.apache.commons.rdf.simple.DummyRDFParserBuilder;
@@ -48,7 +48,7 @@ import org.junit.rules.ExpectedException;
public class AbstractRDFParserTest {
- private RDFFactory factory = new SimpleRDFFactory();
+ private RDF factory = new SimpleRDFFactory();
private DummyRDFParserBuilder dummyParser = new DummyRDFParserBuilder();
private Path testNt;
[34/50] [abbrv] incubator-commonsrdf git commit: RDFDTerm is
IRI/BlankNode/Literal. BlankNodeOrIRI is BlankNode/Literal
Posted by st...@apache.org.
RDFDTerm is IRI/BlankNode/Literal. BlankNodeOrIRI is BlankNode/Literal
Using "SHOULD" to leave open possibility of say a JenaSparqlVariable.
See
https://github.com/apache/incubator-commonsrdf/pull/25#discussion_r85433083
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/fb0dd9c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/fb0dd9c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/fb0dd9c0
Branch: refs/heads/COMMONSRDF-7
Commit: fb0dd9c03ebba0da8cef75c1ee21343c9a1fdd81
Parents: d0501ac
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 28 11:27:45 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 28 11:27:45 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/api/BlankNodeOrIRI.java | 6 ++++--
.../main/java/org/apache/commons/rdf/api/RDFTerm.java | 11 +++++++----
2 files changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fb0dd9c0/api/src/main/java/org/apache/commons/rdf/api/BlankNodeOrIRI.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/BlankNodeOrIRI.java b/api/src/main/java/org/apache/commons/rdf/api/BlankNodeOrIRI.java
index 8999c6f..1c6c469 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/BlankNodeOrIRI.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/BlankNodeOrIRI.java
@@ -19,8 +19,10 @@ package org.apache.commons.rdf.api;
/**
* This interface represents the {@link RDFTerm}s that may be used in the
- * subject position of an RDF-1.1 {@link Triple}, that is {@link BlankNode}
- * and {@link IRI}.
+ * subject position of an RDF-1.1 {@link Triple} as well as the graph name
+ * position of a {@link Quad}.
+ * <p>
+ * Instances of BlankNodeOrIRI SHOULD be a {@link BlankNode} or an {@link IRI}.
*/
public interface BlankNodeOrIRI extends RDFTerm {
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fb0dd9c0/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
index 9488338..59d8fa1 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
@@ -19,12 +19,15 @@ package org.apache.commons.rdf.api;
/**
* An <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-term" >RDF-1.1
- * Term</a>, as defined by <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.<br>
+ * Term</a>, as defined by
+ * <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.<br>
+ * <p>
+ * Instances of RDFTerm SHOULD be an {@link IRI}, {@link BlankNode} or
+ * {@link Literal}.
*
* @see <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-term" >RDF-1.1
- * Term</a>
+ * Term</a>
*/
public interface RDFTerm {
[13/50] [abbrv] incubator-commonsrdf git commit: Rephrase RDF to
avoid "factory" speak
Posted by st...@apache.org.
Rephrase RDF to avoid "factory" speak
..just "RDF" is more difficult in text than the obvious
Java class name "RDFFactory", hence more <code> typigraphy
and "RDF implementation" phrases is needed.
The good thing is that now we can think of instances of "RDF"
as directly representing the implementation, e.g. "Jena".
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/a1112a8f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/a1112a8f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/a1112a8f
Branch: refs/heads/COMMONSRDF-7
Commit: a1112a8f1a8d2c48b344af0d8ee3fa62784fe875
Parents: 430bc4d
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Oct 23 00:47:40 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Oct 23 00:47:40 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/api/RDF.java | 27 ++++++++++++++------
1 file changed, 19 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/a1112a8f/api/src/main/java/org/apache/commons/rdf/api/RDF.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDF.java b/api/src/main/java/org/apache/commons/rdf/api/RDF.java
index 4314568..bd405d0 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDF.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDF.java
@@ -21,16 +21,27 @@ import java.io.Serializable;
import java.util.Locale;
/**
- * Factory for creating RDFTerm and Graph instances.
+ * A RDF implementation.
* <p>
- * If an implementation does not support a particular method (e.g. it requires
- * additional parameters or can't create graphs), then it MAY throw
- * {@link UnsupportedOperationException}, as provided by the <code>default</code>
- * implementations in this interface.
+ * A <code>RDF</code> implementation can create instances of
+ * the {@link RDFTerm} types
+ * {@link IRI}, {@link BlankNode} and {@link Literal}, as well as creating
+ * instances of the types {@link Triple}, {@link Quad}, {@link Graph} or
+ * {@link Dataset}.
* <p>
- * If a factory method does not allow or support a provided parameter, e.g.
- * because an IRI is considered invalid, then it SHOULD throw
- * {@link IllegalArgumentException}.
+ * A <em>partial RDF implementation</em>
+ * should be clearly documented as such, and may throw
+ * {@link UnsupportedOperationException} where applicable, e.g. if it
+ * does not support creating {@link Dataset}s or {@link Quad}s.
+ * <p>
+ * Instances of <code>RDF</code> work like a factory for
+ * creating Commons RDF instances.
+ * spezializations of this interface may also provide methods
+ * for conversions from/to their underlying RDF framework.
+ * <p>
+ * If a factory method of a particular implementation does not allow or support
+ * a provided parameter, e.g. because an IRI is considered invalid, then it
+ * SHOULD throw {@link IllegalArgumentException}.
*
* @since 0.3.0-incubating
* @see RDFTerm
[33/50] [abbrv] incubator-commonsrdf git commit: Use @Ignore rather
than Assume
Posted by st...@apache.org.
Use @Ignore rather than Assume
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/d0501ac0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/d0501ac0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/d0501ac0
Branch: refs/heads/COMMONSRDF-7
Commit: d0501ac0b99a060d8dc11d5a1d9206e4dceec82e
Parents: de6842f
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 28 11:21:21 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 28 11:21:21 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d0501ac0/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java
index 14099e8..99c0771 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java
@@ -19,7 +19,6 @@ package org.apache.commons.rdf.jsonldjava;
import org.apache.commons.rdf.api.AbstractRDFTest;
import org.apache.commons.rdf.api.RDF;
-import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Test;
@@ -31,22 +30,21 @@ public class JsonLdRDFTest extends AbstractRDFTest {
}
// TODO: Add support for checking for invalid lang/iri/blanknode IDs
-
+ @Ignore("JSONLD-Java does not validate lang strings")
@Test
@Override
public void testInvalidLiteralLang() throws Exception {
- Assume.assumeFalse("JSONLD-Java does not validate lang strings", false);
super.testInvalidLiteralLang();
}
+ @Ignore("JSONLD-Java does not validate IRIs")
@Test
@Override
public void testInvalidIRI() throws Exception {
- Assume.assumeFalse("JSONLD-Java does not validate IRIs", false);
super.testInvalidIRI();
}
- @Ignore
+ @Ignore("JSONLD-Java does not validate blanknode identifiers")
@Test
@Override
public void testPossiblyInvalidBlankNode() throws Exception {
[16/50] [abbrv] incubator-commonsrdf git commit: avoid
UnsupportedOperationException
Posted by st...@apache.org.
avoid UnsupportedOperationException
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/3ed42722
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/3ed42722
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/3ed42722
Branch: refs/heads/COMMONSRDF-7
Commit: 3ed4272245535ed2fdb4b29ca074964734ea24ce
Parents: 417963f
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Oct 23 01:32:24 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Oct 23 01:32:24 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/api/RDF.java | 74 +++++---------------
.../rdf/api/DefaultRDFTermFactoryTest.java | 33 ---------
.../commons/rdf/rdf4j/NativeStoreGraphTest.java | 14 ++++
.../commons/rdf/simple/DefaultGraphTest.java | 51 --------------
4 files changed, 30 insertions(+), 142 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/3ed42722/api/src/main/java/org/apache/commons/rdf/api/RDF.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDF.java b/api/src/main/java/org/apache/commons/rdf/api/RDF.java
index bd405d0..0565ba4 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDF.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDF.java
@@ -60,10 +60,7 @@ public interface RDF {
* @throws UnsupportedOperationException
* If the operation is not supported.
*/
- default BlankNode createBlankNode() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createBlankNode() not supported");
- }
+ public BlankNode createBlankNode();
/**
* Create a blank node based on the given name.
@@ -87,14 +84,8 @@ public interface RDF {
* A non-empty, non-null, String that is unique to this blank
* node in the context of this {@link RDF}.
* @return A BlankNode for the given name
- * @throws UnsupportedOperationException
- * If the operation is not supported.
*/
- default BlankNode createBlankNode(String name)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createBlankNode(String) not supported");
- }
+ public BlankNode createBlankNode(String name);
/**
* Create a new graph.
@@ -103,11 +94,8 @@ public interface RDF {
* mechanism.
*
* @return A new Graph
- * @throws UnsupportedOperationException If the operation is not supported.
*/
- default Graph createGraph() throws UnsupportedOperationException {
- throw new UnsupportedOperationException("createGraph() not supported");
- }
+ public Graph createGraph();
/**
* Create a new dataset.
@@ -116,11 +104,8 @@ public interface RDF {
* mechanism.
*
* @return A new Dataset
- * @throws UnsupportedOperationException If the operation is not supported.
*/
- default Dataset createDataset() throws UnsupportedOperationException {
- throw new UnsupportedOperationException("createDataset() not supported");
- }
+ public Dataset createDataset();
/**
* Create an IRI from a (possibly escaped) String.
@@ -133,13 +118,8 @@ public interface RDF {
* @return A new IRI
* @throws IllegalArgumentException If the provided string is not acceptable, e.g. does not
* conform to the RFC3987 syntax.
- * @throws UnsupportedOperationException If the operation is not supported.
*/
- default IRI createIRI(String iri) throws IllegalArgumentException,
- UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createIRI(String) not supported");
- }
+ public IRI createIRI(String iri) throws IllegalArgumentException;
/**
* Create a simple literal.
@@ -157,13 +137,9 @@ public interface RDF {
* @return The created Literal
* @throws IllegalArgumentException If the provided lexicalForm is not acceptable, e.g. because
* it is too large for an underlying storage.
- * @throws UnsupportedOperationException If the operation is not supported.
*/
- default Literal createLiteral(String lexicalForm)
- throws IllegalArgumentException, UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createLiteral(String) not supported");
- }
+ public Literal createLiteral(String lexicalForm)
+ throws IllegalArgumentException;
/**
* Create a literal with the specified data type.
@@ -191,13 +167,9 @@ public interface RDF {
* @return The created Literal
* @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
* because the provided dataType is not permitted.
- * @throws UnsupportedOperationException If the operation is not supported.
*/
- default Literal createLiteral(String lexicalForm, IRI dataType)
- throws IllegalArgumentException, UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createLiteral(String) not supported");
- }
+ public Literal createLiteral(String lexicalForm, IRI dataType)
+ throws IllegalArgumentException;
/**
* Create a language-tagged literal.
@@ -226,13 +198,9 @@ public interface RDF {
* @return The created Literal
* @throws IllegalArgumentException If the provided values are not acceptable, e.g. because the
* languageTag was syntactically invalid.
- * @throws UnsupportedOperationException If the operation is not supported.
*/
- default Literal createLiteral(String lexicalForm, String languageTag)
- throws IllegalArgumentException, UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createLiteral(String,String) not supported");
- }
+ public Literal createLiteral(String lexicalForm, String languageTag)
+ throws IllegalArgumentException;
/**
* Create a triple.
@@ -249,14 +217,9 @@ public interface RDF {
* @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
* because a Literal has a lexicalForm that is too large for an
* underlying storage.
- * @throws UnsupportedOperationException If the operation is not supported.
*/
- default Triple createTriple(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) throws IllegalArgumentException,
- UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createTriple(BlankNodeOrIRI,IRI,RDFTerm) not supported");
- }
+ public Triple createTriple(BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) throws IllegalArgumentException;
/**
* Create a quad.
@@ -268,7 +231,7 @@ public interface RDF {
* equal to the provided predicate, and a {@link Quad#getObject()} that is
* equal to the provided object.
*
- * @param graphName The IRI or BlankNode that this quad belongs to, or <code>null</code> for the default graph
+ * @param graphName The IRI or BlankNode that this quad belongs to, or <code>null</code> for the public graph
* @param subject The IRI or BlankNode that is the subject of the quad
* @param predicate The IRI that is the predicate of the quad
* @param object The IRI, BlankNode or Literal that is the object of the quad
@@ -276,13 +239,8 @@ public interface RDF {
* @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
* because a Literal has a lexicalForm that is too large for an
* underlying storage.
- * @throws UnsupportedOperationException If the operation is not supported.
*/
- default Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) throws IllegalArgumentException,
- UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createQuad(BlankNodeOrIRI,BlankNodeOrIRI,IRI,RDFTerm) not supported");
- }
+ public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) throws IllegalArgumentException;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/3ed42722/api/src/test/java/org/apache/commons/rdf/api/DefaultRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DefaultRDFTermFactoryTest.java b/api/src/test/java/org/apache/commons/rdf/api/DefaultRDFTermFactoryTest.java
deleted file mode 100644
index a800191..0000000
--- a/api/src/test/java/org/apache/commons/rdf/api/DefaultRDFTermFactoryTest.java
+++ /dev/null
@@ -1,33 +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;
-
-/**
- * The default RDF might be useless (every method throws
- * UnsupportedOperationException), but this test ensures that
- * AbstractRDFTermFactoryTest does not fall over on unsupported operations.
- */
-public class DefaultRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
-
- @Override
- public RDF createFactory() {
- return new RDF() {
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/3ed42722/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
index bedea22..e5a9772 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
@@ -24,8 +24,10 @@ import java.util.Set;
import org.apache.commons.rdf.api.AbstractGraphTest;
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.api.RDF;
import org.eclipse.rdf4j.repository.RepositoryConnection;
@@ -59,7 +61,14 @@ public class NativeStoreGraphTest extends AbstractGraphTest {
Set<RDF4JBlankNode> context = Collections.singleton(rdf4jFactory.createBlankNode());
return rdf4jFactory.asRDFTermGraph(getRepository(), context);
}
+ @Override
+ public Dataset createDataset() {
+ throw new UnsupportedOperationException("Can't create more than one Dataset in this test");
+ // ...as the below would re-use the same repository:
+ //return rdf4jFactory.asRDFTermDataset(getRepository());
+ }
+
// Delegate methods
public RDF4JBlankNode createBlankNode() {
return rdf4jFactory.createBlankNode();
@@ -82,6 +91,11 @@ public class NativeStoreGraphTest extends AbstractGraphTest {
public RDF4JTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
return rdf4jFactory.createTriple(subject, predicate, object);
}
+ @Override
+ public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws IllegalArgumentException {
+ return rdf4jFactory.createQuad(graphName, subject, predicate, object);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/3ed42722/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
deleted file mode 100644
index 3d3aad1..0000000
--- a/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
+++ /dev/null
@@ -1,51 +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.simple;
-
-import org.apache.commons.rdf.api.AbstractGraphTest;
-import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.RDF;
-
-/**
- * Ensure AbstractGraphTest does not crash if the RDF throws
- * UnsupportedOperationException
- */
-
-public class DefaultGraphTest extends AbstractGraphTest {
-
- @Override
- public RDF createFactory() {
- // The most minimal RDF that would still
- // make sense with a Graph
- return new RDF() {
- @Override
- public Graph createGraph() throws UnsupportedOperationException {
- return new GraphImpl(new SimpleRDF());
- }
-
- @Override
- public IRI createIRI(String iri)
- throws UnsupportedOperationException,
- IllegalArgumentException {
- return new IRIImpl(iri);
- }
- };
- }
-
-}
[02/50] [abbrv] incubator-commonsrdf git commit: Deprecated
SimpleRDFTermFactory
Posted by st...@apache.org.
Deprecated SimpleRDFTermFactory
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/374bb0f8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/374bb0f8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/374bb0f8
Branch: refs/heads/COMMONSRDF-7
Commit: 374bb0f84a60bcaab5813d49bc7427f7441e5c7d
Parents: 08fbb92
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 19 17:43:19 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 19 17:43:19 2016 +0100
----------------------------------------------------------------------
.../rdf/simple/SimpleRDFTermFactory.java | 70 ++++++++++++++++++++
.../org.apache.commons.rdf.api.RDFFactory | 1 +
.../org.apache.commons.rdf.api.RDFTermFactory | 2 +-
3 files changed, 72 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/374bb0f8/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
new file mode 100644
index 0000000..5f6f5fe
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
@@ -0,0 +1,70 @@
+/**
+ * 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.simple;
+
+import org.apache.commons.rdf.api.BlankNode;
+import org.apache.commons.rdf.api.BlankNodeOrIRI;
+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.RDFTerm;
+import org.apache.commons.rdf.api.RDFTermFactory;
+import org.apache.commons.rdf.api.Triple;
+
+/**
+ * A Simple implementation of {@link RDFTermFactory}
+ * <p>
+ * This class is <strong>deprecated</strong>, use instead {@link SimpleRDFFactory}.
+ */
+@Deprecated
+public class SimpleRDFTermFactory implements RDFTermFactory {
+
+ private SimpleRDFFactory factory = new SimpleRDFFactory();
+
+ public BlankNode createBlankNode() {
+ return factory.createBlankNode();
+ }
+
+ public BlankNode createBlankNode(String name) {
+ return factory.createBlankNode(name);
+ }
+
+ public Graph createGraph() {
+ return factory.createGraph();
+ }
+
+ public IRI createIRI(String iri) {
+ return factory.createIRI(iri);
+ }
+
+ public Literal createLiteral(String literal) {
+ return factory.createLiteral(literal);
+ }
+
+ public Literal createLiteral(String literal, IRI dataType) {
+ return factory.createLiteral(literal, dataType);
+ }
+
+ public Literal createLiteral(String literal, String language) {
+ return factory.createLiteral(literal, language);
+ }
+
+ public Triple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return factory.createTriple(subject, predicate, object);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/374bb0f8/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
----------------------------------------------------------------------
diff --git a/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
new file mode 100644
index 0000000..17d9680
--- /dev/null
+++ b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
@@ -0,0 +1 @@
+org.apache.commons.rdf.simple.SimpleRDFFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/374bb0f8/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
----------------------------------------------------------------------
diff --git a/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
index 17d9680..cc53468 100644
--- a/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
+++ b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFTermFactory
@@ -1 +1 @@
-org.apache.commons.rdf.simple.SimpleRDFFactory
\ No newline at end of file
+org.apache.commons.rdf.simple.SimpleRDFTermFactory
\ No newline at end of file
[47/50] [abbrv] incubator-commonsrdf git commit: Reformat tab ->
spaces
Posted by st...@apache.org.
Reformat tab -> spaces
Using Eclipse Neon profile customized to 4 spaces indent
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/413dd09a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/413dd09a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/413dd09a
Branch: refs/heads/COMMONSRDF-7
Commit: 413dd09a6746a4d6acde9e293b399c735cf7b935
Parents: f1ea9cd
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 28 11:41:50 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 28 11:41:50 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/BlankNode.java | 50 +-
.../org/apache/commons/rdf/api/Dataset.java | 585 ++++----
.../java/org/apache/commons/rdf/api/Graph.java | 141 +-
.../org/apache/commons/rdf/api/GraphLike.java | 100 +-
.../java/org/apache/commons/rdf/api/IRI.java | 20 +-
.../org/apache/commons/rdf/api/Literal.java | 80 +-
.../java/org/apache/commons/rdf/api/Quad.java | 322 ++---
.../org/apache/commons/rdf/api/QuadLike.java | 34 +-
.../java/org/apache/commons/rdf/api/RDF.java | 182 +--
.../org/apache/commons/rdf/api/RDFSyntax.java | 315 ++--
.../org/apache/commons/rdf/api/RDFTerm.java | 5 +-
.../apache/commons/rdf/api/RDFTermFactory.java | 39 +-
.../java/org/apache/commons/rdf/api/Triple.java | 31 +-
.../org/apache/commons/rdf/api/TripleLike.java | 45 +-
.../apache/commons/rdf/api/package-info.java | 26 +-
.../commons/rdf/experimental/RDFParser.java | 814 ++++++-----
.../commons/rdf/api/AbstractBlankNodeTest.java | 84 +-
.../commons/rdf/api/AbstractGraphTest.java | 245 ++--
.../apache/commons/rdf/api/AbstractRDFTest.java | 95 +-
.../apache/commons/rdf/api/RDFSyntaxTest.java | 172 +--
examples/src/example/UserGuideTest.java | 403 +++---
.../rdf/integrationtests/AllToAllTest.java | 253 ++--
.../commons/rdf/jena/ConversionException.java | 26 +-
.../apache/commons/rdf/jena/JenaDataset.java | 45 +-
.../rdf/jena/JenaGeneralizedTripleLike.java | 3 +-
.../org/apache/commons/rdf/jena/JenaGraph.java | 45 +-
.../org/apache/commons/rdf/jena/JenaIRI.java | 2 +-
.../org/apache/commons/rdf/jena/JenaQuad.java | 9 +-
.../apache/commons/rdf/jena/JenaQuadLike.java | 15 +-
.../org/apache/commons/rdf/jena/JenaRDF.java | 1353 +++++++++---------
.../apache/commons/rdf/jena/JenaRDFTerm.java | 2 +-
.../org/apache/commons/rdf/jena/JenaTriple.java | 6 +-
.../apache/commons/rdf/jena/JenaTripleLike.java | 15 +-
.../rdf/jena/experimental/JenaRDFParser.java | 114 +-
.../rdf/jena/experimental/package-info.java | 8 +-
.../rdf/jena/impl/AbstractJenaRDFTerm.java | 32 +-
.../commons/rdf/jena/impl/AbstractQuadLike.java | 191 ++-
.../rdf/jena/impl/InternalJenaFactory.java | 202 +--
.../rdf/jena/impl/JenaBlankNodeImpl.java | 62 +-
.../commons/rdf/jena/impl/JenaDatasetImpl.java | 275 ++--
.../jena/impl/JenaGeneralizedQuadLikeImpl.java | 15 +-
.../impl/JenaGeneralizedTripleLikeImpl.java | 14 +-
.../commons/rdf/jena/impl/JenaGraphImpl.java | 225 ++-
.../commons/rdf/jena/impl/JenaIRIImpl.java | 66 +-
.../commons/rdf/jena/impl/JenaLiteralImpl.java | 79 +-
.../commons/rdf/jena/impl/JenaQuadImpl.java | 58 +-
.../commons/rdf/jena/impl/JenaTripleImpl.java | 66 +-
.../apache/commons/rdf/jena/JenaRDFTest.java | 3 +-
.../commons/rdf/jena/JenaServiceLoaderTest.java | 8 +-
.../commons/rdf/jena/TestBlankNodeJena.java | 16 +-
.../apache/commons/rdf/jena/TestGraphJena.java | 1 -
.../jena/TestJenaGraphToCommonsRDFGraph.java | 105 +-
.../commons/rdf/jena/TestRDFParserBuilder.java | 48 +-
.../commons/rdf/jsonldjava/JsonLdBlankNode.java | 75 +-
.../commons/rdf/jsonldjava/JsonLdDataset.java | 143 +-
.../commons/rdf/jsonldjava/JsonLdGraph.java | 150 +-
.../commons/rdf/jsonldjava/JsonLdGraphLike.java | 341 +++--
.../commons/rdf/jsonldjava/JsonLdIRI.java | 74 +-
.../commons/rdf/jsonldjava/JsonLdLiteral.java | 139 +-
.../commons/rdf/jsonldjava/JsonLdQuad.java | 53 +-
.../commons/rdf/jsonldjava/JsonLdQuadLike.java | 90 +-
.../commons/rdf/jsonldjava/JsonLdRDF.java | 494 +++----
.../commons/rdf/jsonldjava/JsonLdTerm.java | 36 +-
.../commons/rdf/jsonldjava/JsonLdTriple.java | 45 +-
.../rdf/jsonldjava/JsonLdTripleLike.java | 13 +-
.../rdf/jsonldjava/JsonLdUnionGraph.java | 147 +-
.../jsonldjava/experimental/JsonLdParser.java | 218 +--
.../jsonldjava/experimental/package-info.java | 11 +-
jsonld-java/src/main/resources/test.jsonld | 8 +-
.../rdf/jsonldjava/JsonLdBlankNodeTest.java | 22 +-
.../commons/rdf/jsonldjava/JsonLdGraphTest.java | 9 +-
.../rdf/jsonldjava/JsonLdParserBuilderTest.java | 150 +-
.../commons/rdf/jsonldjava/JsonLdRDFTest.java | 54 +-
.../rdf/jsonldjava/JsonLdServiceLoaderTest.java | 10 +-
.../commons/rdf/rdf4j/ClosableIterable.java | 9 +-
.../org/apache/commons/rdf/rdf4j/RDF4J.java | 995 +++++++------
.../commons/rdf/rdf4j/RDF4JBlankNode.java | 18 +-
.../commons/rdf/rdf4j/RDF4JBlankNodeOrIRI.java | 6 +-
.../apache/commons/rdf/rdf4j/RDF4JDataset.java | 190 +--
.../apache/commons/rdf/rdf4j/RDF4JGraph.java | 209 +--
.../commons/rdf/rdf4j/RDF4JGraphLike.java | 47 +-
.../org/apache/commons/rdf/rdf4j/RDF4JIRI.java | 19 +-
.../org/apache/commons/rdf/rdf4j/RDF4JQuad.java | 6 +-
.../org/apache/commons/rdf/rdf4j/RDF4JTerm.java | 17 +-
.../apache/commons/rdf/rdf4j/RDF4JTriple.java | 5 +-
.../commons/rdf/rdf4j/RDF4JTripleLike.java | 19 +-
.../rdf/rdf4j/experimental/RDF4JParser.java | 342 ++---
.../rdf/rdf4j/experimental/package-info.java | 8 +-
.../commons/rdf/rdf4j/impl/AbstractRDFTerm.java | 16 +-
.../rdf4j/impl/AbstractRepositoryGraphLike.java | 75 +-
.../commons/rdf/rdf4j/impl/BlankNodeImpl.java | 121 +-
.../rdf/rdf4j/impl/ConvertedStatements.java | 66 +-
.../apache/commons/rdf/rdf4j/impl/IRIImpl.java | 81 +-
.../rdf/rdf4j/impl/InternalRDF4JFactory.java | 236 +--
.../commons/rdf/rdf4j/impl/LiteralImpl.java | 102 +-
.../commons/rdf/rdf4j/impl/ModelGraphImpl.java | 228 ++-
.../apache/commons/rdf/rdf4j/impl/QuadImpl.java | 129 +-
.../rdf/rdf4j/impl/RepositoryDatasetImpl.java | 361 ++---
.../rdf/rdf4j/impl/RepositoryGraphImpl.java | 297 ++--
.../commons/rdf/rdf4j/impl/TripleImpl.java | 95 +-
.../apache/commons/rdf/rdf4j/package-info.java | 36 +-
.../apache/commons/rdf/rdf4j/BlankNodeTest.java | 20 +-
.../org/apache/commons/rdf/rdf4j/GraphTest.java | 10 +-
.../commons/rdf/rdf4j/MemoryGraphTest.java | 104 +-
.../commons/rdf/rdf4j/MemoryStoreRDFTest.java | 22 +-
.../commons/rdf/rdf4j/NativeStoreGraphTest.java | 236 +--
.../rdf/rdf4j/RDF4JServiceLoaderTest.java | 8 +-
.../org/apache/commons/rdf/rdf4j/RDF4JTest.java | 22 +-
.../commons/rdf/simple/BlankNodeImpl.java | 4 +-
.../commons/rdf/simple/DatasetGraphView.java | 175 +--
.../apache/commons/rdf/simple/DatasetImpl.java | 127 +-
.../apache/commons/rdf/simple/GraphImpl.java | 47 +-
.../apache/commons/rdf/simple/LiteralImpl.java | 15 +-
.../org/apache/commons/rdf/simple/QuadImpl.java | 41 +-
.../apache/commons/rdf/simple/SimpleRDF.java | 46 +-
.../rdf/simple/SimpleRDFTermFactory.java | 50 +-
.../apache/commons/rdf/simple/TripleImpl.java | 15 +-
.../org/apache/commons/rdf/simple/Types.java | 128 +-
.../simple/experimental/AbstractRDFParser.java | 1007 ++++++-------
.../simple/experimental/RDFParseException.java | 52 +-
.../apache/commons/rdf/simple/package-info.java | 16 +-
.../rdf/simple/DummyRDFParserBuilder.java | 101 +-
.../commons/rdf/simple/SimpleGraphTest.java | 11 +-
.../rdf/simple/SimpleNoRelativeIRIRDTest.java | 7 +-
.../rdf/simple/SimpleServiceLoaderTest.java | 8 +-
.../commons/rdf/simple/TestWritingGraph.java | 31 +-
.../apache/commons/rdf/simple/TypesTest.java | 25 +-
.../experimental/AbstractRDFParserTest.java | 402 +++---
128 files changed, 7835 insertions(+), 8060 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java b/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
index f8e6e05..73f8afe 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
@@ -21,25 +21,26 @@ import java.util.UUID;
/**
* A <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node" >RDF-1.1
- * Blank Node</a>, as defined by <a href=
- * "http://www.w3.org/TR/rdf11-concepts/#section-blank-nodes" >RDF-1.1 Concepts
- * and Abstract Syntax</a>, a W3C Recommendation published on 25 February 2014.<br>
+ * Blank Node</a>, as defined by
+ * <a href= "http://www.w3.org/TR/rdf11-concepts/#section-blank-nodes" >RDF-1.1
+ * Concepts and Abstract Syntax</a>, a W3C Recommendation published on 25
+ * February 2014.<br>
*
- * Note: <blockquote> <a
- * href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node">Blank nodes</a>
+ * Note: <blockquote>
+ * <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node">Blank nodes</a>
* are disjoint from IRIs and literals. Otherwise, the set of possible blank
* nodes is arbitrary. RDF makes no reference to any internal structure of blank
* nodes. </blockquote>
*
- * Also note that: <blockquote> <a
- * href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier">Blank
- * node identifiers</a> are local identifiers that are used in some concrete RDF
- * syntaxes or RDF store implementations. They are always
- * <em>locally scoped</em> to the file or RDF store, and are <em>not</em>
- * persistent or portable identifiers for blank nodes. Blank node identifiers
- * are <em>not</em> part of the RDF abstract syntax, but are entirely dependent
- * on the concrete syntax or implementation. The syntactic restrictions on blank
- * node identifiers, if any, therefore also depend on the concrete RDF syntax or
+ * Also note that: <blockquote> <a href=
+ * "http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier">Blank node
+ * identifiers</a> are local identifiers that are used in some concrete RDF
+ * syntaxes or RDF store implementations. They are always <em>locally
+ * scoped</em> to the file or RDF store, and are <em>not</em> persistent or
+ * portable identifiers for blank nodes. Blank node identifiers are <em>not</em>
+ * part of the RDF abstract syntax, but are entirely dependent on the concrete
+ * syntax or implementation. The syntactic restrictions on blank node
+ * identifiers, if any, therefore also depend on the concrete RDF syntax or
* implementation.
*
* Implementations that handle blank node identifiers in concrete syntaxes need
@@ -53,7 +54,7 @@ import java.util.UUID;
* @see RDF#createBlankNode()
* @see RDF#createBlankNode(String)
* @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node">RDF-1.1
- * Blank Node</a>
+ * Blank Node</a>
*/
public interface BlankNode extends BlankNodeOrIRI {
@@ -62,8 +63,8 @@ public interface BlankNode extends BlankNodeOrIRI {
* <p>
* The reference string MUST universally and uniquely identify this blank
* node. That is, different blank nodes created separately in different JVMs
- * or from different {@link RDF} instances MUST NOT have the same
- * reference string.
+ * or from different {@link RDF} instances MUST NOT have the same reference
+ * string.
* <p>
* The {@link #uniqueReference()} of two <code>BlankNode</code> instances
* MUST be equal if and only if the two blank nodes are equal according to
@@ -73,8 +74,8 @@ public interface BlankNode extends BlankNodeOrIRI {
* string, however it is recommended that the reference string contain a
* UUID-derived string, e.g. as returned from {@link UUID#toString()}.
* <p>
- * <strong>IMPORTANT:</strong> This is not a <a
- * href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier">
+ * <strong>IMPORTANT:</strong> This is not a
+ * <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node-identifier">
* blank node identifier</a> nor a serialization/syntax label, and there are
* no guarantees that it is a valid identifier in any concrete RDF syntax.
* For an N-Triples compatible identifier, use {@link #ntriplesString()}.
@@ -91,8 +92,10 @@ public interface BlankNode extends BlankNodeOrIRI {
* Implementations MUST also override {@link #hashCode()} so that two equal
* Literals produce the same hash code.
*
- * @param other Another object
- * @return true if other is a BlankNode instance that represent the same blank node
+ * @param other
+ * Another object
+ * @return true if other is a BlankNode instance that represent the same
+ * blank node
* @see Object#equals(Object)
*/
@Override
@@ -101,9 +104,8 @@ public interface BlankNode extends BlankNodeOrIRI {
/**
* Calculate a hash code for this BlankNode.
* <p>
- * The returned hash code MUST be equal to the
- * {@link String#hashCode()} of the
- * {@link #uniqueReference()}.
+ * The returned hash code MUST be equal to the {@link String#hashCode()} of
+ * the {@link #uniqueReference()}.
* <p>
* This method MUST be implemented in conjunction with
* {@link #equals(Object)} so that two equal BlankNodes produce the same
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/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 03aff91..54721fd 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
@@ -33,309 +33,308 @@ import java.util.stream.Stream;
*/
public interface Dataset extends AutoCloseable, GraphLike<Quad> {
- /**
- * Add a quad to the dataset, possibly mapping any of the components of the
- * Quad to those supported by this dataset.
- *
- * @param quad
- * The quad to add
- */
- 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.
+ *
+ * @param quad
+ * The quad to add
+ */
+ void add(Quad quad);
- /**
- * Add a quad to the dataset, possibly mapping any of the components to
- * those supported by this dataset.
- *
- * @param graphName
- * The graph the quad belongs to, or <code>null</code> for the
- * default graph
- * @param subject
- * The quad subject
- * @param predicate
- * The quad predicate
- * @param object
- * The quad object
- */
- 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.
+ *
+ * @param graphName
+ * The graph the quad belongs to, or <code>null</code> for the
+ * default graph
+ * @param subject
+ * The quad subject
+ * @param predicate
+ * The quad predicate
+ * @param object
+ * The quad object
+ */
+ void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
- /**
- * Check if dataset contains quad.
- *
- * @param quad
- * The quad to check.
- * @return True if the dataset contains the given Quad.
- */
- boolean contains(Quad quad);
+ /**
+ * Check if dataset contains quad.
+ *
+ * @param quad
+ * The quad to check.
+ * @return True if the dataset contains the given Quad.
+ */
+ boolean contains(Quad quad);
- /**
- * Check if dataset contains a pattern of quads.
- *
- * @param graphName
- * The graph the quad belongs to, wrapped as an {@link Optional}
- * (<code>null</code> is a wildcard, {@link Optional#empty()} is
- * the default graph)
- * @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 dataset contains any quads that match the given
- * pattern.
- */
- boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+ /**
+ * Check if dataset contains a pattern of quads.
+ *
+ * @param graphName
+ * The graph the quad belongs to, wrapped as an {@link Optional}
+ * (<code>null</code> is a wildcard, {@link Optional#empty()} is
+ * the default graph)
+ * @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 dataset contains any quads that match the given
+ * pattern.
+ */
+ boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
- /**
- * Close the dataset, relinquishing any underlying resources.
- * <p>
- * For example, this would close any open file and network streams and free
- * database locks held by the dataset implementation.
- * <p>
- * The behaviour of the other dataset methods are undefined after closing
- * the dataset.
- * <p>
- * Implementations might not need {@link #close()}, hence the default
- * implementation does nothing.
- */
- @Override
- default void close() throws Exception {
- }
+ /**
+ * Close the dataset, relinquishing any underlying resources.
+ * <p>
+ * For example, this would close any open file and network streams and free
+ * database locks held by the dataset implementation.
+ * <p>
+ * The behaviour of the other dataset methods are undefined after closing
+ * the dataset.
+ * <p>
+ * Implementations might not need {@link #close()}, hence the default
+ * implementation does nothing.
+ */
+ @Override
+ default void close() throws Exception {
+ }
- /**
- * 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 #stream()} 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
- * quad to remove
- */
- void remove(Quad quad);
+ /**
+ * 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();
- /**
- * 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
- * the default graph)
- * @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(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+ /**
+ * 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);
- /**
- * Clear the dataset, removing all quads.
- */
- void clear();
+ /**
+ * 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 #stream()} 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();
- /**
- * Number of quads contained by the dataset.
- * <p>
- * The count of a set does not include duplicates, consistent with the
- * {@link Quad#equals(Object)} equals method for each {@link Quad}.
- *
- * @return The number of quads in the dataset
- */
- long size();
+ /**
+ * Remove a concrete quad from the dataset.
+ *
+ * @param quad
+ * quad to remove
+ */
+ void remove(Quad quad);
- /**
- * Get all quads contained by the dataset.<br>
- * <p>
- * The iteration does not contain any duplicate quads, as determined by the
- * {@link Quad#equals(Object)} method for each {@link Quad}.
- * <p>
- * The behaviour of the {@link Stream} is not specified if
- * {@link #add(Quad)}, {@link #remove(Quad)} or {@link #clear()} are called
- * on the {@link Dataset} 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 quads in the dataset
- */
- Stream<? extends Quad> stream();
+ /**
+ * 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
+ * the default graph)
+ * @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(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
- /**
- * Get all quads contained by the dataset matched with the pattern.
- * <p>
- * The iteration does not contain any duplicate quads, as determined by the
- * {@link Quad#equals(Object)} method for each {@link Quad}.
- * <p>
- * The behaviour of the {@link Stream} is not specified if
- * {@link #add(Quad)}, {@link #remove(Quad)} or {@link #clear()} are called
- * on the {@link Dataset} before it terminates.
- * <p>
- * Implementations may throw {@link ConcurrentModificationException} from
- * Stream methods if they detect a conflict while the Stream is active.
- *
- * @param graphName
- * The graph the quad belongs to, wrapped as an {@link Optional}
- * (<code>null</code> is a wildcard, {@link Optional#empty()} is
- * the default graph)
- * @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 A {@link Stream} over the matched quads.
- */
- Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object);
+ /**
+ * Clear the dataset, removing all quads.
+ */
+ void clear();
- /**
- * Get an Iterable for iterating over all quads in the dataset.
- * <p>
- * This method is meant to be used with a Java for-each loop, e.g.:
- *
- * <pre>
- * for (Quad t : dataset.iterate()) {
- * System.out.println(t);
- * }
- * </pre>
- *
- * The behaviour of the iterator is not specified if {@link #add(Quad)},
- * {@link #remove(Quad)} or {@link #clear()}, are called on the
- * {@link Dataset} 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
- * quads in the dataset
- * @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<Quad> iterate() throws ConcurrentModificationException, IllegalStateException {
- return ((Stream<Quad>) stream())::iterator;
- }
+ /**
+ * Number of quads contained by the dataset.
+ * <p>
+ * The count of a set does not include duplicates, consistent with the
+ * {@link Quad#equals(Object)} equals method for each {@link Quad}.
+ *
+ * @return The number of quads in the dataset
+ */
+ long size();
- /**
- * Get an Iterable for iterating over the quads in the 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 (Quad t : dataset.iterate(null, alice, knows, null)) {
- * System.out.println(t.getGraphName());
- * System.out.println(t.getObject());
- * }
- * </pre>
- * <p>
- * The behaviour of the iterator is not specified if {@link #add(Quad)},
- * {@link #remove(Quad)} or {@link #clear()}, are called on the
- * {@link Dataset} 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 graphName
- * The graph the quad belongs to, wrapped as an {@link Optional}
- * (<code>null</code> is a wildcard, {@link Optional#empty()} is
- * the default graph)
- * @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 A {@link Iterable} that returns {@link Iterator} over the
- * matching quads in the dataset
- * @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<Quad> iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) throws ConcurrentModificationException, IllegalStateException {
- return ((Stream<Quad>) stream(graphName, subject, predicate, object))::iterator;
- }
+ /**
+ * Get all quads contained by the dataset.<br>
+ * <p>
+ * The iteration does not contain any duplicate quads, as determined by the
+ * {@link Quad#equals(Object)} method for each {@link Quad}.
+ * <p>
+ * The behaviour of the {@link Stream} is not specified if
+ * {@link #add(Quad)}, {@link #remove(Quad)} or {@link #clear()} are called
+ * on the {@link Dataset} 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 quads in the dataset
+ */
+ Stream<? extends Quad> stream();
+
+ /**
+ * Get all quads contained by the dataset matched with the pattern.
+ * <p>
+ * The iteration does not contain any duplicate quads, as determined by the
+ * {@link Quad#equals(Object)} method for each {@link Quad}.
+ * <p>
+ * The behaviour of the {@link Stream} is not specified if
+ * {@link #add(Quad)}, {@link #remove(Quad)} or {@link #clear()} are called
+ * on the {@link Dataset} before it terminates.
+ * <p>
+ * Implementations may throw {@link ConcurrentModificationException} from
+ * Stream methods if they detect a conflict while the Stream is active.
+ *
+ * @param graphName
+ * The graph the quad belongs to, wrapped as an {@link Optional}
+ * (<code>null</code> is a wildcard, {@link Optional#empty()} is
+ * the default graph)
+ * @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 A {@link Stream} over the matched quads.
+ */
+ Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object);
+
+ /**
+ * Get an Iterable for iterating over all quads in the dataset.
+ * <p>
+ * This method is meant to be used with a Java for-each loop, e.g.:
+ *
+ * <pre>
+ * for (Quad t : dataset.iterate()) {
+ * System.out.println(t);
+ * }
+ * </pre>
+ *
+ * The behaviour of the iterator is not specified if {@link #add(Quad)},
+ * {@link #remove(Quad)} or {@link #clear()}, are called on the
+ * {@link Dataset} 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
+ * quads in the dataset
+ * @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<Quad> iterate() throws ConcurrentModificationException, IllegalStateException {
+ return ((Stream<Quad>) stream())::iterator;
+ }
+
+ /**
+ * Get an Iterable for iterating over the quads in the 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 (Quad t : dataset.iterate(null, alice, knows, null)) {
+ * System.out.println(t.getGraphName());
+ * System.out.println(t.getObject());
+ * }
+ * </pre>
+ * <p>
+ * The behaviour of the iterator is not specified if {@link #add(Quad)},
+ * {@link #remove(Quad)} or {@link #clear()}, are called on the
+ * {@link Dataset} 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 graphName
+ * The graph the quad belongs to, wrapped as an {@link Optional}
+ * (<code>null</code> is a wildcard, {@link Optional#empty()} is
+ * the default graph)
+ * @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 A {@link Iterable} that returns {@link Iterator} over the
+ * matching quads in the dataset
+ * @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<Quad> iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) throws ConcurrentModificationException, IllegalStateException {
+ return ((Stream<Quad>) stream(graphName, subject, predicate, object))::iterator;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/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 4e0ed4c..bd6d175 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
@@ -23,19 +23,20 @@ import java.util.stream.Stream;
/**
* An <a href="http://www.w3.org/TR/rdf11-concepts/#section-rdf-graph"> RDF 1.1
- * Graph</a>, a set of RDF triples, as defined by <a
- * href="http://www.w3.org/TR/rdf11-concepts/" >RDF-1.1 Concepts and Abstract
+ * Graph</a>, a set of RDF triples, as defined by
+ * <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.
*
* @see RDF#createGraph()
*/
-public interface Graph extends AutoCloseable,GraphLike<Triple> {
+public interface Graph extends AutoCloseable, GraphLike<Triple> {
/**
* Add a triple to the graph, possibly mapping any of the components of the
* Triple to those supported by this Graph.
*
- * @param triple The triple to add
+ * @param triple
+ * The triple to add
*/
void add(Triple triple);
@@ -43,16 +44,20 @@ public interface Graph extends AutoCloseable,GraphLike<Triple> {
* Add a triple to the graph, possibly mapping any of the components to
* those supported by this Graph.
*
- * @param subject The triple subject
- * @param predicate The triple predicate
- * @param object The triple object
+ * @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 contains triple.
*
- * @param triple The triple to check.
+ * @param triple
+ * The triple to check.
* @return True if the Graph contains the given Triple.
*/
boolean contains(Triple triple);
@@ -60,11 +65,14 @@ public interface Graph extends AutoCloseable,GraphLike<Triple> {
/**
* Check if graph contains a pattern of triples.
*
- * @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)
+ * @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 the Graph contains any Triples that match the given
- * pattern.
+ * pattern.
*/
boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
@@ -87,16 +95,20 @@ public interface Graph extends AutoCloseable,GraphLike<Triple> {
/**
* Remove a concrete triple from the graph.
*
- * @param triple triple to remove
+ * @param triple
+ * triple to remove
*/
void remove(Triple triple);
/**
* Remove a concrete pattern of triples from the graph.
*
- * @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)
+ * @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);
@@ -121,76 +133,82 @@ public interface Graph extends AutoCloseable,GraphLike<Triple> {
* 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(Triple)},
- * {@link #remove(Triple)} or {@link #clear()} are called on the
- * {@link Graph} before it terminates.
+ * The behaviour of the {@link Stream} is not specified if
+ * {@link #add(Triple)}, {@link #remove(Triple)} or {@link #clear()} are
+ * called on the {@link Graph} before it terminates.
* <p>
- * Implementations may throw {@link ConcurrentModificationException} from Stream
- * methods if they detect a conflict while the Stream is active.
+ * Implementations may throw {@link ConcurrentModificationException} from
+ * Stream methods if they detect a conflict while the Stream is active.
*
* @since 0.3.0-incubating
* @return A {@link Stream} over all of the triples in the graph
*/
Stream<? extends Triple> stream();
-
+
/**
* Get all triples contained by the graph matched with 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(Triple)},
- * {@link #remove(Triple)} or {@link #clear()} are called on the
- * {@link Graph} before it terminates.
+ * The behaviour of the {@link Stream} is not specified if
+ * {@link #add(Triple)}, {@link #remove(Triple)} or {@link #clear()} are
+ * called on the {@link Graph} before it terminates.
* <p>
- * Implementations may throw {@link ConcurrentModificationException} from Stream
- * methods if they detect a conflict while the Stream is active.
+ * Implementations may throw {@link ConcurrentModificationException} from
+ * Stream methods if they detect a conflict while the Stream is active.
* <p>
*
* @since 0.3.0-incubating
- * @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)
+ * @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> stream(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object);
+ Stream<? extends Triple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
/**
- * This method is deprecated, use the equivalent method
- * {@link #stream()} instead.
+ * This method is deprecated, use the equivalent method {@link #stream()}
+ * instead.
*
* @return A {@link Stream} over all triples.
*/
@Deprecated
default Stream<? extends Triple> getTriples() {
- return stream();
+ return stream();
}
/**
- * This method is deprecated, use the equivalent method
+ * This method is deprecated, use the equivalent method
* {@link #stream(BlankNodeOrIRI, IRI, RDFTerm)} instead.
*
- * @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)
+ * @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.
*/
- @Deprecated
- default Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) {
- return stream(subject, predicate, object);
+ @Deprecated
+ default Stream<? extends Triple> getTriples(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return stream(subject, predicate, object);
}
-
+
/**
* Get an Iterable for iterating over all triples in the graph.
* <p>
* This method is meant to be used with a Java for-each loop, e.g.:
+ *
* <pre>
- * for (Triple t : graph.iterate()) {
- * System.out.println(t);
- * }
+ * for (Triple t : graph.iterate()) {
+ * System.out.println(t);
+ * }
* </pre>
+ *
* The behaviour of the iterator is not specified if {@link #add(Triple)},
* {@link #remove(Triple)} or {@link #clear()}, are called on the
* {@link Graph} before it terminates. It is undefined if the returned
@@ -213,9 +231,8 @@ public interface Graph extends AutoCloseable,GraphLike<Triple> {
* active.
*/
@SuppressWarnings("unchecked")
- default Iterable<Triple> iterate()
- throws ConcurrentModificationException, IllegalStateException {
- return ((Stream<Triple>)stream())::iterator;
+ default Iterable<Triple> iterate() throws ConcurrentModificationException, IllegalStateException {
+ return ((Stream<Triple>) stream())::iterator;
}
/**
@@ -223,18 +240,19 @@ public interface Graph extends AutoCloseable,GraphLike<Triple> {
* 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 : graph.iterate(alice, knows, null)) {
- * System.out.println(t.getObject());
- * }
+ * 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());
+ * }
* </pre>
* <p>
- * The behaviour of the iterator is not specified if
- * {@link #add(Triple)}, {@link #remove(Triple)} or {@link #clear()}, are
- * called on the {@link Graph} before it terminates. It is undefined if the
- * returned {@link Iterator} supports the {@link Iterator#remove()} method.
+ * The behaviour of the iterator is not specified if {@link #add(Triple)},
+ * {@link #remove(Triple)} or {@link #clear()}, are called on the
+ * {@link Graph} 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
@@ -259,9 +277,8 @@ public interface Graph extends AutoCloseable,GraphLike<Triple> {
* active.
*/
@SuppressWarnings("unchecked")
- default Iterable<Triple> iterate(
- BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
- throws ConcurrentModificationException, IllegalStateException {
+ default Iterable<Triple> iterate(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws ConcurrentModificationException, IllegalStateException {
return ((Stream<Triple>) stream(subject, predicate, object))::iterator;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java b/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
index 0f73c4e..e971801 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/GraphLike.java
@@ -39,7 +39,7 @@ import java.util.stream.Stream;
* @param <T>
* A {@link TripleLike} type used by the graph methods, typically
* {@link Triple} or {@link Quad}
- *
+ *
* @since 0.3.0-incubating
* @see Graph
* @see Dataset
@@ -47,60 +47,60 @@ import java.util.stream.Stream;
*/
public interface GraphLike<T extends TripleLike> {
- /**
- * Add a statement.
- *
- * @param statement
- * The TripleLike statement to add
- */
- void add(T statement);
+ /**
+ * Add a statement.
+ *
+ * @param statement
+ * The TripleLike statement to add
+ */
+ void add(T statement);
- /**
- * Check if statement is contained.
- *
- * @param statement
- * The {@link TripleLike} statement to check
- * @return True if the statement is contained
- */
- boolean contains(T statement);
+ /**
+ * Check if statement is contained.
+ *
+ * @param statement
+ * The {@link TripleLike} statement to check
+ * @return True if the statement is contained
+ */
+ boolean contains(T statement);
- /**
- * Add a statement.
- *
- * @param statement
- * The TripleLike statement to add
- */
- void remove(T statement);
+ /**
+ * Add a statement.
+ *
+ * @param statement
+ * The TripleLike statement to add
+ */
+ void remove(T statement);
- /**
- * Remove all statements.
- */
- void clear();
+ /**
+ * Remove all statements.
+ */
+ void clear();
- /**
- * Number of statements.
- *
- * @return Number of statements
- */
- long size();
+ /**
+ * Number of statements.
+ *
+ * @return Number of statements
+ */
+ long size();
- /**
- * Return a Stream of contained statements.
- *
- * @return A {@link Stream} of {@link TripleLike} statements.
- */
- Stream<? extends T> stream();
+ /**
+ * Return a Stream of contained statements.
+ *
+ * @return A {@link Stream} of {@link TripleLike} statements.
+ */
+ Stream<? extends T> stream();
- /**
- * Iterate over contained statements.
- *
- * @return An {@link Iterable} of {@link TripleLike} statements.
- * @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;
+ /**
+ * Iterate over contained statements.
+ *
+ * @return An {@link Iterable} of {@link TripleLike} statements.
+ * @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;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/api/IRI.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/IRI.java b/api/src/main/java/org/apache/commons/rdf/api/IRI.java
index 152bffd..1398582 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/IRI.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/IRI.java
@@ -38,20 +38,21 @@ public interface IRI extends BlankNodeOrIRI {
String getIRIString();
/**
- * Check it this IRI is equal to another IRI. <blockquote> <a
- * href="http://www.w3.org/TR/rdf11-concepts/#section-IRIs">IRI
+ * Check it this IRI is equal to another IRI. <blockquote>
+ * <a href="http://www.w3.org/TR/rdf11-concepts/#section-IRIs">IRI
* equality</a>: Two IRIs are equal if and only if they are equivalent under
* Simple String Comparison according to section 5.1 of [RFC3987]. Further
* normalization MUST NOT be performed when comparing IRIs for equality.
* </blockquote>
*
- * Two IRI instances are equal if and only if their
- * {@link #getIRIString()} are equal.
+ * Two IRI instances are equal if and only if their {@link #getIRIString()}
+ * are equal.
*
* Implementations MUST also override {@link #hashCode()} so that two equal
* IRIs produce the same hash code.
*
- * @param other Another object
+ * @param other
+ * Another object
* @return true if other is an IRI and is equal to this
* @see Object#equals(Object)
*/
@@ -61,13 +62,12 @@ public interface IRI extends BlankNodeOrIRI {
/**
* Calculate a hash code for this IRI.
* <p>
- * The returned hash code MUST be equal to the
- * {@link String#hashCode()} of the
- * {@link #getIRIString()}.
+ * The returned hash code MUST be equal to the {@link String#hashCode()} of
+ * the {@link #getIRIString()}.
* <p>
* This method MUST be implemented in conjunction with
- * {@link #equals(Object)}
- * so that two equal IRIs produce the same hash code.
+ * {@link #equals(Object)} so that two equal IRIs produce the same hash
+ * code.
*
* @return a hash code value for this IRI.
* @see Object#hashCode()
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/api/Literal.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Literal.java b/api/src/main/java/org/apache/commons/rdf/api/Literal.java
index 4e3c003..a434a73 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Literal.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Literal.java
@@ -22,10 +22,10 @@ import java.util.Objects;
import java.util.Optional;
/**
- * A RDF-1.1 Literal, as defined by <a href=
- * "http://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal" >RDF-1.1
- * Concepts and Abstract Syntax</a>, a W3C Recommendation published on 25
- * February 2014
+ * A RDF-1.1 Literal, as defined by
+ * <a href= "http://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal"
+ * >RDF-1.1 Concepts and Abstract Syntax</a>, a W3C Recommendation published on
+ * 25 February 2014
*
* @see RDF#createLiteral(String)
* @see RDF#createLiteral(String, IRI)
@@ -34,13 +34,13 @@ import java.util.Optional;
public interface Literal extends RDFTerm {
/**
- * The lexical form of this literal, represented by a <a
- * href="http://www.unicode.org/versions/latest/">Unicode string</a>.
+ * The lexical form of this literal, represented by a
+ * <a href="http://www.unicode.org/versions/latest/">Unicode string</a>.
*
* @return The lexical form of this literal.
- * @see <a
- * href="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form">RDF-1.1
- * Literal lexical form</a>
+ * @see <a href=
+ * "http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-form">RDF-1.1
+ * Literal lexical form</a>
*/
String getLexicalForm();
@@ -48,28 +48,28 @@ public interface Literal extends RDFTerm {
* The IRI identifying the datatype that determines how the lexical form
* maps to a literal value.
*
- * If the datatype IRI is <a
- * href="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"
+ * If the datatype IRI is
+ * <a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"
* >http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</a>,
* {@link #getLanguageTag()} must not return {@link Optional#empty()}, and
- * it must return a valid <a
- * href="http://tools.ietf.org/html/bcp47">BCP47</a> language tag.
+ * it must return a valid
+ * <a href="http://tools.ietf.org/html/bcp47">BCP47</a> language tag.
*
* @return The datatype IRI for this literal.
- * @see <a
- * href="http://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri">RDF-1.1
- * Literal datatype IRI</a>
+ * @see <a href=
+ * "http://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri">RDF-1.1
+ * Literal datatype IRI</a>
*/
IRI getDatatype();
/**
- * If and only if the datatype IRI is <a
- * href="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"
+ * If and only if the datatype IRI is
+ * <a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"
* >http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</a>, the language
- * tag for this Literal is a non-empty language tag as defined by <a
- * href="http://tools.ietf.org/html/bcp47">BCP47</a>.<br>
- * If the datatype IRI is not <a
- * href="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"
+ * tag for this Literal is a non-empty language tag as defined by
+ * <a href="http://tools.ietf.org/html/bcp47">BCP47</a>.<br>
+ * If the datatype IRI is not
+ * <a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"
* >http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</a>, this method
* must return {@link Optional#empty()}.
*
@@ -79,20 +79,20 @@ public interface Literal extends RDFTerm {
* return value for this method.
*
* @return The {@link Optional} language tag for this literal. If
- * {@link Optional#isPresent()} returns true, the value returned by
- * {@link Optional#get()} must be a non-empty string conforming to
- * BCP47.
- * @see <a
- * href="http://www.w3.org/TR/rdf11-concepts/#dfn-language-tag">RDF-1.1
- * Literal language tag</a>
+ * {@link Optional#isPresent()} returns true, the value returned by
+ * {@link Optional#get()} must be a non-empty string conforming to
+ * BCP47.
+ * @see <a href=
+ * "http://www.w3.org/TR/rdf11-concepts/#dfn-language-tag">RDF-1.1
+ * Literal language tag</a>
*/
Optional<String> getLanguageTag();
/**
- * Check it this Literal is equal to another Literal. <blockquote> <a
- * href="http://www.w3.org/TR/rdf11-concepts/#dfn-literal-term">Literal term
- * equality</a>: Two literals are term-equal (the same RDF literal) if and
- * only if the two lexical forms, the two datatype IRIs, and the two
+ * Check it this Literal is equal to another Literal. <blockquote>
+ * <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-literal-term">Literal
+ * term equality</a>: Two literals are term-equal (the same RDF literal) if
+ * and only if the two lexical forms, the two datatype IRIs, and the two
* language tags (if any) compare equal, character by character. Thus, two
* literals can have the same value without being the same RDF term.
* </blockquote>
@@ -100,7 +100,8 @@ public interface Literal extends RDFTerm {
* Implementations MUST also override {@link #hashCode()} so that two equal
* Literals produce the same hash code.
*
- * @param other Another object
+ * @param other
+ * Another object
* @return true if other is a Literal and is equal to this
* @see Object#equals(Object)
*/
@@ -110,13 +111,14 @@ public interface Literal extends RDFTerm {
/**
* Calculate a hash code for this Literal.
* <p>
- * The returned hash code MUST be equal to the result
- * of {@link Objects#hash(Object...)} with
- * the arguments
- * {@link #getLexicalForm()}, {@link #getDatatype()}, {@link #getLanguageTag()}.
+ * The returned hash code MUST be equal to the result of
+ * {@link Objects#hash(Object...)} with the arguments
+ * {@link #getLexicalForm()}, {@link #getDatatype()},
+ * {@link #getLanguageTag()}.
* <p>
- * This method MUST be implemented in conjunction with {@link #equals(Object)}
- * so that two equal Literals produce the same hash code.
+ * This method MUST be implemented in conjunction with
+ * {@link #equals(Object)} so that two equal Literals produce the same hash
+ * code.
*
* @return a hash code value for this Literal.
* @see Object#hashCode()
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/api/Quad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Quad.java b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
index ba89823..3b286cb 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Quad.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
@@ -37,177 +37,177 @@ import java.util.Optional;
*/
public interface Quad extends QuadLike<BlankNodeOrIRI> {
- /**
- * The graph name (graph label) of this quad, if present.
- *
- * If {@link Optional#isPresent()}, then the {@link Optional#get()} is
- * either a {@link BlankNode} or an {@link IRI}, indicating the
- * <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-named-graph">graph
- * name</a> of this Quad. If the graph name is not present, e.g. the value is
- * {@link Optional#empty()}, it indicates that this Quad is in the
- * <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph">default
- * graph</a>.
- *
- * @return If {@link Optional#isPresent()}, the graph name
- * {@link BlankNodeOrIRI} of this quad, otherwise
- * {@link Optional#empty()}, indicating the default graph.
- *
- * @see <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset">RDF-
- * 1.1 Dataset</a>
- */
- Optional<BlankNodeOrIRI> getGraphName();
+ /**
+ * The graph name (graph label) of this quad, if present.
+ *
+ * If {@link Optional#isPresent()}, then the {@link Optional#get()} is
+ * either a {@link BlankNode} or an {@link IRI}, indicating the
+ * <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-named-graph">graph
+ * name</a> of this Quad. If the graph name is not present, e.g. the value
+ * is {@link Optional#empty()}, it indicates that this Quad is in the
+ * <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph">default
+ * graph</a>.
+ *
+ * @return If {@link Optional#isPresent()}, the graph name
+ * {@link BlankNodeOrIRI} of this quad, otherwise
+ * {@link Optional#empty()}, indicating the default graph.
+ *
+ * @see <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset">RDF-
+ * 1.1 Dataset</a>
+ */
+ Optional<BlankNodeOrIRI> getGraphName();
- /**
- * The subject of this quad, which may be either a {@link BlankNode} or an
- * {@link IRI}, which are represented in Commons RDF by the interface
- * {@link BlankNodeOrIRI}.
- *
- * @return The subject {@link BlankNodeOrIRI} of this quad.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1
- * Triple subject</a>
- */
- BlankNodeOrIRI getSubject();
+ /**
+ * The subject of this quad, which may be either a {@link BlankNode} or an
+ * {@link IRI}, which are represented in Commons RDF by the interface
+ * {@link BlankNodeOrIRI}.
+ *
+ * @return The subject {@link BlankNodeOrIRI} of this quad.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1
+ * Triple subject</a>
+ */
+ BlankNodeOrIRI getSubject();
- /**
- * The predicate {@link IRI} of this quad.
- *
- * @return The predicate {@link IRI} of this quad.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1
- * Triple predicate</a>
- */
- IRI getPredicate();
+ /**
+ * The predicate {@link IRI} of this quad.
+ *
+ * @return The predicate {@link IRI} of this quad.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1
+ * Triple predicate</a>
+ */
+ IRI getPredicate();
- /**
- * The object of this quad, which may be either a {@link BlankNode}, an
- * {@link IRI}, or a {@link Literal}, which are represented in Commons RDF
- * by the interface {@link RDFTerm}.
- *
- * @return The object {@link RDFTerm} of this quad.
- * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1
- * Triple object</a>
- */
- RDFTerm getObject();
+ /**
+ * The object of this quad, which may be either a {@link BlankNode}, an
+ * {@link IRI}, or a {@link Literal}, which are represented in Commons RDF
+ * by the interface {@link RDFTerm}.
+ *
+ * @return The object {@link RDFTerm} of this quad.
+ * @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1
+ * Triple object</a>
+ */
+ RDFTerm getObject();
- /**
- * Adapt this Quad to a Triple.
- * <p>
- * The returned {@link Triple} will have equivalent values returned from the
- * methods {@link TripleLike#getSubject()},
- * {@link TripleLike#getPredicate()} and {@link TripleLike#getObject()}.
- * <p>
- * The returned {@link Triple} MUST NOT be {@link #equals(Object)} to this
- * {@link Quad}, even if this quad has a default graph
- * {@link #getGraphName()} value of {@link Optional#empty()}, but MUST
- * follow the {@link Triple#equals(Object)} semantics. This means that the
- * following MUST be true:
+ /**
+ * Adapt this Quad to a Triple.
+ * <p>
+ * The returned {@link Triple} will have equivalent values returned from the
+ * methods {@link TripleLike#getSubject()},
+ * {@link TripleLike#getPredicate()} and {@link TripleLike#getObject()}.
+ * <p>
+ * The returned {@link Triple} MUST NOT be {@link #equals(Object)} to this
+ * {@link Quad}, even if this quad has a default graph
+ * {@link #getGraphName()} value of {@link Optional#empty()}, but MUST
+ * follow the {@link Triple#equals(Object)} semantics. This means that the
+ * following MUST be true:
+ *
+ * <pre>
+ * Quad q1, q2;
+ * if (q1.equals(q2)) {
+ * assert (q1.asTriple().equals(q2.asTriple()));
+ * } else if (q1.asTriple().equals(q2.asTriple())) {
+ * assert (q1.getSubject().equals(q2.getSubject()));
+ * assert (q1.getPredicate().equals(q2.getPredicate()));
+ * assert (q1.getObject().equals(q2.getObject()));
+ * assert (!q1.getGraphName().equals(q2.getGraphName()));
+ * }
+ * </pre>
*
- * <pre>
- * Quad q1, q2;
- * if (q1.equals(q2)) {
- * assert(q1.asTriple().equals(q2.asTriple()));
- * } else if (q1.asTriple().equals(q2.asTriple())) {
- * assert(q1.getSubject().equals(q2.getSubject()));
- * assert(q1.getPredicate().equals(q2.getPredicate()));
- * assert(q1.getObject().equals(q2.getObject()));
- * assert(! q1.getGraphName().equals(q2.getGraphName()));
- * }
- * </pre>
- *
- * The <code>default</code> implementation of this method return a proxy
- * {@link Triple} instance that keeps a reference to this {@link Quad} to
- * call the underlying {@link TripleLike} methods, but supplies a
- * {@link Triple} compatible implementation of {@link Triple#equals(Object)}
- * and {@link Triple#hashCode()}. Implementations may override this method,
- * e.g. for a more efficient solution.
- *
- * @return A {@link Triple} that contains the same {@link TripleLike}
- * properties as this Quad.
- */
- default Triple asTriple() {
- return new Triple() {
- @Override
- public BlankNodeOrIRI getSubject() {
- return Quad.this.getSubject();
- }
+ * The <code>default</code> implementation of this method return a proxy
+ * {@link Triple} instance that keeps a reference to this {@link Quad} to
+ * call the underlying {@link TripleLike} methods, but supplies a
+ * {@link Triple} compatible implementation of {@link Triple#equals(Object)}
+ * and {@link Triple#hashCode()}. Implementations may override this method,
+ * e.g. for a more efficient solution.
+ *
+ * @return A {@link Triple} that contains the same {@link TripleLike}
+ * properties as this Quad.
+ */
+ default Triple asTriple() {
+ return new Triple() {
+ @Override
+ public BlankNodeOrIRI getSubject() {
+ return Quad.this.getSubject();
+ }
- @Override
- public IRI getPredicate() {
- return Quad.this.getPredicate();
- }
+ @Override
+ public IRI getPredicate() {
+ return Quad.this.getPredicate();
+ }
- @Override
- public RDFTerm getObject() {
- return Quad.this.getObject();
- }
+ @Override
+ public RDFTerm getObject() {
+ return Quad.this.getObject();
+ }
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof Triple)) {
- return false;
- }
- Triple other = (Triple) obj;
- return Objects.equals(getSubject(), other.getSubject())
- && Objects.equals(getPredicate(), other.getPredicate())
- && Objects.equals(getObject(), other.getObject());
- }
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof Triple)) {
+ return false;
+ }
+ Triple other = (Triple) obj;
+ return Objects.equals(getSubject(), other.getSubject())
+ && Objects.equals(getPredicate(), other.getPredicate())
+ && Objects.equals(getObject(), other.getObject());
+ }
- @Override
- public int hashCode() {
- return Objects.hash(getSubject(), getPredicate(), getObject());
- }
- };
- }
+ @Override
+ public int hashCode() {
+ return Objects.hash(getSubject(), getPredicate(), getObject());
+ }
+ };
+ }
- /**
- * Check it this Quad is equal to another Quad.
- * <p>
- * Two Quads are equal if and only if their {@link #getGraphName()},
- * {@link #getSubject()}, {@link #getPredicate()} and
- * {@link #getObject()} are equal.
- * </p>
- * <p>
- * Implementations MUST also override {@link #hashCode()} so that two equal
- * Quads produce the same hash code.
- * </p>
- * <p>
- * Note that a {@link Quad} MUST NOT be equal to a
- * {@link Triple}, even if this Quad's {@link #getGraphName()}
- * is {@link Optional#empty()}. To test triple-like equivalence,
- * callers can use:
- * </p>
- * <pre>
- * Quad q1;
- * Triple t2;
- * q1.asTriple().equals(t2));
- * </pre>
- *
- * @param other
- * Another object
- * @return true if other is a Quad and is equal to this
- * @see Object#equals(Object)
- */
- @Override
- public boolean equals(Object other);
+ /**
+ * Check it this Quad is equal to another Quad.
+ * <p>
+ * Two Quads are equal if and only if their {@link #getGraphName()},
+ * {@link #getSubject()}, {@link #getPredicate()} and {@link #getObject()}
+ * are equal.
+ * </p>
+ * <p>
+ * Implementations MUST also override {@link #hashCode()} so that two equal
+ * Quads produce the same hash code.
+ * </p>
+ * <p>
+ * Note that a {@link Quad} MUST NOT be equal to a {@link Triple}, even if
+ * this Quad's {@link #getGraphName()} is {@link Optional#empty()}. To test
+ * triple-like equivalence, callers can use:
+ * </p>
+ *
+ * <pre>
+ * Quad q1;
+ * Triple t2;
+ * q1.asTriple().equals(t2));
+ * </pre>
+ *
+ * @param other
+ * Another object
+ * @return true if other is a Quad and is equal to this
+ * @see Object#equals(Object)
+ */
+ @Override
+ public boolean equals(Object other);
- /**
- * Calculate a hash code for this Quad.
- * <p>
- * The returned hash code MUST be equal to the result of
- * {@link Objects#hash(Object...)} with the arguments {@link #getSubject()},
- * {@link #getPredicate()}, {@link #getObject()}, {@link #getGraphName()}.
- * <p>
- * This method MUST be implemented in conjunction with
- * {@link #equals(Object)} so that two equal {@link Quad}s produce the same
- * hash code.
- *
- * @return a hash code value for this Quad.
- * @see Object#hashCode()
- * @see Objects#hash(Object...)
- */
- @Override
- public int hashCode();
+ /**
+ * Calculate a hash code for this Quad.
+ * <p>
+ * The returned hash code MUST be equal to the result of
+ * {@link Objects#hash(Object...)} with the arguments {@link #getSubject()},
+ * {@link #getPredicate()}, {@link #getObject()}, {@link #getGraphName()}.
+ * <p>
+ * This method MUST be implemented in conjunction with
+ * {@link #equals(Object)} so that two equal {@link Quad}s produce the same
+ * hash code.
+ *
+ * @return a hash code value for this Quad.
+ * @see Object#hashCode()
+ * @see Objects#hash(Object...)
+ */
+ @Override
+ public int hashCode();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java b/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
index 9eaa5dc..cfe1733 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/QuadLike.java
@@ -25,10 +25,9 @@ import java.util.Optional;
* A QuadLike statement has at least a {@link #getSubject()},
* {@link #getPredicate()}, {@link #getObject()} and {@link #getGraphName()},
* but unlike a {@link Quad} does not have a formalised
- * {@link Quad#equals(Object)}
- * or {@link Quad#hashCode()}
- * semantics. This interface can also be used for <em>generalised quads</em>
- * (e.g. a {@link BlankNode} as predicate).
+ * {@link Quad#equals(Object)} or {@link Quad#hashCode()} semantics. This
+ * interface can also be used for <em>generalised quads</em> (e.g. a
+ * {@link BlankNode} as predicate).
* <p>
* Implementations should specialise which specific {@link RDFTerm} types they
* return by overriding {@link #getSubject()}, {@link #getPredicate()},
@@ -39,19 +38,18 @@ import java.util.Optional;
*/
public interface QuadLike<G extends RDFTerm> extends TripleLike {
- /**
- * The graph name (graph label) of this statement, if present.
- * <p>
- * If {@link Optional#isPresent()}, then the {@link Optional#get()} indicate
- * the graph name of this statement. If the graph name is not present,e.g.
- * the value is {@link Optional#empty()}, it indicates that this Quad is in
- * the default graph.
- *
- * @return If {@link Optional#isPresent()}, the graph name of this quad,
- * otherwise {@link Optional#empty()}, indicating the default
- * graph. The graph name is typically an {@link IRI} or
- * {@link BlankNode}.
- */
- Optional<G> getGraphName();
+ /**
+ * The graph name (graph label) of this statement, if present.
+ * <p>
+ * If {@link Optional#isPresent()}, then the {@link Optional#get()} indicate
+ * the graph name of this statement. If the graph name is not present,e.g.
+ * the value is {@link Optional#empty()}, it indicates that this Quad is in
+ * the default graph.
+ *
+ * @return If {@link Optional#isPresent()}, the graph name of this quad,
+ * otherwise {@link Optional#empty()}, indicating the default graph.
+ * The graph name is typically an {@link IRI} or {@link BlankNode}.
+ */
+ Optional<G> getGraphName();
}
[22/50] [abbrv] incubator-commonsrdf git commit: COMMONSRDF-46
Javadoc fixed references
Posted by st...@apache.org.
COMMONSRDF-46 Javadoc fixed references
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/400d1e72
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/400d1e72
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/400d1e72
Branch: refs/heads/COMMONSRDF-7
Commit: 400d1e72c27024ca7ec9eb17cf04ff346e5e2ee9
Parents: 46e159d
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 13:40:44 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 13:40:44 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/jena/JenaRDF.java | 2 +-
.../rdf/rdf4j/impl/InternalRDF4JFactory.java | 3 +-
.../apache/commons/rdf/rdf4j/package-info.java | 36 ++++++++++++--------
3 files changed, 24 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/400d1e72/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
index 22db284..a550b06 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
@@ -67,7 +67,7 @@ import org.apache.jena.sparql.graph.GraphFactory;
* {@link BlankNode#uniqueReference()}), each instance of JenaRDF uses an
* internal random state. If for some reason consistent/reproducible BlankNode
* identity is desired, it is possible to retrieve the state as a UUID using
- * {@link #salt} for subsequent use with {@link JenaFactory#JenaFactory(UUID)} -
+ * {@link #salt()} for subsequent use with {@link JenaRDF#JenaRDF(UUID)} -
* note that such consistency is only guaranteed within the same minor version
* of Commons RDF.
*
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/400d1e72/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
index ca97472..b6d6b29 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
@@ -28,6 +28,7 @@ import org.apache.commons.rdf.rdf4j.RDF4JLiteral;
import org.apache.commons.rdf.rdf4j.RDF4JQuad;
import org.apache.commons.rdf.rdf4j.RDF4JTerm;
import org.apache.commons.rdf.rdf4j.RDF4J;
+import org.apache.commons.rdf.rdf4j.RDF4J.Option;
import org.apache.commons.rdf.rdf4j.RDF4JTriple;
import org.eclipse.rdf4j.model.BNode;
import org.eclipse.rdf4j.model.IRI;
@@ -45,7 +46,7 @@ import org.eclipse.rdf4j.repository.Repository;
* {@link RDF4J} methods like
* {@link RDF4J#createBlankNode()},
* {@link RDF4J#asRDFTerm(org.eclipse.rdf4j.model.Value)} and
- * {@link RDF4J#asGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)}
+ * {@link RDF4J#asGraph(Repository, Option...)}
* <p>
* This class exists as a <code>public</code> bridge between the packages
* {@link org.apache.commons.rdf.rdf4j} and
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/400d1e72/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
index dbccdb3..f4bfb7a 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
@@ -18,36 +18,42 @@
/**
* Commons RDF integration with <a href="http://rdf4j.org/">RDF4J</a>.
* <p>
- * Use the {@link org.apache.commons.rdf.rdf4j.RDF4J} to convert
+ * Use the {@link RDF4J} to convert
* between Commons RDF and RDF4J types, for instance
- * {@link org.apache.commons.rdf.rdf4j.RDF4J#asQuad(org.eclipse.rdf4j.model.Statement)}
+ * {@link RDF4J#asQuad(org.eclipse.rdf4j.model.Statement)}
* converts a RDF4J {@link org.eclipse.rdf4j.model.Statement} to a
* {@link org.apache.commons.rdf.api.Quad}. Converted RDF terms implement the
- * {@link org.apache.commons.rdf.rdf4j.RDF4JTerm} interface, and converted
- * statements the {@link org.apache.commons.rdf.rdf4j.RDF4JTripleLike}
+ * {@link RDF4JTerm} interface, and converted
+ * statements the {@link RDF4JTripleLike}
* interface, which provide convenience access to the underlying RDF4J
* implementations.
* <p>
* RDF4J {@link org.eclipse.rdf4j.model.Model}s and
* {@link org.eclipse.rdf4j.repository.Repository} instances can be adapted to
- * Commons RDF {@link org.apache.commons.rdf.api.Graph} and
- * {@link org.apache.commons.rdf.api.Dataset}, e.g. using
- * {@link org.apache.commons.rdf.rdf4j.RDF4J#asGraph(org.eclipse.rdf4j.model.Model)}
+ * Commons RDF {@link Graph} and
+ * {@link Dataset}, e.g. using
+ * {@link RDF4J#asGraph(org.eclipse.rdf4j.model.Model)}
* or
- * {@link org.apache.commons.rdf.rdf4j.RDF4J#asDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)}
+ * {@link RDF4J#asDataset(org.eclipse.rdf4j.repository.Repository, RDF4J.Option...)}
* The returned adapted graph/dataset is directly mapped, so changes are
* propagated both ways. For convenience, the marker interface
- * {@link org.apache.commons.rdf.rdf4j.RDF4JGraph} and
- * {@link org.apache.commons.rdf.rdf4j.RDF4JDataset} provide access to the
+ * {@link RDF4JGraph} and
+ * {@link RDF4JDataset} provide access to the
* underlying RDF4J implementations.
* <p>
- * The {@link org.apache.commons.rdf.rdf4j.experimental.RDF4JParser} can be used to
+ * The {@link RDF4JParser} can be used to
* parse RDF files using RDF4j. It should be most efficient if used with
- * {@link org.apache.commons.rdf.rdf4j.experimental.RDF4JParser#target(org.apache.commons.rdf.api.Dataset)}
- * and an adapted {@link org.apache.commons.rdf.rdf4j.RDF4JDataset}, or
- * {@link org.apache.commons.rdf.rdf4j.experimental.RDF4JParser#target(org.apache.commons.rdf.api.Graph)}
- * and a an adapted {@link org.apache.commons.rdf.rdf4j.RDF4JGraph}
+ * {@link RDF4JParser#target(Dataset)}
+ * and an adapted {@link RDF4JDataset}, or
+ * {@link RDF4JParser#target(Graph)}
+ * and a an adapted {@link RDF4JGraph}
*
*
*/
package org.apache.commons.rdf.rdf4j;
+// Imports for Javadoc, do not remove
+import org.apache.commons.rdf.api.Dataset;
+import org.apache.commons.rdf.api.Graph;
+import org.apache.commons.rdf.rdf4j.*;
+import org.apache.commons.rdf.rdf4j.RDF4J.Option;
+import org.apache.commons.rdf.rdf4j.experimental.RDF4JParser;
[49/50] [abbrv] incubator-commonsrdf git commit: typo it's -> its
Posted by st...@apache.org.
typo it's -> its
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/e0dc34ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/e0dc34ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/e0dc34ad
Branch: refs/heads/COMMONSRDF-7
Commit: e0dc34ade393f6ccb5f3de384cdbb3889f2e7cbb
Parents: 2efe1ab
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 28 11:46:20 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 28 11:46:20 2016 +0100
----------------------------------------------------------------------
api/src/main/java/org/apache/commons/rdf/api/Quad.java | 2 +-
api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java | 2 +-
api/src/main/java/org/apache/commons/rdf/api/Triple.java | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/e0dc34ad/api/src/main/java/org/apache/commons/rdf/api/Quad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Quad.java b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
index b2e8ed5..a242ae3 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Quad.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
@@ -32,7 +32,7 @@ import java.util.Set;
* February 2014.
* <p>
* A {@link Quad} object in Commons RDF is considered <em>immutable</em>, that
- * is, over it's life time it will have consistent behaviour for its
+ * is, over its life time it will have consistent behaviour for its
* {@link #equals(Object)} and {@link #hashCode()}, and the instances returned
* from {@link #getGraphName()}, {@link #getSubject()}, {@link #getPredicate()}
* and {@link #getObject()} will have consistent {@link Object#equals(Object)}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/e0dc34ad/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
index a277140..47fd432 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
@@ -28,7 +28,7 @@ import java.util.Set;
* Abstract Syntax</a>, a W3C Recommendation published on 25 February 2014.
* <p>
* A {@link RDFTerm} object in Commons RDF is considered <em>immutable</em>,
- * that is, over it's life time it will have consistent behaviour for its
+ * that is, over its life time it will have consistent behaviour for its
* {@link #equals(Object)} and {@link #hashCode()}, and objects returned from
* its getter methods (e.g. {@link IRI#getIRIString()} and
* {@link Literal#getLanguageTag()}) will have consistent
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/e0dc34ad/api/src/main/java/org/apache/commons/rdf/api/Triple.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Triple.java b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
index 57934fa..51c4a39 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Triple.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
@@ -29,7 +29,7 @@ import java.util.Set;
* Abstract Syntax</a>, a W3C Recommendation published on 25 February 2014.<br>
* <p>
* A {@link Triple} object in Commons RDF is considered <em>immutable</em>, that
- * is, over it's life time it will have consistent behaviour for its
+ * is, over its life time it will have consistent behaviour for its
* {@link #equals(Object)} and {@link #hashCode()}, and the {@link RDFTerm}
* instances returned from {@link #getSubject()}, {@link #getPredicate()} and
* {@link #getObject()} will have consistent {@link RDFTerm#equals(Object)}
[46/50] [abbrv] incubator-commonsrdf git commit: Reformat tab ->
spaces
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/api/RDF.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDF.java b/api/src/main/java/org/apache/commons/rdf/api/RDF.java
index 32b7f66..b942b30 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDF.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDF.java
@@ -23,21 +23,18 @@ import java.util.Locale;
/**
* A RDF implementation.
* <p>
- * A <code>RDF</code> implementation can create instances of
- * the {@link RDFTerm} types
- * {@link IRI}, {@link BlankNode} and {@link Literal}, as well as creating
+ * A <code>RDF</code> implementation can create instances of the {@link RDFTerm}
+ * types {@link IRI}, {@link BlankNode} and {@link Literal}, as well as creating
* instances of the types {@link Triple}, {@link Quad}, {@link Graph} or
* {@link Dataset}.
* <p>
- * A <em>partial RDF implementation</em>
- * should be clearly documented as such, and may throw
- * {@link UnsupportedOperationException} where applicable, e.g. if it
- * does not support creating {@link Dataset}s or {@link Quad}s.
+ * A <em>partial RDF implementation</em> should be clearly documented as such,
+ * and may throw {@link UnsupportedOperationException} where applicable, e.g. if
+ * it does not support creating {@link Dataset}s or {@link Quad}s.
* <p>
- * Instances of <code>RDF</code> work like a factory for
- * creating Commons RDF instances.
- * spezializations of this interface may also provide methods
- * for conversions from/to their underlying RDF framework.
+ * Instances of <code>RDF</code> work like a factory for creating Commons RDF
+ * instances. spezializations of this interface may also provide methods for
+ * conversions from/to their underlying RDF framework.
* <p>
* If a factory method of a particular implementation does not allow or support
* a provided parameter, e.g. because an IRI is considered invalid, then it
@@ -54,36 +51,37 @@ public interface RDF {
* Create a new blank node.
* <p>
* The returned blank node MUST NOT be equal to any existing
- * {@link BlankNode} instances according to {@link BlankNode#equals(Object)}.
+ * {@link BlankNode} instances according to
+ * {@link BlankNode#equals(Object)}.
*
* @return A new, unique {@link BlankNode}
*/
- public BlankNode createBlankNode();
+ public BlankNode createBlankNode();
/**
* Create a blank node based on the given name.
* <p>
- * All {@link BlankNode}s created with the given <code>name</code>
- * <em>on a particular instance</em> of <code>RDF</code> MUST be
- * equivalent according to {@link BlankNode#equals(Object)},
+ * All {@link BlankNode}s created with the given <code>name</code> <em>on a
+ * particular instance</em> of <code>RDF</code> MUST be equivalent according
+ * to {@link BlankNode#equals(Object)},
* <p>
* The returned BlankNode MUST NOT be equal to <code>BlankNode</code>
* instances returned for any other <code>name</code> or those returned from
* {@link #createBlankNode()}.
* <p>
* The returned BlankNode SHOULD NOT be equivalent to any BlankNodes created
- * on a <em>different</em> <code>RDF</code> instance, e.g.
- * different instances of <code>RDF</code> should produce
- * different blank nodes for the same <code>name</code> unless they
- * purposely are intending to create equivalent {@link BlankNode}
- * instances (e.g. a reinstated {@link Serializable} factory).
+ * on a <em>different</em> <code>RDF</code> instance, e.g. different
+ * instances of <code>RDF</code> should produce different blank nodes for
+ * the same <code>name</code> unless they purposely are intending to create
+ * equivalent {@link BlankNode} instances (e.g. a reinstated
+ * {@link Serializable} factory).
*
* @param name
* A non-empty, non-null, String that is unique to this blank
* node in the context of this {@link RDF}.
* @return A BlankNode for the given name
*/
- public BlankNode createBlankNode(String name);
+ public BlankNode createBlankNode(String name);
/**
* Create a new graph.
@@ -93,31 +91,33 @@ public interface RDF {
*
* @return A new Graph
*/
- public Graph createGraph();
+ public Graph createGraph();
/**
* Create a new dataset.
*
- * It is undefined if the dataset will be persisted by any underlying storage
- * mechanism.
+ * It is undefined if the dataset will be persisted by any underlying
+ * storage mechanism.
*
* @return A new Dataset
*/
- public Dataset createDataset();
+ public Dataset createDataset();
/**
* Create an IRI from a (possibly escaped) String.
*
- * The provided iri string MUST be valid according to the <a
- * href="http://www.w3.org/TR/rdf11-concepts/#dfn-iri">W3C RDF-1.1 IRI</a>
- * definition.
+ * The provided iri string MUST be valid according to the
+ * <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-iri">W3C RDF-1.1
+ * IRI</a> definition.
*
- * @param iri Internationalized Resource Identifier
+ * @param iri
+ * Internationalized Resource Identifier
* @return A new IRI
- * @throws IllegalArgumentException If the provided string is not acceptable, e.g. does not
- * conform to the RFC3987 syntax.
+ * @throws IllegalArgumentException
+ * If the provided string is not acceptable, e.g. does not
+ * conform to the RFC3987 syntax.
*/
- public IRI createIRI(String iri) throws IllegalArgumentException;
+ public IRI createIRI(String iri) throws IllegalArgumentException;
/**
* Create a simple literal.
@@ -131,13 +131,14 @@ public interface RDF {
* {@link Literal#getDatatype()} that is equal to the IRI
* <code>http://www.w3.org/2001/XMLSchema#string</code>.
*
- * @param lexicalForm The literal value in plain text
+ * @param lexicalForm
+ * The literal value in plain text
* @return The created Literal
- * @throws IllegalArgumentException If the provided lexicalForm is not acceptable, e.g. because
- * it is too large for an underlying storage.
+ * @throws IllegalArgumentException
+ * If the provided lexicalForm is not acceptable, e.g. because
+ * it is too large for an underlying storage.
*/
- public Literal createLiteral(String lexicalForm)
- throws IllegalArgumentException;
+ public Literal createLiteral(String lexicalForm) throws IllegalArgumentException;
/**
* Create a literal with the specified data type.
@@ -145,12 +146,12 @@ public interface RDF {
* The provided lexical form should not be escaped in any sense, e.g. should
* not include "quotes" unless those are part of the literal value.
*
- * It is RECOMMENDED that the provided dataType is one of the <a
- * href="http://www.w3.org/TR/rdf11-concepts/#xsd-datatypes">RDF-compatible
- * XSD types</a>.
+ * It is RECOMMENDED that the provided dataType is one of the <a href=
+ * "http://www.w3.org/TR/rdf11-concepts/#xsd-datatypes">RDF-compatible XSD
+ * types</a>.
*
- * The provided lexical form SHOULD be in the <a
- * href="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-space">lexical
+ * The provided lexical form SHOULD be in the
+ * <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-space">lexical
* space</a> of the provided dataType.
*
* The returned Literal SHOULD have a {@link Literal#getLexicalForm()} that
@@ -159,15 +160,17 @@ public interface RDF {
* {@link Literal#getDatatype()} that is equivalent to the provided dataType
* IRI.
*
- * @param lexicalForm The literal value
- * @param dataType The data type IRI for the literal value, e.g.
- * <code>http://www.w3.org/2001/XMLSchema#integer</code>
+ * @param lexicalForm
+ * The literal value
+ * @param dataType
+ * The data type IRI for the literal value, e.g.
+ * <code>http://www.w3.org/2001/XMLSchema#integer</code>
* @return The created Literal
- * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
- * because the provided dataType is not permitted.
+ * @throws IllegalArgumentException
+ * If any of the provided arguments are not acceptable, e.g.
+ * because the provided dataType is not permitted.
*/
- public Literal createLiteral(String lexicalForm, IRI dataType)
- throws IllegalArgumentException;
+ public Literal createLiteral(String lexicalForm, IRI dataType) throws IllegalArgumentException;
/**
* Create a language-tagged literal.
@@ -175,11 +178,12 @@ public interface RDF {
* The provided lexical form should not be escaped in any sense, e.g. should
* not include "quotes" unless those are part of the literal value.
*
- * The provided language tag MUST be valid according to <a
- * href="http://tools.ietf.org/html/bcp47">BCP47</a>, e.g. <code>en</code>.
+ * The provided language tag MUST be valid according to
+ * <a href="http://tools.ietf.org/html/bcp47">BCP47</a>, e.g.
+ * <code>en</code>.
*
- * The provided language tag <a
- * href="http://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string"
+ * The provided language tag
+ * <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string"
* >MAY be converted to lower case</a>.
*
* The returned Literal SHOULD have a {@link Literal#getLexicalForm()} which
@@ -190,15 +194,17 @@ public interface RDF {
* equal to the provided language tag (compared as
* {@link String#toLowerCase(Locale)} using {@link Locale#ENGLISH}).
*
- * @param lexicalForm The literal value
- * @param languageTag The non-empty language tag as defined by <a
- * href="http://tools.ietf.org/html/bcp47">BCP47</a>
+ * @param lexicalForm
+ * The literal value
+ * @param languageTag
+ * The non-empty language tag as defined by
+ * <a href="http://tools.ietf.org/html/bcp47">BCP47</a>
* @return The created Literal
- * @throws IllegalArgumentException If the provided values are not acceptable, e.g. because the
- * languageTag was syntactically invalid.
+ * @throws IllegalArgumentException
+ * If the provided values are not acceptable, e.g. because the
+ * languageTag was syntactically invalid.
*/
- public Literal createLiteral(String lexicalForm, String languageTag)
- throws IllegalArgumentException;
+ public Literal createLiteral(String lexicalForm, String languageTag) throws IllegalArgumentException;
/**
* Create a triple.
@@ -208,37 +214,45 @@ public interface RDF {
* equal to the provided predicate, and a {@link Triple#getObject()} that is
* equal to the provided object.
*
- * @param subject The IRI or BlankNode that is the subject of the triple
- * @param predicate The IRI that is the predicate of the triple
- * @param object The IRI, BlankNode or Literal that is the object of the triple
+ * @param subject
+ * The IRI or BlankNode that is the subject of the triple
+ * @param predicate
+ * The IRI that is the predicate of the triple
+ * @param object
+ * The IRI, BlankNode or Literal that is the object of the triple
* @return The created Triple
- * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
- * because a Literal has a lexicalForm that is too large for an
- * underlying storage.
+ * @throws IllegalArgumentException
+ * If any of the provided arguments are not acceptable, e.g.
+ * because a Literal has a lexicalForm that is too large for an
+ * underlying storage.
*/
- public Triple createTriple(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) throws IllegalArgumentException;
+ public Triple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) throws IllegalArgumentException;
/**
* Create a quad.
* <p>
- * The returned Quad SHOULD have a
- * {@link Quad#getGraphName()} that is equal to the provided graphName, a
- * {@link Quad#getSubject()} that is
- * equal to the provided subject, a {@link Quad#getPredicate()} that is
- * equal to the provided predicate, and a {@link Quad#getObject()} that is
- * equal to the provided object.
+ * The returned Quad SHOULD have a {@link Quad#getGraphName()} that is equal
+ * to the provided graphName, a {@link Quad#getSubject()} that is equal to
+ * the provided subject, a {@link Quad#getPredicate()} that is equal to the
+ * provided predicate, and a {@link Quad#getObject()} that is equal to the
+ * provided object.
*
- * @param graphName The IRI or BlankNode that this quad belongs to, or <code>null</code> for the public graph
- * @param subject The IRI or BlankNode that is the subject of the quad
- * @param predicate The IRI that is the predicate of the quad
- * @param object The IRI, BlankNode or Literal that is the object of the quad
+ * @param graphName
+ * The IRI or BlankNode that this quad belongs to, or
+ * <code>null</code> for the public graph
+ * @param subject
+ * The IRI or BlankNode that is the subject of the quad
+ * @param predicate
+ * The IRI that is the predicate of the quad
+ * @param object
+ * The IRI, BlankNode or Literal that is the object of the quad
* @return The created Quad
- * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
- * because a Literal has a lexicalForm that is too large for an
- * underlying storage.
+ * @throws IllegalArgumentException
+ * If any of the provided arguments are not acceptable, e.g.
+ * because a Literal has a lexicalForm that is too large for an
+ * underlying storage.
*/
- public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) throws IllegalArgumentException;
+ public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws IllegalArgumentException;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java b/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
index 541469f..2637a96 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
@@ -21,163 +21,174 @@ import java.util.Arrays;
import java.util.Locale;
import java.util.Optional;
-/**
+/**
* Enumeration of the RDF 1.1 serialization syntaxes.
* <p>
- * This enumeration lists the W3C standardized
- * RDF 1.1 syntaxes like {@link #TURTLE} and {@link #JSONLD}.
- * Note the existence of other RDF syntaxes that are not included here,
- * e.g. <a href="http://www.w3.org/TeamSubmission/n3/">N3</a>
- * and <a href="https://en.wikipedia.org/wiki/TriX_%28syntax%29">TriX</a>.
+ * This enumeration lists the W3C standardized RDF 1.1 syntaxes like
+ * {@link #TURTLE} and {@link #JSONLD}. Note the existence of other RDF syntaxes
+ * that are not included here, e.g.
+ * <a href="http://www.w3.org/TeamSubmission/n3/">N3</a> and
+ * <a href="https://en.wikipedia.org/wiki/TriX_%28syntax%29">TriX</a>.
*
- * @see <a href="https://www.w3.org/TR/rdf11-primer/#section-graph-syntax">RDF 1.1 Primer</a>
+ * @see <a href="https://www.w3.org/TR/rdf11-primer/#section-graph-syntax">RDF
+ * 1.1 Primer</a>
* @see org.apache.commons.rdf.experimental.RDFParser
*/
public enum RDFSyntax {
-
- /**
- * JSON-LD 1.0
- *
- * @see <a href="https://www.w3.org/TR/json-ld/">https://www.w3.org/TR/json-ld/</a>
- *
- */
- JSONLD("JSON-LD 1.0", "application/ld+json", ".jsonld", true),
-
- /**
- * RDF 1.1 Turtle
- *
- * @see <a href="https://www.w3.org/TR/turtle/">https://www.w3.org/TR/turtle/</a>
- *
- */
- TURTLE("RDF 1.1 Turtle", "text/turtle", ".ttl", false),
-
- /**
- * RDF 1.1 N-Quads
- *
- * @see <a href="https://www.w3.org/TR/n-quads/">https://www.w3.org/TR/n-quads/</a>
- */
- NQUADS("RDF 1.1 N-Quads", "application/n-quads", ".nq", true),
-
- /**
- * RDF 1.1 N-Triples
- *
- * @see <a href="https://www.w3.org/TR/n-triples/">https://www.w3.org/TR/n-triples/</a>
- */
- NTRIPLES("RDF 1.1 N-Triples", "application/n-triples", ".nt", false),
-
- /**
- * HTML+RDFa 1.1
- *
- * @see <a href="https://www.w3.org/TR/html-rdfa/">https://www.w3.org/TR/html-rdfa/</a>
- */
- RDFA_HTML("HTML+RDFa 1.1", "text/html", ".html", false),
-
- /**
- * XHTML+RDFa 1.1
- *
- * @see <a href="https://www.w3.org/TR/xhtml-rdfa/">https://www.w3.org/TR/xhtml-rdfa/</a>
- */
- RDFA_XHTML("XHTML+RDFa 1.1", "application/xhtml+xml", ".xhtml", false),
-
- /**
- * RDF 1.1 XML Syntax
- *
- * @see <a href="https://www.w3.org/TR/rdf-syntax-grammar/">https://www.w3.org/TR/rdf-syntax-grammar/</a>
- */
- RDFXML("RDF 1.1 XML Syntax", "application/rdf+xml", ".rdf", false),
-
- /**
- * RDF 1.1 TriG
- *
- * @see <a href="https://www.w3.org/TR/trig/">https://www.w3.org/TR/trig/</a>
- */
- TRIG("RDF 1.1 TriG", "application/trig", ".trig", true);
-
- /**
- * The <a href="https://tools.ietf.org/html/rfc2046">IANA media type</a> for the RDF syntax.
- * <p>
- * The media type can be used as part of
- * <code>Content-Type</code>
- * and <code>Accept</code> for <em>content negotiation</em> in the
- * <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP protocol</a>.
- */
- public final String mediaType;
-
- /**
- * The <a href="https://tools.ietf.org/html/rfc2046">IANA-registered</a> file extension.
- * <p>
- * The file extension includes the leading period, e.g. <code>.jsonld</code>
- */
- public final String fileExtension;
-
- /**
- * Indicate if this RDF syntax supports <a href="https://www.w3.org/TR/rdf11-concepts/#section-dataset">RDF Datasets</a>.
- */
- public final boolean supportsDataset;
-
- private final String name;
-
- /**
- * A human-readable name for the RDF syntax.
- * <p>
- * The name is equivalent to the the title of the corresponding W3C Specification.
- */
- @Override
- public String toString() {
- return name;
- }
-
- private RDFSyntax(String name, String mediaType, String fileExtension, boolean supportsDataset) {
- this.name = name;
- this.mediaType = mediaType;
- this.fileExtension = fileExtension;
- this.supportsDataset = supportsDataset;
- }
-
- /**
- * Return the RDFSyntax with the specified media type.
- * <p>
- * The <code>mediaType</code> is compared in lower case, therefore it might
- * not be equal to the {@link RDFSyntax#mediaType} of the returned
- * RDFSyntax.
- * <p>
- * For convenience matching of media types used in a
- * <code>Content-Type</code> header, if the <code>mediaType</code> contains
- * the characters <code>;</code>, <code>,</code> or white space, only the
- * part of the string to the left of those characters are considered.
- *
- * @param mediaType
- * The media type to match
- * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
- * a matching {@link RDFSyntax#mediaType}, otherwise
- * {@link Optional#empty()} indicating that
- * no matching syntax was found.
- */
- public static Optional<RDFSyntax> byMediaType(String mediaType) {
- final String type = mediaType.toLowerCase(Locale.ENGLISH).
- split("\\s*[;,]", 2)[0];
- return Arrays.stream(RDFSyntax.values()).filter(
- t -> t.mediaType.equals(type)).findAny();
- }
-
- /**
- * Return the RDFSyntax with the specified file extension.
- * <p>
- * The <code>fileExtension</code> is compared in lower case, therefore it
- * might not be equal to the {@link RDFSyntax#fileExtension} of the returned
- * RDFSyntax.
- *
- * @param fileExtension
- * The fileExtension to match, starting with <code>.</code>
- * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
- * a matching {@link RDFSyntax#fileExtension}, otherwise
- * {@link Optional#empty()} indicating that no matching file
- * extension was found.
- */
- public static Optional<RDFSyntax> byFileExtension(String fileExtension) {
- final String ext = fileExtension.toLowerCase(Locale.ENGLISH);
- return Arrays.stream(RDFSyntax.values()).filter(
- t -> t.fileExtension.equals(ext)).findAny();
- }
+
+ /**
+ * JSON-LD 1.0
+ *
+ * @see <a href=
+ * "https://www.w3.org/TR/json-ld/">https://www.w3.org/TR/json-ld/</a>
+ *
+ */
+ JSONLD("JSON-LD 1.0", "application/ld+json", ".jsonld", true),
+
+ /**
+ * RDF 1.1 Turtle
+ *
+ * @see <a href=
+ * "https://www.w3.org/TR/turtle/">https://www.w3.org/TR/turtle/</a>
+ *
+ */
+ TURTLE("RDF 1.1 Turtle", "text/turtle", ".ttl", false),
+
+ /**
+ * RDF 1.1 N-Quads
+ *
+ * @see <a href=
+ * "https://www.w3.org/TR/n-quads/">https://www.w3.org/TR/n-quads/</a>
+ */
+ NQUADS("RDF 1.1 N-Quads", "application/n-quads", ".nq", true),
+
+ /**
+ * RDF 1.1 N-Triples
+ *
+ * @see <a href=
+ * "https://www.w3.org/TR/n-triples/">https://www.w3.org/TR/n-triples/</a>
+ */
+ NTRIPLES("RDF 1.1 N-Triples", "application/n-triples", ".nt", false),
+
+ /**
+ * HTML+RDFa 1.1
+ *
+ * @see <a href=
+ * "https://www.w3.org/TR/html-rdfa/">https://www.w3.org/TR/html-rdfa/</a>
+ */
+ RDFA_HTML("HTML+RDFa 1.1", "text/html", ".html", false),
+
+ /**
+ * XHTML+RDFa 1.1
+ *
+ * @see <a href=
+ * "https://www.w3.org/TR/xhtml-rdfa/">https://www.w3.org/TR/xhtml-rdfa/</a>
+ */
+ RDFA_XHTML("XHTML+RDFa 1.1", "application/xhtml+xml", ".xhtml", false),
+
+ /**
+ * RDF 1.1 XML Syntax
+ *
+ * @see <a href=
+ * "https://www.w3.org/TR/rdf-syntax-grammar/">https://www.w3.org/TR/rdf-syntax-grammar/</a>
+ */
+ RDFXML("RDF 1.1 XML Syntax", "application/rdf+xml", ".rdf", false),
+
+ /**
+ * RDF 1.1 TriG
+ *
+ * @see <a href=
+ * "https://www.w3.org/TR/trig/">https://www.w3.org/TR/trig/</a>
+ */
+ TRIG("RDF 1.1 TriG", "application/trig", ".trig", true);
+
+ /**
+ * The <a href="https://tools.ietf.org/html/rfc2046">IANA media type</a> for
+ * the RDF syntax.
+ * <p>
+ * The media type can be used as part of <code>Content-Type</code> and
+ * <code>Accept</code> for <em>content negotiation</em> in the
+ * <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP
+ * protocol</a>.
+ */
+ public final String mediaType;
+
+ /**
+ * The <a href="https://tools.ietf.org/html/rfc2046">IANA-registered</a>
+ * file extension.
+ * <p>
+ * The file extension includes the leading period, e.g. <code>.jsonld</code>
+ */
+ public final String fileExtension;
+
+ /**
+ * Indicate if this RDF syntax supports
+ * <a href="https://www.w3.org/TR/rdf11-concepts/#section-dataset">RDF
+ * Datasets</a>.
+ */
+ public final boolean supportsDataset;
+
+ private final String name;
+
+ /**
+ * A human-readable name for the RDF syntax.
+ * <p>
+ * The name is equivalent to the the title of the corresponding W3C
+ * Specification.
+ */
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ private RDFSyntax(String name, String mediaType, String fileExtension, boolean supportsDataset) {
+ this.name = name;
+ this.mediaType = mediaType;
+ this.fileExtension = fileExtension;
+ this.supportsDataset = supportsDataset;
+ }
+
+ /**
+ * Return the RDFSyntax with the specified media type.
+ * <p>
+ * The <code>mediaType</code> is compared in lower case, therefore it might
+ * not be equal to the {@link RDFSyntax#mediaType} of the returned
+ * RDFSyntax.
+ * <p>
+ * For convenience matching of media types used in a
+ * <code>Content-Type</code> header, if the <code>mediaType</code> contains
+ * the characters <code>;</code>, <code>,</code> or white space, only the
+ * part of the string to the left of those characters are considered.
+ *
+ * @param mediaType
+ * The media type to match
+ * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
+ * a matching {@link RDFSyntax#mediaType}, otherwise
+ * {@link Optional#empty()} indicating that no matching syntax was
+ * found.
+ */
+ public static Optional<RDFSyntax> byMediaType(String mediaType) {
+ final String type = mediaType.toLowerCase(Locale.ENGLISH).split("\\s*[;,]", 2)[0];
+ return Arrays.stream(RDFSyntax.values()).filter(t -> t.mediaType.equals(type)).findAny();
+ }
+
+ /**
+ * Return the RDFSyntax with the specified file extension.
+ * <p>
+ * The <code>fileExtension</code> is compared in lower case, therefore it
+ * might not be equal to the {@link RDFSyntax#fileExtension} of the returned
+ * RDFSyntax.
+ *
+ * @param fileExtension
+ * The fileExtension to match, starting with <code>.</code>
+ * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
+ * a matching {@link RDFSyntax#fileExtension}, otherwise
+ * {@link Optional#empty()} indicating that no matching file
+ * extension was found.
+ */
+ public static Optional<RDFSyntax> byFileExtension(String fileExtension) {
+ final String ext = fileExtension.toLowerCase(Locale.ENGLISH);
+ return Arrays.stream(RDFSyntax.values()).filter(t -> t.fileExtension.equals(ext)).findAny();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
index 59d8fa1..2b69b24 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
@@ -32,11 +32,12 @@ package org.apache.commons.rdf.api;
public interface RDFTerm {
/**
- * Return the term serialised as specified by the RDF-1.1 N-Triples Canonical form.
+ * Return the term serialised as specified by the RDF-1.1 N-Triples
+ * Canonical form.
*
* @return The term serialised as RDF-1.1 N-Triples.
* @see <a href="http://www.w3.org/TR/n-triples/#canonical-ntriples">
- * RDF-1.1 N-Triples Canonical form</a>
+ * RDF-1.1 N-Triples Canonical form</a>
*/
String ntriplesString();
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
index 37c4ead..f245cce 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
@@ -20,8 +20,8 @@ package org.apache.commons.rdf.api;
/**
* Factory for creating RDFTerm instances..
* <p>
- * This interface is <strong>deprecated</strong> in favour of
- * the richer {@link RDF}.
+ * This interface is <strong>deprecated</strong> in favour of the richer
+ * {@link RDF}.
*
* @see RDF
*/
@@ -29,49 +29,38 @@ package org.apache.commons.rdf.api;
public interface RDFTermFactory {
default BlankNode createBlankNode() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createBlankNode() not supported");
+ throw new UnsupportedOperationException("createBlankNode() not supported");
}
- default BlankNode createBlankNode(String name)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createBlankNode(String) not supported");
+ default BlankNode createBlankNode(String name) throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("createBlankNode(String) not supported");
}
default Graph createGraph() throws UnsupportedOperationException {
throw new UnsupportedOperationException("createGraph() not supported");
}
- default IRI createIRI(String iri) throws IllegalArgumentException,
- UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createIRI(String) not supported");
+ default IRI createIRI(String iri) throws IllegalArgumentException, UnsupportedOperationException {
+ throw new UnsupportedOperationException("createIRI(String) not supported");
}
- default Literal createLiteral(String lexicalForm)
- throws IllegalArgumentException, UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createLiteral(String) not supported");
+ default Literal createLiteral(String lexicalForm) throws IllegalArgumentException, UnsupportedOperationException {
+ throw new UnsupportedOperationException("createLiteral(String) not supported");
}
default Literal createLiteral(String lexicalForm, IRI dataType)
throws IllegalArgumentException, UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createLiteral(String) not supported");
+ throw new UnsupportedOperationException("createLiteral(String) not supported");
}
default Literal createLiteral(String lexicalForm, String languageTag)
throws IllegalArgumentException, UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createLiteral(String,String) not supported");
+ throw new UnsupportedOperationException("createLiteral(String,String) not supported");
}
- default Triple createTriple(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) throws IllegalArgumentException,
- UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createTriple(BlankNodeOrIRI,IRI,RDFTerm) not supported");
+ default Triple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws IllegalArgumentException, UnsupportedOperationException {
+ throw new UnsupportedOperationException("createTriple(BlankNodeOrIRI,IRI,RDFTerm) not supported");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/api/Triple.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Triple.java b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
index b0866bd..ef9bdaa 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Triple.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
@@ -21,14 +21,14 @@ import java.util.Objects;
/**
* An <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple" >RDF-1.1
- * Triple</a>, as defined by <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.<br>
+ * Triple</a>, as defined by
+ * <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.<br>
*
- * @see Quad
+ * @see Quad
* @see RDF#createTriple(BlankNodeOrIRI,IRI,RDFTerm)
* @see <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple" >RDF-1.1
- * Triple</a>
+ * Triple</a>
*/
public interface Triple extends TripleLike {
@@ -39,7 +39,7 @@ public interface Triple extends TripleLike {
*
* @return The subject {@link BlankNodeOrIRI} of this triple.
* @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-subject">RDF-1.1
- * Triple subject</a>
+ * Triple subject</a>
*/
BlankNodeOrIRI getSubject();
@@ -48,7 +48,7 @@ public interface Triple extends TripleLike {
*
* @return The predicate {@link IRI} of this triple.
* @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-predicate">RDF-1.1
- * Triple predicate</a>
+ * Triple predicate</a>
*/
IRI getPredicate();
@@ -59,7 +59,7 @@ public interface Triple extends TripleLike {
*
* @return The object {@link RDFTerm} of this triple.
* @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-object">RDF-1.1
- * Triple object</a>
+ * Triple object</a>
*/
RDFTerm getObject();
@@ -74,7 +74,8 @@ public interface Triple extends TripleLike {
* Triples produce the same hash code.
* </p>
*
- * @param other Another object
+ * @param other
+ * Another object
* @return true if other is a Triple and is equal to this
* @see Object#equals(Object)
*/
@@ -84,13 +85,13 @@ public interface Triple extends TripleLike {
/**
* Calculate a hash code for this Triple.
* <p>
- * The returned hash code MUST be equal to the result
- * of {@link Objects#hash(Object...)} with
- * the arguments
- * {@link #getSubject()}, {@link #getPredicate()}, {@link #getObject()}.
+ * The returned hash code MUST be equal to the result of
+ * {@link Objects#hash(Object...)} with the arguments {@link #getSubject()},
+ * {@link #getPredicate()}, {@link #getObject()}.
* <p>
- * This method MUST be implemented in conjunction with {@link #equals(Object)}
- * so that two equal {@link Triple}s produce the same hash code.
+ * This method MUST be implemented in conjunction with
+ * {@link #equals(Object)} so that two equal {@link Triple}s produce the
+ * same hash code.
*
* @return a hash code value for this Triple.
* @see Object#hashCode()
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java b/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
index 30e303a..b469aa4 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/TripleLike.java
@@ -23,10 +23,9 @@ package org.apache.commons.rdf.api;
* <p>
* A TripleLike statement has at least a {@link #getSubject()},
* {@link #getPredicate()} and {@link #getObject()}, but unlike a {@link Triple}
- * does not have a formalised
- * {@link Triple#equals(Object)} or
- * {@link Triple#hashCode()} semantics. This interfaced can also be
- * used for <em>generalised triples</em> (e.g. a {@link BlankNode} as predicate).
+ * does not have a formalised {@link Triple#equals(Object)} or
+ * {@link Triple#hashCode()} semantics. This interfaced can also be used for
+ * <em>generalised triples</em> (e.g. a {@link BlankNode} as predicate).
* <p>
* Implementations should specialise which specific {@link RDFTerm} types they
* return by overriding {@link #getSubject()}, {@link #getPredicate()} and
@@ -40,25 +39,25 @@ package org.apache.commons.rdf.api;
*/
public interface TripleLike {
- /**
- * The subject of this statement.
- *
- * @return The subject, typically an {@link IRI} or {@link BlankNode}.
- */
- RDFTerm getSubject();
+ /**
+ * The subject of this statement.
+ *
+ * @return The subject, typically an {@link IRI} or {@link BlankNode}.
+ */
+ RDFTerm getSubject();
- /**
- * The predicate of this statement.
- *
- * @return The predicate, typically an {@link IRI}.
- */
- RDFTerm getPredicate();
+ /**
+ * The predicate of this statement.
+ *
+ * @return The predicate, typically an {@link IRI}.
+ */
+ RDFTerm getPredicate();
- /**
- * The object of this statement.
- *
- * @return The object, typically an {@link IRI}, {@link BlankNode} or
- * {@link Literal}.
- */
- RDFTerm getObject();
+ /**
+ * The object of this statement.
+ *
+ * @return The object, typically an {@link IRI}, {@link BlankNode} or
+ * {@link Literal}.
+ */
+ RDFTerm getObject();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/api/package-info.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/package-info.java b/api/src/main/java/org/apache/commons/rdf/api/package-info.java
index 4cecc4f..5099cb0 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/package-info.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/package-info.java
@@ -22,30 +22,26 @@
* are represented by corresponding interfaces:
* <p>
* A {@link org.apache.commons.rdf.api.Graph} is a collection of
- * {@link org.apache.commons.rdf.api.Triple}s,
- * which have a <em>subject</em>, <em>predicate</em> and <em>object</em> of
- * {@link org.apache.commons.rdf.api.RDFTerm}s.
- * The three types of RDF terms are {@link org.apache.commons.rdf.api.IRI},
+ * {@link org.apache.commons.rdf.api.Triple}s, which have a <em>subject</em>,
+ * <em>predicate</em> and <em>object</em> of
+ * {@link org.apache.commons.rdf.api.RDFTerm}s. The three types of RDF terms are
+ * {@link org.apache.commons.rdf.api.IRI},
* {@link org.apache.commons.rdf.api.Literal} and
* {@link org.apache.commons.rdf.api.BlankNode}.
* <p>
* Implementations of this API should provide an
- * {@link org.apache.commons.rdf.api.RDF} to facilitate
- * creation of these objects.
+ * {@link org.apache.commons.rdf.api.RDF} to facilitate creation of these
+ * objects.
* <p>
* All the {@link org.apache.commons.rdf.api.RDFTerm} objects are immutable,
- * while a {@link org.apache.commons.rdf.api.Graph}
- * MAY be mutable (e.g. support methods like
- * {@link org.apache.commons.rdf.api.Graph#add(Triple)}).
+ * while a {@link org.apache.commons.rdf.api.Graph} MAY be mutable (e.g. support
+ * methods like {@link org.apache.commons.rdf.api.Graph#add(Triple)}).
* <p>
- * {@link org.apache.commons.rdf.api.RDFSyntax} enumerates the
- * W3C standard RDF 1.1 syntaxes and their media types.
+ * {@link org.apache.commons.rdf.api.RDFSyntax} enumerates the W3C standard RDF
+ * 1.1 syntaxes and their media types.
* <p>
* For further documentation and contact details, see the
- * <a href="http://commonsrdf.incubator.apache.org/">Commons RDF</a>
- * web site.
+ * <a href="http://commonsrdf.incubator.apache.org/">Commons RDF</a> web site.
*
*/
package org.apache.commons.rdf.api;
-
-
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java b/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
index d5684e4..6c93998 100644
--- a/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
+++ b/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
@@ -37,11 +37,10 @@ import org.apache.commons.rdf.api.Triple;
/**
* Parse an RDF source into a target (e.g. a Graph/Dataset).
- * <h2>Experimental</h2>
- * This interface (and its implementations) should be considered <strong>at
- * risk</strong>; they might change or be removed in the next minor update of
- * Commons RDF. It may move to the the {@link org.apache.commons.rdf.api}
- * package when it has stabilized.
+ * <h2>Experimental</h2> This interface (and its implementations) should be
+ * considered <strong>at risk</strong>; they might change or be removed in the
+ * next minor update of Commons RDF. It may move to the the
+ * {@link org.apache.commons.rdf.api} package when it has stabilized.
* <h2>Description</h2>
* <p>
* This interface follows the
@@ -62,436 +61,425 @@ import org.apache.commons.rdf.api.Triple;
* Setting a method that has already been set will override any existing value
* in the returned builder - regardless of the parameter type (e.g.
* {@link #source(IRI)} will override a previous {@link #source(Path)}. Settings
- * can be unset by passing <code>null</code> - note that this may
- * require casting, e.g. <code>contentType( (RDFSyntax) null )</code>
- * to undo a previous call to {@link #contentType(RDFSyntax)}.
+ * can be unset by passing <code>null</code> - note that this may require
+ * casting, e.g. <code>contentType( (RDFSyntax) null )</code> to undo a previous
+ * call to {@link #contentType(RDFSyntax)}.
* <p>
- * It is undefined if a RDFParser is mutable or thread-safe, so callers
- * should always use the returned modified RDFParser from the builder
- * methods. The builder may return itself after modification,
- * or a cloned builder with the modified settings applied.
- * Implementations are however encouraged to be immutable,
- * thread-safe and document this. As an example starting point, see
+ * It is undefined if a RDFParser is mutable or thread-safe, so callers should
+ * always use the returned modified RDFParser from the builder methods. The
+ * builder may return itself after modification, or a cloned builder with the
+ * modified settings applied. Implementations are however encouraged to be
+ * immutable, thread-safe and document this. As an example starting point, see
* <code>org.apache.commons.rdf.simple.AbstractRDFParser</code>.
* <p>
* Example usage:
* </p>
*
* <pre>
- * Graph g1 = rDFTermFactory.createGraph();
- * new ExampleRDFParserBuilder()
- * .source(Paths.get("/tmp/graph.ttl"))
- * .contentType(RDFSyntax.TURTLE)
- * .target(g1)
- * .parse().get(30, TimeUnit.Seconds);
+ * Graph g1 = rDFTermFactory.createGraph();
+ * new ExampleRDFParserBuilder().source(Paths.get("/tmp/graph.ttl")).contentType(RDFSyntax.TURTLE).target(g1).parse()
+ * .get(30, TimeUnit.Seconds);
* </pre>
*
*/
public interface RDFParser {
- /**
- * The result of {@link RDFParser#parse()} indicating
- * parsing completed.
- * <p>
- * This is a marker interface that may be subclassed to include
- * parser details, e.g. warning messages or triple counts.
- */
- public interface ParseResult {
- }
+ /**
+ * The result of {@link RDFParser#parse()} indicating parsing completed.
+ * <p>
+ * This is a marker interface that may be subclassed to include parser
+ * details, e.g. warning messages or triple counts.
+ */
+ public interface ParseResult {
+ }
- /**
- * Specify which {@link RDF} to use for generating
- * {@link RDFTerm}s.
- * <p>
- * This option may be used together with {@link #target(Graph)} to
- * override the implementation's default factory and graph.
- * <p>
- * <strong>Warning:</strong> Using the same {@link RDF} for
- * multiple {@link #parse()} calls may accidentally merge
- * {@link BlankNode}s having the same label, as the parser may
- * use the {@link RDF#createBlankNode(String)} method
- * from the parsed blank node labels.
- *
- * @see #target(Graph)
- * @param rdfTermFactory
- * {@link RDF} to use for generating RDFTerms.
- * @return An {@link RDFParser} that will use the specified
- * rdfTermFactory
- */
- RDFParser rdfTermFactory(RDF rdfTermFactory);
+ /**
+ * Specify which {@link RDF} to use for generating {@link RDFTerm}s.
+ * <p>
+ * This option may be used together with {@link #target(Graph)} to override
+ * the implementation's default factory and graph.
+ * <p>
+ * <strong>Warning:</strong> Using the same {@link RDF} for multiple
+ * {@link #parse()} calls may accidentally merge {@link BlankNode}s having
+ * the same label, as the parser may use the
+ * {@link RDF#createBlankNode(String)} method from the parsed blank node
+ * labels.
+ *
+ * @see #target(Graph)
+ * @param rdfTermFactory
+ * {@link RDF} to use for generating RDFTerms.
+ * @return An {@link RDFParser} that will use the specified rdfTermFactory
+ */
+ RDFParser rdfTermFactory(RDF rdfTermFactory);
- /**
- * Specify the content type of the RDF syntax to parse.
- * <p>
- * This option can be used to select the RDFSyntax of the source, overriding
- * any <code>Content-Type</code> headers or equivalent.
- * <p>
- * The character set of the RDFSyntax is assumed to be
- * {@link StandardCharsets#UTF_8} unless overridden within the document
- * (e.g. {@code <?xml version="1.0" encoding="iso-8859-1"?>} in
- * {@link RDFSyntax#RDFXML}).
- * <p>
- * This method will override any contentType set with
- * {@link #contentType(String)}.
- *
- * @see #contentType(String)
- * @param rdfSyntax
- * An {@link RDFSyntax} to parse the source according to, e.g.
- * {@link RDFSyntax#TURTLE}.
- * @throws IllegalArgumentException
- * If this RDFParser does not support the specified
- * RDFSyntax.
- * @return An {@link RDFParser} that will use the specified content
- * type.
- */
- RDFParser contentType(RDFSyntax rdfSyntax) throws IllegalArgumentException;
+ /**
+ * Specify the content type of the RDF syntax to parse.
+ * <p>
+ * This option can be used to select the RDFSyntax of the source, overriding
+ * any <code>Content-Type</code> headers or equivalent.
+ * <p>
+ * The character set of the RDFSyntax is assumed to be
+ * {@link StandardCharsets#UTF_8} unless overridden within the document
+ * (e.g. {@code <?xml version="1.0" encoding="iso-8859-1"?>} in
+ * {@link RDFSyntax#RDFXML}).
+ * <p>
+ * This method will override any contentType set with
+ * {@link #contentType(String)}.
+ *
+ * @see #contentType(String)
+ * @param rdfSyntax
+ * An {@link RDFSyntax} to parse the source according to, e.g.
+ * {@link RDFSyntax#TURTLE}.
+ * @throws IllegalArgumentException
+ * If this RDFParser does not support the specified RDFSyntax.
+ * @return An {@link RDFParser} that will use the specified content type.
+ */
+ RDFParser contentType(RDFSyntax rdfSyntax) throws IllegalArgumentException;
- /**
- * Specify the content type of the RDF syntax to parse.
- * <p>
- * This option can be used to select the RDFSyntax of the source, overriding
- * any <code>Content-Type</code> headers or equivalent.
- * <p>
- * The content type MAY include a <code>charset</code> parameter if the RDF
- * media types permit it; the default charset is
- * {@link StandardCharsets#UTF_8} unless overridden within the document.
- * <p>
- * This method will override any contentType set with
- * {@link #contentType(RDFSyntax)}.
- *
- * @see #contentType(RDFSyntax)
- * @param contentType
- * A content-type string, e.g. <code>application/ld+json</code>
- * or <code>text/turtle;charset="UTF-8"</code> as specified by
- * <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">
- * RFC7231</a>.
- * @return An {@link RDFParser} that will use the specified content
- * type.
- * @throws IllegalArgumentException
- * If the contentType has an invalid syntax, or this
- * RDFParser does not support the specified contentType.
- */
- RDFParser contentType(String contentType) throws IllegalArgumentException;
+ /**
+ * Specify the content type of the RDF syntax to parse.
+ * <p>
+ * This option can be used to select the RDFSyntax of the source, overriding
+ * any <code>Content-Type</code> headers or equivalent.
+ * <p>
+ * The content type MAY include a <code>charset</code> parameter if the RDF
+ * media types permit it; the default charset is
+ * {@link StandardCharsets#UTF_8} unless overridden within the document.
+ * <p>
+ * This method will override any contentType set with
+ * {@link #contentType(RDFSyntax)}.
+ *
+ * @see #contentType(RDFSyntax)
+ * @param contentType
+ * A content-type string, e.g. <code>application/ld+json</code>
+ * or <code>text/turtle;charset="UTF-8"</code> as specified by
+ * <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">
+ * RFC7231</a>.
+ * @return An {@link RDFParser} that will use the specified content type.
+ * @throws IllegalArgumentException
+ * If the contentType has an invalid syntax, or this RDFParser
+ * does not support the specified contentType.
+ */
+ RDFParser contentType(String contentType) throws IllegalArgumentException;
- /**
- * Specify a {@link Graph} to add parsed triples to.
- * <p>
- * If the source supports datasets (e.g. the {@link #contentType(RDFSyntax)}
- * set has {@link RDFSyntax#supportsDataset} is true)), then only quads in
- * the <em>default graph</em> will be added to the Graph as {@link Triple}s.
- * <p>
- * It is undefined if any triples are added to the specified {@link Graph}
- * if {@link #parse()} throws any exceptions. (However implementations are
- * free to prevent this using transaction mechanisms or similar). If
- * {@link Future#get()} does not indicate an exception, the parser
- * implementation SHOULD have inserted all parsed triples to the specified
- * graph.
- * <p>
- * Calling this method will override any earlier targets set with
- * {@link #target(Graph)}, {@link #target(Consumer)} or
- * {@link #target(Dataset)}.
- * <p>
- * The default implementation of this method calls {@link #target(Consumer)}
- * with a {@link Consumer} that does {@link Graph#add(Triple)} with
- * {@link Quad#asTriple()} if the quad is in the default graph.
- *
- * @param graph
- * The {@link Graph} to add triples to.
- * @return An {@link RDFParser} that will insert triples into the
- * specified graph.
- */
- default RDFParser target(Graph graph) {
- return target(q -> {
- if (! q.getGraphName().isPresent()) {
- graph.add(q.asTriple());
- }
- });
- }
+ /**
+ * Specify a {@link Graph} to add parsed triples to.
+ * <p>
+ * If the source supports datasets (e.g. the {@link #contentType(RDFSyntax)}
+ * set has {@link RDFSyntax#supportsDataset} is true)), then only quads in
+ * the <em>default graph</em> will be added to the Graph as {@link Triple}s.
+ * <p>
+ * It is undefined if any triples are added to the specified {@link Graph}
+ * if {@link #parse()} throws any exceptions. (However implementations are
+ * free to prevent this using transaction mechanisms or similar). If
+ * {@link Future#get()} does not indicate an exception, the parser
+ * implementation SHOULD have inserted all parsed triples to the specified
+ * graph.
+ * <p>
+ * Calling this method will override any earlier targets set with
+ * {@link #target(Graph)}, {@link #target(Consumer)} or
+ * {@link #target(Dataset)}.
+ * <p>
+ * The default implementation of this method calls {@link #target(Consumer)}
+ * with a {@link Consumer} that does {@link Graph#add(Triple)} with
+ * {@link Quad#asTriple()} if the quad is in the default graph.
+ *
+ * @param graph
+ * The {@link Graph} to add triples to.
+ * @return An {@link RDFParser} that will insert triples into the specified
+ * graph.
+ */
+ default RDFParser target(Graph graph) {
+ return target(q -> {
+ if (!q.getGraphName().isPresent()) {
+ graph.add(q.asTriple());
+ }
+ });
+ }
- /**
- * Specify a {@link Dataset} to add parsed quads to.
- * <p>
- * It is undefined if any quads are added to the specified
- * {@link Dataset} if {@link #parse()} throws any exceptions.
- * (However implementations are free to prevent this using transaction
- * mechanisms or similar). On the other hand, if {@link #parse()}
- * does not indicate an exception, the
- * implementation SHOULD have inserted all parsed quads
- * to the specified dataset.
- * <p>
- * Calling this method will override any earlier targets set with
- * {@link #target(Graph)}, {@link #target(Consumer)} or {@link #target(Dataset)}.
- * <p>
- * The default implementation of this method calls {@link #target(Consumer)}
- * with a {@link Consumer} that does {@link Dataset#add(Quad)}.
- *
- * @param dataset
- * The {@link Dataset} to add quads to.
- * @return An {@link RDFParser} that will insert triples into the
- * specified dataset.
- */
- default RDFParser target(Dataset dataset) {
- return target(dataset::add);
- }
+ /**
+ * Specify a {@link Dataset} to add parsed quads to.
+ * <p>
+ * It is undefined if any quads are added to the specified {@link Dataset}
+ * if {@link #parse()} throws any exceptions. (However implementations are
+ * free to prevent this using transaction mechanisms or similar). On the
+ * other hand, if {@link #parse()} does not indicate an exception, the
+ * implementation SHOULD have inserted all parsed quads to the specified
+ * dataset.
+ * <p>
+ * Calling this method will override any earlier targets set with
+ * {@link #target(Graph)}, {@link #target(Consumer)} or
+ * {@link #target(Dataset)}.
+ * <p>
+ * The default implementation of this method calls {@link #target(Consumer)}
+ * with a {@link Consumer} that does {@link Dataset#add(Quad)}.
+ *
+ * @param dataset
+ * The {@link Dataset} to add quads to.
+ * @return An {@link RDFParser} that will insert triples into the specified
+ * dataset.
+ */
+ default RDFParser target(Dataset dataset) {
+ return target(dataset::add);
+ }
- /**
- * Specify a consumer for parsed quads.
- * <p>
- * The quads will include triples in all named graphs of the parsed
- * source, including any triples in the default graph.
- * When parsing a source format which do not support datasets, all quads
- * delivered to the consumer will be in the default graph
- * (e.g. their {@link Quad#getGraphName()} will be
- * as {@link Optional#empty()}), while for a source
- * <p>
- * It is undefined if any quads are consumed if {@link #parse()} throws any
- * exceptions. On the other hand, if {@link #parse()} does not indicate an
- * exception, the implementation SHOULD have produced all parsed quads to
- * the specified consumer.
- * <p>
- * Calling this method will override any earlier targets set with
- * {@link #target(Graph)}, {@link #target(Consumer)} or
- * {@link #target(Dataset)}.
- * <p>
- * The consumer is not assumed to be thread safe - only one
- * {@link Consumer#accept(Object)} is delivered at a time for a given
- * {@link RDFParser#parse()} call.
- * <p>
- * This method is typically called with a functional consumer, for example:
- * <pre>
- * {@code
- * List<Quad> quads = new ArrayList<Quad>;
- * parserBuilder.target(quads::add).parse();
- * }
- * </pre>
- *
- * @param consumer
- * A {@link Consumer} of {@link Quad}s
- * @return An {@link RDFParser} that will call the consumer for into
- * the specified dataset.
- */
- RDFParser target(Consumer<Quad> consumer);
-
- /**
- * Specify a base IRI to use for parsing any relative IRI references.
- * <p>
- * Setting this option will override any protocol-specific base IRI (e.g.
- * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
- * but does not override any base IRIs set within the source document (e.g.
- * <code>@base</code> in Turtle documents).
- * <p>
- * If the source is in a syntax that does not support relative IRI
- * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
- * <code>base</code> has no effect.
- * <p>
- * This method will override any base IRI set with {@link #base(String)}.
- *
- * @see #base(String)
- * @param base
- * An absolute IRI to use as a base.
- * @return An {@link RDFParser} that will use the specified base IRI.
- */
- RDFParser base(IRI base);
+ /**
+ * Specify a consumer for parsed quads.
+ * <p>
+ * The quads will include triples in all named graphs of the parsed source,
+ * including any triples in the default graph. When parsing a source format
+ * which do not support datasets, all quads delivered to the consumer will
+ * be in the default graph (e.g. their {@link Quad#getGraphName()} will be
+ * as {@link Optional#empty()}), while for a source
+ * <p>
+ * It is undefined if any quads are consumed if {@link #parse()} throws any
+ * exceptions. On the other hand, if {@link #parse()} does not indicate an
+ * exception, the implementation SHOULD have produced all parsed quads to
+ * the specified consumer.
+ * <p>
+ * Calling this method will override any earlier targets set with
+ * {@link #target(Graph)}, {@link #target(Consumer)} or
+ * {@link #target(Dataset)}.
+ * <p>
+ * The consumer is not assumed to be thread safe - only one
+ * {@link Consumer#accept(Object)} is delivered at a time for a given
+ * {@link RDFParser#parse()} call.
+ * <p>
+ * This method is typically called with a functional consumer, for example:
+ *
+ * <pre>
+ * {@code
+ * List<Quad> quads = new ArrayList<Quad>;
+ * parserBuilder.target(quads::add).parse();
+ * }
+ * </pre>
+ *
+ * @param consumer
+ * A {@link Consumer} of {@link Quad}s
+ * @return An {@link RDFParser} that will call the consumer for into the
+ * specified dataset.
+ */
+ RDFParser target(Consumer<Quad> consumer);
- /**
- * Specify a base IRI to use for parsing any relative IRI references.
- * <p>
- * Setting this option will override any protocol-specific base IRI (e.g.
- * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
- * but does not override any base IRIs set within the source document (e.g.
- * <code>@base</code> in Turtle documents).
- * <p>
- * If the source is in a syntax that does not support relative IRI
- * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
- * <code>base</code> has no effect.
- * <p>
- * This method will override any base IRI set with {@link #base(IRI)}.
- *
- * @see #base(IRI)
- * @param base
- * An absolute IRI to use as a base.
- * @return An {@link RDFParser} that will use the specified base IRI.
- * @throws IllegalArgumentException
- * If the base is not a valid absolute IRI string
- */
- RDFParser base(String base) throws IllegalArgumentException;
+ /**
+ * Specify a base IRI to use for parsing any relative IRI references.
+ * <p>
+ * Setting this option will override any protocol-specific base IRI (e.g.
+ * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
+ * but does not override any base IRIs set within the source document (e.g.
+ * <code>@base</code> in Turtle documents).
+ * <p>
+ * If the source is in a syntax that does not support relative IRI
+ * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
+ * <code>base</code> has no effect.
+ * <p>
+ * This method will override any base IRI set with {@link #base(String)}.
+ *
+ * @see #base(String)
+ * @param base
+ * An absolute IRI to use as a base.
+ * @return An {@link RDFParser} that will use the specified base IRI.
+ */
+ RDFParser base(IRI base);
- /**
- * Specify a source {@link InputStream} to parse.
- * <p>
- * The source set will not be read before the call to {@link #parse()}.
- * <p>
- * The InputStream will not be closed after parsing. The InputStream does
- * not need to support {@link InputStream#markSupported()}.
- * <p>
- * The parser might not consume the complete stream (e.g. an RDF/XML parser
- * may not read beyond the closing tag of
- * <code></rdf:Description></code>).
- * <p>
- * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
- * SHOULD be set before calling {@link #parse()}.
- * <p>
- * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
- * the {@link #contentType(String)} specifies otherwise or the document
- * declares its own charset (e.g. RDF/XML with a
- * <code><?xml encoding="iso-8859-1"></code> header).
- * <p>
- * The {@link #base(IRI)} or {@link #base(String)} MUST be set before
- * calling {@link #parse()}, unless the RDF syntax does not permit relative
- * IRIs (e.g. {@link RDFSyntax#NTRIPLES}).
- * <p>
- * This method will override any source set with {@link #source(IRI)},
- * {@link #source(Path)} or {@link #source(String)}.
- *
- * @param inputStream
- * An InputStream to consume
- * @return An {@link RDFParser} that will use the specified source.
- */
- RDFParser source(InputStream inputStream);
+ /**
+ * Specify a base IRI to use for parsing any relative IRI references.
+ * <p>
+ * Setting this option will override any protocol-specific base IRI (e.g.
+ * <code>Content-Location</code> header) or the {@link #source(IRI)} IRI,
+ * but does not override any base IRIs set within the source document (e.g.
+ * <code>@base</code> in Turtle documents).
+ * <p>
+ * If the source is in a syntax that does not support relative IRI
+ * references (e.g. {@link RDFSyntax#NTRIPLES}), setting the
+ * <code>base</code> has no effect.
+ * <p>
+ * This method will override any base IRI set with {@link #base(IRI)}.
+ *
+ * @see #base(IRI)
+ * @param base
+ * An absolute IRI to use as a base.
+ * @return An {@link RDFParser} that will use the specified base IRI.
+ * @throws IllegalArgumentException
+ * If the base is not a valid absolute IRI string
+ */
+ RDFParser base(String base) throws IllegalArgumentException;
- /**
- * Specify a source file {@link Path} to parse.
- * <p>
- * The source set will not be read before the call to {@link #parse()}.
- * <p>
- * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
- * SHOULD be set before calling {@link #parse()}.
- * <p>
- * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
- * the {@link #contentType(String)} specifies otherwise or the document
- * declares its own charset (e.g. RDF/XML with a
- * <code><?xml encoding="iso-8859-1"></code> header).
- * <p>
- * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
- * {@link #parse()}, otherwise {@link Path#toUri()} will be used as the base
- * IRI.
- * <p>
- * This method will override any source set with {@link #source(IRI)},
- * {@link #source(InputStream)} or {@link #source(String)}.
- *
- * @param file
- * A Path for a file to parse
- * @return An {@link RDFParser} that will use the specified source.
- */
- RDFParser source(Path file);
+ /**
+ * Specify a source {@link InputStream} to parse.
+ * <p>
+ * The source set will not be read before the call to {@link #parse()}.
+ * <p>
+ * The InputStream will not be closed after parsing. The InputStream does
+ * not need to support {@link InputStream#markSupported()}.
+ * <p>
+ * The parser might not consume the complete stream (e.g. an RDF/XML parser
+ * may not read beyond the closing tag of
+ * <code></rdf:Description></code>).
+ * <p>
+ * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
+ * SHOULD be set before calling {@link #parse()}.
+ * <p>
+ * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
+ * the {@link #contentType(String)} specifies otherwise or the document
+ * declares its own charset (e.g. RDF/XML with a
+ * <code><?xml encoding="iso-8859-1"></code> header).
+ * <p>
+ * The {@link #base(IRI)} or {@link #base(String)} MUST be set before
+ * calling {@link #parse()}, unless the RDF syntax does not permit relative
+ * IRIs (e.g. {@link RDFSyntax#NTRIPLES}).
+ * <p>
+ * This method will override any source set with {@link #source(IRI)},
+ * {@link #source(Path)} or {@link #source(String)}.
+ *
+ * @param inputStream
+ * An InputStream to consume
+ * @return An {@link RDFParser} that will use the specified source.
+ */
+ RDFParser source(InputStream inputStream);
- /**
- * Specify an absolute source {@link IRI} to retrieve and parse.
- * <p>
- * The source set will not be read before the call to {@link #parse()}.
- * <p>
- * If this builder does not support the given IRI protocol (e.g.
- * <code>urn:uuid:ce667463-c5ab-4c23-9b64-701d055c4890</code>), this method
- * should succeed, while the {@link #parse()} should throw an
- * {@link IOException}.
- * <p>
- * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)} MAY
- * be set before calling {@link #parse()}, in which case that type MAY be
- * used for content negotiation (e.g. <code>Accept</code> header in HTTP),
- * and SHOULD be used for selecting the RDFSyntax.
- * <p>
- * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
- * the protocol's equivalent of <code>Content-Type</code> specifies
- * otherwise or the document declares its own charset (e.g. RDF/XML with a
- * <code><?xml encoding="iso-8859-1"></code> header).
- * <p>
- * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
- * {@link #parse()}, otherwise the source IRI will be used as the base IRI.
- * <p>
- * This method will override any source set with {@link #source(Path)},
- * {@link #source(InputStream)} or {@link #source(String)}.
- *
- * @param iri
- * An IRI to retrieve and parse
- * @return An {@link RDFParser} that will use the specified source.
- */
- RDFParser source(IRI iri);
+ /**
+ * Specify a source file {@link Path} to parse.
+ * <p>
+ * The source set will not be read before the call to {@link #parse()}.
+ * <p>
+ * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
+ * SHOULD be set before calling {@link #parse()}.
+ * <p>
+ * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
+ * the {@link #contentType(String)} specifies otherwise or the document
+ * declares its own charset (e.g. RDF/XML with a
+ * <code><?xml encoding="iso-8859-1"></code> header).
+ * <p>
+ * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
+ * {@link #parse()}, otherwise {@link Path#toUri()} will be used as the base
+ * IRI.
+ * <p>
+ * This method will override any source set with {@link #source(IRI)},
+ * {@link #source(InputStream)} or {@link #source(String)}.
+ *
+ * @param file
+ * A Path for a file to parse
+ * @return An {@link RDFParser} that will use the specified source.
+ */
+ RDFParser source(Path file);
- /**
- * Specify an absolute source IRI to retrieve and parse.
- * <p>
- * The source set will not be read before the call to {@link #parse()}.
- * <p>
- * If this builder does not support the given IRI (e.g.
- * <code>urn:uuid:ce667463-c5ab-4c23-9b64-701d055c4890</code>), this method
- * should succeed, while the {@link #parse()} should throw an
- * {@link IOException}.
- * <p>
- * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)} MAY
- * be set before calling {@link #parse()}, in which case that type MAY be
- * used for content negotiation (e.g. <code>Accept</code> header in HTTP),
- * and SHOULD be used for selecting the RDFSyntax.
- * <p>
- * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
- * the protocol's equivalent of <code>Content-Type</code> specifies
- * otherwise or the document declares its own charset (e.g. RDF/XML with a
- * <code><?xml encoding="iso-8859-1"></code> header).
- * <p>
- * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
- * {@link #parse()}, otherwise the source IRI will be used as the base IRI.
- * <p>
- * This method will override any source set with {@link #source(Path)},
- * {@link #source(InputStream)} or {@link #source(IRI)}.
- *
- * @param iri
- * An IRI to retrieve and parse
- * @return An {@link RDFParser} that will use the specified source.
- * @throws IllegalArgumentException
- * If the base is not a valid absolute IRI string
- *
- */
- RDFParser source(String iri) throws IllegalArgumentException;
+ /**
+ * Specify an absolute source {@link IRI} to retrieve and parse.
+ * <p>
+ * The source set will not be read before the call to {@link #parse()}.
+ * <p>
+ * If this builder does not support the given IRI protocol (e.g.
+ * <code>urn:uuid:ce667463-c5ab-4c23-9b64-701d055c4890</code>), this method
+ * should succeed, while the {@link #parse()} should throw an
+ * {@link IOException}.
+ * <p>
+ * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)} MAY
+ * be set before calling {@link #parse()}, in which case that type MAY be
+ * used for content negotiation (e.g. <code>Accept</code> header in HTTP),
+ * and SHOULD be used for selecting the RDFSyntax.
+ * <p>
+ * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
+ * the protocol's equivalent of <code>Content-Type</code> specifies
+ * otherwise or the document declares its own charset (e.g. RDF/XML with a
+ * <code><?xml encoding="iso-8859-1"></code> header).
+ * <p>
+ * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
+ * {@link #parse()}, otherwise the source IRI will be used as the base IRI.
+ * <p>
+ * This method will override any source set with {@link #source(Path)},
+ * {@link #source(InputStream)} or {@link #source(String)}.
+ *
+ * @param iri
+ * An IRI to retrieve and parse
+ * @return An {@link RDFParser} that will use the specified source.
+ */
+ RDFParser source(IRI iri);
- /**
- * Parse the specified source.
- * <p>
- * A source method (e.g. {@link #source(InputStream)}, {@link #source(IRI)},
- * {@link #source(Path)}, {@link #source(String)} or an equivalent subclass
- * method) MUST have been called before calling this method, otherwise an
- * {@link IllegalStateException} will be thrown.
- * <p>
- * A target method (e.g. {@link #target(Consumer)}, {@link #target(Dataset)},
- * {@link #target(Graph)} or an equivalent subclass method) MUST have been
- * called before calling parse(), otherwise an
- * {@link IllegalStateException} will be thrown.
- * <p>
- * It is undefined if this method is thread-safe, however the
- * {@link RDFParser} may be reused (e.g. setting a different source)
- * as soon as the {@link Future} has been returned from this method.
- * <p>
- * The RDFParser SHOULD perform the parsing as an asynchronous
- * operation, and return the {@link Future} as soon as preliminary checks
- * (such as validity of the {@link #source(IRI)} and
- * {@link #contentType(RDFSyntax)} settings) have finished. The future
- * SHOULD not mark {@link Future#isDone()} before parsing is complete. A
- * synchronous implementation MAY be blocking on the <code>parse()</code>
- * call and return a Future that is already {@link Future#isDone()}.
- * <p>
- * The returned {@link Future} contains a {@link ParseResult}.
- * Implementations may subclass this interface to provide any
- * parser details, e.g. list of warnings. <code>null</code> is a
- * possible return value if no details are available, but
- * parsing succeeded.
- * <p>
- * If an exception occurs during parsing, (e.g. {@link IOException} or
- * <code>org.apache.commons.rdf.simple.experimental.RDFParseException</code>),
- * it should be indicated as the
- * {@link java.util.concurrent.ExecutionException#getCause()} in the
- * {@link java.util.concurrent.ExecutionException} thrown on
- * {@link Future#get()}.
- *
- * @return A Future that will return the populated {@link Graph} when the
- * parsing has finished.
- * @throws IOException
- * If an error occurred while starting to read the source (e.g.
- * file not found, unsupported IRI protocol). Note that IO
- * errors during parsing would instead be the
- * {@link java.util.concurrent.ExecutionException#getCause()} of
- * the {@link java.util.concurrent.ExecutionException} thrown on
- * {@link Future#get()}.
- * @throws IllegalStateException
- * If the builder is in an invalid state, e.g. a
- * <code>source</code> has not been set.
- */
- Future<? extends ParseResult> parse() throws IOException, IllegalStateException;
+ /**
+ * Specify an absolute source IRI to retrieve and parse.
+ * <p>
+ * The source set will not be read before the call to {@link #parse()}.
+ * <p>
+ * If this builder does not support the given IRI (e.g.
+ * <code>urn:uuid:ce667463-c5ab-4c23-9b64-701d055c4890</code>), this method
+ * should succeed, while the {@link #parse()} should throw an
+ * {@link IOException}.
+ * <p>
+ * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)} MAY
+ * be set before calling {@link #parse()}, in which case that type MAY be
+ * used for content negotiation (e.g. <code>Accept</code> header in HTTP),
+ * and SHOULD be used for selecting the RDFSyntax.
+ * <p>
+ * The character set is assumed to be {@link StandardCharsets#UTF_8} unless
+ * the protocol's equivalent of <code>Content-Type</code> specifies
+ * otherwise or the document declares its own charset (e.g. RDF/XML with a
+ * <code><?xml encoding="iso-8859-1"></code> header).
+ * <p>
+ * The {@link #base(IRI)} or {@link #base(String)} MAY be set before calling
+ * {@link #parse()}, otherwise the source IRI will be used as the base IRI.
+ * <p>
+ * This method will override any source set with {@link #source(Path)},
+ * {@link #source(InputStream)} or {@link #source(IRI)}.
+ *
+ * @param iri
+ * An IRI to retrieve and parse
+ * @return An {@link RDFParser} that will use the specified source.
+ * @throws IllegalArgumentException
+ * If the base is not a valid absolute IRI string
+ *
+ */
+ RDFParser source(String iri) throws IllegalArgumentException;
+
+ /**
+ * Parse the specified source.
+ * <p>
+ * A source method (e.g. {@link #source(InputStream)}, {@link #source(IRI)},
+ * {@link #source(Path)}, {@link #source(String)} or an equivalent subclass
+ * method) MUST have been called before calling this method, otherwise an
+ * {@link IllegalStateException} will be thrown.
+ * <p>
+ * A target method (e.g. {@link #target(Consumer)},
+ * {@link #target(Dataset)}, {@link #target(Graph)} or an equivalent
+ * subclass method) MUST have been called before calling parse(), otherwise
+ * an {@link IllegalStateException} will be thrown.
+ * <p>
+ * It is undefined if this method is thread-safe, however the
+ * {@link RDFParser} may be reused (e.g. setting a different source) as soon
+ * as the {@link Future} has been returned from this method.
+ * <p>
+ * The RDFParser SHOULD perform the parsing as an asynchronous operation,
+ * and return the {@link Future} as soon as preliminary checks (such as
+ * validity of the {@link #source(IRI)} and {@link #contentType(RDFSyntax)}
+ * settings) have finished. The future SHOULD not mark
+ * {@link Future#isDone()} before parsing is complete. A synchronous
+ * implementation MAY be blocking on the <code>parse()</code> call and
+ * return a Future that is already {@link Future#isDone()}.
+ * <p>
+ * The returned {@link Future} contains a {@link ParseResult}.
+ * Implementations may subclass this interface to provide any parser
+ * details, e.g. list of warnings. <code>null</code> is a possible return
+ * value if no details are available, but parsing succeeded.
+ * <p>
+ * If an exception occurs during parsing, (e.g. {@link IOException} or
+ * <code>org.apache.commons.rdf.simple.experimental.RDFParseException</code>),
+ * it should be indicated as the
+ * {@link java.util.concurrent.ExecutionException#getCause()} in the
+ * {@link java.util.concurrent.ExecutionException} thrown on
+ * {@link Future#get()}.
+ *
+ * @return A Future that will return the populated {@link Graph} when the
+ * parsing has finished.
+ * @throws IOException
+ * If an error occurred while starting to read the source (e.g.
+ * file not found, unsupported IRI protocol). Note that IO
+ * errors during parsing would instead be the
+ * {@link java.util.concurrent.ExecutionException#getCause()} of
+ * the {@link java.util.concurrent.ExecutionException} thrown on
+ * {@link Future#get()}.
+ * @throws IllegalStateException
+ * If the builder is in an invalid state, e.g. a
+ * <code>source</code> has not been set.
+ */
+ Future<? extends ParseResult> parse() throws IOException, IllegalStateException;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java
index b61c64a..31593c5 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java
@@ -28,8 +28,8 @@ import static org.junit.Assert.assertNotEquals;
public abstract class AbstractBlankNodeTest {
/**
- * This method must be overridden by the implementing test to
- * create a {@link BlankNode} to be tested.
+ * This method must be overridden by the implementing test to create a
+ * {@link BlankNode} to be tested.
* <p>
* Each call to this method must provide a new, unique BlankNode.
*
@@ -46,15 +46,15 @@ public abstract class AbstractBlankNodeTest {
* test may be the same object, or they may be different objects.
* </p>
*
- * @param identifier The identifier to use as the reference for creating the blank
- * node that is returned.
+ * @param identifier
+ * The identifier to use as the reference for creating the blank
+ * node that is returned.
* @return A new blank node based on the
*/
protected abstract BlankNode getBlankNode(String identifier);
/**
- * Test method for
- * {@link BlankNode#uniqueReference()}.
+ * Test method for {@link BlankNode#uniqueReference()}.
*/
@Test
public final void testInternalIdentifier() {
@@ -76,35 +76,23 @@ public abstract class AbstractBlankNodeTest {
BlankNode testManual4 = getBlankNode("4");
// Test against our fake stub
- assertNotEquals(testNull.uniqueReference(),
- testAutomatic1.uniqueReference());
- assertNotEquals(testAutomatic1.uniqueReference(),
- testNull.uniqueReference());
- assertNotEquals(testNull.uniqueReference(),
- testManual3a.uniqueReference());
- assertNotEquals(testManual3a.uniqueReference(),
- testNull.uniqueReference());
+ assertNotEquals(testNull.uniqueReference(), testAutomatic1.uniqueReference());
+ assertNotEquals(testAutomatic1.uniqueReference(), testNull.uniqueReference());
+ assertNotEquals(testNull.uniqueReference(), testManual3a.uniqueReference());
+ assertNotEquals(testManual3a.uniqueReference(), testNull.uniqueReference());
// Test the two imported instances against each other
- assertEquals(testAutomatic1.uniqueReference(),
- testAutomatic1.uniqueReference());
- assertEquals(testAutomatic2.uniqueReference(),
- testAutomatic2.uniqueReference());
- assertNotEquals(testAutomatic1.uniqueReference(),
- testAutomatic2.uniqueReference());
- assertNotEquals(testAutomatic2.uniqueReference(),
- testAutomatic1.uniqueReference());
- assertNotEquals(testAutomatic1.uniqueReference(),
- testManual3a.uniqueReference());
- assertEquals(testManual3b.uniqueReference(),
- testManual3a.uniqueReference());
- assertNotEquals(testManual3a.uniqueReference(),
- testManual4.uniqueReference());
+ assertEquals(testAutomatic1.uniqueReference(), testAutomatic1.uniqueReference());
+ assertEquals(testAutomatic2.uniqueReference(), testAutomatic2.uniqueReference());
+ assertNotEquals(testAutomatic1.uniqueReference(), testAutomatic2.uniqueReference());
+ assertNotEquals(testAutomatic2.uniqueReference(), testAutomatic1.uniqueReference());
+ assertNotEquals(testAutomatic1.uniqueReference(), testManual3a.uniqueReference());
+ assertEquals(testManual3b.uniqueReference(), testManual3a.uniqueReference());
+ assertNotEquals(testManual3a.uniqueReference(), testManual4.uniqueReference());
}
/**
- * Test method for
- * {@link BlankNode#equals(java.lang.Object)}.
+ * Test method for {@link BlankNode#equals(java.lang.Object)}.
*/
@Test
public final void testEquals() {
@@ -180,8 +168,7 @@ public abstract class AbstractBlankNodeTest {
}
/**
- * Test method for
- * {@link RDFTerm#ntriplesString()}.
+ * Test method for {@link RDFTerm#ntriplesString()}.
*/
@Test
public final void testNtriplesString() {
@@ -203,30 +190,19 @@ public abstract class AbstractBlankNodeTest {
BlankNode testManual4 = getBlankNode("4");
// Test against our fake stub
- assertNotEquals(testNull.ntriplesString(),
- testAutomatic1.ntriplesString());
- assertNotEquals(testAutomatic1.ntriplesString(),
- testNull.ntriplesString());
- assertNotEquals(testNull.ntriplesString(),
- testManual3a.ntriplesString());
- assertNotEquals(testManual3a.ntriplesString(),
- testNull.ntriplesString());
+ assertNotEquals(testNull.ntriplesString(), testAutomatic1.ntriplesString());
+ assertNotEquals(testAutomatic1.ntriplesString(), testNull.ntriplesString());
+ assertNotEquals(testNull.ntriplesString(), testManual3a.ntriplesString());
+ assertNotEquals(testManual3a.ntriplesString(), testNull.ntriplesString());
// Test the two imported instances against each other
- assertEquals(testAutomatic1.ntriplesString(),
- testAutomatic1.ntriplesString());
- assertEquals(testAutomatic2.ntriplesString(),
- testAutomatic2.ntriplesString());
- assertNotEquals(testAutomatic1.ntriplesString(),
- testAutomatic2.ntriplesString());
- assertNotEquals(testAutomatic2.ntriplesString(),
- testAutomatic1.ntriplesString());
- assertNotEquals(testAutomatic1.ntriplesString(),
- testManual3a.ntriplesString());
- assertEquals(testManual3b.ntriplesString(),
- testManual3a.ntriplesString());
- assertNotEquals(testManual3a.ntriplesString(),
- testManual4.ntriplesString());
+ assertEquals(testAutomatic1.ntriplesString(), testAutomatic1.ntriplesString());
+ assertEquals(testAutomatic2.ntriplesString(), testAutomatic2.ntriplesString());
+ assertNotEquals(testAutomatic1.ntriplesString(), testAutomatic2.ntriplesString());
+ assertNotEquals(testAutomatic2.ntriplesString(), testAutomatic1.ntriplesString());
+ assertNotEquals(testAutomatic1.ntriplesString(), testManual3a.ntriplesString());
+ assertEquals(testManual3b.ntriplesString(), testManual3a.ntriplesString());
+ assertNotEquals(testManual3a.ntriplesString(), testManual4.ntriplesString());
}
}
[14/50] [abbrv] incubator-commonsrdf git commit: SimpleRDFFactory ->
SimpleRDF
Posted by st...@apache.org.
SimpleRDFFactory -> SimpleRDF
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/d261f64f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/d261f64f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/d261f64f
Branch: refs/heads/COMMONSRDF-7
Commit: d261f64f78e1c458d1c81b345a6869b53b5c1497
Parents: a1112a8
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Oct 23 00:49:59 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Oct 23 00:49:59 2016 +0100
----------------------------------------------------------------------
examples/src/example/UserGuideTest.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d261f64f/examples/src/example/UserGuideTest.java
----------------------------------------------------------------------
diff --git a/examples/src/example/UserGuideTest.java b/examples/src/example/UserGuideTest.java
index 7b423cf..fe884dd 100644
--- a/examples/src/example/UserGuideTest.java
+++ b/examples/src/example/UserGuideTest.java
@@ -35,7 +35,7 @@ import org.apache.commons.rdf.api.RDFTerm;
import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.api.TripleLike;
-import org.apache.commons.rdf.simple.SimpleRDFFactory;
+import org.apache.commons.rdf.simple.SimpleRDF;
import org.apache.commons.rdf.simple.Types;
import org.junit.Before;
import org.junit.Test;
@@ -46,7 +46,7 @@ public class UserGuideTest {
@Before
public void factory() {
- factory = new SimpleRDFFactory();
+ factory = new SimpleRDF();
}
@Test
@@ -89,7 +89,7 @@ public class UserGuideTest {
System.out.println(b1.ntriplesString());
System.out.println(b1.equals(factory.createBlankNode("b1")));
- System.out.println(b1.equals(new SimpleRDFFactory().createBlankNode("b1")));
+ System.out.println(b1.equals(new SimpleRDF().createBlankNode("b1")));
System.out.println(bnode.uniqueReference());
}
[10/50] [abbrv] incubator-commonsrdf git commit: SimpleFactory ->
SimpleRDF
Posted by st...@apache.org.
SimpleFactory -> SimpleRDF
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/790b6059
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/790b6059
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/790b6059
Branch: refs/heads/COMMONSRDF-7
Commit: 790b60591d23e5a332932d530f4e98c7e162eb59
Parents: 384a833
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Oct 23 00:44:53 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Oct 23 00:44:53 2016 +0100
----------------------------------------------------------------------
.../commons/rdf/jsonldjava/JsonLdFactory.java | 306 -------------------
.../commons/rdf/jsonldjava/JsonLdRDF.java | 306 +++++++++++++++++++
.../commons/rdf/simple/BlankNodeImpl.java | 2 +-
.../apache/commons/rdf/simple/DatasetImpl.java | 8 +-
.../apache/commons/rdf/simple/GraphImpl.java | 8 +-
.../org/apache/commons/rdf/simple/IRIImpl.java | 2 +-
.../apache/commons/rdf/simple/LiteralImpl.java | 2 +-
.../org/apache/commons/rdf/simple/QuadImpl.java | 2 +-
.../apache/commons/rdf/simple/SimpleRDF.java | 114 +++++++
.../commons/rdf/simple/SimpleRDFFactory.java | 114 -------
.../rdf/simple/SimpleRDFTermFactory.java | 4 +-
.../apache/commons/rdf/simple/TripleImpl.java | 2 +-
.../org/apache/commons/rdf/simple/Types.java | 2 +-
.../simple/experimental/AbstractRDFParser.java | 8 +-
.../apache/commons/rdf/simple/package-info.java | 6 +-
.../org.apache.commons.rdf.api.RDFFactory | 2 +-
.../commons/rdf/simple/DefaultGraphTest.java | 2 +-
.../commons/rdf/simple/SimpleGraphTest.java | 4 +-
.../SimpleNoRelativeIRIRDFTermFactoryTest.java | 2 +-
.../rdf/simple/SimpleRDFTermFactoryTest.java | 2 +-
.../rdf/simple/SimpleServiceLoaderTest.java | 4 +-
.../commons/rdf/simple/TestWritingGraph.java | 2 +-
.../experimental/AbstractRDFParserTest.java | 4 +-
23 files changed, 454 insertions(+), 454 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdFactory.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdFactory.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdFactory.java
deleted file mode 100644
index d5c49f8..0000000
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdFactory.java
+++ /dev/null
@@ -1,306 +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.jsonldjava;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Objects;
-import java.util.UUID;
-
-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.RDFTerm;
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.api.Triple;
-import org.apache.commons.rdf.simple.Types;
-
-import com.github.jsonldjava.core.RDFDataset;
-import com.github.jsonldjava.core.RDFDataset.Node;
-
-public final class JsonLdFactory implements RDF {
-
- final String bnodePrefix;
-
- public JsonLdFactory() {
- // An "outside Graph" bnodePrefix
- this("urn:uuid:" + UUID.randomUUID() + "#b");
- }
-
- JsonLdFactory(String bnodePrefix) {
- this.bnodePrefix = Objects.requireNonNull(bnodePrefix);
- }
-
- /**
- * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Dataset}.
- * <p>
- * Changes to the Commons RDF {@link Dataset} are reflected in the JsonLd
- * {@link RDFDataset} and vice versa.
- *
- * @see #asGraph(RDFDataset)
- * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
- * @return Adapted {@link Dataset}
- */
- public JsonLdDataset asDataset(RDFDataset rdfDataSet) {
- return new JsonLdDatasetImpl(rdfDataSet);
- }
-
- /**
- * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Graph}.
- * <p>
- * Only triples in the <em>default graph</em> are included. To retrieve
- * any other graph, {@link #asDataset(RDFDataset)} together with
- * {@link Dataset#getGraph(BlankNodeOrIRI)}.
- * <p>
- * Changes to the Commons RDF {@link Graph} are reflected in the JsonLd
- * {@link RDFDataset} and vice versa.
- *
- * @see #asDataset(RDFDataset)
- * @see #asUnionGraph(RDFDataset)
- * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
- * @return Adapted {@link Graph} covering the <em>default graph</em>
- */
- public JsonLdGraph asGraph(RDFDataset rdfDataSet) {
- return new JsonLdGraphImpl(rdfDataSet);
- }
-
- public Node asJsonLdNode(RDFTerm term) {
- if (term instanceof JsonLdBlankNode) {
- JsonLdBlankNode jsonLdBlankNode = (JsonLdBlankNode) term;
- if (jsonLdBlankNode.uniqueReference().startsWith(bnodePrefix)) {
- // Only return blank nodes 'as is' if they have the same prefix
- return jsonLdBlankNode.asJsonLdNode();
- }
- } else if (term instanceof JsonLdTerm) {
- // non-Bnodes can always be return as-is
- return ((JsonLdTerm) term).asJsonLdNode();
- }
- if (term instanceof IRI) {
- return new RDFDataset.IRI(((IRI) term).getIRIString());
- }
- if (term instanceof BlankNode) {
- String ref = ((BlankNode) term).uniqueReference();
- if (ref.startsWith(bnodePrefix)) {
- // one of our own (but no longer a JsonLdBlankNode),
- // we can recover the label after our unique prefix
- return new RDFDataset.BlankNode(ref.replace(bnodePrefix, ""));
- }
- // The "foreign" unique reference might not be a valid bnode string,
- // we'll convert to a UUID
- UUID uuid = UUID.nameUUIDFromBytes(ref.getBytes(StandardCharsets.UTF_8));
- return new RDFDataset.BlankNode("_:" + uuid);
- }
- if (term instanceof Literal) {
- Literal literal = (Literal) term;
- return new RDFDataset.Literal(literal.getLexicalForm(), literal.getDatatype().getIRIString(),
- literal.getLanguageTag().orElse(null));
- }
- throw new IllegalArgumentException("RDFTerm not instanceof IRI, BlankNode or Literal: " + term);
- }
-
- /**
- * Adapt a Commons RDF {@link org.apache.commons.rdf.api.Quad} as a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}.
- *
- * @param quad Commons RDF {@link org.apache.commons.rdf.api.Quad} to adapt
- * @return Adapted JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}
- */
- public RDFDataset.Quad asJsonLdQuad(org.apache.commons.rdf.api.Quad quad) {
- BlankNodeOrIRI g = quad.getGraphName().orElse(null);
- return createJsonLdQuad(g, quad.getSubject(), quad.getPredicate(), quad.getObject());
- }
-
- /**
- * Adapt a Commons RDF {@link Triple} as a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}.
- *
- * @param triple Commons RDF {@link Triple} to adapt
- * @return Adapted JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}
- */
- public RDFDataset.Quad asJsonLdQuad(Triple triple) {
- return createJsonLdQuad(null, triple.getSubject(), triple.getPredicate(), triple.getObject());
- }
-
- /**
- * Adapt a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} as a Commons RDF
- * {@link org.apache.commons.rdf.api.Quad}.
- * <p>
- * The underlying JsonLd quad can be retrieved with
- * {@link JsonLdQuad#asJsonLdQuad()}.
- *
- * @param quad
- * A JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} to adapt
- * @return Adapted {@link JsonLdQuad}
- */
- public JsonLdQuad asQuad(final RDFDataset.Quad quad) {
- return new JsonLdQuadImpl(quad, bnodePrefix);
- }
-
- /**
- * Adapt a JsonLd {@link Node} as a Commons RDF {@link RDFTerm}.
- * <p>
- * The underlying node can be retrieved with
- * {@link JsonLdTerm#asJsonLdNode()}.
- *
- * @param node
- * A JsonLd {@link Node} to adapt
- * @return Adapted {@link JsonLdTerm}
- */
- public JsonLdTerm asRDFTerm(final Node node) {
- return asRDFTerm(node, bnodePrefix);
- }
-
- /**
- * Adapt a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} as a Commons RDF
- * {@link org.apache.commons.rdf.api.Triple}.
- * <p>
- * The underlying JsonLd quad can be retrieved with
- * {@link JsonLdTriple#asJsonLdQuad()}.
- *
- * @param quad
- * A JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} to adapt
- * @return Adapted {@link JsonLdTriple}
- */
- public JsonLdTriple asTriple(final RDFDataset.Quad quad) {
- return new JsonLdTripleImpl(quad, bnodePrefix);
- }
-
- /**
- * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Graph}.
- * <p>
- * The graph can be seen as a <em>union graph</em> as it will contains all the
- * triples across all the graphs of the underlying {@link RDFDataset}.
- * <p>
- * Note that some triple operations on a union graph
- * can be inefficient as they need to remove any duplicate
- * triples across the graphs.
- * <p>
- * Changes to the Commons RDF {@link Graph} are reflected in the JsonLd
- * {@link RDFDataset} and vice versa. Triples removed from the graph are
- * removed from <strong>all</strong> graphs, while triples added
- * are added to the <em>default graph</em>.
- *
- * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
- * @return Adapted {@link Dataset}
- */
- public JsonLdUnionGraph asUnionGraph(RDFDataset rdfDataSet) {
- return new JsonLdUnionGraphImpl(rdfDataSet);
- }
-
- @Override
- public JsonLdBlankNode createBlankNode() {
- String id = "_:" + UUID.randomUUID().toString();
- return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
- }
-
- @Override
- public JsonLdBlankNode createBlankNode(String name) {
- String id = "_:" + name;
- // TODO: Check if name is valid JSON-LD BlankNode identifier
- return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
- }
-
- @Override
- public JsonLdDataset createDataset() {
- return new JsonLdDatasetImpl(bnodePrefix);
- }
-
- @Override
- public JsonLdGraph createGraph() {
- return new JsonLdGraphImpl(bnodePrefix);
- }
-
- @Override
- public JsonLdIRI createIRI(String iri) {
- return new JsonLdIRIImpl(iri);
- }
-
- @Override
- public JsonLdLiteral createLiteral(String literal) {
- return new JsonLdLiteralImpl(new RDFDataset.Literal(literal, null, null));
- }
-
- @Override
- public JsonLdLiteral createLiteral(String literal, IRI dataType) {
- return new JsonLdLiteralImpl(new RDFDataset.Literal(literal, dataType.getIRIString(), null));
- }
-
- @Override
- public JsonLdLiteral createLiteral(String literal, String language) {
- return new JsonLdLiteralImpl(new RDFDataset.Literal(literal, Types.RDF_LANGSTRING.getIRIString(), language));
- }
-
- @Override
- public JsonLdQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
- throws IllegalArgumentException, UnsupportedOperationException {
- return new JsonLdQuadImpl(createJsonLdQuad(graphName, subject, predicate, object), bnodePrefix);
- }
-
- @Override
- public JsonLdTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return new JsonLdTripleImpl(createJsonLdQuad(null, subject, predicate, object), bnodePrefix);
- }
-
- String asJsonLdString(BlankNodeOrIRI blankNodeOrIRI) {
- if (blankNodeOrIRI == null) {
- return null;
- }
- if (blankNodeOrIRI instanceof IRI) {
- return ((IRI)blankNodeOrIRI).getIRIString();
- } else if (blankNodeOrIRI instanceof BlankNode) {
- BlankNode blankNode = (BlankNode) blankNodeOrIRI;
- String ref = blankNode.uniqueReference();
- if (ref.startsWith(bnodePrefix)) {
- // One of ours (but possibly not a JsonLdBlankNode) -
- // we can use the suffix directly
- return ref.replace(bnodePrefix, "_:");
- } else {
- // Map to unique bnode identifier, e.g. _:0dbd92ee-ab1a-45e7-bba2-7ade54f87ec5
- UUID uuid = UUID.nameUUIDFromBytes(ref.getBytes(StandardCharsets.UTF_8));
- return "_:"+ uuid;
- }
- } else {
- throw new IllegalArgumentException("Expected a BlankNode or IRI, not: " + blankNodeOrIRI);
- }
- }
-
- JsonLdTerm asRDFTerm(final Node node, String blankNodePrefix) {
- if (node == null) {
- return null; // e.g. default graph
- }
- if (node.isIRI()) {
- return new JsonLdIRIImpl(node);
- } else if (node.isBlankNode()) {
- return new JsonLdBlankNodeImpl(node, blankNodePrefix);
- } else if (node.isLiteral()) {
- // TODO: Our own JsonLdLiteral
- if (node.getLanguage() != null) {
- return createLiteral(node.getValue(), node.getLanguage());
- } else {
- return createLiteral(node.getValue(), createIRI(node.getDatatype()));
- }
- } else {
- throw new IllegalArgumentException("Node is neither IRI, BlankNode nor Literal: " + node);
- }
- }
-
- RDFDataset.Quad createJsonLdQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return new RDFDataset.Quad(asJsonLdNode(subject), asJsonLdNode(predicate), asJsonLdNode(object), asJsonLdString(graphName));
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
new file mode 100644
index 0000000..d5c49f8
--- /dev/null
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
@@ -0,0 +1,306 @@
+/**
+ * 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.jsonldjava;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Objects;
+import java.util.UUID;
+
+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.RDFTerm;
+import org.apache.commons.rdf.api.RDF;
+import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.simple.Types;
+
+import com.github.jsonldjava.core.RDFDataset;
+import com.github.jsonldjava.core.RDFDataset.Node;
+
+public final class JsonLdFactory implements RDF {
+
+ final String bnodePrefix;
+
+ public JsonLdFactory() {
+ // An "outside Graph" bnodePrefix
+ this("urn:uuid:" + UUID.randomUUID() + "#b");
+ }
+
+ JsonLdFactory(String bnodePrefix) {
+ this.bnodePrefix = Objects.requireNonNull(bnodePrefix);
+ }
+
+ /**
+ * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Dataset}.
+ * <p>
+ * Changes to the Commons RDF {@link Dataset} are reflected in the JsonLd
+ * {@link RDFDataset} and vice versa.
+ *
+ * @see #asGraph(RDFDataset)
+ * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
+ * @return Adapted {@link Dataset}
+ */
+ public JsonLdDataset asDataset(RDFDataset rdfDataSet) {
+ return new JsonLdDatasetImpl(rdfDataSet);
+ }
+
+ /**
+ * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Graph}.
+ * <p>
+ * Only triples in the <em>default graph</em> are included. To retrieve
+ * any other graph, {@link #asDataset(RDFDataset)} together with
+ * {@link Dataset#getGraph(BlankNodeOrIRI)}.
+ * <p>
+ * Changes to the Commons RDF {@link Graph} are reflected in the JsonLd
+ * {@link RDFDataset} and vice versa.
+ *
+ * @see #asDataset(RDFDataset)
+ * @see #asUnionGraph(RDFDataset)
+ * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
+ * @return Adapted {@link Graph} covering the <em>default graph</em>
+ */
+ public JsonLdGraph asGraph(RDFDataset rdfDataSet) {
+ return new JsonLdGraphImpl(rdfDataSet);
+ }
+
+ public Node asJsonLdNode(RDFTerm term) {
+ if (term instanceof JsonLdBlankNode) {
+ JsonLdBlankNode jsonLdBlankNode = (JsonLdBlankNode) term;
+ if (jsonLdBlankNode.uniqueReference().startsWith(bnodePrefix)) {
+ // Only return blank nodes 'as is' if they have the same prefix
+ return jsonLdBlankNode.asJsonLdNode();
+ }
+ } else if (term instanceof JsonLdTerm) {
+ // non-Bnodes can always be return as-is
+ return ((JsonLdTerm) term).asJsonLdNode();
+ }
+ if (term instanceof IRI) {
+ return new RDFDataset.IRI(((IRI) term).getIRIString());
+ }
+ if (term instanceof BlankNode) {
+ String ref = ((BlankNode) term).uniqueReference();
+ if (ref.startsWith(bnodePrefix)) {
+ // one of our own (but no longer a JsonLdBlankNode),
+ // we can recover the label after our unique prefix
+ return new RDFDataset.BlankNode(ref.replace(bnodePrefix, ""));
+ }
+ // The "foreign" unique reference might not be a valid bnode string,
+ // we'll convert to a UUID
+ UUID uuid = UUID.nameUUIDFromBytes(ref.getBytes(StandardCharsets.UTF_8));
+ return new RDFDataset.BlankNode("_:" + uuid);
+ }
+ if (term instanceof Literal) {
+ Literal literal = (Literal) term;
+ return new RDFDataset.Literal(literal.getLexicalForm(), literal.getDatatype().getIRIString(),
+ literal.getLanguageTag().orElse(null));
+ }
+ throw new IllegalArgumentException("RDFTerm not instanceof IRI, BlankNode or Literal: " + term);
+ }
+
+ /**
+ * Adapt a Commons RDF {@link org.apache.commons.rdf.api.Quad} as a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}.
+ *
+ * @param quad Commons RDF {@link org.apache.commons.rdf.api.Quad} to adapt
+ * @return Adapted JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}
+ */
+ public RDFDataset.Quad asJsonLdQuad(org.apache.commons.rdf.api.Quad quad) {
+ BlankNodeOrIRI g = quad.getGraphName().orElse(null);
+ return createJsonLdQuad(g, quad.getSubject(), quad.getPredicate(), quad.getObject());
+ }
+
+ /**
+ * Adapt a Commons RDF {@link Triple} as a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}.
+ *
+ * @param triple Commons RDF {@link Triple} to adapt
+ * @return Adapted JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}
+ */
+ public RDFDataset.Quad asJsonLdQuad(Triple triple) {
+ return createJsonLdQuad(null, triple.getSubject(), triple.getPredicate(), triple.getObject());
+ }
+
+ /**
+ * Adapt a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} as a Commons RDF
+ * {@link org.apache.commons.rdf.api.Quad}.
+ * <p>
+ * The underlying JsonLd quad can be retrieved with
+ * {@link JsonLdQuad#asJsonLdQuad()}.
+ *
+ * @param quad
+ * A JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} to adapt
+ * @return Adapted {@link JsonLdQuad}
+ */
+ public JsonLdQuad asQuad(final RDFDataset.Quad quad) {
+ return new JsonLdQuadImpl(quad, bnodePrefix);
+ }
+
+ /**
+ * Adapt a JsonLd {@link Node} as a Commons RDF {@link RDFTerm}.
+ * <p>
+ * The underlying node can be retrieved with
+ * {@link JsonLdTerm#asJsonLdNode()}.
+ *
+ * @param node
+ * A JsonLd {@link Node} to adapt
+ * @return Adapted {@link JsonLdTerm}
+ */
+ public JsonLdTerm asRDFTerm(final Node node) {
+ return asRDFTerm(node, bnodePrefix);
+ }
+
+ /**
+ * Adapt a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} as a Commons RDF
+ * {@link org.apache.commons.rdf.api.Triple}.
+ * <p>
+ * The underlying JsonLd quad can be retrieved with
+ * {@link JsonLdTriple#asJsonLdQuad()}.
+ *
+ * @param quad
+ * A JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} to adapt
+ * @return Adapted {@link JsonLdTriple}
+ */
+ public JsonLdTriple asTriple(final RDFDataset.Quad quad) {
+ return new JsonLdTripleImpl(quad, bnodePrefix);
+ }
+
+ /**
+ * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Graph}.
+ * <p>
+ * The graph can be seen as a <em>union graph</em> as it will contains all the
+ * triples across all the graphs of the underlying {@link RDFDataset}.
+ * <p>
+ * Note that some triple operations on a union graph
+ * can be inefficient as they need to remove any duplicate
+ * triples across the graphs.
+ * <p>
+ * Changes to the Commons RDF {@link Graph} are reflected in the JsonLd
+ * {@link RDFDataset} and vice versa. Triples removed from the graph are
+ * removed from <strong>all</strong> graphs, while triples added
+ * are added to the <em>default graph</em>.
+ *
+ * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
+ * @return Adapted {@link Dataset}
+ */
+ public JsonLdUnionGraph asUnionGraph(RDFDataset rdfDataSet) {
+ return new JsonLdUnionGraphImpl(rdfDataSet);
+ }
+
+ @Override
+ public JsonLdBlankNode createBlankNode() {
+ String id = "_:" + UUID.randomUUID().toString();
+ return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
+ }
+
+ @Override
+ public JsonLdBlankNode createBlankNode(String name) {
+ String id = "_:" + name;
+ // TODO: Check if name is valid JSON-LD BlankNode identifier
+ return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
+ }
+
+ @Override
+ public JsonLdDataset createDataset() {
+ return new JsonLdDatasetImpl(bnodePrefix);
+ }
+
+ @Override
+ public JsonLdGraph createGraph() {
+ return new JsonLdGraphImpl(bnodePrefix);
+ }
+
+ @Override
+ public JsonLdIRI createIRI(String iri) {
+ return new JsonLdIRIImpl(iri);
+ }
+
+ @Override
+ public JsonLdLiteral createLiteral(String literal) {
+ return new JsonLdLiteralImpl(new RDFDataset.Literal(literal, null, null));
+ }
+
+ @Override
+ public JsonLdLiteral createLiteral(String literal, IRI dataType) {
+ return new JsonLdLiteralImpl(new RDFDataset.Literal(literal, dataType.getIRIString(), null));
+ }
+
+ @Override
+ public JsonLdLiteral createLiteral(String literal, String language) {
+ return new JsonLdLiteralImpl(new RDFDataset.Literal(literal, Types.RDF_LANGSTRING.getIRIString(), language));
+ }
+
+ @Override
+ public JsonLdQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws IllegalArgumentException, UnsupportedOperationException {
+ return new JsonLdQuadImpl(createJsonLdQuad(graphName, subject, predicate, object), bnodePrefix);
+ }
+
+ @Override
+ public JsonLdTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return new JsonLdTripleImpl(createJsonLdQuad(null, subject, predicate, object), bnodePrefix);
+ }
+
+ String asJsonLdString(BlankNodeOrIRI blankNodeOrIRI) {
+ if (blankNodeOrIRI == null) {
+ return null;
+ }
+ if (blankNodeOrIRI instanceof IRI) {
+ return ((IRI)blankNodeOrIRI).getIRIString();
+ } else if (blankNodeOrIRI instanceof BlankNode) {
+ BlankNode blankNode = (BlankNode) blankNodeOrIRI;
+ String ref = blankNode.uniqueReference();
+ if (ref.startsWith(bnodePrefix)) {
+ // One of ours (but possibly not a JsonLdBlankNode) -
+ // we can use the suffix directly
+ return ref.replace(bnodePrefix, "_:");
+ } else {
+ // Map to unique bnode identifier, e.g. _:0dbd92ee-ab1a-45e7-bba2-7ade54f87ec5
+ UUID uuid = UUID.nameUUIDFromBytes(ref.getBytes(StandardCharsets.UTF_8));
+ return "_:"+ uuid;
+ }
+ } else {
+ throw new IllegalArgumentException("Expected a BlankNode or IRI, not: " + blankNodeOrIRI);
+ }
+ }
+
+ JsonLdTerm asRDFTerm(final Node node, String blankNodePrefix) {
+ if (node == null) {
+ return null; // e.g. default graph
+ }
+ if (node.isIRI()) {
+ return new JsonLdIRIImpl(node);
+ } else if (node.isBlankNode()) {
+ return new JsonLdBlankNodeImpl(node, blankNodePrefix);
+ } else if (node.isLiteral()) {
+ // TODO: Our own JsonLdLiteral
+ if (node.getLanguage() != null) {
+ return createLiteral(node.getValue(), node.getLanguage());
+ } else {
+ return createLiteral(node.getValue(), createIRI(node.getDatatype()));
+ }
+ } else {
+ throw new IllegalArgumentException("Node is neither IRI, BlankNode nor Literal: " + node);
+ }
+ }
+
+ RDFDataset.Quad createJsonLdQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return new RDFDataset.Quad(asJsonLdNode(subject), asJsonLdNode(predicate), asJsonLdNode(object), asJsonLdString(graphName));
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
index 7147322..4b20618 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
@@ -23,7 +23,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.rdf.api.BlankNode;
-import org.apache.commons.rdf.simple.SimpleRDFFactory.SimpleRDFTerm;
+import org.apache.commons.rdf.simple.SimpleRDF.SimpleRDFTerm;
/**
* A simple implementation of BlankNode.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/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 78f1981..a23f27e 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
@@ -33,7 +33,7 @@ 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.SimpleRDFFactory.SimpleRDFTerm;
+import org.apache.commons.rdf.simple.SimpleRDF.SimpleRDFTerm;
/**
* A simple, memory-based implementation of Dataset.
@@ -46,10 +46,10 @@ final class DatasetImpl implements Dataset {
private static final int TO_STRING_MAX = 10;
private final Set<Quad> quads = new HashSet<Quad>();
- private final SimpleRDFFactory factory;
+ private final SimpleRDF factory;
- DatasetImpl(SimpleRDFFactory simpleRDFFactory) {
- this.factory = simpleRDFFactory;
+ DatasetImpl(SimpleRDF simpleRDF) {
+ this.factory = simpleRDF;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index 1173d53..fb95577 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -18,7 +18,7 @@
package org.apache.commons.rdf.simple;
import org.apache.commons.rdf.api.*;
-import org.apache.commons.rdf.simple.SimpleRDFFactory.SimpleRDFTerm;
+import org.apache.commons.rdf.simple.SimpleRDF.SimpleRDFTerm;
import java.util.HashSet;
import java.util.Objects;
@@ -38,10 +38,10 @@ final class GraphImpl implements Graph {
private static final int TO_STRING_MAX = 10;
private final Set<Triple> triples = new HashSet<Triple>();
- private final SimpleRDFFactory factory;
+ private final SimpleRDF factory;
- GraphImpl(SimpleRDFFactory simpleRDFFactory) {
- this.factory = simpleRDFFactory;
+ GraphImpl(SimpleRDF simpleRDF) {
+ this.factory = simpleRDF;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
index c3ef547..8c81913 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/IRIImpl.java
@@ -24,7 +24,7 @@ import java.net.URI;
/**
* A simple implementation of IRI.
*/
-final class IRIImpl implements IRI, SimpleRDFFactory.SimpleRDFTerm {
+final class IRIImpl implements IRI, SimpleRDF.SimpleRDFTerm {
private final String iri;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
index b3f7042..d477e43 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
@@ -28,7 +28,7 @@ import org.apache.commons.rdf.api.Literal;
/**
* A simple implementation of Literal.
*/
-final class LiteralImpl implements Literal, SimpleRDFFactory.SimpleRDFTerm {
+final class LiteralImpl implements Literal, SimpleRDF.SimpleRDFTerm {
private static final String QUOTE = "\"";
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
index 54c5fc1..00f8fa8 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
@@ -40,7 +40,7 @@ final class QuadImpl implements Quad {
* Construct Quad from its constituent parts.
* <p>
* The objects are not changed. All mapping of BNode objects is done in
- * {@link SimpleRDFFactory#createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)}.
+ * {@link SimpleRDF#createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)}.
*
* @param graphName graphName of triple
* @param subject subject of triple
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
new file mode 100644
index 0000000..91bd7da
--- /dev/null
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
@@ -0,0 +1,114 @@
+/**
+ * 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.simple;
+
+import java.util.UUID;
+
+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;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.RDF;
+import org.apache.commons.rdf.api.Triple;
+
+/**
+ * A simple implementation of RDF.
+ * <p>
+ * The {@link RDFTerm}, {@link Triple}, {@link Quad}, {@link Graph}
+ * and {@link Dataset} instances created by this factory are
+ * simple in-memory Implementations that are not thread-safe or efficient, but
+ * which may be useful for testing and prototyping purposes.
+ */
+public class SimpleRDF implements RDF {
+
+ /**
+ * Marker interface to say that this RDFTerm is part of the
+ * Simple implementation. Used by {@link GraphImpl} to avoid
+ * double remapping.
+ * <p>
+ * This method is package protected to avoid any third-party
+ * subclasses.
+ *
+ */
+ static interface SimpleRDFTerm extends RDFTerm {
+ }
+
+ /** Unique salt per instance, for {@link #createBlankNode(String)}
+ */
+ private final UUID SALT = UUID.randomUUID();
+
+ @Override
+ public BlankNode createBlankNode() {
+ return new BlankNodeImpl();
+ }
+
+ @Override
+ public BlankNode createBlankNode(String name) {
+ return new BlankNodeImpl(SALT, name);
+ }
+
+ @Override
+ public Graph createGraph() {
+ // Creates a GraphImpl object using this object as the factory for
+ // delegating all object creation to
+ return new GraphImpl(this);
+ }
+
+ @Override
+ public Dataset createDataset() throws UnsupportedOperationException {
+ return new DatasetImpl(this);
+ }
+
+ @Override
+ public IRI createIRI(String iri) {
+ IRI result = new IRIImpl(iri);
+ // Reuse any IRI objects already created in Types
+ return Types.get(result).orElse(result);
+ }
+
+ @Override
+ public Literal createLiteral(String literal) {
+ return new LiteralImpl(literal);
+ }
+
+ @Override
+ public Literal createLiteral(String literal, IRI dataType) {
+ return new LiteralImpl(literal, dataType);
+ }
+
+ @Override
+ public Literal createLiteral(String literal, String language) {
+ return new LiteralImpl(literal, language);
+ }
+
+ @Override
+ public Triple createTriple(BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) {
+ return new TripleImpl(subject, predicate, object);
+ }
+
+ @Override
+ public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws IllegalArgumentException {
+ return new QuadImpl(graphName, subject, predicate, object);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFFactory.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFFactory.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFFactory.java
deleted file mode 100644
index d8103fe..0000000
--- a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFFactory.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.simple;
-
-import java.util.UUID;
-
-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;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.api.Triple;
-
-/**
- * A simple implementation of RDF.
- * <p>
- * The {@link RDFTerm}, {@link Triple}, {@link Quad}, {@link Graph}
- * and {@link Dataset} instances created by this factory are
- * simple in-memory Implementations that are not thread-safe or efficient, but
- * which may be useful for testing and prototyping purposes.
- */
-public class SimpleRDFFactory implements RDF {
-
- /**
- * Marker interface to say that this RDFTerm is part of the
- * Simple implementation. Used by {@link GraphImpl} to avoid
- * double remapping.
- * <p>
- * This method is package protected to avoid any third-party
- * subclasses.
- *
- */
- static interface SimpleRDFTerm extends RDFTerm {
- }
-
- /** Unique salt per instance, for {@link #createBlankNode(String)}
- */
- private final UUID SALT = UUID.randomUUID();
-
- @Override
- public BlankNode createBlankNode() {
- return new BlankNodeImpl();
- }
-
- @Override
- public BlankNode createBlankNode(String name) {
- return new BlankNodeImpl(SALT, name);
- }
-
- @Override
- public Graph createGraph() {
- // Creates a GraphImpl object using this object as the factory for
- // delegating all object creation to
- return new GraphImpl(this);
- }
-
- @Override
- public Dataset createDataset() throws UnsupportedOperationException {
- return new DatasetImpl(this);
- }
-
- @Override
- public IRI createIRI(String iri) {
- IRI result = new IRIImpl(iri);
- // Reuse any IRI objects already created in Types
- return Types.get(result).orElse(result);
- }
-
- @Override
- public Literal createLiteral(String literal) {
- return new LiteralImpl(literal);
- }
-
- @Override
- public Literal createLiteral(String literal, IRI dataType) {
- return new LiteralImpl(literal, dataType);
- }
-
- @Override
- public Literal createLiteral(String literal, String language) {
- return new LiteralImpl(literal, language);
- }
-
- @Override
- public Triple createTriple(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) {
- return new TripleImpl(subject, predicate, object);
- }
-
- @Override
- public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
- throws IllegalArgumentException {
- return new QuadImpl(graphName, subject, predicate, object);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
index 5f6f5fe..fa242b1 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
@@ -29,12 +29,12 @@ import org.apache.commons.rdf.api.Triple;
/**
* A Simple implementation of {@link RDFTermFactory}
* <p>
- * This class is <strong>deprecated</strong>, use instead {@link SimpleRDFFactory}.
+ * This class is <strong>deprecated</strong>, use instead {@link SimpleRDF}.
*/
@Deprecated
public class SimpleRDFTermFactory implements RDFTermFactory {
- private SimpleRDFFactory factory = new SimpleRDFFactory();
+ private SimpleRDF factory = new SimpleRDF();
public BlankNode createBlankNode() {
return factory.createBlankNode();
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
index bc7f103..1abd905 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
@@ -37,7 +37,7 @@ final class TripleImpl implements Triple {
* Construct Triple from its constituent parts.
* <p>
* The objects are not changed. All mapping of BNode objects is done in
- * {@link SimpleRDFFactory#createTriple(BlankNodeOrIRI, IRI, RDFTerm)}.
+ * {@link SimpleRDF#createTriple(BlankNodeOrIRI, IRI, RDFTerm)}.
*
* @param subject subject of triple
* @param predicate predicate of triple
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
index 8ad6df8..b6dd8ee 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
@@ -27,7 +27,7 @@ import java.util.Set;
/**
* Types from the RDF and XML Schema vocabularies.
*/
-public final class Types implements IRI, SimpleRDFFactory.SimpleRDFTerm {
+public final class Types implements IRI, SimpleRDF.SimpleRDFTerm {
/**
* <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML</tt>
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
index b34bc4d..e478c39 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
@@ -35,7 +35,7 @@ import org.apache.commons.rdf.api.Quad;
import org.apache.commons.rdf.api.RDFSyntax;
import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.experimental.RDFParser;
-import org.apache.commons.rdf.simple.SimpleRDFFactory;
+import org.apache.commons.rdf.simple.SimpleRDF;
/**
* Abstract RDFParser
@@ -63,7 +63,7 @@ public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>>
private static final ExecutorService threadpool = Executors.newCachedThreadPool(r -> new Thread(threadGroup, r));
// Basically only used for creating IRIs
- private static RDF internalRdfTermFactory = new SimpleRDFFactory();
+ private static RDF internalRdfTermFactory = new SimpleRDF();
/**
* Get the set {@link RDF}, if any.
@@ -418,7 +418,7 @@ public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>>
// parseSynchronously()
AbstractRDFParser<T> c = clone();
- // Use a fresh SimpleRDFFactory for each parse
+ // Use a fresh SimpleRDF for each parse
if (!c.rdfTermFactory.isPresent()) {
c.rdfTermFactory = Optional.of(createRDFTermFactory());
}
@@ -515,7 +515,7 @@ public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>>
* @return A new {@link RDF}
*/
protected RDF createRDFTermFactory() {
- return new SimpleRDFFactory();
+ return new SimpleRDF();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java b/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java
index 5405cef..f536594 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java
@@ -28,10 +28,10 @@
* testing and simple usage (e.g. prototyping).
* <p>
* To use this implementation, create an instance of
- * {@link org.apache.commons.rdf.simple.SimpleRDFFactory}
+ * {@link org.apache.commons.rdf.simple.SimpleRDF}
* and use methods like
- * {@link org.apache.commons.rdf.simple.SimpleRDFFactory#createGraph} and
- * {@link org.apache.commons.rdf.simple.SimpleRDFFactory#createIRI(String)}.
+ * {@link org.apache.commons.rdf.simple.SimpleRDF#createGraph} and
+ * {@link org.apache.commons.rdf.simple.SimpleRDF#createIRI(String)}.
* <p>
* The {@link org.apache.commons.rdf.simple.Types} class provide constant
* {@link org.apache.commons.rdf.api.IRI}s of the common RDF XML datatypes.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
----------------------------------------------------------------------
diff --git a/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
index 67557cf..4003034 100644
--- a/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
+++ b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
@@ -1 +1 @@
-org.apache.commons.rdf.simple.SimpleRDFFactory
+org.apache.commons.rdf.simple.SimpleRDF
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
index 64f5acd..3d3aad1 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
@@ -36,7 +36,7 @@ public class DefaultGraphTest extends AbstractGraphTest {
return new RDF() {
@Override
public Graph createGraph() throws UnsupportedOperationException {
- return new GraphImpl(new SimpleRDFFactory());
+ return new GraphImpl(new SimpleRDF());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
index e4cdf8e..ebfdc6b 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
@@ -25,13 +25,13 @@ import org.junit.Assume;
import org.junit.Test;
/**
- * Test SimpleRDFFactory with AbstractGraphTest
+ * Test SimpleRDF with AbstractGraphTest
*/
public class SimpleGraphTest extends AbstractGraphTest {
@Override
public RDF createFactory() {
- return new SimpleRDFFactory();
+ return new SimpleRDF();
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
index 527d7b9..3167243 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
@@ -33,7 +33,7 @@ public class SimpleNoRelativeIRIRDFTermFactoryTest extends
AbstractRDFTermFactoryTest {
@Override
public RDF createFactory() {
- return new SimpleRDFFactory() {
+ return new SimpleRDF() {
@Override
public IRI createIRI(String iri) {
if (!URI.create(iri).isAbsolute()) {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
index e308f00..816eef9 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
@@ -27,7 +27,7 @@ public class SimpleRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
@Override
public RDF createFactory() {
- return new SimpleRDFFactory();
+ return new SimpleRDF();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
index 08930ac..8ec0649 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
@@ -31,10 +31,10 @@ public class SimpleServiceLoaderTest {
public void testServiceLoaderLookup() {
ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class);
for (RDF impl : loader) {
- if (impl instanceof SimpleRDFFactory) {
+ if (impl instanceof SimpleRDF) {
return; // yay
}
}
- fail("SimpleRDFFactory not found in ServiceLoader");
+ fail("SimpleRDF not found in ServiceLoader");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
index 8af3034..ca4925f 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
@@ -57,7 +57,7 @@ public class TestWritingGraph {
@BeforeClass
public static void createGraph() throws Exception {
- factory = new SimpleRDFFactory();
+ factory = new SimpleRDF();
graph = factory.createGraph();
IRI subject = factory.createIRI("subj");
IRI predicate = factory.createIRI("pred");
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/790b6059/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
index 732df71..fed76b3 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
@@ -38,7 +38,7 @@ import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.experimental.RDFParser;
import org.apache.commons.rdf.simple.DummyRDFParserBuilder;
-import org.apache.commons.rdf.simple.SimpleRDFFactory;
+import org.apache.commons.rdf.simple.SimpleRDF;
import org.apache.commons.rdf.simple.Types;
import org.junit.After;
import org.junit.Before;
@@ -48,7 +48,7 @@ import org.junit.rules.ExpectedException;
public class AbstractRDFParserTest {
- private RDF factory = new SimpleRDFFactory();
+ private RDF factory = new SimpleRDF();
private DummyRDFParserBuilder dummyParser = new DummyRDFParserBuilder();
private Path testNt;
[44/50] [abbrv] incubator-commonsrdf git commit: Reformat tab ->
spaces
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
index a550b06..b49656f 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
@@ -50,12 +50,11 @@ import org.apache.jena.sparql.graph.GraphFactory;
/**
* Apache Jena RDF implementation.
* <p>
- * Instances of JenaRDF can also
- * convert existing objects from Jena with methods like
- * {@link #asRDFTerm(Node)} and {@link #asGraph(org.apache.jena.graph.Graph)},
- * and vice versa from any Commons RDF object to Jena with the
- * <code>asJena*</code> methods like {@link #asJenaNode(RDFTerm)} and
- * {@link #asJenaGraph(Graph)}.
+ * Instances of JenaRDF can also convert existing objects from Jena with methods
+ * like {@link #asRDFTerm(Node)} and
+ * {@link #asGraph(org.apache.jena.graph.Graph)}, and vice versa from any
+ * Commons RDF object to Jena with the <code>asJena*</code> methods like
+ * {@link #asJenaNode(RDFTerm)} and {@link #asJenaGraph(Graph)}.
* <p>
* Note that Commons RDF objects created by this class implement the
* specializations interfaces like {@link JenaRDFTerm}, {@link JenaGraph} and
@@ -67,676 +66,686 @@ import org.apache.jena.sparql.graph.GraphFactory;
* {@link BlankNode#uniqueReference()}), each instance of JenaRDF uses an
* internal random state. If for some reason consistent/reproducible BlankNode
* identity is desired, it is possible to retrieve the state as a UUID using
- * {@link #salt()} for subsequent use with {@link JenaRDF#JenaRDF(UUID)} -
- * note that such consistency is only guaranteed within the same minor version
- * of Commons RDF.
+ * {@link #salt()} for subsequent use with {@link JenaRDF#JenaRDF(UUID)} - note
+ * that such consistency is only guaranteed within the same minor version of
+ * Commons RDF.
*
* @see RDF
*/
public final class JenaRDF implements RDF {
- private static InternalJenaFactory internalJenaFactory = new InternalJenaFactory(){};
-
- private final UUID salt;
-
- /**
- * Create a JenaRDF.
- * <p>
- * This constructor will use a randomly generated {@link UUID} as a salt
- * for the purposes of {@link BlankNode} identity, see {@link #salt()}.
- */
- public JenaRDF() {
- this.salt = UUID.randomUUID();
- }
-
- /**
- * Create a JenaRDF.
- * <p>
- * This constructor will use the specified {@link UUID} as a salt for
- * the purposes of {@link BlankNode} identity, and should only be used in
- * cases where predictable and consistent
- * {@link BlankNode#uniqueReference()} are important.
- *
- * @param salt
- * {@link UUID} to use as salt for {@link BlankNode} equality
- */
- public JenaRDF(UUID salt) {
- this.salt = salt;
- }
-
- @Override
- public JenaBlankNode createBlankNode() {
- return internalJenaFactory.createBlankNode(salt());
- }
-
- @Override
- public JenaBlankNode createBlankNode(String name) {
- return internalJenaFactory.createBlankNode(name, salt());
- }
-
- @Override
- public JenaDataset createDataset() {
- return internalJenaFactory.createDataset(salt());
- }
-
- @Override
- public JenaGraph createGraph() {
- return internalJenaFactory.createGraph(salt());
- }
-
- @Override
- public JenaIRI createIRI(String iri) {
- validateIRI(iri);
- return internalJenaFactory.createIRI(iri);
- }
-
- @Override
- public JenaLiteral createLiteral(String lexicalForm) {
- return internalJenaFactory.createLiteral(lexicalForm);
- }
-
- @Override
- public JenaLiteral createLiteral(String lexicalForm, IRI dataType) {
- return internalJenaFactory.createLiteralDT(lexicalForm, dataType.getIRIString());
- }
-
- @Override
- public JenaLiteral createLiteral(String lexicalForm, String languageTag) {
- validateLang(languageTag);
- return internalJenaFactory.createLiteralLang(lexicalForm, languageTag);
- }
-
- @Override
- public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return internalJenaFactory.createTriple(subject, predicate, object);
- }
-
- @Override
- public JenaQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
- throws IllegalArgumentException, UnsupportedOperationException {
- return internalJenaFactory.createQuad(subject, predicate, object, graphName);
- }
-
- /**
- * Create a generalized Jena triple.
- * <p>
- * The <em>generalized triple</em> supports any {@link RDFTerm} as its
- * {@link TripleLike#getSubject()} {@link TripleLike#getPredicate()} or
- * {@link TripleLike#getObject()}.
- *
- * @see #createTriple(BlankNodeOrIRI, IRI, RDFTerm)
- * @see #createGeneralizedQuad(RDFTerm, RDFTerm, RDFTerm, RDFTerm)
- *
- * @param subject
- * The subject of the statement
- * @param predicate
- * The predicate of the statement
- * @param object
- * The object of the statement
- * @return Generalized {@link TripleLike}. Note that the generalized triple
- * does <strong>not</strong> implement {@link Triple#equals(Object)}
- * or {@link Triple#hashCode()}.
- */
- public JenaGeneralizedTripleLike createGeneralizedTriple(
- RDFTerm subject, RDFTerm predicate, RDFTerm object) {
- return internalJenaFactory.createGeneralizedTriple(subject, predicate, object);
- }
-
- /**
- * Create a generalized Jena quad.
- * <p>
- * The <em>generalized quad</em> supports any {@link RDFTerm} as its
- * {@link QuadLike#getSubject()} {@link QuadLike#getPredicate()},
- * {@link QuadLike#getObject()} or {@link QuadLike#getObject()}.
- *
- * @see #createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)
- * @see #createGeneralizedTriple(RDFTerm, RDFTerm, RDFTerm)
- *
- * @param subject
- * The subject of the statement
- * @param predicate
- * The predicate of the statement
- * @param object
- * The object of the statement
- * @param graphName
- * The graph name of the statement
- * @return Generalized {@link QuadLike}. Note that the generalized quad does
- * <strong>not</strong> implement {@link Quad#equals(Object)} or
- * {@link Quad#hashCode()}.
- */
- public JenaGeneralizedQuadLike createGeneralizedQuad(
- RDFTerm subject, RDFTerm predicate, RDFTerm object, RDFTerm graphName) {
- return internalJenaFactory.createGeneralizedQuad(subject, predicate, object, graphName);
- }
- /**
- * Adapt an existing Jena Node to CommonsRDF {@link RDFTerm}.
- * <p>
- * If {@link Node#isLiteral()}, then the returned value is a {@link Literal}.
- * If {@link Node#isURI()}, the returned value is a IRI. If {$@link Node#isBlank()},
- * the returned value is a {@link BlankNode}, which will use a {@link UUID}
- * salt from this {@link JenaRDF} instance in combination with
- * {@link Node#getBlankNodeId()} for the purpose of its
- * {@link BlankNode#uniqueReference()}.
- *
- * @see #asRDFTerm(RDF, Node)
- *
- * @param node
- * The Jena Node to adapt. It's {@link Node#isConcrete()} must be
- * <code>true</code>.
- * @return Adapted {@link JenaRDFTerm}
- * @throws ConversionException If the {@link Node} can't be represented as an {@link RDFTerm}, e.g.
- * if the node is not concrete or represents a variable in Jena.
- */
- public JenaRDFTerm asRDFTerm(Node node) throws ConversionException {
- return internalJenaFactory.createRDFTerm(node, salt());
- }
-
- /**
- * Convert from Jena {@link Node} to any Commons RDF implementation.
- * <p>
- * Note that if the {@link Node#isBlank()}, then the factory's
- * {@link RDF#createBlankNode(String)} will be used, meaning
- * that care should be taken if reusing an {@link RDF} instance
- * for multiple conversion sessions.
- *
- * @see #asRDFTerm(Node)
- *
- * @param factory {@link RDF} to use for creating {@link RDFTerm}.
- * @param node
- * The Jena Node to adapt. It's {@link Node#isConcrete()} must be
- * <code>true</code>.
- * @return Adapted {@link RDFTerm}
- * @throws ConversionException If the {@link Node} can't be represented as an {@link RDFTerm}, e.g.
- * if the node is not concrete or represents a variable in Jena.
- */
- public static RDFTerm asRDFTerm(RDF factory, Node node) {
- if (node == null) {
- return null;
- }
- if (factory instanceof JenaRDF) {
- // No need to convert, just wrap
- return ((JenaRDF) factory).asRDFTerm(node);
- }
- if (node.isURI())
- return factory.createIRI(node.getURI());
- if (node.isLiteral()) {
- String lang = node.getLiteralLanguage();
- if (lang != null && !lang.isEmpty())
- return factory.createLiteral(node.getLiteralLexicalForm(), lang);
- if (node.getLiteralDatatype().equals(XSDDatatype.XSDstring))
- return factory.createLiteral(node.getLiteralLexicalForm());
- IRI dt = factory.createIRI(node.getLiteralDatatype().getURI());
- return factory.createLiteral(node.getLiteralLexicalForm(), dt);
- }
- if (node.isBlank())
- // The factory
- return factory.createBlankNode(node.getBlankNodeLabel());
- throw new ConversionException("Node is not a concrete RDF Term: " + node);
- }
-
- /**
- * Adapt an existing Jena Triple to CommonsRDF {@link Triple}.
- * <p>
- * If the triple contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaRDF} instance in combination with
- * {@link Node#getBlankNodeId()} for the purpose of its
- * {@link BlankNode#uniqueReference()}.
- *
- * @see #asTriple(RDF, org.apache.jena.graph.Triple)
- *
- * @param triple
- * Jena {@link org.apache.jena.graph.Triple} to adapt
- * @return Adapted {@link JenaTriple}
- * @throws ConversionException
- * if any of the triple's nodes are not concrete or the triple
- * is a generalized triple
- */
- public JenaTriple asTriple(org.apache.jena.graph.Triple triple) throws ConversionException {
- return internalJenaFactory.createTriple(triple, salt());
- }
-
- /**
- * Adapt a generalized Jena {@link org.apache.jena.graph.Triple} to a CommonsRDF {@link TripleLike}.
- * <p>
- * The generalized triple supports any {@link RDFTerm} as its {@link TripleLike#getSubject()}
- * {@link TripleLike#getPredicate()} or {@link TripleLike#getObject()}.
- * <p>
- * If the Jena triple contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaRDF} instance in combination with
- * {@link Node#getBlankNodeId()} for the purpose of its
- * {@link BlankNode#uniqueReference()}.
- *
- * @see #asTriple(RDF, org.apache.jena.graph.Triple)
- *
- * @param triple
- * Jena triple
- * @return Adapted {@link TripleLike}. Note that the generalized triple does
- * <strong>not</strong> implement {@link Triple#equals(Object)} or
- * {@link Triple#hashCode()}.
- * @throws ConversionException
- * if any of the triple's nodes are not concrete
- */
- public JenaTripleLike asGeneralizedTriple(org.apache.jena.graph.Triple triple) throws ConversionException {
- return internalJenaFactory.createGeneralizedTriple(triple, salt());
- }
-
- /**
- * Adapt a generalized Jena {@link org.apache.jena.sparql.core.Quad} to a CommonsRDF {@link QuadLike}.
- * <p>
- * The generalized quad supports any {@link RDFTerm} as its
- * {@link QuadLike#getGraphName()},
- * {@link QuadLike#getSubject()}
- * {@link QuadLike#getPredicate()} or
- * {@link QuadLike#getObject()}.
- * <p>
- * If the Jena quad contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaRDF} instance in combination with
- * {@link Node#getBlankNodeId()} for the purpose of its
- * {@link BlankNode#uniqueReference()}.
- *
- * @see #asQuad(org.apache.jena.sparql.core.Quad)
- * @see #asGeneralizedTriple(org.apache.jena.graph.Triple)
- *
- * @param quad
- * Jena quad
- * @return Adapted {@link QuadLike}. Note that the generalized quad does
- * <strong>not</strong> implement {@link Quad#equals(Object)} or
- * {@link Quad#hashCode()}.
- * @throws ConversionException
- * if any of the quad nodes are not concrete
- */
- public JenaQuadLike<RDFTerm> asGeneralizedQuad(org.apache.jena.sparql.core.Quad quad) throws ConversionException {
- return internalJenaFactory.createGeneralizedQuad(quad, salt());
- }
-
- /**
- * Convert from Jena {@link org.apache.jena.graph.Triple} to a Commons RDF
- * {@link Triple}.
- * <p>
- * Note that if any of the triple's nodes {@link Node#isBlank()}, then the factory's
- * {@link RDF#createBlankNode(String)} will be used, meaning
- * that care should be taken if reusing an {@link RDF} instance
- * for multiple conversion sessions.
- *
- * @see #asTriple(org.apache.jena.graph.Triple)
- *
- * @param factory {@link RDF} to use for creating the {@link Triple} and its
- * {@link RDFTerm}s.
- * @param triple
- * Jena triple
- * @return Converted triple
- * @throws ConversionException
- * if any of the triple's nodes are not concrete or the triple
- * is a generalized triple
- */
- public static Triple asTriple(RDF factory, org.apache.jena.graph.Triple triple)
- throws ConversionException{
- if (factory instanceof JenaRDF) {
- // No need to convert, just wrap
- return ((JenaRDF) factory).asTriple(triple);
- }
- final BlankNodeOrIRI subject;
- final IRI predicate;
- try {
- subject = (BlankNodeOrIRI) asRDFTerm(factory, triple.getSubject());
- predicate = (IRI) asRDFTerm(factory, triple.getPredicate());
- } catch (ClassCastException ex) {
- throw new ConversionException("Can't convert generalized triple: " + triple, ex);
- }
- RDFTerm object = asRDFTerm(factory, triple.getObject());
- return factory.createTriple(subject, predicate, object);
- }
-
- /**
- * Adapt an existing Jena {@link org.apache.jena.sparql.core.Quad} to CommonsRDF {@link Quad}.
- * <p>
- * If the quad contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaRDF} instance
- * in combination with {@link Node#getBlankNodeId()}
- * for the purpose of its {@link BlankNode#uniqueReference()}.
- *
- * @param quad
- * Jena quad
- * @return Adapted quad
- */
- public JenaQuad asQuad(org.apache.jena.sparql.core.Quad quad) {
- return internalJenaFactory.createQuad(quad, salt());
- }
-
- /**
- * Adapt an existing Jena {@link org.apache.jena.graph.Graph} to CommonsRDF
- * {@link Graph}.
- * <p>
- * This does not take a copy, changes to the CommonsRDF Graph are reflected
- * in the jena graph, which is accessible from
- * {@link JenaGraph#asJenaGraph()}.
- * <p>
- * If the graph contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaRDF} instance in combination with
- * {@link Node#getBlankNodeId()} for the purpose of its
- * {@link BlankNode#uniqueReference()}.
- *
- * @param graph
- * Jena {@link org.apache.jena.graph.Graph} to adapt
- * @return Adapted {@link JenaGraph}
- */
- public JenaGraph asGraph(org.apache.jena.graph.Graph graph) {
- return internalJenaFactory.createGraph(graph, salt());
- }
-
- /**
- * Adapt an existing Jena {@link org.apache.jena.rdf.model.Model} to CommonsRDF {@link Graph}.
- * <p>
- * This does not ake a copy, changes to the CommonsRDF Graph are reflected in the jena
- * graph, which is accessible from {@link JenaGraph#asJenaGraph()}.
- * <p>
- * If the graph contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaRDF} instance
- * in combination with {@link Node#getBlankNodeId()}
- * for the purpose of its {@link BlankNode#uniqueReference()}.
- * @param model
- * Jena {@link org.apache.jena.rdf.model.Model} to adapt
- * @return Adapted {@link JenaGraph}
- */
- public JenaGraph asGraph(org.apache.jena.rdf.model.Model model) {
- return internalJenaFactory.createGraph(model, salt());
- }
-
- /**
- * Adapt an existing Jena {@link DatasetGraph} to CommonsRDF {@link Dataset}.
- * <p>
- * This does not
- * take a copy, changes to the CommonsRDF Dataset are reflected in the jena
- * dataset graph, which is accessible from {@link JenaDataset#asJenaDatasetGraph()}.
- * <p>
- * If the dataset contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaRDF} instance
- * in combination with {@link Node#getBlankNodeId()}
- * for the purpose of its {@link BlankNode#uniqueReference()}.
- *
- * @param datasetGraph Jena {@link DatasetGraph} to adapt
- * @return Adapted {@link JenaDataset}
- */
- public JenaDataset asDataset(DatasetGraph datasetGraph) {
- return internalJenaFactory.createDataset(datasetGraph, salt());
- }
-
- /**
- * Adapt an existing Jena {@link org.apache.jena.query.Dataset} to CommonsRDF {@link Dataset}.
- * <p>
- * This does not
- * take a copy, changes to the CommonsRDF Dataset are reflected in the jena
- * dataset graph, which is accessible from {@link JenaDataset#asJenaDatasetGraph()}.
- * <p>
- * If the dataset contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaRDF} instance
- * in combination with {@link Node#getBlankNodeId()}
- * for the purpose of its {@link BlankNode#uniqueReference()}.
- *
- * @param datasetGraph Jena {@link org.apache.jena.query.Dataset} to adapt
- * @return Adapted {@link JenaDataset}
- */
- public JenaDataset asDataset(org.apache.jena.query.Dataset datasetGraph) {
- return internalJenaFactory.createDataset(datasetGraph.asDatasetGraph(), salt());
- }
-
- /**
- * Convert from Jena {@link org.apache.jena.sparql.core.Quad} to a Commons
- * RDF {@link Quad}.
- * <p>
- * Note that if any of the quad's nodes {@link Node#isBlank()}, then the
- * factory's {@link RDF#createBlankNode(String)} will be used,
- * meaning that care should be taken if reusing an {@link RDF}
- * instance for multiple conversion sessions.
- *
- * @see #asQuad(org.apache.jena.sparql.core.Quad)
- * @see #asGeneralizedQuad(org.apache.jena.sparql.core.Quad)
- *
- * @param factory
- * {@link RDF} to use for creating the {@link Triple}
- * and its {@link RDFTerm}s.
- * @param quad
- * Jena {@link org.apache.jena.sparql.core.Quad} to adapt
- * @return Converted {@link Quad}
- * @throws ConversionException
- * if any of the quad's nodes are not concrete or the quad
- * is a generalized quad
- */
- public static Quad asQuad(RDF factory, org.apache.jena.sparql.core.Quad quad) {
- if (factory instanceof JenaRDF) {
- // No need to convert, just wrap
- return ((JenaRDF) factory).asQuad(quad);
- }
- BlankNodeOrIRI graphName = (BlankNodeOrIRI) (asRDFTerm(factory, quad.getGraph()));
- BlankNodeOrIRI subject = (BlankNodeOrIRI) (asRDFTerm(factory, quad.getSubject()));
- IRI predicate = (IRI) (asRDFTerm(factory, quad.getPredicate()));
- RDFTerm object = asRDFTerm(factory, quad.getObject());
- return factory.createQuad(graphName, subject, predicate, object);
- }
-
- /**
- * Return {@link RDFSyntax} corresponding to a Jena {@link Lang}.
- *
- * @param lang {@link Lang} to convert
- * @return Matched {@link RDFSyntax}, otherwise {@link Optional#empty()}
- */
- public Optional<RDFSyntax> asRDFSyntax(Lang lang) {
- return RDFSyntax.byMediaType(lang.getContentType().getContentType());
- }
-
- /**
- * Return Jena {@link Lang} corresponding to a {@link RDFSyntax}.
- *
- * @param rdfSyntax {@link RDFSyntax} to convert
- * @return Matched {@link Lang}, otherwise {@link Optional#empty()}
- */
- public Optional<Lang> asJenaLang(RDFSyntax rdfSyntax) {
- return Optional.ofNullable(RDFLanguages.contentTypeToLang(rdfSyntax.mediaType));
- }
-
- /**
- * Create a {@link StreamRDF} instance that inserts the converted
- * {@link Quad}s. into a the provided {@link Consumer}.
- * <p>
- * The returned {@link StreamRDF} can be used for instance with Jena's
- * {@link RDFDataMgr#parse(StreamRDF, String)}.
- *
- * @param factory
- * {@link RDF} to use for creating {@link RDFTerm}s
- * and {@link Quad}s.
- * @param consumer
- * A {@link Consumer} of {@link Quad}s
- * @return A {@link StreamRDF} that will stream converted quads to the
- * consumer
- */
- public static StreamRDF streamJenaToQuad(RDF factory, Consumer<Quad> consumer) {
- return new StreamRDFBase() {
- @Override
- public void quad(org.apache.jena.sparql.core.Quad quad) {
- consumer.accept(asQuad(factory, quad));
- }
- };
- }
-
- /**
- * Create a {@link StreamRDF} instance that inserts generalized
- * {@link TripleLike}s. into a the provided {@link Consumer}.
- * <p>
- * A generalized triple allows any {@link RDFTerm} for
- * {@link TripleLike#getSubject()}, {@link TripleLike#getPredicate()} and
- * {@link TripleLike#getObject()}.
- * <p>
- * The returned {@link StreamRDF} can be used for instance with Jena's
- * {@link RDFDataMgr#parse(StreamRDF, String)}.
- *
- * @param generalizedConsumer
- * A {@link Consumer} of generalized {@link TripleLike}s
- * @return A {@link StreamRDF} that will stream generalized triples to the
- * consumer
- */
- public StreamRDF streamJenaToGeneralizedTriple(Consumer<TripleLike> generalizedConsumer) {
- return new StreamRDFBase() {
- @Override
- public void triple(org.apache.jena.graph.Triple triple) {
- generalizedConsumer.accept(asGeneralizedTriple(triple));
- }
- };
- }
-
- /**
- * Create a {@link StreamRDF} instance that inserts generalized
- * {@link QuadLike}s. into a the provided {@link Consumer}.
- * <p>
- * A generalized quad allows any {@link RDFTerm} for
- * {@link QuadLike#getSubject()}, {@link TripleLike#getPredicate()},
- * {@link QuadLike#getObject()} and {@link QuadLike#getGraphName()} .
- * <p>
- * The returned {@link StreamRDF} can be used for instance with Jena's
- * {@link RDFDataMgr#parse(StreamRDF, String)}.
- *
- * @param generalizedConsumer
- * A {@link Consumer} of generalized {@link QuadLike}s
- * @return A {@link StreamRDF} that will stream generalized quads to the
- * consumer
- */
- public StreamRDF streamJenaToGeneralizedQuad(Consumer<QuadLike<RDFTerm>> generalizedConsumer) {
- return new StreamRDFBase() {
- @Override
- public void quad(org.apache.jena.sparql.core.Quad quad) {
- generalizedConsumer.accept(asGeneralizedQuad(quad));
- }
- };
- }
-
- /**
- * Convert a CommonsRDF Graph to a Jena Graph. If the Graph was from Jena
- * originally, return that original object else create a copy using Jena
- * objects.
- *
- * @param graph Commons RDF {@link Graph} to convert
- * @return Converted Jena {@link org.apache.jena.graph.Graph}
- */
- public org.apache.jena.graph.Graph asJenaGraph(Graph graph) {
- if (graph instanceof JenaGraph)
- return ((JenaGraph) graph).asJenaGraph();
- org.apache.jena.graph.Graph g = GraphFactory.createGraphMem();
- graph.stream().forEach(t -> g.add(asJenaTriple(t)));
- return g;
- }
-
- /**
- * Convert a CommonsRDF RDFTerm to a Jena Node. If the RDFTerm was from Jena
- * originally, return that original object, else create a copy using Jena
- * objects.
- *
- * @param term Commons RDF {@link RDFTerm} to convert
- * @return Converted Jena {@link Node}
- */
- public Node asJenaNode(RDFTerm term) {
- if (term == null) {
- return null;
- }
- if (term instanceof JenaRDFTerm)
- // TODO: What if it's a JenaBlankNodeImpl with
- // a different salt? Do we need to rewrite the
- // jena blanknode identifier?
- return ((JenaRDFTerm) term).asJenaNode();
-
- if (term instanceof IRI)
- return NodeFactory.createURI(((IRI) term).getIRIString());
-
- if (term instanceof Literal) {
- Literal lit = (Literal) term;
- RDFDatatype dt = NodeFactory.getType(lit.getDatatype().getIRIString());
- String lang = lit.getLanguageTag().orElse("");
- return NodeFactory.createLiteral(lit.getLexicalForm(), lang, dt);
- }
-
- if (term instanceof BlankNode) {
- String id = ((BlankNode) term).uniqueReference();
- return NodeFactory.createBlankNode(id);
- }
- throw new ConversionException("Not a concrete RDF Term: " + term);
- }
-
- /**
- * Convert a CommonsRDF {@link Triple} to a Jena
- * {@link org.apache.jena.graph.Triple}.
- * <p>
- * If the triple was from Jena originally, return that original object, else
- * create a copy using Jena objects.
- *
- * @param triple Commons RDF {@link Triple} to convert
- * @return Converted Jena {@link org.apache.jena.graph.Triple}
- */
- public org.apache.jena.graph.Triple asJenaTriple(Triple triple) {
- if (triple instanceof JenaTriple)
- return ((JenaTriple) triple).asJenaTriple();
- return org.apache.jena.graph.Triple.create(
- asJenaNode(triple.getSubject()),
- asJenaNode(triple.getPredicate()),
- asJenaNode(triple.getObject()));
- }
-
-
- /**
- * Convert a CommonsRDF {@link Quad} to a Jena
- * {@link org.apache.jena.sparql.core.Quad}.
- * <p>
- * If the quad was from Jena originally, return that original object,
- * otherwise create a copy using Jena objects.
- *
- * @param quad Commons RDF {@link Quad} to convert
- * @return Converted Jena {@link org.apache.jena.sparql.core.Quad}
- */
- public org.apache.jena.sparql.core.Quad asJenaQuad(Quad quad) {
- if (quad instanceof JenaQuad) {
- return ((JenaQuad) quad).asJenaQuad();
- }
- return org.apache.jena.sparql.core.Quad.create(
- asJenaNode(quad.getGraphName().orElse(null)),
- asJenaNode(quad.getSubject()),
- asJenaNode(quad.getPredicate()),
- asJenaNode(quad.getObject()));
- }
-
- // Some simple validations - full IRI parsing is not cheap.
- private void validateIRI(String iri) {
- if (iri.contains(" "))
- throw new IllegalArgumentException();
- if (iri.contains("<"))
- throw new IllegalArgumentException();
- if (iri.contains(">"))
- throw new IllegalArgumentException();
- }
-
- private static void validateLang(String languageTag) {
- if (languageTag.contains(" "))
- throw new IllegalArgumentException("Invalid language tag: " + languageTag);
- }
-
- /**
- * Return the {@link UUID} salt used by this factory.
- * <p>
- * The salt is used for the purposes of {@link BlankNode} identity, see
- * {@link BlankNode#uniqueReference()} for details.
- * <p>
- * This salt can be used with the constructor
- * {@link JenaRDF#JenaRDF(UUID)}
- * if consistent or reproducible {@link BlankNode}s are desirable.
- *
- * @return The {@link UUID} used as salt
- */
- public UUID salt() {
- return salt;
- }
+ private static InternalJenaFactory internalJenaFactory = new InternalJenaFactory() {
+ };
+
+ private final UUID salt;
+
+ /**
+ * Create a JenaRDF.
+ * <p>
+ * This constructor will use a randomly generated {@link UUID} as a salt for
+ * the purposes of {@link BlankNode} identity, see {@link #salt()}.
+ */
+ public JenaRDF() {
+ this.salt = UUID.randomUUID();
+ }
+
+ /**
+ * Create a JenaRDF.
+ * <p>
+ * This constructor will use the specified {@link UUID} as a salt for the
+ * purposes of {@link BlankNode} identity, and should only be used in cases
+ * where predictable and consistent {@link BlankNode#uniqueReference()} are
+ * important.
+ *
+ * @param salt
+ * {@link UUID} to use as salt for {@link BlankNode} equality
+ */
+ public JenaRDF(UUID salt) {
+ this.salt = salt;
+ }
+
+ @Override
+ public JenaBlankNode createBlankNode() {
+ return internalJenaFactory.createBlankNode(salt());
+ }
+
+ @Override
+ public JenaBlankNode createBlankNode(String name) {
+ return internalJenaFactory.createBlankNode(name, salt());
+ }
+
+ @Override
+ public JenaDataset createDataset() {
+ return internalJenaFactory.createDataset(salt());
+ }
+
+ @Override
+ public JenaGraph createGraph() {
+ return internalJenaFactory.createGraph(salt());
+ }
+
+ @Override
+ public JenaIRI createIRI(String iri) {
+ validateIRI(iri);
+ return internalJenaFactory.createIRI(iri);
+ }
+
+ @Override
+ public JenaLiteral createLiteral(String lexicalForm) {
+ return internalJenaFactory.createLiteral(lexicalForm);
+ }
+
+ @Override
+ public JenaLiteral createLiteral(String lexicalForm, IRI dataType) {
+ return internalJenaFactory.createLiteralDT(lexicalForm, dataType.getIRIString());
+ }
+
+ @Override
+ public JenaLiteral createLiteral(String lexicalForm, String languageTag) {
+ validateLang(languageTag);
+ return internalJenaFactory.createLiteralLang(lexicalForm, languageTag);
+ }
+
+ @Override
+ public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return internalJenaFactory.createTriple(subject, predicate, object);
+ }
+
+ @Override
+ public JenaQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws IllegalArgumentException, UnsupportedOperationException {
+ return internalJenaFactory.createQuad(subject, predicate, object, graphName);
+ }
+
+ /**
+ * Create a generalized Jena triple.
+ * <p>
+ * The <em>generalized triple</em> supports any {@link RDFTerm} as its
+ * {@link TripleLike#getSubject()} {@link TripleLike#getPredicate()} or
+ * {@link TripleLike#getObject()}.
+ *
+ * @see #createTriple(BlankNodeOrIRI, IRI, RDFTerm)
+ * @see #createGeneralizedQuad(RDFTerm, RDFTerm, RDFTerm, RDFTerm)
+ *
+ * @param subject
+ * The subject of the statement
+ * @param predicate
+ * The predicate of the statement
+ * @param object
+ * The object of the statement
+ * @return Generalized {@link TripleLike}. Note that the generalized triple
+ * does <strong>not</strong> implement {@link Triple#equals(Object)}
+ * or {@link Triple#hashCode()}.
+ */
+ public JenaGeneralizedTripleLike createGeneralizedTriple(RDFTerm subject, RDFTerm predicate, RDFTerm object) {
+ return internalJenaFactory.createGeneralizedTriple(subject, predicate, object);
+ }
+
+ /**
+ * Create a generalized Jena quad.
+ * <p>
+ * The <em>generalized quad</em> supports any {@link RDFTerm} as its
+ * {@link QuadLike#getSubject()} {@link QuadLike#getPredicate()},
+ * {@link QuadLike#getObject()} or {@link QuadLike#getObject()}.
+ *
+ * @see #createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)
+ * @see #createGeneralizedTriple(RDFTerm, RDFTerm, RDFTerm)
+ *
+ * @param subject
+ * The subject of the statement
+ * @param predicate
+ * The predicate of the statement
+ * @param object
+ * The object of the statement
+ * @param graphName
+ * The graph name of the statement
+ * @return Generalized {@link QuadLike}. Note that the generalized quad does
+ * <strong>not</strong> implement {@link Quad#equals(Object)} or
+ * {@link Quad#hashCode()}.
+ */
+ public JenaGeneralizedQuadLike createGeneralizedQuad(RDFTerm subject, RDFTerm predicate, RDFTerm object,
+ RDFTerm graphName) {
+ return internalJenaFactory.createGeneralizedQuad(subject, predicate, object, graphName);
+ }
+
+ /**
+ * Adapt an existing Jena Node to CommonsRDF {@link RDFTerm}.
+ * <p>
+ * If {@link Node#isLiteral()}, then the returned value is a
+ * {@link Literal}. If {@link Node#isURI()}, the returned value is a IRI. If
+ * {$@link Node#isBlank()}, the returned value is a {@link BlankNode}, which
+ * will use a {@link UUID} salt from this {@link JenaRDF} instance in
+ * combination with {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
+ * @see #asRDFTerm(RDF, Node)
+ *
+ * @param node
+ * The Jena Node to adapt. It's {@link Node#isConcrete()} must be
+ * <code>true</code>.
+ * @return Adapted {@link JenaRDFTerm}
+ * @throws ConversionException
+ * If the {@link Node} can't be represented as an
+ * {@link RDFTerm}, e.g. if the node is not concrete or
+ * represents a variable in Jena.
+ */
+ public JenaRDFTerm asRDFTerm(Node node) throws ConversionException {
+ return internalJenaFactory.createRDFTerm(node, salt());
+ }
+
+ /**
+ * Convert from Jena {@link Node} to any Commons RDF implementation.
+ * <p>
+ * Note that if the {@link Node#isBlank()}, then the factory's
+ * {@link RDF#createBlankNode(String)} will be used, meaning that care
+ * should be taken if reusing an {@link RDF} instance for multiple
+ * conversion sessions.
+ *
+ * @see #asRDFTerm(Node)
+ *
+ * @param factory
+ * {@link RDF} to use for creating {@link RDFTerm}.
+ * @param node
+ * The Jena Node to adapt. It's {@link Node#isConcrete()} must be
+ * <code>true</code>.
+ * @return Adapted {@link RDFTerm}
+ * @throws ConversionException
+ * If the {@link Node} can't be represented as an
+ * {@link RDFTerm}, e.g. if the node is not concrete or
+ * represents a variable in Jena.
+ */
+ public static RDFTerm asRDFTerm(RDF factory, Node node) {
+ if (node == null) {
+ return null;
+ }
+ if (factory instanceof JenaRDF) {
+ // No need to convert, just wrap
+ return ((JenaRDF) factory).asRDFTerm(node);
+ }
+ if (node.isURI())
+ return factory.createIRI(node.getURI());
+ if (node.isLiteral()) {
+ String lang = node.getLiteralLanguage();
+ if (lang != null && !lang.isEmpty())
+ return factory.createLiteral(node.getLiteralLexicalForm(), lang);
+ if (node.getLiteralDatatype().equals(XSDDatatype.XSDstring))
+ return factory.createLiteral(node.getLiteralLexicalForm());
+ IRI dt = factory.createIRI(node.getLiteralDatatype().getURI());
+ return factory.createLiteral(node.getLiteralLexicalForm(), dt);
+ }
+ if (node.isBlank())
+ // The factory
+ return factory.createBlankNode(node.getBlankNodeLabel());
+ throw new ConversionException("Node is not a concrete RDF Term: " + node);
+ }
+
+ /**
+ * Adapt an existing Jena Triple to CommonsRDF {@link Triple}.
+ * <p>
+ * If the triple contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this {@link JenaRDF}
+ * instance in combination with {@link Node#getBlankNodeId()} for the
+ * purpose of its {@link BlankNode#uniqueReference()}.
+ *
+ * @see #asTriple(RDF, org.apache.jena.graph.Triple)
+ *
+ * @param triple
+ * Jena {@link org.apache.jena.graph.Triple} to adapt
+ * @return Adapted {@link JenaTriple}
+ * @throws ConversionException
+ * if any of the triple's nodes are not concrete or the triple
+ * is a generalized triple
+ */
+ public JenaTriple asTriple(org.apache.jena.graph.Triple triple) throws ConversionException {
+ return internalJenaFactory.createTriple(triple, salt());
+ }
+
+ /**
+ * Adapt a generalized Jena {@link org.apache.jena.graph.Triple} to a
+ * CommonsRDF {@link TripleLike}.
+ * <p>
+ * The generalized triple supports any {@link RDFTerm} as its
+ * {@link TripleLike#getSubject()} {@link TripleLike#getPredicate()} or
+ * {@link TripleLike#getObject()}.
+ * <p>
+ * If the Jena triple contains any {@link Node#isBlank()}, then any
+ * corresponding {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
+ * @see #asTriple(RDF, org.apache.jena.graph.Triple)
+ *
+ * @param triple
+ * Jena triple
+ * @return Adapted {@link TripleLike}. Note that the generalized triple does
+ * <strong>not</strong> implement {@link Triple#equals(Object)} or
+ * {@link Triple#hashCode()}.
+ * @throws ConversionException
+ * if any of the triple's nodes are not concrete
+ */
+ public JenaTripleLike asGeneralizedTriple(org.apache.jena.graph.Triple triple) throws ConversionException {
+ return internalJenaFactory.createGeneralizedTriple(triple, salt());
+ }
+
+ /**
+ * Adapt a generalized Jena {@link org.apache.jena.sparql.core.Quad} to a
+ * CommonsRDF {@link QuadLike}.
+ * <p>
+ * The generalized quad supports any {@link RDFTerm} as its
+ * {@link QuadLike#getGraphName()}, {@link QuadLike#getSubject()}
+ * {@link QuadLike#getPredicate()} or {@link QuadLike#getObject()}.
+ * <p>
+ * If the Jena quad contains any {@link Node#isBlank()}, then any
+ * corresponding {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
+ * @see #asQuad(org.apache.jena.sparql.core.Quad)
+ * @see #asGeneralizedTriple(org.apache.jena.graph.Triple)
+ *
+ * @param quad
+ * Jena quad
+ * @return Adapted {@link QuadLike}. Note that the generalized quad does
+ * <strong>not</strong> implement {@link Quad#equals(Object)} or
+ * {@link Quad#hashCode()}.
+ * @throws ConversionException
+ * if any of the quad nodes are not concrete
+ */
+ public JenaQuadLike<RDFTerm> asGeneralizedQuad(org.apache.jena.sparql.core.Quad quad) throws ConversionException {
+ return internalJenaFactory.createGeneralizedQuad(quad, salt());
+ }
+
+ /**
+ * Convert from Jena {@link org.apache.jena.graph.Triple} to a Commons RDF
+ * {@link Triple}.
+ * <p>
+ * Note that if any of the triple's nodes {@link Node#isBlank()}, then the
+ * factory's {@link RDF#createBlankNode(String)} will be used, meaning that
+ * care should be taken if reusing an {@link RDF} instance for multiple
+ * conversion sessions.
+ *
+ * @see #asTriple(org.apache.jena.graph.Triple)
+ *
+ * @param factory
+ * {@link RDF} to use for creating the {@link Triple} and its
+ * {@link RDFTerm}s.
+ * @param triple
+ * Jena triple
+ * @return Converted triple
+ * @throws ConversionException
+ * if any of the triple's nodes are not concrete or the triple
+ * is a generalized triple
+ */
+ public static Triple asTriple(RDF factory, org.apache.jena.graph.Triple triple) throws ConversionException {
+ if (factory instanceof JenaRDF) {
+ // No need to convert, just wrap
+ return ((JenaRDF) factory).asTriple(triple);
+ }
+ final BlankNodeOrIRI subject;
+ final IRI predicate;
+ try {
+ subject = (BlankNodeOrIRI) asRDFTerm(factory, triple.getSubject());
+ predicate = (IRI) asRDFTerm(factory, triple.getPredicate());
+ } catch (ClassCastException ex) {
+ throw new ConversionException("Can't convert generalized triple: " + triple, ex);
+ }
+ RDFTerm object = asRDFTerm(factory, triple.getObject());
+ return factory.createTriple(subject, predicate, object);
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.sparql.core.Quad} to
+ * CommonsRDF {@link Quad}.
+ * <p>
+ * If the quad contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this {@link JenaRDF}
+ * instance in combination with {@link Node#getBlankNodeId()} for the
+ * purpose of its {@link BlankNode#uniqueReference()}.
+ *
+ * @param quad
+ * Jena quad
+ * @return Adapted quad
+ */
+ public JenaQuad asQuad(org.apache.jena.sparql.core.Quad quad) {
+ return internalJenaFactory.createQuad(quad, salt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.graph.Graph} to CommonsRDF
+ * {@link Graph}.
+ * <p>
+ * This does not take a copy, changes to the CommonsRDF Graph are reflected
+ * in the jena graph, which is accessible from
+ * {@link JenaGraph#asJenaGraph()}.
+ * <p>
+ * If the graph contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this {@link JenaRDF}
+ * instance in combination with {@link Node#getBlankNodeId()} for the
+ * purpose of its {@link BlankNode#uniqueReference()}.
+ *
+ * @param graph
+ * Jena {@link org.apache.jena.graph.Graph} to adapt
+ * @return Adapted {@link JenaGraph}
+ */
+ public JenaGraph asGraph(org.apache.jena.graph.Graph graph) {
+ return internalJenaFactory.createGraph(graph, salt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.rdf.model.Model} to
+ * CommonsRDF {@link Graph}.
+ * <p>
+ * This does not ake a copy, changes to the CommonsRDF Graph are reflected
+ * in the jena graph, which is accessible from
+ * {@link JenaGraph#asJenaGraph()}.
+ * <p>
+ * If the graph contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this {@link JenaRDF}
+ * instance in combination with {@link Node#getBlankNodeId()} for the
+ * purpose of its {@link BlankNode#uniqueReference()}.
+ *
+ * @param model
+ * Jena {@link org.apache.jena.rdf.model.Model} to adapt
+ * @return Adapted {@link JenaGraph}
+ */
+ public JenaGraph asGraph(org.apache.jena.rdf.model.Model model) {
+ return internalJenaFactory.createGraph(model, salt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link DatasetGraph} to CommonsRDF
+ * {@link Dataset}.
+ * <p>
+ * This does not take a copy, changes to the CommonsRDF Dataset are
+ * reflected in the jena dataset graph, which is accessible from
+ * {@link JenaDataset#asJenaDatasetGraph()}.
+ * <p>
+ * If the dataset contains any {@link Node#isBlank()}, then any
+ * corresponding {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
+ * @param datasetGraph
+ * Jena {@link DatasetGraph} to adapt
+ * @return Adapted {@link JenaDataset}
+ */
+ public JenaDataset asDataset(DatasetGraph datasetGraph) {
+ return internalJenaFactory.createDataset(datasetGraph, salt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.query.Dataset} to
+ * CommonsRDF {@link Dataset}.
+ * <p>
+ * This does not take a copy, changes to the CommonsRDF Dataset are
+ * reflected in the jena dataset graph, which is accessible from
+ * {@link JenaDataset#asJenaDatasetGraph()}.
+ * <p>
+ * If the dataset contains any {@link Node#isBlank()}, then any
+ * corresponding {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
+ * @param datasetGraph
+ * Jena {@link org.apache.jena.query.Dataset} to adapt
+ * @return Adapted {@link JenaDataset}
+ */
+ public JenaDataset asDataset(org.apache.jena.query.Dataset datasetGraph) {
+ return internalJenaFactory.createDataset(datasetGraph.asDatasetGraph(), salt());
+ }
+
+ /**
+ * Convert from Jena {@link org.apache.jena.sparql.core.Quad} to a Commons
+ * RDF {@link Quad}.
+ * <p>
+ * Note that if any of the quad's nodes {@link Node#isBlank()}, then the
+ * factory's {@link RDF#createBlankNode(String)} will be used, meaning that
+ * care should be taken if reusing an {@link RDF} instance for multiple
+ * conversion sessions.
+ *
+ * @see #asQuad(org.apache.jena.sparql.core.Quad)
+ * @see #asGeneralizedQuad(org.apache.jena.sparql.core.Quad)
+ *
+ * @param factory
+ * {@link RDF} to use for creating the {@link Triple} and its
+ * {@link RDFTerm}s.
+ * @param quad
+ * Jena {@link org.apache.jena.sparql.core.Quad} to adapt
+ * @return Converted {@link Quad}
+ * @throws ConversionException
+ * if any of the quad's nodes are not concrete or the quad is a
+ * generalized quad
+ */
+ public static Quad asQuad(RDF factory, org.apache.jena.sparql.core.Quad quad) {
+ if (factory instanceof JenaRDF) {
+ // No need to convert, just wrap
+ return ((JenaRDF) factory).asQuad(quad);
+ }
+ BlankNodeOrIRI graphName = (BlankNodeOrIRI) (asRDFTerm(factory, quad.getGraph()));
+ BlankNodeOrIRI subject = (BlankNodeOrIRI) (asRDFTerm(factory, quad.getSubject()));
+ IRI predicate = (IRI) (asRDFTerm(factory, quad.getPredicate()));
+ RDFTerm object = asRDFTerm(factory, quad.getObject());
+ return factory.createQuad(graphName, subject, predicate, object);
+ }
+
+ /**
+ * Return {@link RDFSyntax} corresponding to a Jena {@link Lang}.
+ *
+ * @param lang
+ * {@link Lang} to convert
+ * @return Matched {@link RDFSyntax}, otherwise {@link Optional#empty()}
+ */
+ public Optional<RDFSyntax> asRDFSyntax(Lang lang) {
+ return RDFSyntax.byMediaType(lang.getContentType().getContentType());
+ }
+
+ /**
+ * Return Jena {@link Lang} corresponding to a {@link RDFSyntax}.
+ *
+ * @param rdfSyntax
+ * {@link RDFSyntax} to convert
+ * @return Matched {@link Lang}, otherwise {@link Optional#empty()}
+ */
+ public Optional<Lang> asJenaLang(RDFSyntax rdfSyntax) {
+ return Optional.ofNullable(RDFLanguages.contentTypeToLang(rdfSyntax.mediaType));
+ }
+
+ /**
+ * Create a {@link StreamRDF} instance that inserts the converted
+ * {@link Quad}s. into a the provided {@link Consumer}.
+ * <p>
+ * The returned {@link StreamRDF} can be used for instance with Jena's
+ * {@link RDFDataMgr#parse(StreamRDF, String)}.
+ *
+ * @param factory
+ * {@link RDF} to use for creating {@link RDFTerm}s and
+ * {@link Quad}s.
+ * @param consumer
+ * A {@link Consumer} of {@link Quad}s
+ * @return A {@link StreamRDF} that will stream converted quads to the
+ * consumer
+ */
+ public static StreamRDF streamJenaToQuad(RDF factory, Consumer<Quad> consumer) {
+ return new StreamRDFBase() {
+ @Override
+ public void quad(org.apache.jena.sparql.core.Quad quad) {
+ consumer.accept(asQuad(factory, quad));
+ }
+ };
+ }
+
+ /**
+ * Create a {@link StreamRDF} instance that inserts generalized
+ * {@link TripleLike}s. into a the provided {@link Consumer}.
+ * <p>
+ * A generalized triple allows any {@link RDFTerm} for
+ * {@link TripleLike#getSubject()}, {@link TripleLike#getPredicate()} and
+ * {@link TripleLike#getObject()}.
+ * <p>
+ * The returned {@link StreamRDF} can be used for instance with Jena's
+ * {@link RDFDataMgr#parse(StreamRDF, String)}.
+ *
+ * @param generalizedConsumer
+ * A {@link Consumer} of generalized {@link TripleLike}s
+ * @return A {@link StreamRDF} that will stream generalized triples to the
+ * consumer
+ */
+ public StreamRDF streamJenaToGeneralizedTriple(Consumer<TripleLike> generalizedConsumer) {
+ return new StreamRDFBase() {
+ @Override
+ public void triple(org.apache.jena.graph.Triple triple) {
+ generalizedConsumer.accept(asGeneralizedTriple(triple));
+ }
+ };
+ }
+
+ /**
+ * Create a {@link StreamRDF} instance that inserts generalized
+ * {@link QuadLike}s. into a the provided {@link Consumer}.
+ * <p>
+ * A generalized quad allows any {@link RDFTerm} for
+ * {@link QuadLike#getSubject()}, {@link TripleLike#getPredicate()},
+ * {@link QuadLike#getObject()} and {@link QuadLike#getGraphName()} .
+ * <p>
+ * The returned {@link StreamRDF} can be used for instance with Jena's
+ * {@link RDFDataMgr#parse(StreamRDF, String)}.
+ *
+ * @param generalizedConsumer
+ * A {@link Consumer} of generalized {@link QuadLike}s
+ * @return A {@link StreamRDF} that will stream generalized quads to the
+ * consumer
+ */
+ public StreamRDF streamJenaToGeneralizedQuad(Consumer<QuadLike<RDFTerm>> generalizedConsumer) {
+ return new StreamRDFBase() {
+ @Override
+ public void quad(org.apache.jena.sparql.core.Quad quad) {
+ generalizedConsumer.accept(asGeneralizedQuad(quad));
+ }
+ };
+ }
+
+ /**
+ * Convert a CommonsRDF Graph to a Jena Graph. If the Graph was from Jena
+ * originally, return that original object else create a copy using Jena
+ * objects.
+ *
+ * @param graph
+ * Commons RDF {@link Graph} to convert
+ * @return Converted Jena {@link org.apache.jena.graph.Graph}
+ */
+ public org.apache.jena.graph.Graph asJenaGraph(Graph graph) {
+ if (graph instanceof JenaGraph)
+ return ((JenaGraph) graph).asJenaGraph();
+ org.apache.jena.graph.Graph g = GraphFactory.createGraphMem();
+ graph.stream().forEach(t -> g.add(asJenaTriple(t)));
+ return g;
+ }
+
+ /**
+ * Convert a CommonsRDF RDFTerm to a Jena Node. If the RDFTerm was from Jena
+ * originally, return that original object, else create a copy using Jena
+ * objects.
+ *
+ * @param term
+ * Commons RDF {@link RDFTerm} to convert
+ * @return Converted Jena {@link Node}
+ */
+ public Node asJenaNode(RDFTerm term) {
+ if (term == null) {
+ return null;
+ }
+ if (term instanceof JenaRDFTerm)
+ // TODO: What if it's a JenaBlankNodeImpl with
+ // a different salt? Do we need to rewrite the
+ // jena blanknode identifier?
+ return ((JenaRDFTerm) term).asJenaNode();
+
+ if (term instanceof IRI)
+ return NodeFactory.createURI(((IRI) term).getIRIString());
+
+ if (term instanceof Literal) {
+ Literal lit = (Literal) term;
+ RDFDatatype dt = NodeFactory.getType(lit.getDatatype().getIRIString());
+ String lang = lit.getLanguageTag().orElse("");
+ return NodeFactory.createLiteral(lit.getLexicalForm(), lang, dt);
+ }
+
+ if (term instanceof BlankNode) {
+ String id = ((BlankNode) term).uniqueReference();
+ return NodeFactory.createBlankNode(id);
+ }
+ throw new ConversionException("Not a concrete RDF Term: " + term);
+ }
+
+ /**
+ * Convert a CommonsRDF {@link Triple} to a Jena
+ * {@link org.apache.jena.graph.Triple}.
+ * <p>
+ * If the triple was from Jena originally, return that original object, else
+ * create a copy using Jena objects.
+ *
+ * @param triple
+ * Commons RDF {@link Triple} to convert
+ * @return Converted Jena {@link org.apache.jena.graph.Triple}
+ */
+ public org.apache.jena.graph.Triple asJenaTriple(Triple triple) {
+ if (triple instanceof JenaTriple)
+ return ((JenaTriple) triple).asJenaTriple();
+ return org.apache.jena.graph.Triple.create(asJenaNode(triple.getSubject()), asJenaNode(triple.getPredicate()),
+ asJenaNode(triple.getObject()));
+ }
+
+ /**
+ * Convert a CommonsRDF {@link Quad} to a Jena
+ * {@link org.apache.jena.sparql.core.Quad}.
+ * <p>
+ * If the quad was from Jena originally, return that original object,
+ * otherwise create a copy using Jena objects.
+ *
+ * @param quad
+ * Commons RDF {@link Quad} to convert
+ * @return Converted Jena {@link org.apache.jena.sparql.core.Quad}
+ */
+ public org.apache.jena.sparql.core.Quad asJenaQuad(Quad quad) {
+ if (quad instanceof JenaQuad) {
+ return ((JenaQuad) quad).asJenaQuad();
+ }
+ return org.apache.jena.sparql.core.Quad.create(asJenaNode(quad.getGraphName().orElse(null)),
+ asJenaNode(quad.getSubject()), asJenaNode(quad.getPredicate()), asJenaNode(quad.getObject()));
+ }
+
+ // Some simple validations - full IRI parsing is not cheap.
+ private void validateIRI(String iri) {
+ if (iri.contains(" "))
+ throw new IllegalArgumentException();
+ if (iri.contains("<"))
+ throw new IllegalArgumentException();
+ if (iri.contains(">"))
+ throw new IllegalArgumentException();
+ }
+
+ private static void validateLang(String languageTag) {
+ if (languageTag.contains(" "))
+ throw new IllegalArgumentException("Invalid language tag: " + languageTag);
+ }
+
+ /**
+ * Return the {@link UUID} salt used by this factory.
+ * <p>
+ * The salt is used for the purposes of {@link BlankNode} identity, see
+ * {@link BlankNode#uniqueReference()} for details.
+ * <p>
+ * This salt can be used with the constructor {@link JenaRDF#JenaRDF(UUID)}
+ * if consistent or reproducible {@link BlankNode}s are desirable.
+ *
+ * @return The {@link UUID} used as salt
+ */
+ public UUID salt() {
+ return salt;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTerm.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTerm.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTerm.java
index 0bbe26b..bd854d1 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTerm.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDFTerm.java
@@ -31,5 +31,5 @@ import org.apache.jena.graph.Node;
* @see JenaBlankNode
*/
public interface JenaRDFTerm extends RDFTerm {
- public Node asJenaNode();
+ public Node asJenaNode();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/JenaTriple.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaTriple.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaTriple.java
index 09fe76d..c73e018 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaTriple.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaTriple.java
@@ -17,11 +17,11 @@
*/
package org.apache.commons.rdf.jena;
-/**
+/**
* A Jena-backed {@link org.apache.commons.rdf.api.Triple}.
* <p>
- * The underlying Jena {@link org.apache.jena.graph.Triple}
- * can be accessed with {@link #asJenaTriple()}.
+ * The underlying Jena {@link org.apache.jena.graph.Triple} can be accessed with
+ * {@link #asJenaTriple()}.
*/
public interface JenaTriple extends org.apache.commons.rdf.api.Triple, JenaTripleLike {
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/JenaTripleLike.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaTripleLike.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaTripleLike.java
index 96daa02..49a8eb5 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaTripleLike.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaTripleLike.java
@@ -34,13 +34,12 @@ import org.apache.jena.graph.Triple;
* @see JenaGeneralizedQuadLike
*
*/
-public interface JenaTripleLike
- extends org.apache.commons.rdf.api.TripleLike {
+public interface JenaTripleLike extends org.apache.commons.rdf.api.TripleLike {
- /**
- * Return the adapted Jena triple
- *
- * @return Adapted Jena {@link Triple}.
- */
- Triple asJenaTriple();
+ /**
+ * Return the adapted Jena triple
+ *
+ * @return Adapted Jena {@link Triple}.
+ */
+ Triple asJenaTriple();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java b/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
index 81069f0..bf2b4bf 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
@@ -40,69 +40,67 @@ import org.apache.jena.riot.system.StreamRDFLib;
public class JenaRDFParser extends AbstractRDFParser<JenaRDFParser> implements RDFParser {
- private Consumer<TripleLike> generalizedConsumerTriple;
- private Consumer<QuadLike<RDFTerm>> generalizedConsumerQuad;
+ private Consumer<TripleLike> generalizedConsumerTriple;
+ private Consumer<QuadLike<RDFTerm>> generalizedConsumerQuad;
- protected RDF createRDFTermFactory() {
- return new JenaRDF();
- }
+ protected RDF createRDFTermFactory() {
+ return new JenaRDF();
+ }
- public JenaRDFParser targetGeneralizedTriple(Consumer<TripleLike> consumer) {
- JenaRDFParser c = this.clone();
- c.resetTarget();
- c.generalizedConsumerTriple = consumer;
- return c;
- }
+ public JenaRDFParser targetGeneralizedTriple(Consumer<TripleLike> consumer) {
+ JenaRDFParser c = this.clone();
+ c.resetTarget();
+ c.generalizedConsumerTriple = consumer;
+ return c;
+ }
- public JenaRDFParser targetGeneralizedQuad(Consumer<QuadLike<RDFTerm>> consumer) {
- JenaRDFParser c = this.clone();
- c.resetTarget();
- c.generalizedConsumerQuad = consumer;
- return c;
- }
-
- @Override
- protected void resetTarget() {
- super.resetTarget();
- this.generalizedConsumerTriple = null;
- this.generalizedConsumerQuad = null;
- }
-
- @Override
- protected void parseSynchronusly() throws IOException {
- StreamRDF dest;
- JenaRDF jenaRDF = getJenaFactory();
- if (getTargetGraph().isPresent() && getTargetGraph().get() instanceof JenaGraph) {
- Graph jenaGraph = ((JenaGraph) getTargetGraph().get()).asJenaGraph();
- dest = StreamRDFLib.graph(jenaGraph);
- } else {
- if (generalizedConsumerQuad != null) {
- dest = jenaRDF.streamJenaToGeneralizedQuad(generalizedConsumerQuad);
- } else if (generalizedConsumerTriple != null) {
- dest = jenaRDF.streamJenaToGeneralizedTriple(generalizedConsumerTriple);
- } else {
- dest = JenaRDF.streamJenaToQuad(getRdfTermFactory().get(), getTarget());
- }
- }
+ public JenaRDFParser targetGeneralizedQuad(Consumer<QuadLike<RDFTerm>> consumer) {
+ JenaRDFParser c = this.clone();
+ c.resetTarget();
+ c.generalizedConsumerQuad = consumer;
+ return c;
+ }
- Lang lang = getContentTypeSyntax().flatMap(jenaRDF::asJenaLang).orElse(null);
- String baseStr = getBase().map(IRI::getIRIString).orElse(null);
+ @Override
+ protected void resetTarget() {
+ super.resetTarget();
+ this.generalizedConsumerTriple = null;
+ this.generalizedConsumerQuad = null;
+ }
- if (getSourceIri().isPresent()) {
- RDFDataMgr.parse(dest, getSourceIri().get().toString(), baseStr, lang, null);
- } else if (getSourceFile().isPresent()) {
- try (InputStream s = Files.newInputStream(getSourceFile().get())) {
- RDFDataMgr.parse(dest, s, baseStr, lang, null);
- }
- } else {
- RDFDataMgr.parse(dest, getSourceInputStream().get(), baseStr, lang, null);
- }
- }
+ @Override
+ protected void parseSynchronusly() throws IOException {
+ StreamRDF dest;
+ JenaRDF jenaRDF = getJenaFactory();
+ if (getTargetGraph().isPresent() && getTargetGraph().get() instanceof JenaGraph) {
+ Graph jenaGraph = ((JenaGraph) getTargetGraph().get()).asJenaGraph();
+ dest = StreamRDFLib.graph(jenaGraph);
+ } else {
+ if (generalizedConsumerQuad != null) {
+ dest = jenaRDF.streamJenaToGeneralizedQuad(generalizedConsumerQuad);
+ } else if (generalizedConsumerTriple != null) {
+ dest = jenaRDF.streamJenaToGeneralizedTriple(generalizedConsumerTriple);
+ } else {
+ dest = JenaRDF.streamJenaToQuad(getRdfTermFactory().get(), getTarget());
+ }
+ }
- private JenaRDF getJenaFactory() {
- return (JenaRDF) getRdfTermFactory()
- .filter(JenaRDF.class::isInstance)
- .orElseGet(this::createRDFTermFactory);
- }
+ Lang lang = getContentTypeSyntax().flatMap(jenaRDF::asJenaLang).orElse(null);
+ String baseStr = getBase().map(IRI::getIRIString).orElse(null);
+
+ if (getSourceIri().isPresent()) {
+ RDFDataMgr.parse(dest, getSourceIri().get().toString(), baseStr, lang, null);
+ } else if (getSourceFile().isPresent()) {
+ try (InputStream s = Files.newInputStream(getSourceFile().get())) {
+ RDFDataMgr.parse(dest, s, baseStr, lang, null);
+ }
+ } else {
+ RDFDataMgr.parse(dest, getSourceInputStream().get(), baseStr, lang, null);
+ }
+ }
+
+ private JenaRDF getJenaFactory() {
+ return (JenaRDF) getRdfTermFactory().filter(JenaRDF.class::isInstance).orElseGet(this::createRDFTermFactory);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/experimental/package-info.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/experimental/package-info.java b/jena/src/main/java/org/apache/commons/rdf/jena/experimental/package-info.java
index aa2201d..10a1f11 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/experimental/package-info.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/experimental/package-info.java
@@ -18,15 +18,13 @@
/**
* Experimental Commons RDF Jena implementations.
* <p>
- * Classes in this package should be considered <strong>at
- * risk</strong>; they might change or be removed in the next minor update of
- * Commons RDF.
+ * Classes in this package should be considered <strong>at risk</strong>; they
+ * might change or be removed in the next minor update of Commons RDF.
* <p>
* When a class has stabilized, it will move to the
* {@link org.apache.commons.rdf.jena} package.
* <ul>
- * <li>{@link JenaRDFParser} - a Jena-backed
- * implementations of
+ * <li>{@link JenaRDFParser} - a Jena-backed implementations of
* {@link org.apache.commons.rdf.experimental.RDFParser}.</li>
* </ul>
*/
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java
index fd117a2..a4e3f1e 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java
@@ -24,24 +24,24 @@ import org.apache.jena.graph.Node;
import org.apache.jena.riot.out.NodeFmtLib;
class AbstractJenaRDFTerm implements JenaRDFTerm, RDFTerm {
- private Node node;
- // static private PrefixMapping empty = new PrefixMappingImpl();
+ private Node node;
+ // static private PrefixMapping empty = new PrefixMappingImpl();
- protected AbstractJenaRDFTerm(Node node) {
- this.node = node;
- }
+ protected AbstractJenaRDFTerm(Node node) {
+ this.node = node;
+ }
- @Override
- public Node asJenaNode() {
- return node;
- }
+ @Override
+ public Node asJenaNode() {
+ return node;
+ }
- public String ntriplesString() {
- return NodeFmtLib.str(node);
- }
+ public String ntriplesString() {
+ return NodeFmtLib.str(node);
+ }
- @Override
- public String toString() {
- return ntriplesString();
- }
+ @Override
+ public String toString() {
+ return ntriplesString();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
index 10dc069..691eeee 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
@@ -32,110 +32,107 @@ import org.apache.jena.graph.Triple;
import org.apache.jena.sparql.core.Quad;
/**
- * A generalized {@link QuadLike}, backed by a Jena {@link Quad} or {@link Triple}.
+ * A generalized {@link QuadLike}, backed by a Jena {@link Quad} or
+ * {@link Triple}.
* <p>
* This class does not implement any particular {@link #equals(Object)} or
- * {@link #hashCode()} but can otherwise be used as a base class for both
- * a {@link JenaTriple} and a {@link JenaQuad}.
+ * {@link #hashCode()} but can otherwise be used as a base class for both a
+ * {@link JenaTriple} and a {@link JenaQuad}.
*
* @see JenaTripleImpl
* @see JenaQuadImpl
* @see internalJenaFactory#createGeneralizedTriple(RDFTerm, RDFTerm, RDFTerm)
- * @see internalJenaFactory#createGeneralizedQuad(RDFTerm, RDFTerm, RDFTerm, RDFTerm)
+ * @see internalJenaFactory#createGeneralizedQuad(RDFTerm, RDFTerm, RDFTerm,
+ * RDFTerm)
*
*/
-abstract class AbstractQuadLike<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm> implements JenaQuadLike<G> {
-
- private static InternalJenaFactory internalJenaFactory = new InternalJenaFactory(){};
-
- final Optional<G> graphName;
- final S subject;
- final P predicate;
- final O object;
- org.apache.jena.sparql.core.Quad quad = null;
- org.apache.jena.graph.Triple triple = null;
-
- AbstractQuadLike(S subject, P predicate, O object, Optional<G> graphName) {
- this.subject = Objects.requireNonNull(subject);
- this.predicate = Objects.requireNonNull(predicate);
- this.object = Objects.requireNonNull(object);
- this.graphName = Objects.requireNonNull(graphName);
- }
-
- AbstractQuadLike(S subject, P predicate, O object) {
- this(subject, predicate, object, Optional.empty());
- }
-
- @SuppressWarnings("unchecked")
- AbstractQuadLike(org.apache.jena.sparql.core.Quad quad, UUID salt) {
- this.quad = Objects.requireNonNull(quad);
- this.subject = (S) internalJenaFactory.createRDFTerm(quad.getSubject(), salt);
- this.predicate = (P) internalJenaFactory.createRDFTerm(quad.getPredicate(), salt);
- this.object = (O)internalJenaFactory.createRDFTerm(quad.getObject(), salt);
- this.graphName = Optional.of((G) internalJenaFactory.createRDFTerm(quad.getGraph(), salt));
- }
-
- @SuppressWarnings("unchecked")
- AbstractQuadLike(org.apache.jena.graph.Triple triple, UUID salt) {
- this.triple = Objects.requireNonNull(triple);
- this.subject = (S) internalJenaFactory.createRDFTerm(triple.getSubject(), salt);
- this.predicate = (P) internalJenaFactory.createRDFTerm(triple.getPredicate(), salt);
- this.object = (O)internalJenaFactory.createRDFTerm(triple.getObject(), salt);
- this.graphName = Optional.empty();
- }
-
- @Override
- public org.apache.jena.sparql.core.Quad asJenaQuad() {
- JenaRDF factory = new JenaRDF();
- if (quad == null) {
- quad = org.apache.jena.sparql.core.Quad.create(
- factory.asJenaNode(graphName.orElse(null)),
- factory.asJenaNode(subject),
- factory.asJenaNode(predicate),
- factory.asJenaNode(object));
- }
- return quad;
- }
-
- @Override
- public org.apache.jena.graph.Triple asJenaTriple() {
- JenaRDF factory = new JenaRDF();
- if (triple == null) {
- triple = org.apache.jena.graph.Triple.create(
- factory.asJenaNode(subject),
- factory.asJenaNode(predicate),
- factory.asJenaNode(object));
- }
- return triple;
- }
-
- @Override
- public S getSubject() {
- return subject;
- }
-
- @Override
- public P getPredicate() {
- return predicate;
- }
-
- @Override
- public O getObject() {
- return object;
- }
-
- @Override
- public Optional<G> getGraphName() {
- return graphName;
- }
-
- @Override
- public String toString() {
- // kind of nquad syntax
- return getSubject().ntriplesString() + " " +
- getPredicate().ntriplesString() + " "
- + getObject().ntriplesString() + " " +
- getGraphName().map(RDFTerm::ntriplesString).orElse("") + ".";
- }
+abstract class AbstractQuadLike<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm>
+ implements JenaQuadLike<G> {
+
+ private static InternalJenaFactory internalJenaFactory = new InternalJenaFactory() {
+ };
+
+ final Optional<G> graphName;
+ final S subject;
+ final P predicate;
+ final O object;
+ org.apache.jena.sparql.core.Quad quad = null;
+ org.apache.jena.graph.Triple triple = null;
+
+ AbstractQuadLike(S subject, P predicate, O object, Optional<G> graphName) {
+ this.subject = Objects.requireNonNull(subject);
+ this.predicate = Objects.requireNonNull(predicate);
+ this.object = Objects.requireNonNull(object);
+ this.graphName = Objects.requireNonNull(graphName);
+ }
+
+ AbstractQuadLike(S subject, P predicate, O object) {
+ this(subject, predicate, object, Optional.empty());
+ }
+
+ @SuppressWarnings("unchecked")
+ AbstractQuadLike(org.apache.jena.sparql.core.Quad quad, UUID salt) {
+ this.quad = Objects.requireNonNull(quad);
+ this.subject = (S) internalJenaFactory.createRDFTerm(quad.getSubject(), salt);
+ this.predicate = (P) internalJenaFactory.createRDFTerm(quad.getPredicate(), salt);
+ this.object = (O) internalJenaFactory.createRDFTerm(quad.getObject(), salt);
+ this.graphName = Optional.of((G) internalJenaFactory.createRDFTerm(quad.getGraph(), salt));
+ }
+
+ @SuppressWarnings("unchecked")
+ AbstractQuadLike(org.apache.jena.graph.Triple triple, UUID salt) {
+ this.triple = Objects.requireNonNull(triple);
+ this.subject = (S) internalJenaFactory.createRDFTerm(triple.getSubject(), salt);
+ this.predicate = (P) internalJenaFactory.createRDFTerm(triple.getPredicate(), salt);
+ this.object = (O) internalJenaFactory.createRDFTerm(triple.getObject(), salt);
+ this.graphName = Optional.empty();
+ }
+
+ @Override
+ public org.apache.jena.sparql.core.Quad asJenaQuad() {
+ JenaRDF factory = new JenaRDF();
+ if (quad == null) {
+ quad = org.apache.jena.sparql.core.Quad.create(factory.asJenaNode(graphName.orElse(null)),
+ factory.asJenaNode(subject), factory.asJenaNode(predicate), factory.asJenaNode(object));
+ }
+ return quad;
+ }
+
+ @Override
+ public org.apache.jena.graph.Triple asJenaTriple() {
+ JenaRDF factory = new JenaRDF();
+ if (triple == null) {
+ triple = org.apache.jena.graph.Triple.create(factory.asJenaNode(subject), factory.asJenaNode(predicate),
+ factory.asJenaNode(object));
+ }
+ return triple;
+ }
+
+ @Override
+ public S getSubject() {
+ return subject;
+ }
+
+ @Override
+ public P getPredicate() {
+ return predicate;
+ }
+
+ @Override
+ public O getObject() {
+ return object;
+ }
+
+ @Override
+ public Optional<G> getGraphName() {
+ return graphName;
+ }
+
+ @Override
+ public String toString() {
+ // kind of nquad syntax
+ return getSubject().ntriplesString() + " " + getPredicate().ntriplesString() + " "
+ + getObject().ntriplesString() + " " + getGraphName().map(RDFTerm::ntriplesString).orElse("") + ".";
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
index 7da2d1e..aa11572 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
@@ -58,105 +58,107 @@ import org.apache.jena.sparql.graph.GraphFactory;
*/
public abstract class InternalJenaFactory {
- public JenaBlankNode createBlankNode(String id, UUID salt) {
- return new JenaBlankNodeImpl(NodeFactory.createBlankNode(id), salt);
- }
-
- public JenaBlankNode createBlankNode(UUID salt) {
- return new JenaBlankNodeImpl(NodeFactory.createBlankNode(), salt);
- }
- public JenaDataset createDataset(DatasetGraph datasetGraph, UUID salt) {
- return new JenaDatasetImpl(datasetGraph, salt);
- }
-
- public JenaDataset createDataset(UUID salt) {
- DatasetGraph dg = DatasetGraphFactory.createGeneral();
- // Or which createMethod() -- a bit confusing with lots of choice..
- return new JenaDatasetImpl(dg, salt);
- }
-
- public JenaGeneralizedQuadLike createGeneralizedQuad(org.apache.jena.sparql.core.Quad quad, UUID salt) {
- return new JenaGeneralizedQuadLikeImpl(quad, salt);
- }
-
- public JenaGeneralizedQuadLike createGeneralizedQuad(RDFTerm subject, RDFTerm predicate, RDFTerm object, RDFTerm graphName) {
- return new JenaGeneralizedQuadLikeImpl(subject, predicate, object, Optional.ofNullable(graphName));
- }
-
- public JenaGeneralizedTripleLike createGeneralizedTriple(org.apache.jena.graph.Triple triple, UUID salt) {
- return new JenaGeneralizedTripleLikeImpl(triple, salt);
- }
-
- public JenaGeneralizedTripleLike createGeneralizedTriple(RDFTerm subject, RDFTerm predicate, RDFTerm object) {
- return new JenaGeneralizedTripleLikeImpl(subject, predicate, object);
- }
-
- public JenaGraph createGraph(Model model, UUID salt) {
- return new JenaGraphImpl(model, salt);
- }
-
- public JenaGraph createGraph(org.apache.jena.graph.Graph graph, UUID salt) {
- return new JenaGraphImpl(graph, salt);
- }
-
- public JenaGraph createGraph(UUID salt) {
- return new JenaGraphImpl(GraphFactory.createDefaultGraph(), salt);
- }
-
- public JenaIRI createIRI(String iriStr) {
- return new JenaIRIImpl(iriStr);
- }
-
- public JenaLiteral createLiteral(String lexStr) {
- return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr));
- }
-
- public JenaLiteral createLiteralDT(String lexStr, String datatypeIRI) {
- return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr, NodeFactory.getType(datatypeIRI)));
- }
-
- public JenaLiteral createLiteralLang(String lexStr, String langTag) {
- return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr, langTag));
- }
-
- public JenaQuad createQuad(BlankNodeOrIRI subject, IRI predicate, RDFTerm object, BlankNodeOrIRI graphName) {
- return new JenaQuadImpl(subject, predicate, object, Optional.ofNullable(graphName));
- }
-
- public JenaQuad createQuad(org.apache.jena.sparql.core.Quad quad, UUID salt) {
- return new JenaQuadImpl(quad, salt);
- }
-
- public JenaRDFTerm createRDFTerm(Node node, UUID salt) throws ConversionException {
- if (! node.isConcrete()) {
- throw new ConversionException("Node is not a concrete RDF Term: " + node);
- }
- if (node.isURI()) {
- return new JenaIRIImpl(node);
- }
- if (node.isLiteral()) {
- return new JenaLiteralImpl(node);
- }
- if (node.isBlank()) {
- return new JenaBlankNodeImpl(node, salt);
- }
- if (node.equals(Node.ANY)) {
- // NOTE: JenaAny no longer supported by Commons RDF
- //return JenaAnyImpl.Singleton.instance;
- }
- if (node.isVariable()) {
- // NOTE: JenaVariable no longer supported by Commons RDF
- //return new JenaVariableImpl(node);
- }
- throw new ConversionException("Unrecognized node type: " + node);
- }
-
- public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return new JenaTripleImpl(subject, predicate, object);
- }
-
- public JenaTriple createTriple(org.apache.jena.graph.Triple triple, UUID salt) {
- return new JenaTripleImpl(triple, salt);
- }
+ public JenaBlankNode createBlankNode(String id, UUID salt) {
+ return new JenaBlankNodeImpl(NodeFactory.createBlankNode(id), salt);
+ }
+
+ public JenaBlankNode createBlankNode(UUID salt) {
+ return new JenaBlankNodeImpl(NodeFactory.createBlankNode(), salt);
+ }
+
+ public JenaDataset createDataset(DatasetGraph datasetGraph, UUID salt) {
+ return new JenaDatasetImpl(datasetGraph, salt);
+ }
+
+ public JenaDataset createDataset(UUID salt) {
+ DatasetGraph dg = DatasetGraphFactory.createGeneral();
+ // Or which createMethod() -- a bit confusing with lots of choice..
+ return new JenaDatasetImpl(dg, salt);
+ }
+
+ public JenaGeneralizedQuadLike createGeneralizedQuad(org.apache.jena.sparql.core.Quad quad, UUID salt) {
+ return new JenaGeneralizedQuadLikeImpl(quad, salt);
+ }
+
+ public JenaGeneralizedQuadLike createGeneralizedQuad(RDFTerm subject, RDFTerm predicate, RDFTerm object,
+ RDFTerm graphName) {
+ return new JenaGeneralizedQuadLikeImpl(subject, predicate, object, Optional.ofNullable(graphName));
+ }
+
+ public JenaGeneralizedTripleLike createGeneralizedTriple(org.apache.jena.graph.Triple triple, UUID salt) {
+ return new JenaGeneralizedTripleLikeImpl(triple, salt);
+ }
+
+ public JenaGeneralizedTripleLike createGeneralizedTriple(RDFTerm subject, RDFTerm predicate, RDFTerm object) {
+ return new JenaGeneralizedTripleLikeImpl(subject, predicate, object);
+ }
+
+ public JenaGraph createGraph(Model model, UUID salt) {
+ return new JenaGraphImpl(model, salt);
+ }
+
+ public JenaGraph createGraph(org.apache.jena.graph.Graph graph, UUID salt) {
+ return new JenaGraphImpl(graph, salt);
+ }
+
+ public JenaGraph createGraph(UUID salt) {
+ return new JenaGraphImpl(GraphFactory.createDefaultGraph(), salt);
+ }
+
+ public JenaIRI createIRI(String iriStr) {
+ return new JenaIRIImpl(iriStr);
+ }
+
+ public JenaLiteral createLiteral(String lexStr) {
+ return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr));
+ }
+
+ public JenaLiteral createLiteralDT(String lexStr, String datatypeIRI) {
+ return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr, NodeFactory.getType(datatypeIRI)));
+ }
+
+ public JenaLiteral createLiteralLang(String lexStr, String langTag) {
+ return new JenaLiteralImpl(NodeFactory.createLiteral(lexStr, langTag));
+ }
+
+ public JenaQuad createQuad(BlankNodeOrIRI subject, IRI predicate, RDFTerm object, BlankNodeOrIRI graphName) {
+ return new JenaQuadImpl(subject, predicate, object, Optional.ofNullable(graphName));
+ }
+
+ public JenaQuad createQuad(org.apache.jena.sparql.core.Quad quad, UUID salt) {
+ return new JenaQuadImpl(quad, salt);
+ }
+
+ public JenaRDFTerm createRDFTerm(Node node, UUID salt) throws ConversionException {
+ if (!node.isConcrete()) {
+ throw new ConversionException("Node is not a concrete RDF Term: " + node);
+ }
+ if (node.isURI()) {
+ return new JenaIRIImpl(node);
+ }
+ if (node.isLiteral()) {
+ return new JenaLiteralImpl(node);
+ }
+ if (node.isBlank()) {
+ return new JenaBlankNodeImpl(node, salt);
+ }
+ if (node.equals(Node.ANY)) {
+ // NOTE: JenaAny no longer supported by Commons RDF
+ // return JenaAnyImpl.Singleton.instance;
+ }
+ if (node.isVariable()) {
+ // NOTE: JenaVariable no longer supported by Commons RDF
+ // return new JenaVariableImpl(node);
+ }
+ throw new ConversionException("Unrecognized node type: " + node);
+ }
+
+ public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return new JenaTripleImpl(subject, predicate, object);
+ }
+
+ public JenaTriple createTriple(org.apache.jena.graph.Triple triple, UUID salt) {
+ return new JenaTripleImpl(triple, salt);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaBlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaBlankNodeImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaBlankNodeImpl.java
index a4cc3af..6e4d966 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaBlankNodeImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaBlankNodeImpl.java
@@ -26,36 +26,36 @@ import org.apache.jena.graph.Node;
class JenaBlankNodeImpl extends AbstractJenaRDFTerm implements JenaBlankNode {
- private UUID salt;
-
- JenaBlankNodeImpl(Node node, UUID salt) {
- super(node);
- if (! node.isBlank()) {
- throw new IllegalArgumentException("Node is not a blank node: " + node);
- }
- this.salt = salt;
- }
-
- @Override
- public boolean equals(Object other) {
- if (other == this)
- return true;
- if (other == null)
- return false;
- if (!(other instanceof BlankNode))
- return false;
- BlankNode bNode = (BlankNode) other;
- return uniqueReference().equals(bNode.uniqueReference());
- }
-
- @Override
- public int hashCode() {
- return uniqueReference().hashCode();
- }
-
- @Override
- public String uniqueReference() {
- return salt + asJenaNode().getBlankNodeLabel();
- }
+ private UUID salt;
+
+ JenaBlankNodeImpl(Node node, UUID salt) {
+ super(node);
+ if (!node.isBlank()) {
+ throw new IllegalArgumentException("Node is not a blank node: " + node);
+ }
+ this.salt = salt;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this)
+ return true;
+ if (other == null)
+ return false;
+ if (!(other instanceof BlankNode))
+ return false;
+ BlankNode bNode = (BlankNode) other;
+ return uniqueReference().equals(bNode.uniqueReference());
+ }
+
+ @Override
+ public int hashCode() {
+ return uniqueReference().hashCode();
+ }
+
+ @Override
+ public String uniqueReference() {
+ return salt + asJenaNode().getBlankNodeLabel();
+ }
}
[08/50] [abbrv] incubator-commonsrdf git commit: RDFFactory -> RDF
Posted by st...@apache.org.
RDFFactory -> RDF
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/ff94b9da
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/ff94b9da
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/ff94b9da
Branch: refs/heads/COMMONSRDF-7
Commit: ff94b9da54f1176816c48cb95edd12928eb0b035
Parents: 9addc8c
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Oct 23 00:17:49 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Oct 23 00:17:49 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/BlankNode.java | 6 +-
.../org/apache/commons/rdf/api/Dataset.java | 2 +-
.../java/org/apache/commons/rdf/api/Graph.java | 2 +-
.../java/org/apache/commons/rdf/api/IRI.java | 2 +-
.../org/apache/commons/rdf/api/Literal.java | 6 +-
.../java/org/apache/commons/rdf/api/Quad.java | 2 +-
.../java/org/apache/commons/rdf/api/RDF.java | 277 ++++++++++++++++++
.../org/apache/commons/rdf/api/RDFFactory.java | 279 -------------------
.../apache/commons/rdf/api/RDFTermFactory.java | 4 +-
.../java/org/apache/commons/rdf/api/Triple.java | 2 +-
.../apache/commons/rdf/api/package-info.java | 2 +-
.../commons/rdf/experimental/RDFParser.java | 12 +-
.../commons/rdf/api/AbstractGraphTest.java | 14 +-
.../rdf/api/AbstractRDFTermFactoryTest.java | 14 +-
.../rdf/api/DefaultRDFTermFactoryTest.java | 6 +-
examples/src/example/UserGuideTest.java | 4 +-
.../apache/commons/rdf/jena/JenaFactory.java | 42 +--
.../rdf/jena/experimental/JenaRDFParser.java | 4 +-
.../commons/rdf/jena/JenaServiceLoaderTest.java | 6 +-
.../apache/commons/rdf/jena/TestGraphJena.java | 4 +-
.../jena/TestJenaGraphToCommonsRDFGraph.java | 4 +-
.../rdf/jena/TestRDFTermFactoryJena.java | 4 +-
.../commons/rdf/jsonldjava/JsonLdFactory.java | 4 +-
.../rdf/jsonldjava/JsonLdFactoryTest.java | 4 +-
.../commons/rdf/jsonldjava/JsonLdGraphTest.java | 4 +-
.../rdf/jsonldjava/JsonLdServiceLoaderTest.java | 6 +-
.../apache/commons/rdf/rdf4j/RDF4JFactory.java | 6 +-
.../org/apache/commons/rdf/rdf4j/GraphTest.java | 4 +-
.../commons/rdf/rdf4j/MemoryGraphTest.java | 6 +-
.../rdf/rdf4j/MemoryRDFTermFactoryTest.java | 4 +-
.../commons/rdf/rdf4j/NativeStoreGraphTest.java | 6 +-
.../rdf/rdf4j/RDF4JServiceLoaderTest.java | 6 +-
.../rdf/rdf4j/Rdf4JRDFTermFactoryTest.java | 4 +-
.../commons/rdf/simple/BlankNodeImpl.java | 6 +-
.../commons/rdf/simple/SimpleRDFFactory.java | 6 +-
.../simple/experimental/AbstractRDFParser.java | 26 +-
.../commons/rdf/simple/DefaultGraphTest.java | 10 +-
.../rdf/simple/DummyRDFParserBuilder.java | 4 +-
.../commons/rdf/simple/SimpleGraphTest.java | 4 +-
.../SimpleNoRelativeIRIRDFTermFactoryTest.java | 4 +-
.../rdf/simple/SimpleRDFTermFactoryTest.java | 6 +-
.../rdf/simple/SimpleServiceLoaderTest.java | 6 +-
.../commons/rdf/simple/TestWritingGraph.java | 4 +-
.../experimental/AbstractRDFParserTest.java | 4 +-
44 files changed, 415 insertions(+), 417 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java b/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
index efa4dfb..f8e6e05 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/BlankNode.java
@@ -50,8 +50,8 @@ import java.util.UUID;
* A BlankNode SHOULD contain a {@link UUID}-derived string as part of its
* universally unique {@link #uniqueReference()}.
*
- * @see RDFFactory#createBlankNode()
- * @see RDFFactory#createBlankNode(String)
+ * @see RDF#createBlankNode()
+ * @see RDF#createBlankNode(String)
* @see <a href="http://www.w3.org/TR/rdf11-concepts/#dfn-blank-node">RDF-1.1
* Blank Node</a>
*/
@@ -62,7 +62,7 @@ public interface BlankNode extends BlankNodeOrIRI {
* <p>
* The reference string MUST universally and uniquely identify this blank
* node. That is, different blank nodes created separately in different JVMs
- * or from different {@link RDFFactory} instances MUST NOT have the same
+ * or from different {@link RDF} instances MUST NOT have the same
* reference string.
* <p>
* The {@link #uniqueReference()} of two <code>BlankNode</code> instances
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/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 9e6f6d7..03aff91 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
@@ -29,7 +29,7 @@ import java.util.stream.Stream;
* Syntax</a>, a W3C Recommendation published on 25 February 2014.
*
* @since 0.3.0-incubating
- * @see RDFFactory#createDataset()
+ * @see RDF#createDataset()
*/
public interface Dataset extends AutoCloseable, GraphLike<Quad> {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/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 ccf9c9d..4e0ed4c 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.
*
- * @see RDFFactory#createGraph()
+ * @see RDF#createGraph()
*/
public interface Graph extends AutoCloseable,GraphLike<Triple> {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/api/src/main/java/org/apache/commons/rdf/api/IRI.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/IRI.java b/api/src/main/java/org/apache/commons/rdf/api/IRI.java
index f3588cb..152bffd 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/IRI.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/IRI.java
@@ -23,7 +23,7 @@ package org.apache.commons.rdf.api;
* Concepts and Abstract Syntax</a>, a W3C Recommendation published on 25
* February 2014.
*
- * @see RDFFactory#createIRI(String)
+ * @see RDF#createIRI(String)
*/
public interface IRI extends BlankNodeOrIRI {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/api/src/main/java/org/apache/commons/rdf/api/Literal.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Literal.java b/api/src/main/java/org/apache/commons/rdf/api/Literal.java
index 29b7f77..4e3c003 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Literal.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Literal.java
@@ -27,9 +27,9 @@ import java.util.Optional;
* Concepts and Abstract Syntax</a>, a W3C Recommendation published on 25
* February 2014
*
- * @see RDFFactory#createLiteral(String)
- * @see RDFFactory#createLiteral(String, IRI)
- * @see RDFFactory#createLiteral(String, String)
+ * @see RDF#createLiteral(String)
+ * @see RDF#createLiteral(String, IRI)
+ * @see RDF#createLiteral(String, String)
*/
public interface Literal extends RDFTerm {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/api/src/main/java/org/apache/commons/rdf/api/Quad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Quad.java b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
index 494600f..ba89823 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Quad.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
@@ -30,7 +30,7 @@ import java.util.Optional;
*
* @since 0.3.0-incubating
* @see Dataset
- * @see RDFFactory#createQuad(BlankNodeOrIRI,BlankNodeOrIRI,IRI,RDFTerm)
+ * @see RDF#createQuad(BlankNodeOrIRI,BlankNodeOrIRI,IRI,RDFTerm)
* @see <a href="http://www.w3.org/TR/2014/NOTE-rdf11-datasets-20140225/">RDF
* 1.1: On Semantics of RDF Datasets</a>
* @see <a href="http://www.w3.org/TR/rdf11-concepts/#section-dataset"> </a>
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/api/src/main/java/org/apache/commons/rdf/api/RDF.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDF.java b/api/src/main/java/org/apache/commons/rdf/api/RDF.java
new file mode 100644
index 0000000..4314568
--- /dev/null
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDF.java
@@ -0,0 +1,277 @@
+/**
+ * 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.io.Serializable;
+import java.util.Locale;
+
+/**
+ * Factory for creating RDFTerm and Graph instances.
+ * <p>
+ * If an implementation does not support a particular method (e.g. it requires
+ * additional parameters or can't create graphs), then it MAY throw
+ * {@link UnsupportedOperationException}, as provided by the <code>default</code>
+ * implementations in this interface.
+ * <p>
+ * If a factory method does not allow or support a provided parameter, e.g.
+ * because an IRI is considered invalid, then it SHOULD throw
+ * {@link IllegalArgumentException}.
+ *
+ * @since 0.3.0-incubating
+ * @see RDFTerm
+ * @see Graph
+ * @see Quad
+ */
+public interface RDF {
+
+ /**
+ * Create a new blank node.
+ * <p>
+ * The returned blank node MUST NOT be equal to any existing
+ * {@link BlankNode} instances according to {@link BlankNode#equals(Object)}.
+ *
+ * @return A new, unique {@link BlankNode}
+ * @throws UnsupportedOperationException
+ * If the operation is not supported.
+ */
+ default BlankNode createBlankNode() throws UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "createBlankNode() not supported");
+ }
+
+ /**
+ * Create a blank node based on the given name.
+ * <p>
+ * All {@link BlankNode}s created with the given <code>name</code>
+ * <em>on a particular instance</em> of <code>RDF</code> MUST be
+ * equivalent according to {@link BlankNode#equals(Object)},
+ * <p>
+ * The returned BlankNode MUST NOT be equal to <code>BlankNode</code>
+ * instances returned for any other <code>name</code> or those returned from
+ * {@link #createBlankNode()}.
+ * <p>
+ * The returned BlankNode SHOULD NOT be equivalent to any BlankNodes created
+ * on a <em>different</em> <code>RDF</code> instance, e.g.
+ * different instances of <code>RDF</code> should produce
+ * different blank nodes for the same <code>name</code> unless they
+ * purposely are intending to create equivalent {@link BlankNode}
+ * instances (e.g. a reinstated {@link Serializable} factory).
+ *
+ * @param name
+ * A non-empty, non-null, String that is unique to this blank
+ * node in the context of this {@link RDF}.
+ * @return A BlankNode for the given name
+ * @throws UnsupportedOperationException
+ * If the operation is not supported.
+ */
+ default BlankNode createBlankNode(String name)
+ throws UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "createBlankNode(String) not supported");
+ }
+
+ /**
+ * Create a new graph.
+ *
+ * It is undefined if the graph will be persisted by any underlying storage
+ * mechanism.
+ *
+ * @return A new Graph
+ * @throws UnsupportedOperationException If the operation is not supported.
+ */
+ default Graph createGraph() throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("createGraph() not supported");
+ }
+
+ /**
+ * Create a new dataset.
+ *
+ * It is undefined if the dataset will be persisted by any underlying storage
+ * mechanism.
+ *
+ * @return A new Dataset
+ * @throws UnsupportedOperationException If the operation is not supported.
+ */
+ default Dataset createDataset() throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("createDataset() not supported");
+ }
+
+ /**
+ * Create an IRI from a (possibly escaped) String.
+ *
+ * The provided iri string MUST be valid according to the <a
+ * href="http://www.w3.org/TR/rdf11-concepts/#dfn-iri">W3C RDF-1.1 IRI</a>
+ * definition.
+ *
+ * @param iri Internationalized Resource Identifier
+ * @return A new IRI
+ * @throws IllegalArgumentException If the provided string is not acceptable, e.g. does not
+ * conform to the RFC3987 syntax.
+ * @throws UnsupportedOperationException If the operation is not supported.
+ */
+ default IRI createIRI(String iri) throws IllegalArgumentException,
+ UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "createIRI(String) not supported");
+ }
+
+ /**
+ * Create a simple literal.
+ *
+ * The provided lexical form should not be escaped in any sense, e.g. should
+ * not include "quotes" unless those are part of the literal value.
+ *
+ * The returned Literal MUST have a {@link Literal#getLexicalForm()} that is
+ * equal to the provided lexical form, MUST NOT have a
+ * {@link Literal#getLanguageTag()} present, and SHOULD return a
+ * {@link Literal#getDatatype()} that is equal to the IRI
+ * <code>http://www.w3.org/2001/XMLSchema#string</code>.
+ *
+ * @param lexicalForm The literal value in plain text
+ * @return The created Literal
+ * @throws IllegalArgumentException If the provided lexicalForm is not acceptable, e.g. because
+ * it is too large for an underlying storage.
+ * @throws UnsupportedOperationException If the operation is not supported.
+ */
+ default Literal createLiteral(String lexicalForm)
+ throws IllegalArgumentException, UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "createLiteral(String) not supported");
+ }
+
+ /**
+ * Create a literal with the specified data type.
+ *
+ * The provided lexical form should not be escaped in any sense, e.g. should
+ * not include "quotes" unless those are part of the literal value.
+ *
+ * It is RECOMMENDED that the provided dataType is one of the <a
+ * href="http://www.w3.org/TR/rdf11-concepts/#xsd-datatypes">RDF-compatible
+ * XSD types</a>.
+ *
+ * The provided lexical form SHOULD be in the <a
+ * href="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-space">lexical
+ * space</a> of the provided dataType.
+ *
+ * The returned Literal SHOULD have a {@link Literal#getLexicalForm()} that
+ * is equal to the provided lexicalForm, MUST NOT have a
+ * {@link Literal#getLanguageTag()} present, and MUST return a
+ * {@link Literal#getDatatype()} that is equivalent to the provided dataType
+ * IRI.
+ *
+ * @param lexicalForm The literal value
+ * @param dataType The data type IRI for the literal value, e.g.
+ * <code>http://www.w3.org/2001/XMLSchema#integer</code>
+ * @return The created Literal
+ * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
+ * because the provided dataType is not permitted.
+ * @throws UnsupportedOperationException If the operation is not supported.
+ */
+ default Literal createLiteral(String lexicalForm, IRI dataType)
+ throws IllegalArgumentException, UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "createLiteral(String) not supported");
+ }
+
+ /**
+ * Create a language-tagged literal.
+ *
+ * The provided lexical form should not be escaped in any sense, e.g. should
+ * not include "quotes" unless those are part of the literal value.
+ *
+ * The provided language tag MUST be valid according to <a
+ * href="http://tools.ietf.org/html/bcp47">BCP47</a>, e.g. <code>en</code>.
+ *
+ * The provided language tag <a
+ * href="http://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string"
+ * >MAY be converted to lower case</a>.
+ *
+ * The returned Literal SHOULD have a {@link Literal#getLexicalForm()} which
+ * is equal to the provided lexicalForm, MUST return a
+ * {@link Literal#getDatatype()} that is equal to the IRI
+ * <code>http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</code>, and
+ * MUST have a {@link Literal#getLanguageTag()} present which SHOULD be
+ * equal to the provided language tag (compared as
+ * {@link String#toLowerCase(Locale)} using {@link Locale#ENGLISH}).
+ *
+ * @param lexicalForm The literal value
+ * @param languageTag The non-empty language tag as defined by <a
+ * href="http://tools.ietf.org/html/bcp47">BCP47</a>
+ * @return The created Literal
+ * @throws IllegalArgumentException If the provided values are not acceptable, e.g. because the
+ * languageTag was syntactically invalid.
+ * @throws UnsupportedOperationException If the operation is not supported.
+ */
+ default Literal createLiteral(String lexicalForm, String languageTag)
+ throws IllegalArgumentException, UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "createLiteral(String,String) not supported");
+ }
+
+ /**
+ * Create a triple.
+ *
+ * The returned Triple SHOULD have a {@link Triple#getSubject()} that is
+ * equal to the provided subject, a {@link Triple#getPredicate()} that is
+ * equal to the provided predicate, and a {@link Triple#getObject()} that is
+ * equal to the provided object.
+ *
+ * @param subject The IRI or BlankNode that is the subject of the triple
+ * @param predicate The IRI that is the predicate of the triple
+ * @param object The IRI, BlankNode or Literal that is the object of the triple
+ * @return The created Triple
+ * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
+ * because a Literal has a lexicalForm that is too large for an
+ * underlying storage.
+ * @throws UnsupportedOperationException If the operation is not supported.
+ */
+ default Triple createTriple(BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) throws IllegalArgumentException,
+ UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "createTriple(BlankNodeOrIRI,IRI,RDFTerm) not supported");
+ }
+
+ /**
+ * Create a quad.
+ * <p>
+ * The returned Quad SHOULD have a
+ * {@link Quad#getGraphName()} that is equal to the provided graphName, a
+ * {@link Quad#getSubject()} that is
+ * equal to the provided subject, a {@link Quad#getPredicate()} that is
+ * equal to the provided predicate, and a {@link Quad#getObject()} that is
+ * equal to the provided object.
+ *
+ * @param graphName The IRI or BlankNode that this quad belongs to, or <code>null</code> for the default graph
+ * @param subject The IRI or BlankNode that is the subject of the quad
+ * @param predicate The IRI that is the predicate of the quad
+ * @param object The IRI, BlankNode or Literal that is the object of the quad
+ * @return The created Quad
+ * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
+ * because a Literal has a lexicalForm that is too large for an
+ * underlying storage.
+ * @throws UnsupportedOperationException If the operation is not supported.
+ */
+ default Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) throws IllegalArgumentException,
+ UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "createQuad(BlankNodeOrIRI,BlankNodeOrIRI,IRI,RDFTerm) not supported");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/api/src/main/java/org/apache/commons/rdf/api/RDFFactory.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFFactory.java b/api/src/main/java/org/apache/commons/rdf/api/RDFFactory.java
deleted file mode 100644
index a116153..0000000
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFFactory.java
+++ /dev/null
@@ -1,279 +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.io.Serializable;
-import java.util.Locale;
-
-/**
- * Factory for creating RDFTerm and Graph instances.
- * <p>
- * It is not specified how an implementation should provide a RDFFactory.
- * <p>
- * If an implementation does not support a particular method (e.g. it requires
- * additional parameters or can't create graphs), then it MAY throw
- * {@link UnsupportedOperationException}, as provided by the <code>default</code>
- * implementations in this interface.
- * <p>
- * If a factory method does not allow or support a provided parameter, e.g.
- * because an IRI is considered invalid, then it SHOULD throw
- * {@link IllegalArgumentException}.
- *
- * @since 0.3.0-incubating
- * @see RDFTerm
- * @see Graph
- * @see Quad
- */
-public interface RDFFactory {
-
- /**
- * Create a new blank node.
- * <p>
- * The returned blank node MUST NOT be equal to any existing
- * {@link BlankNode} instances according to {@link BlankNode#equals(Object)}.
- *
- * @return A new, unique {@link BlankNode}
- * @throws UnsupportedOperationException
- * If the operation is not supported.
- */
- default BlankNode createBlankNode() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createBlankNode() not supported");
- }
-
- /**
- * Create a blank node based on the given name.
- * <p>
- * All {@link BlankNode}s created with the given <code>name</code>
- * <em>on a particular instance</em> of <code>RDFFactory</code> MUST be
- * equivalent according to {@link BlankNode#equals(Object)},
- * <p>
- * The returned BlankNode MUST NOT be equal to <code>BlankNode</code>
- * instances returned for any other <code>name</code> or those returned from
- * {@link #createBlankNode()}.
- * <p>
- * The returned BlankNode SHOULD NOT be equivalent to any BlankNodes created
- * on a <em>different</em> <code>RDFFactory</code> instance, e.g.
- * different instances of <code>RDFFactory</code> should produce
- * different blank nodes for the same <code>name</code> unless they
- * purposely are intending to create equivalent {@link BlankNode}
- * instances (e.g. a reinstated {@link Serializable} factory).
- *
- * @param name
- * A non-empty, non-null, String that is unique to this blank
- * node in the context of this {@link RDFFactory}.
- * @return A BlankNode for the given name
- * @throws UnsupportedOperationException
- * If the operation is not supported.
- */
- default BlankNode createBlankNode(String name)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createBlankNode(String) not supported");
- }
-
- /**
- * Create a new graph.
- *
- * It is undefined if the graph will be persisted by any underlying storage
- * mechanism.
- *
- * @return A new Graph
- * @throws UnsupportedOperationException If the operation is not supported.
- */
- default Graph createGraph() throws UnsupportedOperationException {
- throw new UnsupportedOperationException("createGraph() not supported");
- }
-
- /**
- * Create a new dataset.
- *
- * It is undefined if the dataset will be persisted by any underlying storage
- * mechanism.
- *
- * @return A new Dataset
- * @throws UnsupportedOperationException If the operation is not supported.
- */
- default Dataset createDataset() throws UnsupportedOperationException {
- throw new UnsupportedOperationException("createDataset() not supported");
- }
-
- /**
- * Create an IRI from a (possibly escaped) String.
- *
- * The provided iri string MUST be valid according to the <a
- * href="http://www.w3.org/TR/rdf11-concepts/#dfn-iri">W3C RDF-1.1 IRI</a>
- * definition.
- *
- * @param iri Internationalized Resource Identifier
- * @return A new IRI
- * @throws IllegalArgumentException If the provided string is not acceptable, e.g. does not
- * conform to the RFC3987 syntax.
- * @throws UnsupportedOperationException If the operation is not supported.
- */
- default IRI createIRI(String iri) throws IllegalArgumentException,
- UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createIRI(String) not supported");
- }
-
- /**
- * Create a simple literal.
- *
- * The provided lexical form should not be escaped in any sense, e.g. should
- * not include "quotes" unless those are part of the literal value.
- *
- * The returned Literal MUST have a {@link Literal#getLexicalForm()} that is
- * equal to the provided lexical form, MUST NOT have a
- * {@link Literal#getLanguageTag()} present, and SHOULD return a
- * {@link Literal#getDatatype()} that is equal to the IRI
- * <code>http://www.w3.org/2001/XMLSchema#string</code>.
- *
- * @param lexicalForm The literal value in plain text
- * @return The created Literal
- * @throws IllegalArgumentException If the provided lexicalForm is not acceptable, e.g. because
- * it is too large for an underlying storage.
- * @throws UnsupportedOperationException If the operation is not supported.
- */
- default Literal createLiteral(String lexicalForm)
- throws IllegalArgumentException, UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createLiteral(String) not supported");
- }
-
- /**
- * Create a literal with the specified data type.
- *
- * The provided lexical form should not be escaped in any sense, e.g. should
- * not include "quotes" unless those are part of the literal value.
- *
- * It is RECOMMENDED that the provided dataType is one of the <a
- * href="http://www.w3.org/TR/rdf11-concepts/#xsd-datatypes">RDF-compatible
- * XSD types</a>.
- *
- * The provided lexical form SHOULD be in the <a
- * href="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-space">lexical
- * space</a> of the provided dataType.
- *
- * The returned Literal SHOULD have a {@link Literal#getLexicalForm()} that
- * is equal to the provided lexicalForm, MUST NOT have a
- * {@link Literal#getLanguageTag()} present, and MUST return a
- * {@link Literal#getDatatype()} that is equivalent to the provided dataType
- * IRI.
- *
- * @param lexicalForm The literal value
- * @param dataType The data type IRI for the literal value, e.g.
- * <code>http://www.w3.org/2001/XMLSchema#integer</code>
- * @return The created Literal
- * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
- * because the provided dataType is not permitted.
- * @throws UnsupportedOperationException If the operation is not supported.
- */
- default Literal createLiteral(String lexicalForm, IRI dataType)
- throws IllegalArgumentException, UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createLiteral(String) not supported");
- }
-
- /**
- * Create a language-tagged literal.
- *
- * The provided lexical form should not be escaped in any sense, e.g. should
- * not include "quotes" unless those are part of the literal value.
- *
- * The provided language tag MUST be valid according to <a
- * href="http://tools.ietf.org/html/bcp47">BCP47</a>, e.g. <code>en</code>.
- *
- * The provided language tag <a
- * href="http://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string"
- * >MAY be converted to lower case</a>.
- *
- * The returned Literal SHOULD have a {@link Literal#getLexicalForm()} which
- * is equal to the provided lexicalForm, MUST return a
- * {@link Literal#getDatatype()} that is equal to the IRI
- * <code>http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</code>, and
- * MUST have a {@link Literal#getLanguageTag()} present which SHOULD be
- * equal to the provided language tag (compared as
- * {@link String#toLowerCase(Locale)} using {@link Locale#ENGLISH}).
- *
- * @param lexicalForm The literal value
- * @param languageTag The non-empty language tag as defined by <a
- * href="http://tools.ietf.org/html/bcp47">BCP47</a>
- * @return The created Literal
- * @throws IllegalArgumentException If the provided values are not acceptable, e.g. because the
- * languageTag was syntactically invalid.
- * @throws UnsupportedOperationException If the operation is not supported.
- */
- default Literal createLiteral(String lexicalForm, String languageTag)
- throws IllegalArgumentException, UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createLiteral(String,String) not supported");
- }
-
- /**
- * Create a triple.
- *
- * The returned Triple SHOULD have a {@link Triple#getSubject()} that is
- * equal to the provided subject, a {@link Triple#getPredicate()} that is
- * equal to the provided predicate, and a {@link Triple#getObject()} that is
- * equal to the provided object.
- *
- * @param subject The IRI or BlankNode that is the subject of the triple
- * @param predicate The IRI that is the predicate of the triple
- * @param object The IRI, BlankNode or Literal that is the object of the triple
- * @return The created Triple
- * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
- * because a Literal has a lexicalForm that is too large for an
- * underlying storage.
- * @throws UnsupportedOperationException If the operation is not supported.
- */
- default Triple createTriple(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) throws IllegalArgumentException,
- UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createTriple(BlankNodeOrIRI,IRI,RDFTerm) not supported");
- }
-
- /**
- * Create a quad.
- * <p>
- * The returned Quad SHOULD have a
- * {@link Quad#getGraphName()} that is equal to the provided graphName, a
- * {@link Quad#getSubject()} that is
- * equal to the provided subject, a {@link Quad#getPredicate()} that is
- * equal to the provided predicate, and a {@link Quad#getObject()} that is
- * equal to the provided object.
- *
- * @param graphName The IRI or BlankNode that this quad belongs to, or <code>null</code> for the default graph
- * @param subject The IRI or BlankNode that is the subject of the quad
- * @param predicate The IRI that is the predicate of the quad
- * @param object The IRI, BlankNode or Literal that is the object of the quad
- * @return The created Quad
- * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
- * because a Literal has a lexicalForm that is too large for an
- * underlying storage.
- * @throws UnsupportedOperationException If the operation is not supported.
- */
- default Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) throws IllegalArgumentException,
- UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "createQuad(BlankNodeOrIRI,BlankNodeOrIRI,IRI,RDFTerm) not supported");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
index ef4e38e..37c4ead 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTermFactory.java
@@ -21,9 +21,9 @@ package org.apache.commons.rdf.api;
* Factory for creating RDFTerm instances..
* <p>
* This interface is <strong>deprecated</strong> in favour of
- * the richer {@link RDFFactory}.
+ * the richer {@link RDF}.
*
- * @see RDFFactory
+ * @see RDF
*/
@Deprecated
public interface RDFTermFactory {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/api/src/main/java/org/apache/commons/rdf/api/Triple.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Triple.java b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
index 9e359d7..b0866bd 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Triple.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
@@ -26,7 +26,7 @@ import java.util.Objects;
* 25 February 2014.<br>
*
* @see Quad
- * @see RDFFactory#createTriple(BlankNodeOrIRI,IRI,RDFTerm)
+ * @see RDF#createTriple(BlankNodeOrIRI,IRI,RDFTerm)
* @see <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple" >RDF-1.1
* Triple</a>
*/
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/api/src/main/java/org/apache/commons/rdf/api/package-info.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/package-info.java b/api/src/main/java/org/apache/commons/rdf/api/package-info.java
index 19d1462..4cecc4f 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/package-info.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/package-info.java
@@ -30,7 +30,7 @@
* {@link org.apache.commons.rdf.api.BlankNode}.
* <p>
* Implementations of this API should provide an
- * {@link org.apache.commons.rdf.api.RDFFactory} to facilitate
+ * {@link org.apache.commons.rdf.api.RDF} to facilitate
* creation of these objects.
* <p>
* All the {@link org.apache.commons.rdf.api.RDFTerm} objects are immutable,
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java b/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
index e77926d..d5684e4 100644
--- a/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
+++ b/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java
@@ -32,7 +32,7 @@ import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.Quad;
import org.apache.commons.rdf.api.RDFSyntax;
import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.Triple;
/**
@@ -100,25 +100,25 @@ public interface RDFParser {
}
/**
- * Specify which {@link RDFFactory} to use for generating
+ * Specify which {@link RDF} to use for generating
* {@link RDFTerm}s.
* <p>
* This option may be used together with {@link #target(Graph)} to
* override the implementation's default factory and graph.
* <p>
- * <strong>Warning:</strong> Using the same {@link RDFFactory} for
+ * <strong>Warning:</strong> Using the same {@link RDF} for
* multiple {@link #parse()} calls may accidentally merge
* {@link BlankNode}s having the same label, as the parser may
- * use the {@link RDFFactory#createBlankNode(String)} method
+ * use the {@link RDF#createBlankNode(String)} method
* from the parsed blank node labels.
*
* @see #target(Graph)
* @param rdfTermFactory
- * {@link RDFFactory} to use for generating RDFTerms.
+ * {@link RDF} to use for generating RDFTerms.
* @return An {@link RDFParser} that will use the specified
* rdfTermFactory
*/
- RDFParser rdfTermFactory(RDFFactory rdfTermFactory);
+ RDFParser rdfTermFactory(RDF rdfTermFactory);
/**
* Specify the content type of the RDF syntax to parse.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
index bd68f51..ba930eb 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
@@ -41,18 +41,18 @@ import org.junit.Test;
* <p>
* To add to your implementation's tests, create a subclass with a name ending
* in <code>Test</code> and provide {@link #createFactory()} which minimally
- * must support {@link RDFFactory#createGraph()} and
- * {@link RDFFactory#createIRI(String)}, but ideally support all operations.
+ * must support {@link RDF#createGraph()} and
+ * {@link RDF#createIRI(String)}, but ideally support all operations.
* <p>
* This test uses try-with-resources blocks for calls to {@link Graph#stream()}
* and {@link Graph#iterate()}.
*
* @see Graph
- * @see RDFFactory
+ * @see RDF
*/
public abstract class AbstractGraphTest {
- protected RDFFactory factory;
+ protected RDF factory;
protected Graph graph;
protected IRI alice;
protected IRI bob;
@@ -67,7 +67,7 @@ public abstract class AbstractGraphTest {
protected Literal companyName;
protected Triple bobNameTriple;
- public abstract RDFFactory createFactory();
+ public abstract RDF createFactory();
@Before
public void createGraphAndAdd() {
@@ -413,7 +413,7 @@ public abstract class AbstractGraphTest {
* Make a new graph with two BlankNodes - each with a different uniqueReference
*/
private Graph createGraph1() {
- RDFFactory factory1 = createFactory();
+ RDF factory1 = createFactory();
IRI name = factory1.createIRI("http://xmlns.com/foaf/0.1/name");
Graph g1 = factory1.createGraph();
@@ -465,7 +465,7 @@ public abstract class AbstractGraphTest {
}
private Graph createGraph2() {
- RDFFactory factory2 = createFactory();
+ RDF factory2 = createFactory();
IRI name = factory2.createIRI("http://xmlns.com/foaf/0.1/name");
Graph g2 = factory2.createGraph();
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
index 412b812..2595621 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
@@ -29,26 +29,26 @@ import org.junit.Before;
import org.junit.Test;
/**
- * Test RDFFactory implementation (and thus its RDFTerm implementations)
+ * Test RDF implementation (and thus its RDFTerm implementations)
* <p>
* To add to your implementation's tests, create a subclass with a name ending
* in <code>Test</code> and provide {@link #createFactory()} which minimally
* supports one of the operations, but ideally supports all operations.
*
- * @see RDFFactory
+ * @see RDF
*/
public abstract class AbstractRDFTermFactoryTest {
- private RDFFactory factory;
+ private RDF factory;
/**
- * testCreate a new, distinct {@link RDFFactory} object using the
+ * testCreate a new, distinct {@link RDF} object using the
* implementation being tested here.
*
- * @return a new, distinct {@link RDFFactory} object using the
+ * @return a new, distinct {@link RDF} object using the
* implementation being tested here
*/
- public abstract RDFFactory createFactory();
+ public abstract RDF createFactory();
@Before
public void setUp() {
@@ -126,7 +126,7 @@ public abstract class AbstractRDFTermFactoryTest {
// only says:
//
// * BlankNodes created using this method with the same parameter, for
- // * different instances of RDFFactory, SHOULD NOT be equivalent.
+ // * different instances of RDF, SHOULD NOT be equivalent.
//
// https://github.com/apache/incubator-commonsrdf/pull/7#issuecomment-92312779
} catch (UnsupportedOperationException ex) {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/api/src/test/java/org/apache/commons/rdf/api/DefaultRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/DefaultRDFTermFactoryTest.java b/api/src/test/java/org/apache/commons/rdf/api/DefaultRDFTermFactoryTest.java
index d7db514..a800191 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/DefaultRDFTermFactoryTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/DefaultRDFTermFactoryTest.java
@@ -18,15 +18,15 @@
package org.apache.commons.rdf.api;
/**
- * The default RDFFactory might be useless (every method throws
+ * The default RDF might be useless (every method throws
* UnsupportedOperationException), but this test ensures that
* AbstractRDFTermFactoryTest does not fall over on unsupported operations.
*/
public class DefaultRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
@Override
- public RDFFactory createFactory() {
- return new RDFFactory() {
+ public RDF createFactory() {
+ return new RDF() {
};
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/examples/src/example/UserGuideTest.java
----------------------------------------------------------------------
diff --git a/examples/src/example/UserGuideTest.java b/examples/src/example/UserGuideTest.java
index c9487e3..7b423cf 100644
--- a/examples/src/example/UserGuideTest.java
+++ b/examples/src/example/UserGuideTest.java
@@ -32,7 +32,7 @@ import org.apache.commons.rdf.api.Literal;
import org.apache.commons.rdf.api.Quad;
import org.apache.commons.rdf.api.QuadLike;
import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.api.TripleLike;
import org.apache.commons.rdf.simple.SimpleRDFFactory;
@@ -42,7 +42,7 @@ import org.junit.Test;
public class UserGuideTest {
- private RDFFactory factory;
+ private RDF factory;
@Before
public void factory() {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java
index 0a5b44b..4832e44 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java
@@ -31,7 +31,7 @@ import org.apache.commons.rdf.api.Quad;
import org.apache.commons.rdf.api.QuadLike;
import org.apache.commons.rdf.api.RDFSyntax;
import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.api.TripleLike;
import org.apache.commons.rdf.jena.impl.InternalJenaFactory;
@@ -48,7 +48,7 @@ import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.graph.GraphFactory;
/**
- * RDFFactory with Jena-backed objects.
+ * RDF with Jena-backed objects.
* <p>
* This factory can also convert existing objects from/to Jena with methods like
* {@link #fromJena(org.apache.jena.graph.Graph)} and {@link #toJena(Graph)}.
@@ -56,9 +56,9 @@ import org.apache.jena.sparql.graph.GraphFactory;
* For the purpose of {@link BlankNode} identity, this factory will use an internal
* {@link UUID} as a salt. See {@link BlankNode#uniqueReference()} for details.
*
- * @see RDFFactory
+ * @see RDF
*/
-public final class JenaFactory implements RDFFactory {
+public final class JenaFactory implements RDF {
private static InternalJenaFactory internalJenaFactory = new InternalJenaFactory(){};
@@ -203,7 +203,7 @@ public final class JenaFactory implements RDFFactory {
* {@link Node#getBlankNodeId()} for the purpose of its
* {@link BlankNode#uniqueReference()}.
*
- * @see #fromJena(RDFFactory, Node)
+ * @see #fromJena(RDF, Node)
*
* @param node
* The Jena Node to adapt. It's {@link Node#isConcrete()} must be
@@ -220,13 +220,13 @@ public final class JenaFactory implements RDFFactory {
* Convert from Jena {@link Node} to any Commons RDF implementation.
* <p>
* Note that if the {@link Node#isBlank()}, then the factory's
- * {@link RDFFactory#createBlankNode(String)} will be used, meaning
- * that care should be taken if reusing an {@link RDFFactory} instance
+ * {@link RDF#createBlankNode(String)} will be used, meaning
+ * that care should be taken if reusing an {@link RDF} instance
* for multiple conversion sessions.
*
* @see #fromJena(Node)
*
- * @param factory {@link RDFFactory} to use for creating {@link RDFTerm}.
+ * @param factory {@link RDF} to use for creating {@link RDFTerm}.
* @param node
* The Jena Node to adapt. It's {@link Node#isConcrete()} must be
* <code>true</code>.
@@ -234,7 +234,7 @@ public final class JenaFactory implements RDFFactory {
* @throws ConversionException If the {@link Node} can't be represented as an {@link RDFTerm}, e.g.
* if the node is not concrete or represents a variable in Jena.
*/
- public static RDFTerm fromJena(RDFFactory factory, Node node) {
+ public static RDFTerm fromJena(RDF factory, Node node) {
if (node == null) {
return null;
}
@@ -268,7 +268,7 @@ public final class JenaFactory implements RDFFactory {
* {@link Node#getBlankNodeId()} for the purpose of its
* {@link BlankNode#uniqueReference()}.
*
- * @see #fromJena(RDFFactory, org.apache.jena.graph.Triple)
+ * @see #fromJena(RDF, org.apache.jena.graph.Triple)
*
* @param triple
* Jena {@link org.apache.jena.graph.Triple} to adapt
@@ -293,7 +293,7 @@ public final class JenaFactory implements RDFFactory {
* {@link Node#getBlankNodeId()} for the purpose of its
* {@link BlankNode#uniqueReference()}.
*
- * @see #fromJena(RDFFactory, org.apache.jena.graph.Triple)
+ * @see #fromJena(RDF, org.apache.jena.graph.Triple)
*
* @param triple
* Jena triple
@@ -342,13 +342,13 @@ public final class JenaFactory implements RDFFactory {
* {@link Triple}.
* <p>
* Note that if any of the triple's nodes {@link Node#isBlank()}, then the factory's
- * {@link RDFFactory#createBlankNode(String)} will be used, meaning
- * that care should be taken if reusing an {@link RDFFactory} instance
+ * {@link RDF#createBlankNode(String)} will be used, meaning
+ * that care should be taken if reusing an {@link RDF} instance
* for multiple conversion sessions.
*
* @see #fromJena(org.apache.jena.graph.Triple)
*
- * @param factory {@link RDFFactory} to use for creating the {@link Triple} and its
+ * @param factory {@link RDF} to use for creating the {@link Triple} and its
* {@link RDFTerm}s.
* @param triple
* Jena triple
@@ -357,7 +357,7 @@ public final class JenaFactory implements RDFFactory {
* if any of the triple's nodes are not concrete or the triple
* is a generalized triple
*/
- public static Triple fromJena(RDFFactory factory, org.apache.jena.graph.Triple triple)
+ public static Triple fromJena(RDF factory, org.apache.jena.graph.Triple triple)
throws ConversionException{
if (factory instanceof JenaFactory) {
// No need to convert, just wrap
@@ -478,15 +478,15 @@ public final class JenaFactory implements RDFFactory {
* RDF {@link Quad}.
* <p>
* Note that if any of the quad's nodes {@link Node#isBlank()}, then the
- * factory's {@link RDFFactory#createBlankNode(String)} will be used,
- * meaning that care should be taken if reusing an {@link RDFFactory}
+ * factory's {@link RDF#createBlankNode(String)} will be used,
+ * meaning that care should be taken if reusing an {@link RDF}
* instance for multiple conversion sessions.
*
* @see #fromJena(org.apache.jena.sparql.core.Quad)
* @see #fromJenaGeneralized(org.apache.jena.sparql.core.Quad)
*
* @param factory
- * {@link RDFFactory} to use for creating the {@link Triple}
+ * {@link RDF} to use for creating the {@link Triple}
* and its {@link RDFTerm}s.
* @param quad
* Jena {@link org.apache.jena.sparql.core.Quad} to adapt
@@ -495,7 +495,7 @@ public final class JenaFactory implements RDFFactory {
* if any of the quad's nodes are not concrete or the quad
* is a generalized quad
*/
- public static Quad fromJena(RDFFactory factory, org.apache.jena.sparql.core.Quad quad) {
+ public static Quad fromJena(RDF factory, org.apache.jena.sparql.core.Quad quad) {
if (factory instanceof JenaFactory) {
// No need to convert, just wrap
return ((JenaFactory) factory).fromJena(quad);
@@ -535,14 +535,14 @@ public final class JenaFactory implements RDFFactory {
* {@link RDFDataMgr#parse(StreamRDF, String)}.
*
* @param factory
- * {@link RDFFactory} to use for creating {@link RDFTerm}s
+ * {@link RDF} to use for creating {@link RDFTerm}s
* and {@link Quad}s.
* @param consumer
* A {@link Consumer} of {@link Quad}s
* @return A {@link StreamRDF} that will stream converted quads to the
* consumer
*/
- public static StreamRDF streamJenaToCommonsRDF(RDFFactory factory, Consumer<Quad> consumer) {
+ public static StreamRDF streamJenaToCommonsRDF(RDF factory, Consumer<Quad> consumer) {
return new StreamRDFBase() {
@Override
public void quad(org.apache.jena.sparql.core.Quad quad) {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java b/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
index f14532c..ffbb61c 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
@@ -26,7 +26,7 @@ import java.util.function.Consumer;
import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.QuadLike;
import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.TripleLike;
import org.apache.commons.rdf.experimental.RDFParser;
import org.apache.commons.rdf.jena.JenaGraph;
@@ -43,7 +43,7 @@ public class JenaRDFParser extends AbstractRDFParser<JenaRDFParser> implements R
private Consumer<TripleLike> generalizedConsumerTriple;
private Consumer<QuadLike<RDFTerm>> generalizedConsumerQuad;
- protected RDFFactory createRDFTermFactory() {
+ protected RDF createRDFTermFactory() {
return new JenaFactory();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java b/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
index 1793c3e..87ce543 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
@@ -22,15 +22,15 @@ import static org.junit.Assert.fail;
import java.util.ServiceLoader;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.junit.Test;
public class JenaServiceLoaderTest {
@Test
public void testServiceLoaderLookup() {
- ServiceLoader<RDFFactory> loader = ServiceLoader.load(RDFFactory.class);
- for (RDFFactory impl : loader) {
+ ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class);
+ for (RDF impl : loader) {
if (impl instanceof JenaFactory) {
return; // yay
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
index 5690721..3c7caa8 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
@@ -19,12 +19,12 @@
package org.apache.commons.rdf.jena;
import org.apache.commons.rdf.api.AbstractGraphTest ;
-import org.apache.commons.rdf.api.RDFFactory ;
+import org.apache.commons.rdf.api.RDF ;
public class TestGraphJena extends AbstractGraphTest {
@Override
- public RDFFactory createFactory() {
+ public RDF createFactory() {
return new JenaFactory() ;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
index 7f08382..ad71a58 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
@@ -24,7 +24,7 @@ import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import org.apache.commons.rdf.api.Graph ;
-import org.apache.commons.rdf.api.RDFFactory ;
+import org.apache.commons.rdf.api.RDF ;
import org.apache.jena.riot.Lang ;
import org.apache.jena.riot.RDFDataMgr ;
import org.apache.jena.sparql.graph.GraphFactory ;
@@ -59,7 +59,7 @@ public class TestJenaGraphToCommonsRDFGraph {
Graph graph = new JenaFactory().fromJena(jGraph) ;
// Add to CommonsRDF Graph
- RDFFactory rft = new JenaFactory() ;
+ RDF rft = new JenaFactory() ;
graph.add(rft.createIRI("http://example/s2"),
rft.createIRI("http://example/p2"),
rft.createLiteral("foo")) ;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
index 6ca14b7..f917a68 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
@@ -19,12 +19,12 @@
package org.apache.commons.rdf.jena;
import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest ;
-import org.apache.commons.rdf.api.RDFFactory ;
+import org.apache.commons.rdf.api.RDF ;
public class TestRDFTermFactoryJena extends AbstractRDFTermFactoryTest {
@Override
- public RDFFactory createFactory() {
+ public RDF createFactory() {
return new JenaFactory() ;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdFactory.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdFactory.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdFactory.java
index 0dd8486..d5c49f8 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdFactory.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdFactory.java
@@ -28,14 +28,14 @@ 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.RDFTerm;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.simple.Types;
import com.github.jsonldjava.core.RDFDataset;
import com.github.jsonldjava.core.RDFDataset.Node;
-public final class JsonLdFactory implements RDFFactory {
+public final class JsonLdFactory implements RDF {
final String bnodePrefix;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
index 02b2695..ea87fa8 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
@@ -18,14 +18,14 @@
package org.apache.commons.rdf.jsonldjava;
import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.junit.Ignore;
import org.junit.Test;
public class JsonLdFactoryTest extends AbstractRDFTermFactoryTest {
@Override
- public RDFFactory createFactory() {
+ public RDF createFactory() {
return new JsonLdFactory();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java
index 1f98c74..51c768f 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java
@@ -18,12 +18,12 @@
package org.apache.commons.rdf.jsonldjava;
import org.apache.commons.rdf.api.AbstractGraphTest;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
public class JsonLdGraphTest extends AbstractGraphTest {
@Override
- public RDFFactory createFactory() {
+ public RDF createFactory() {
return new JsonLdFactory();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
index ce07a37..f35a41b 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
@@ -22,15 +22,15 @@ import static org.junit.Assert.fail;
import java.util.ServiceLoader;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.junit.Test;
public class JsonLdServiceLoaderTest {
@Test
public void testServiceLoaderLookup() {
- ServiceLoader<RDFFactory> loader = ServiceLoader.load(RDFFactory.class);
- for (RDFFactory impl : loader) {
+ ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class);
+ for (RDF impl : loader) {
if (impl instanceof JsonLdFactory) {
return; // yay
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JFactory.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JFactory.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JFactory.java
index 6b3717b..8dd9745 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JFactory.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JFactory.java
@@ -32,7 +32,7 @@ import org.apache.commons.rdf.api.Dataset;
import org.apache.commons.rdf.api.Graph;
import org.apache.commons.rdf.api.Quad;
import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.api.TripleLike;
import org.apache.commons.rdf.rdf4j.impl.InternalRDF4JFactory;
@@ -51,7 +51,7 @@ import org.eclipse.rdf4j.sail.Sail;
import org.eclipse.rdf4j.sail.memory.MemoryStore;
/**
- * RDF4J implementation of RDFFactory.
+ * RDF4J implementation of RDF.
* <p>
* The {@link #RDF4JFactory()} constructor uses a {@link SimpleValueFactory}
* to create corresponding RDF4J {@link Value} instances. Alternatively, this
@@ -99,7 +99,7 @@ import org.eclipse.rdf4j.sail.memory.MemoryStore;
* therefore uses a unique {@link RDF4JFactory} internally.
*
*/
-public final class RDF4JFactory implements RDFFactory {
+public final class RDF4JFactory implements RDF {
/**
* InternalRDF4JFactory is deliberately abstract
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java
index 8cba53e..7d6104d 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java
@@ -18,12 +18,12 @@
package org.apache.commons.rdf.rdf4j;
import org.apache.commons.rdf.api.AbstractGraphTest;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
public class GraphTest extends AbstractGraphTest{
@Override
- public RDFFactory createFactory() {
+ public RDF createFactory() {
return new RDF4JFactory();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java
index ce449bf..5377983 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java
@@ -24,7 +24,7 @@ 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.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.sail.Sail;
@@ -33,7 +33,7 @@ import org.eclipse.rdf4j.sail.memory.model.MemValueFactory;
public class MemoryGraphTest extends AbstractGraphTest {
- public static final class MemoryStoreFactory implements RDFFactory {
+ public static final class MemoryStoreFactory implements RDF {
RDF4JFactory rdf4jFactory = new RDF4JFactory(new MemValueFactory());
@@ -82,7 +82,7 @@ public class MemoryGraphTest extends AbstractGraphTest {
}
@Override
- public RDFFactory createFactory() {
+ public RDF createFactory() {
return new MemoryStoreFactory();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java
index 07d6a13..73ea05e 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java
@@ -18,13 +18,13 @@
package org.apache.commons.rdf.rdf4j;
import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.junit.Assume;
public class MemoryRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
@Override
- public RDFFactory createFactory() {
+ public RDF createFactory() {
return new MemoryGraphTest.MemoryStoreFactory();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
index 9a5ab50..7b31738 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
@@ -27,7 +27,7 @@ import org.apache.commons.rdf.api.BlankNodeOrIRI;
import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.Literal;
import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryResult;
import org.eclipse.rdf4j.repository.sail.SailRepository;
@@ -49,7 +49,7 @@ import org.junit.rules.Timeout;
*/
public class NativeStoreGraphTest extends AbstractGraphTest {
- public final class NativeStoreFactory implements RDFFactory {
+ public final class NativeStoreFactory implements RDF {
RDF4JFactory rdf4jFactory = new RDF4JFactory(getRepository().getValueFactory());
@@ -145,7 +145,7 @@ public class NativeStoreGraphTest extends AbstractGraphTest {
// }
@Override
- public RDFFactory createFactory() {
+ public RDF createFactory() {
return new NativeStoreFactory();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
index 77c396c..46da04a 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
@@ -22,15 +22,15 @@ import static org.junit.Assert.fail;
import java.util.ServiceLoader;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.junit.Test;
public class RDF4JServiceLoaderTest {
@Test
public void testServiceLoaderLookup() {
- ServiceLoader<RDFFactory> loader = ServiceLoader.load(RDFFactory.class);
- for (RDFFactory impl : loader) {
+ ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class);
+ for (RDF impl : loader) {
if (impl instanceof RDF4JFactory) {
return; // yay
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
index 4e075ac..24283c3 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
@@ -18,13 +18,13 @@
package org.apache.commons.rdf.rdf4j;
import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.junit.Assume;
public class Rdf4JRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
@Override
- public RDFFactory createFactory() {
+ public RDF createFactory() {
return new RDF4JFactory();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
index fbbdb26..7147322 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
@@ -47,13 +47,13 @@ final class BlankNodeImpl implements BlankNode, SimpleRDFTerm {
// Build a semi-URN - to be hashed for a name-based UUID below
// Both the scope and the id are used to create the UUID, ensuring that
// a caller can reliably create the same bnode if necessary by sending
- // in the same scope to RDFFactory.createBlankNode(String)
+ // in the same scope to RDF.createBlankNode(String)
String uuidInput = "urn:uuid:" + uuidSalt + "#" + name;
// The above is not a good value for this.id, as the id
// needs to be further escaped for
// ntriplesString() (there are no restrictions on
- // RDFFactory.createBlankNode(String) ).
+ // RDF.createBlankNode(String) ).
// Rather than implement ntriples escaping here, and knowing
@@ -63,7 +63,7 @@ final class BlankNodeImpl implements BlankNode, SimpleRDFTerm {
//
// A side-effect from this is that the blank node identifier
// is not preserved or shown in ntriplesString. In a way
- // this is a feature, not a bug. as the contract for RDFFactory
+ // this is a feature, not a bug. as the contract for RDF
// has no such requirement.
this.uniqueReference = UUID.nameUUIDFromBytes(
uuidInput.getBytes(StandardCharsets.UTF_8)).toString();
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFFactory.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFFactory.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFFactory.java
index 4b89603..d8103fe 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFFactory.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFFactory.java
@@ -27,18 +27,18 @@ 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.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.Triple;
/**
- * A simple implementation of RDFFactory.
+ * A simple implementation of RDF.
* <p>
* The {@link RDFTerm}, {@link Triple}, {@link Quad}, {@link Graph}
* and {@link Dataset} instances created by this factory are
* simple in-memory Implementations that are not thread-safe or efficient, but
* which may be useful for testing and prototyping purposes.
*/
-public class SimpleRDFFactory implements RDFFactory {
+public class SimpleRDFFactory implements RDF {
/**
* Marker interface to say that this RDFTerm is part of the
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
index a37a3c4..b34bc4d 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
@@ -33,7 +33,7 @@ import org.apache.commons.rdf.api.Graph;
import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.Quad;
import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.experimental.RDFParser;
import org.apache.commons.rdf.simple.SimpleRDFFactory;
@@ -63,15 +63,15 @@ public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>>
private static final ExecutorService threadpool = Executors.newCachedThreadPool(r -> new Thread(threadGroup, r));
// Basically only used for creating IRIs
- private static RDFFactory internalRdfTermFactory = new SimpleRDFFactory();
+ private static RDF internalRdfTermFactory = new SimpleRDFFactory();
/**
- * Get the set {@link RDFFactory}, if any.
+ * Get the set {@link RDF}, if any.
*
- * @return The {@link RDFFactory} to use, or {@link Optional#empty()} if
+ * @return The {@link RDF} to use, or {@link Optional#empty()} if
* it has not been set
*/
- public Optional<RDFFactory> getRdfTermFactory() {
+ public Optional<RDF> getRdfTermFactory() {
return rdfTermFactory;
}
@@ -200,7 +200,7 @@ public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>>
}
- private Optional<RDFFactory> rdfTermFactory = Optional.empty();
+ private Optional<RDF> rdfTermFactory = Optional.empty();
private Optional<RDFSyntax> contentTypeSyntax = Optional.empty();
private Optional<String> contentType = Optional.empty();
private Optional<IRI> base = Optional.empty();
@@ -227,7 +227,7 @@ public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>>
}
@Override
- public T rdfTermFactory(RDFFactory rdfTermFactory) {
+ public T rdfTermFactory(RDF rdfTermFactory) {
AbstractRDFParser<T> c = clone();
c.rdfTermFactory = Optional.ofNullable(rdfTermFactory);
return c.asT();
@@ -501,20 +501,20 @@ public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>>
/**
- * Create a new {@link RDFFactory} for a parse session.
+ * Create a new {@link RDF} for a parse session.
* <p>
* This is called by {@link #parse()} to set
- * {@link #rdfTermFactory(RDFFactory)} if it is
+ * {@link #rdfTermFactory(RDF)} if it is
* {@link Optional#empty()}.
* <p>
* As parsed blank nodes might be made with
- * {@link RDFFactory#createBlankNode(String)},
+ * {@link RDF#createBlankNode(String)},
* each call to this method SHOULD return
- * a new RDFFactory instance.
+ * a new RDF instance.
*
- * @return A new {@link RDFFactory}
+ * @return A new {@link RDF}
*/
- protected RDFFactory createRDFTermFactory() {
+ protected RDF createRDFTermFactory() {
return new SimpleRDFFactory();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
index ab2cf50..64f5acd 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/DefaultGraphTest.java
@@ -20,20 +20,20 @@ package org.apache.commons.rdf.simple;
import org.apache.commons.rdf.api.AbstractGraphTest;
import org.apache.commons.rdf.api.Graph;
import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
/**
- * Ensure AbstractGraphTest does not crash if the RDFFactory throws
+ * Ensure AbstractGraphTest does not crash if the RDF throws
* UnsupportedOperationException
*/
public class DefaultGraphTest extends AbstractGraphTest {
@Override
- public RDFFactory createFactory() {
- // The most minimal RDFFactory that would still
+ public RDF createFactory() {
+ // The most minimal RDF that would still
// make sense with a Graph
- return new RDFFactory() {
+ return new RDF() {
@Override
public Graph createGraph() throws UnsupportedOperationException {
return new GraphImpl(new SimpleRDFFactory());
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java b/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java
index c635aff..af91978 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java
@@ -23,7 +23,7 @@ import java.util.function.Consumer;
import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.Quad;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.experimental.RDFParser;
import org.apache.commons.rdf.simple.experimental.AbstractRDFParser;
import org.apache.commons.rdf.simple.experimental.RDFParseException;
@@ -50,7 +50,7 @@ public class DummyRDFParserBuilder extends AbstractRDFParser<DummyRDFParserBuild
@Override
protected void parseSynchronusly() throws IOException, IllegalStateException, RDFParseException {
// From parseSynchronusly both of these are always present
- RDFFactory factory = getRdfTermFactory().get();
+ RDF factory = getRdfTermFactory().get();
Consumer<Quad> t = getTarget();
// well - each parsing is unique. This should hopefully
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
index 3872f11..e4cdf8e 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
@@ -20,7 +20,7 @@ package org.apache.commons.rdf.simple;
import static org.junit.Assert.assertTrue;
import org.apache.commons.rdf.api.AbstractGraphTest;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.junit.Assume;
import org.junit.Test;
@@ -30,7 +30,7 @@ import org.junit.Test;
public class SimpleGraphTest extends AbstractGraphTest {
@Override
- public RDFFactory createFactory() {
+ public RDF createFactory() {
return new SimpleRDFFactory();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
index 752c465..527d7b9 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
@@ -19,7 +19,7 @@ package org.apache.commons.rdf.simple;
import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import java.net.URI;
@@ -32,7 +32,7 @@ import java.net.URI;
public class SimpleNoRelativeIRIRDFTermFactoryTest extends
AbstractRDFTermFactoryTest {
@Override
- public RDFFactory createFactory() {
+ public RDF createFactory() {
return new SimpleRDFFactory() {
@Override
public IRI createIRI(String iri) {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
index bd3b5ad..e308f00 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
@@ -18,15 +18,15 @@
package org.apache.commons.rdf.simple;
import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
/**
- * Simple RDFFactory Test
+ * Simple RDF Test
*/
public class SimpleRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
@Override
- public RDFFactory createFactory() {
+ public RDF createFactory() {
return new SimpleRDFFactory();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
index 00e33d3..08930ac 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
@@ -22,15 +22,15 @@ import static org.junit.Assert.fail;
import java.util.ServiceLoader;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.junit.Test;
public class SimpleServiceLoaderTest {
@Test
public void testServiceLoaderLookup() {
- ServiceLoader<RDFFactory> loader = ServiceLoader.load(RDFFactory.class);
- for (RDFFactory impl : loader) {
+ ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class);
+ for (RDF impl : loader) {
if (impl instanceof SimpleRDFFactory) {
return; // yay
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ff94b9da/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
index 57ee24a..8af3034 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
@@ -29,7 +29,7 @@ import java.util.stream.Stream;
import org.apache.commons.rdf.api.Graph;
import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.Triple;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -53,7 +53,7 @@ public class TestWritingGraph {
private static Graph graph;
- private static RDFFactory factory;
+ private static RDF factory;
@BeforeClass
public static void createGraph() throws Exception {
[41/50] [abbrv] incubator-commonsrdf git commit: Reformat tab ->
spaces
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
index 7f70c75..8df26e0 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
@@ -53,9 +53,9 @@ import org.eclipse.rdf4j.sail.memory.MemoryStore;
/**
* RDF4J implementation of RDF.
* <p>
- * The {@link #RDF4J()} constructor uses a {@link SimpleValueFactory}
- * to create corresponding RDF4J {@link Value} instances. Alternatively, this
- * factory can be constructed with a different {@link ValueFactory} using
+ * The {@link #RDF4J()} constructor uses a {@link SimpleValueFactory} to create
+ * corresponding RDF4J {@link Value} instances. Alternatively, this factory can
+ * be constructed with a different {@link ValueFactory} using
* {@link #RDF4J(ValueFactory)}.
* <p>
* {@link #asRDFTerm(Value)} can be used to convert any RDF4J {@link Value} to
@@ -67,8 +67,7 @@ import org.eclipse.rdf4j.sail.memory.MemoryStore;
* To use other models, see {@link #asGraph(Model)}.
* <p>
* To adapt a RDF4J {@link Repository} as a {@link Dataset} or {@link Graph},
- * use {@link #asDataset(Repository, Option...)}
- * or
+ * use {@link #asDataset(Repository, Option...)} or
* {@link #asGraph(Repository, Option...)}.
* <p>
* {@link #asTriple(Statement)} can be used to convert a RDF4J {@link Statement}
@@ -93,511 +92,495 @@ import org.eclipse.rdf4j.sail.memory.MemoryStore;
* the same {@link BNode#getID()}, converting them with the above methods might
* cause accidental {@link BlankNode} equivalence. Note that the {@link Graph}
* and {@link Dataset} adapter methods like
- * {@link #asDataset(Repository, Option...)}
- * and
- * {@link #asGraph(Repository, Option...)}
- * therefore uses a unique {@link RDF4J} internally.
+ * {@link #asDataset(Repository, Option...)} and
+ * {@link #asGraph(Repository, Option...)} therefore uses a unique {@link RDF4J}
+ * internally.
*
* @see RDF
*
*/
public final class RDF4J implements RDF {
- /**
- * InternalRDF4JFactory is deliberately abstract
- */
- private static InternalRDF4JFactory rdf4j = new InternalRDF4JFactory() {
- };
-
- public enum Option {
- /**
- * The Graph/Dataset should include any inferred statements
- */
- includeInferred,
- /**
- * The graph/dataset should handle {@link Repository#initialize()} (if
- * needed) and {@link Repository#shutDown()} on {@link Graph#close()} /
- * {@link Dataset#close()}.
- */
- handleInitAndShutdown
- }
-
- private final UUID salt;
-
- private final ValueFactory valueFactory;
-
- /**
- * Construct an {@link RDF4J}.
- *
- */
- public RDF4J() {
- this(SimpleValueFactory.getInstance(), UUID.randomUUID());
- }
-
- /**
- * Construct an {@link RDF4J}.
- * <p>
- * This constructor is intended for use with the value factory from
- * {@link Repository#getValueFactory()} when using
- * Repository-based graphs and datasets.
- *
- * @param valueFactory
- * The RDF4J {@link ValueFactory} to use
- */
- public RDF4J(ValueFactory valueFactory) {
- this(valueFactory, UUID.randomUUID());
- }
-
- /**
- * Construct an {@link RDF4J}.
- * <p>
- * This constructor may be used if reproducible
- * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable.
- *
- * @param salt
- * An {@link UUID} salt to be used by any created
- * {@link BlankNode}s for the purpose of
- * {@link BlankNode#uniqueReference()}
- */
- public RDF4J(UUID salt) {
- this(SimpleValueFactory.getInstance(), salt);
- }
- /**
- * Construct an {@link RDF4J}.
- * <p>
- * This constructor may be used if reproducible
- * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable.
- *
- * @param valueFactory
- * The RDF4J {@link ValueFactory} to use
- * @param salt
- * An {@link UUID} salt to be used by any created
- * {@link BlankNode}s for the purpose of
- * {@link BlankNode#uniqueReference()}
- */
- public RDF4J(ValueFactory valueFactory, UUID salt) {
- this.valueFactory = valueFactory;
- this.salt = salt;
- }
-
- /**
- * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Quad}.
- * <p>
- * For the purpose of {@link BlankNode} equivalence, this method will use an
- * internal salt UUID that is unique per instance of
- * {@link RDF4J}.
- * <p>
- * <strong>NOTE:</strong> If combining RDF4J {@link Statement}s multiple
- * repositories or models, then their {@link BNode}s may have the same
- * {@link BNode#getID()}, which with this method would become equivalent
- * according to {@link BlankNode#equals(Object)} and
- * {@link BlankNode#uniqueReference()}, unless a separate
- * {@link RDF4J} instance is used per RDF4J repository/model.
- *
- * @param statement
- * The statement to convert
- * @return A {@link RDF4JQuad} that is equivalent to the statement
- */
- public RDF4JQuad asQuad(final Statement statement) {
- return rdf4j.createQuadImpl(statement, salt);
- }
-
- /**
- *
- * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
- * <p>
- * The value will be of the same kind as the term, e.g. a
- * {@link org.eclipse.rdf4j.model.BNode} is converted to a
- * {@link org.apache.commons.rdf.api.BlankNode}, a
- * {@link org.eclipse.rdf4j.model.IRI} is converted to a
- * {@link org.apache.commons.rdf.api.IRI} and a
- * {@link org.eclipse.rdf4j.model.Literal}. is converted to a
- * {@link org.apache.commons.rdf.api.Literal}
- * <p>
- * For the purpose of {@link BlankNode} equivalence, this method will use an
- * internal salt UUID that is unique per instance of
- * {@link RDF4J}.
- * <p>
- * <strong>NOTE:</strong> If combining RDF4J values from multiple
- * repositories or models, then their {@link BNode}s may have the same
- * {@link BNode#getID()}, which with this method would become equivalent
- * according to {@link BlankNode#equals(Object)} and
- * {@link BlankNode#uniqueReference()}, unless a separate
- * {@link RDF4J} instance is used per RDF4J repository/model.
- *
- * @param value
- * The RDF4J {@link Value} to convert.
- * @return A {@link RDFTerm} that corresponds to the RDF4J value
- * @throws IllegalArgumentException
- * if the value is not a BNode, Literal or IRI
- */
- public RDF4JTerm asRDFTerm(Value value) {
- return asRDFTerm(value, salt);
- }
-
- /**
- * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
- * <p>
- * The value will be of the same kind as the term, e.g. a
- * {@link org.eclipse.rdf4j.model.BNode} is converted to a
- * {@link org.apache.commons.rdf.api.BlankNode}, a
- * {@link org.eclipse.rdf4j.model.IRI} is converted to a
- * {@link org.apache.commons.rdf.api.IRI} and a
- * {@link org.eclipse.rdf4j.model.Literal}. is converted to a
- * {@link org.apache.commons.rdf.api.Literal}
- *
- * @param value
- * The RDF4J {@link Value} to convert.
- * @param salt
- * A {@link UUID} salt to use for uniquely mapping any
- * {@link BNode}s. The salt should typically be the same for
- * multiple statements in the same {@link Repository} or
- * {@link Model} to ensure {@link BlankNode#equals(Object)} and
- * {@link BlankNode#uniqueReference()} works as intended.
- * @return A {@link RDFTerm} that corresponds to the RDF4J value
- * @throws IllegalArgumentException
- * if the value is not a BNode, Literal or IRI
- */
- public static RDF4JTerm asRDFTerm(final Value value, UUID salt) {
- if (value instanceof BNode) {
- return rdf4j.createBlankNodeImpl((BNode) value, salt);
- }
- if (value instanceof org.eclipse.rdf4j.model.Literal) {
- return rdf4j.createLiteralImpl((org.eclipse.rdf4j.model.Literal) value);
- }
- if (value instanceof org.eclipse.rdf4j.model.IRI) {
- return rdf4j.createIRIImpl((org.eclipse.rdf4j.model.IRI) value);
- }
- throw new IllegalArgumentException("Value is not a BNode, Literal or IRI: " + value.getClass());
- }
-
- /**
- * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Dataset}.
- * <p>
- * Changes to the dataset are reflected in the repository, and vice versa.
- * <p>
- * <strong>Note:</strong> Some operations on the {@link RDF4JDataset}
- * requires the use of try-with-resources to close underlying
- * {@link RepositoryConnection}s, including
- * {@link RDF4JDataset#iterate()},
- * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}.
- *
- * @param repository
- * RDF4J {@link Repository} to connect to.
- * @param options
- * Zero or more {@link Option}
- * @return A {@link Dataset} backed by the RDF4J repository.
- */
- public RDF4JDataset asDataset(Repository repository, Option... options) {
- EnumSet<Option> opts = optionSet(options);
- return rdf4j.createRepositoryDatasetImpl(repository,
- opts.contains(Option.handleInitAndShutdown),
- opts.contains(Option.includeInferred));
- }
-
- /**
- * Adapt an RDF4J {@link Model} as a Commons RDF {@link Graph}.
- * <p>
- * Changes to the graph are reflected in the model, and vice versa.
- *
- * @param model
- * RDF4J {@link Model} to adapt.
- * @return Adapted {@link Graph}.
- */
- public RDF4JGraph asGraph(Model model) {
- return rdf4j.createModelGraphImpl(model, this);
- }
-
- /**
- * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
- * <p>
- * The graph will only include triples in the default graph (equivalent to
- * context <code>new Resource[0]{null})</code> in RDF4J).
- * <p>
- * Changes to the graph are reflected in the repository, and vice versa.
- * <p>
- * <strong>Note:</strong> Some operations on the {@link RDF4JGraph}
- * requires the use of try-with-resources to close underlying
- * {@link RepositoryConnection}s, including
- * {@link RDF4JGraph#iterate()} and
- * {@link RDF4JGraph#stream()}.
- *
- * @param repository
- * RDF4J {@link Repository} to connect to.
- * @param options
- * Zero or more {@link Option}
- * @return A {@link Graph} backed by the RDF4J repository.
- */
- public RDF4JGraph asGraph(Repository repository, Option... options) {
- EnumSet<Option> opts = optionSet(options);
- return rdf4j.createRepositoryGraphImpl(repository,
- opts.contains(Option.handleInitAndShutdown),
- opts.contains(Option.includeInferred),
- new Resource[]{null}); // default graph
- }
-
- /**
- * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
- * <p>
- * The graph will include triples in any contexts (e.g. the union graph).
- * <p>
- * Changes to the graph are reflected in the repository, and vice versa.
- *
- * @param repository
- * RDF4J {@link Repository} to connect to.
- * @param options
- * Zero or more {@link Option}
- * @return A union {@link Graph} backed by the RDF4J repository.
- */
- public RDF4JGraph asGraphUnion(Repository repository, Option... options) {
- EnumSet<Option> opts = optionSet(options);
- return rdf4j.createRepositoryGraphImpl(repository,
- opts.contains(Option.handleInitAndShutdown),
- opts.contains(Option.includeInferred),
- new Resource[]{}); // union graph
-
- }
-
- /**
- * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
- * <p>
- * The graph will include triples in the specified contexts.
- * <p>
- * Changes to the graph are reflected in the repository, and vice versa.
- * Triples added/removed to the graph are reflected in all the specified
- * contexts.
- * <p>
- * <strong>Note:</strong> Some operations on the {@link RDF4JGraph}
- * requires the use of try-with-resources to close underlying
- * {@link RepositoryConnection}s, including
- * {@link RDF4JGraph#iterate()} and
- * {@link RDF4JGraph#stream()}.
- *
- * @param repository
- * RDF4J {@link Repository} to connect to.
- * @param contexts
- * A {@link Set} of {@link BlankNodeOrIRI} specifying the graph
- * names to use as a context. The set may include the value
- * <code>null</code> to indicate the default graph. The empty set
- * indicates any context, e.g. the <em>union graph</em>.
- * @param option
- * Zero or more {@link Option}s
- * @return A {@link Graph} backed by the RDF4J repository.
- */
- public RDF4JGraph asGraph(Repository repository, Set<? extends BlankNodeOrIRI> contexts,
- Option... option) {
- EnumSet<Option> opts = optionSet(option);
- /** NOTE: asValue() deliberately CAN handle <code>null</code> */
- Resource[] resources = contexts.stream().map(g -> (Resource) asValue(g)).toArray(Resource[]::new);
- return rdf4j.createRepositoryGraphImpl(Objects.requireNonNull(repository),
- opts.contains(Option.handleInitAndShutdown),
- opts.contains(Option.includeInferred),
- resources);
- }
-
- /**
- * Adapt a Commons RDF {@link Triple} or {@link Quad} as a RDF4J
- * {@link Statement}.
- * <p>
- * If the <code>tripleLike</code> argument is an {@link RDF4JTriple} or a
- * {@link RDF4JQuad}, then its {@link RDF4JTripleLike#asStatement()} is
- * returned as-is. Note that this means that a {@link RDF4JTriple} would
- * preserve its {@link Statement#getContext()}, and that any
- * {@link BlankNode}s would be deemed equivalent in RDF4J if they have the
- * same {@link BNode#getID()}.
- *
- * @param tripleLike
- * A {@link Triple} or {@link Quad} to adapt
- * @return A corresponding {@link Statement}
- */
- public Statement asStatement(TripleLike tripleLike) {
- if (tripleLike instanceof RDF4JTripleLike) {
- // Return original statement - this covers both RDF4JQuad and
- // RDF4JTriple
- return ((RDF4JTripleLike) tripleLike).asStatement();
- }
-
- org.eclipse.rdf4j.model.Resource subject = (org.eclipse.rdf4j.model.Resource) asValue(tripleLike.getSubject());
- org.eclipse.rdf4j.model.IRI predicate = (org.eclipse.rdf4j.model.IRI) asValue(tripleLike.getPredicate());
- Value object = asValue(tripleLike.getObject());
-
- org.eclipse.rdf4j.model.Resource context = null;
- if (tripleLike instanceof Quad) {
- Quad quad = (Quad) tripleLike;
- context = (org.eclipse.rdf4j.model.Resource) asValue(quad.getGraphName().orElse(null));
- }
-
- return getValueFactory().createStatement(subject, predicate, object, context);
- }
-
- /**
- * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Triple}.
- * <p>
- * For the purpose of {@link BlankNode} equivalence, this method will use an
- * internal salt UUID that is unique per instance of
- * {@link RDF4J}.
- * <p>
- * <strong>NOTE:</strong> If combining RDF4J statements from multiple
- * repositories or models, then their {@link BNode}s may have the same
- * {@link BNode#getID()}, which with this method would become equivalent
- * according to {@link BlankNode#equals(Object)} and
- * {@link BlankNode#uniqueReference()}, unless a separate
- * {@link RDF4J} instance is used per RDF4J repository/model.
- *
- * @param statement
- * The RDF4J {@link Statement} to adapt.
- * @return A {@link RDF4JTriple} that is equivalent to the statement
- */
- public RDF4JTriple asTriple(final Statement statement) {
- return rdf4j.createTripleImpl(statement, salt);
- }
-
- /**
- * Adapt a Commons RDF {@link RDFTerm} as a RDF4J {@link Value}.
- * <p>
- * The value will be of the same kind as the term, e.g. a
- * {@link org.apache.commons.rdf.api.BlankNode} is converted to a
- * {@link org.eclipse.rdf4j.model.BNode}, a
- * {@link org.apache.commons.rdf.api.IRI} is converted to a
- * {@link org.eclipse.rdf4j.model.IRI} and a
- * {@link org.apache.commons.rdf.api.Literal} is converted to a
- * {@link org.eclipse.rdf4j.model.Literal}.
- * <p>
- * If the provided {@link RDFTerm} is <code>null</code>, then the returned
- * value is <code>null</code>.
- * <p>
- * If the provided term is an instance of {@link RDF4JTerm}, then the
- * {@link RDF4JTerm#asValue()} is returned without any conversion. Note that
- * this could mean that a {@link Value} from a different kind of
- * {@link ValueFactory} could be returned.
- *
- * @param term
- * RDFTerm to adapt to RDF4J Value
- * @return Adapted RDF4J {@link Value}
- */
- public Value asValue(RDFTerm term) {
- if (term == null) {
- return null;
- }
- if (term instanceof RDF4JTerm) {
- // One of our own - avoid converting again.
- // (This is crucial to avoid double-escaping in BlankNode)
- return ((RDF4JTerm) term).asValue();
- }
- if (term instanceof org.apache.commons.rdf.api.IRI) {
- org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) term;
- return getValueFactory().createIRI(iri.getIRIString());
- }
- if (term instanceof org.apache.commons.rdf.api.Literal) {
- org.apache.commons.rdf.api.Literal literal = (org.apache.commons.rdf.api.Literal) term;
- String label = literal.getLexicalForm();
- if (literal.getLanguageTag().isPresent()) {
- String lang = literal.getLanguageTag().get();
- return getValueFactory().createLiteral(label, lang);
- }
- org.eclipse.rdf4j.model.IRI dataType = (org.eclipse.rdf4j.model.IRI) asValue(literal.getDatatype());
- return getValueFactory().createLiteral(label, dataType);
- }
- if (term instanceof BlankNode) {
- // This is where it gets tricky to support round trips!
- BlankNode blankNode = (BlankNode) term;
- // FIXME: The uniqueReference might not be a valid BlankNode
- // identifier..
- // does it have to be in RDF4J?
- return getValueFactory().createBNode(blankNode.uniqueReference());
- }
- throw new IllegalArgumentException("RDFTerm was not an IRI, Literal or BlankNode: " + term.getClass());
- }
-
- @Override
- public RDF4JBlankNode createBlankNode() {
- BNode bnode = getValueFactory().createBNode();
- return (RDF4JBlankNode) asRDFTerm(bnode);
- }
-
- @Override
- public RDF4JBlankNode createBlankNode(String name) {
- BNode bnode = getValueFactory().createBNode(name);
- return (RDF4JBlankNode) asRDFTerm(bnode);
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * <strong>Note:</strong> Some operations on the {@link RDF4JDataset}
- * requires the use of try-with-resources to close underlying
- * {@link RepositoryConnection}s, including
- * {@link RDF4JDataset#iterate()},
- * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}.
- *
- */
- @Override
- public RDF4JDataset createDataset() {
- Sail sail = new MemoryStore();
- Repository repository = new SailRepository(sail);
- return rdf4j.createRepositoryDatasetImpl(repository, true, false);
- }
-
- @Override
- public RDF4JGraph createGraph() {
- return asGraph(new LinkedHashModel());
- }
-
- @Override
- public RDF4JIRI createIRI(String iri) throws IllegalArgumentException {
- return (RDF4JIRI) asRDFTerm(getValueFactory().createIRI(iri));
- }
-
- @Override
- public RDF4JLiteral createLiteral(String lexicalForm)
- throws IllegalArgumentException {
- org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm);
- return (RDF4JLiteral) asRDFTerm(lit);
- }
-
- @Override
- public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, org.apache.commons.rdf.api.IRI dataType)
- throws IllegalArgumentException {
- org.eclipse.rdf4j.model.IRI iri = getValueFactory().createIRI(dataType.getIRIString());
- org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, iri);
- return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit);
- }
-
- @Override
- public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, String languageTag)
- throws IllegalArgumentException {
- org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, languageTag);
- return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit);
- }
-
- @Override
- public RDF4JTriple createTriple(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object)
- throws IllegalArgumentException {
- final Statement statement = getValueFactory().createStatement(
- (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate),
- asValue(object));
- return asTriple(statement);
- }
-
- @Override
- public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate,
- RDFTerm object) throws IllegalArgumentException {
- final Statement statement = getValueFactory().createStatement(
- (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate),
- asValue(object), (org.eclipse.rdf4j.model.Resource) asValue(graphName));
- return asQuad(statement);
- }
-
- public ValueFactory getValueFactory() {
- return valueFactory;
- }
-
- private EnumSet<Option> optionSet(Option... options) {
- EnumSet<Option> opts = EnumSet.noneOf(Option.class);
- opts.addAll(Arrays.asList(options));
- return opts;
- }
-
-
-
+ /**
+ * InternalRDF4JFactory is deliberately abstract
+ */
+ private static InternalRDF4JFactory rdf4j = new InternalRDF4JFactory() {
+ };
+
+ public enum Option {
+ /**
+ * The Graph/Dataset should include any inferred statements
+ */
+ includeInferred,
+ /**
+ * The graph/dataset should handle {@link Repository#initialize()} (if
+ * needed) and {@link Repository#shutDown()} on {@link Graph#close()} /
+ * {@link Dataset#close()}.
+ */
+ handleInitAndShutdown
+ }
+
+ private final UUID salt;
+
+ private final ValueFactory valueFactory;
+
+ /**
+ * Construct an {@link RDF4J}.
+ *
+ */
+ public RDF4J() {
+ this(SimpleValueFactory.getInstance(), UUID.randomUUID());
+ }
+
+ /**
+ * Construct an {@link RDF4J}.
+ * <p>
+ * This constructor is intended for use with the value factory from
+ * {@link Repository#getValueFactory()} when using Repository-based graphs
+ * and datasets.
+ *
+ * @param valueFactory
+ * The RDF4J {@link ValueFactory} to use
+ */
+ public RDF4J(ValueFactory valueFactory) {
+ this(valueFactory, UUID.randomUUID());
+ }
+
+ /**
+ * Construct an {@link RDF4J}.
+ * <p>
+ * This constructor may be used if reproducible
+ * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable.
+ *
+ * @param salt
+ * An {@link UUID} salt to be used by any created
+ * {@link BlankNode}s for the purpose of
+ * {@link BlankNode#uniqueReference()}
+ */
+ public RDF4J(UUID salt) {
+ this(SimpleValueFactory.getInstance(), salt);
+ }
+
+ /**
+ * Construct an {@link RDF4J}.
+ * <p>
+ * This constructor may be used if reproducible
+ * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable.
+ *
+ * @param valueFactory
+ * The RDF4J {@link ValueFactory} to use
+ * @param salt
+ * An {@link UUID} salt to be used by any created
+ * {@link BlankNode}s for the purpose of
+ * {@link BlankNode#uniqueReference()}
+ */
+ public RDF4J(ValueFactory valueFactory, UUID salt) {
+ this.valueFactory = valueFactory;
+ this.salt = salt;
+ }
+
+ /**
+ * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Quad}.
+ * <p>
+ * For the purpose of {@link BlankNode} equivalence, this method will use an
+ * internal salt UUID that is unique per instance of {@link RDF4J}.
+ * <p>
+ * <strong>NOTE:</strong> If combining RDF4J {@link Statement}s multiple
+ * repositories or models, then their {@link BNode}s may have the same
+ * {@link BNode#getID()}, which with this method would become equivalent
+ * according to {@link BlankNode#equals(Object)} and
+ * {@link BlankNode#uniqueReference()}, unless a separate {@link RDF4J}
+ * instance is used per RDF4J repository/model.
+ *
+ * @param statement
+ * The statement to convert
+ * @return A {@link RDF4JQuad} that is equivalent to the statement
+ */
+ public RDF4JQuad asQuad(final Statement statement) {
+ return rdf4j.createQuadImpl(statement, salt);
+ }
+
+ /**
+ *
+ * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
+ * <p>
+ * The value will be of the same kind as the term, e.g. a
+ * {@link org.eclipse.rdf4j.model.BNode} is converted to a
+ * {@link org.apache.commons.rdf.api.BlankNode}, a
+ * {@link org.eclipse.rdf4j.model.IRI} is converted to a
+ * {@link org.apache.commons.rdf.api.IRI} and a
+ * {@link org.eclipse.rdf4j.model.Literal}. is converted to a
+ * {@link org.apache.commons.rdf.api.Literal}
+ * <p>
+ * For the purpose of {@link BlankNode} equivalence, this method will use an
+ * internal salt UUID that is unique per instance of {@link RDF4J}.
+ * <p>
+ * <strong>NOTE:</strong> If combining RDF4J values from multiple
+ * repositories or models, then their {@link BNode}s may have the same
+ * {@link BNode#getID()}, which with this method would become equivalent
+ * according to {@link BlankNode#equals(Object)} and
+ * {@link BlankNode#uniqueReference()}, unless a separate {@link RDF4J}
+ * instance is used per RDF4J repository/model.
+ *
+ * @param value
+ * The RDF4J {@link Value} to convert.
+ * @return A {@link RDFTerm} that corresponds to the RDF4J value
+ * @throws IllegalArgumentException
+ * if the value is not a BNode, Literal or IRI
+ */
+ public RDF4JTerm asRDFTerm(Value value) {
+ return asRDFTerm(value, salt);
+ }
+
+ /**
+ * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
+ * <p>
+ * The value will be of the same kind as the term, e.g. a
+ * {@link org.eclipse.rdf4j.model.BNode} is converted to a
+ * {@link org.apache.commons.rdf.api.BlankNode}, a
+ * {@link org.eclipse.rdf4j.model.IRI} is converted to a
+ * {@link org.apache.commons.rdf.api.IRI} and a
+ * {@link org.eclipse.rdf4j.model.Literal}. is converted to a
+ * {@link org.apache.commons.rdf.api.Literal}
+ *
+ * @param value
+ * The RDF4J {@link Value} to convert.
+ * @param salt
+ * A {@link UUID} salt to use for uniquely mapping any
+ * {@link BNode}s. The salt should typically be the same for
+ * multiple statements in the same {@link Repository} or
+ * {@link Model} to ensure {@link BlankNode#equals(Object)} and
+ * {@link BlankNode#uniqueReference()} works as intended.
+ * @return A {@link RDFTerm} that corresponds to the RDF4J value
+ * @throws IllegalArgumentException
+ * if the value is not a BNode, Literal or IRI
+ */
+ public static RDF4JTerm asRDFTerm(final Value value, UUID salt) {
+ if (value instanceof BNode) {
+ return rdf4j.createBlankNodeImpl((BNode) value, salt);
+ }
+ if (value instanceof org.eclipse.rdf4j.model.Literal) {
+ return rdf4j.createLiteralImpl((org.eclipse.rdf4j.model.Literal) value);
+ }
+ if (value instanceof org.eclipse.rdf4j.model.IRI) {
+ return rdf4j.createIRIImpl((org.eclipse.rdf4j.model.IRI) value);
+ }
+ throw new IllegalArgumentException("Value is not a BNode, Literal or IRI: " + value.getClass());
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Dataset}.
+ * <p>
+ * Changes to the dataset are reflected in the repository, and vice versa.
+ * <p>
+ * <strong>Note:</strong> Some operations on the {@link RDF4JDataset}
+ * requires the use of try-with-resources to close underlying
+ * {@link RepositoryConnection}s, including {@link RDF4JDataset#iterate()},
+ * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param options
+ * Zero or more {@link Option}
+ * @return A {@link Dataset} backed by the RDF4J repository.
+ */
+ public RDF4JDataset asDataset(Repository repository, Option... options) {
+ EnumSet<Option> opts = optionSet(options);
+ return rdf4j.createRepositoryDatasetImpl(repository, opts.contains(Option.handleInitAndShutdown),
+ opts.contains(Option.includeInferred));
+ }
+
+ /**
+ * Adapt an RDF4J {@link Model} as a Commons RDF {@link Graph}.
+ * <p>
+ * Changes to the graph are reflected in the model, and vice versa.
+ *
+ * @param model
+ * RDF4J {@link Model} to adapt.
+ * @return Adapted {@link Graph}.
+ */
+ public RDF4JGraph asGraph(Model model) {
+ return rdf4j.createModelGraphImpl(model, this);
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
+ * <p>
+ * The graph will only include triples in the default graph (equivalent to
+ * context <code>new Resource[0]{null})</code> in RDF4J).
+ * <p>
+ * Changes to the graph are reflected in the repository, and vice versa.
+ * <p>
+ * <strong>Note:</strong> Some operations on the {@link RDF4JGraph} requires
+ * the use of try-with-resources to close underlying
+ * {@link RepositoryConnection}s, including {@link RDF4JGraph#iterate()} and
+ * {@link RDF4JGraph#stream()}.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param options
+ * Zero or more {@link Option}
+ * @return A {@link Graph} backed by the RDF4J repository.
+ */
+ public RDF4JGraph asGraph(Repository repository, Option... options) {
+ EnumSet<Option> opts = optionSet(options);
+ return rdf4j.createRepositoryGraphImpl(repository, opts.contains(Option.handleInitAndShutdown),
+ opts.contains(Option.includeInferred), new Resource[] { null }); // default
+ // graph
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
+ * <p>
+ * The graph will include triples in any contexts (e.g. the union graph).
+ * <p>
+ * Changes to the graph are reflected in the repository, and vice versa.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param options
+ * Zero or more {@link Option}
+ * @return A union {@link Graph} backed by the RDF4J repository.
+ */
+ public RDF4JGraph asGraphUnion(Repository repository, Option... options) {
+ EnumSet<Option> opts = optionSet(options);
+ return rdf4j.createRepositoryGraphImpl(repository, opts.contains(Option.handleInitAndShutdown),
+ opts.contains(Option.includeInferred), new Resource[] {}); // union
+ // graph
+
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
+ * <p>
+ * The graph will include triples in the specified contexts.
+ * <p>
+ * Changes to the graph are reflected in the repository, and vice versa.
+ * Triples added/removed to the graph are reflected in all the specified
+ * contexts.
+ * <p>
+ * <strong>Note:</strong> Some operations on the {@link RDF4JGraph} requires
+ * the use of try-with-resources to close underlying
+ * {@link RepositoryConnection}s, including {@link RDF4JGraph#iterate()} and
+ * {@link RDF4JGraph#stream()}.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param contexts
+ * A {@link Set} of {@link BlankNodeOrIRI} specifying the graph
+ * names to use as a context. The set may include the value
+ * <code>null</code> to indicate the default graph. The empty set
+ * indicates any context, e.g. the <em>union graph</em>.
+ * @param option
+ * Zero or more {@link Option}s
+ * @return A {@link Graph} backed by the RDF4J repository.
+ */
+ public RDF4JGraph asGraph(Repository repository, Set<? extends BlankNodeOrIRI> contexts, Option... option) {
+ EnumSet<Option> opts = optionSet(option);
+ /** NOTE: asValue() deliberately CAN handle <code>null</code> */
+ Resource[] resources = contexts.stream().map(g -> (Resource) asValue(g)).toArray(Resource[]::new);
+ return rdf4j.createRepositoryGraphImpl(Objects.requireNonNull(repository),
+ opts.contains(Option.handleInitAndShutdown), opts.contains(Option.includeInferred), resources);
+ }
+
+ /**
+ * Adapt a Commons RDF {@link Triple} or {@link Quad} as a RDF4J
+ * {@link Statement}.
+ * <p>
+ * If the <code>tripleLike</code> argument is an {@link RDF4JTriple} or a
+ * {@link RDF4JQuad}, then its {@link RDF4JTripleLike#asStatement()} is
+ * returned as-is. Note that this means that a {@link RDF4JTriple} would
+ * preserve its {@link Statement#getContext()}, and that any
+ * {@link BlankNode}s would be deemed equivalent in RDF4J if they have the
+ * same {@link BNode#getID()}.
+ *
+ * @param tripleLike
+ * A {@link Triple} or {@link Quad} to adapt
+ * @return A corresponding {@link Statement}
+ */
+ public Statement asStatement(TripleLike tripleLike) {
+ if (tripleLike instanceof RDF4JTripleLike) {
+ // Return original statement - this covers both RDF4JQuad and
+ // RDF4JTriple
+ return ((RDF4JTripleLike) tripleLike).asStatement();
+ }
+
+ org.eclipse.rdf4j.model.Resource subject = (org.eclipse.rdf4j.model.Resource) asValue(tripleLike.getSubject());
+ org.eclipse.rdf4j.model.IRI predicate = (org.eclipse.rdf4j.model.IRI) asValue(tripleLike.getPredicate());
+ Value object = asValue(tripleLike.getObject());
+
+ org.eclipse.rdf4j.model.Resource context = null;
+ if (tripleLike instanceof Quad) {
+ Quad quad = (Quad) tripleLike;
+ context = (org.eclipse.rdf4j.model.Resource) asValue(quad.getGraphName().orElse(null));
+ }
+
+ return getValueFactory().createStatement(subject, predicate, object, context);
+ }
+
+ /**
+ * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Triple}.
+ * <p>
+ * For the purpose of {@link BlankNode} equivalence, this method will use an
+ * internal salt UUID that is unique per instance of {@link RDF4J}.
+ * <p>
+ * <strong>NOTE:</strong> If combining RDF4J statements from multiple
+ * repositories or models, then their {@link BNode}s may have the same
+ * {@link BNode#getID()}, which with this method would become equivalent
+ * according to {@link BlankNode#equals(Object)} and
+ * {@link BlankNode#uniqueReference()}, unless a separate {@link RDF4J}
+ * instance is used per RDF4J repository/model.
+ *
+ * @param statement
+ * The RDF4J {@link Statement} to adapt.
+ * @return A {@link RDF4JTriple} that is equivalent to the statement
+ */
+ public RDF4JTriple asTriple(final Statement statement) {
+ return rdf4j.createTripleImpl(statement, salt);
+ }
+
+ /**
+ * Adapt a Commons RDF {@link RDFTerm} as a RDF4J {@link Value}.
+ * <p>
+ * The value will be of the same kind as the term, e.g. a
+ * {@link org.apache.commons.rdf.api.BlankNode} is converted to a
+ * {@link org.eclipse.rdf4j.model.BNode}, a
+ * {@link org.apache.commons.rdf.api.IRI} is converted to a
+ * {@link org.eclipse.rdf4j.model.IRI} and a
+ * {@link org.apache.commons.rdf.api.Literal} is converted to a
+ * {@link org.eclipse.rdf4j.model.Literal}.
+ * <p>
+ * If the provided {@link RDFTerm} is <code>null</code>, then the returned
+ * value is <code>null</code>.
+ * <p>
+ * If the provided term is an instance of {@link RDF4JTerm}, then the
+ * {@link RDF4JTerm#asValue()} is returned without any conversion. Note that
+ * this could mean that a {@link Value} from a different kind of
+ * {@link ValueFactory} could be returned.
+ *
+ * @param term
+ * RDFTerm to adapt to RDF4J Value
+ * @return Adapted RDF4J {@link Value}
+ */
+ public Value asValue(RDFTerm term) {
+ if (term == null) {
+ return null;
+ }
+ if (term instanceof RDF4JTerm) {
+ // One of our own - avoid converting again.
+ // (This is crucial to avoid double-escaping in BlankNode)
+ return ((RDF4JTerm) term).asValue();
+ }
+ if (term instanceof org.apache.commons.rdf.api.IRI) {
+ org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) term;
+ return getValueFactory().createIRI(iri.getIRIString());
+ }
+ if (term instanceof org.apache.commons.rdf.api.Literal) {
+ org.apache.commons.rdf.api.Literal literal = (org.apache.commons.rdf.api.Literal) term;
+ String label = literal.getLexicalForm();
+ if (literal.getLanguageTag().isPresent()) {
+ String lang = literal.getLanguageTag().get();
+ return getValueFactory().createLiteral(label, lang);
+ }
+ org.eclipse.rdf4j.model.IRI dataType = (org.eclipse.rdf4j.model.IRI) asValue(literal.getDatatype());
+ return getValueFactory().createLiteral(label, dataType);
+ }
+ if (term instanceof BlankNode) {
+ // This is where it gets tricky to support round trips!
+ BlankNode blankNode = (BlankNode) term;
+ // FIXME: The uniqueReference might not be a valid BlankNode
+ // identifier..
+ // does it have to be in RDF4J?
+ return getValueFactory().createBNode(blankNode.uniqueReference());
+ }
+ throw new IllegalArgumentException("RDFTerm was not an IRI, Literal or BlankNode: " + term.getClass());
+ }
+
+ @Override
+ public RDF4JBlankNode createBlankNode() {
+ BNode bnode = getValueFactory().createBNode();
+ return (RDF4JBlankNode) asRDFTerm(bnode);
+ }
+
+ @Override
+ public RDF4JBlankNode createBlankNode(String name) {
+ BNode bnode = getValueFactory().createBNode(name);
+ return (RDF4JBlankNode) asRDFTerm(bnode);
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * <strong>Note:</strong> Some operations on the {@link RDF4JDataset}
+ * requires the use of try-with-resources to close underlying
+ * {@link RepositoryConnection}s, including {@link RDF4JDataset#iterate()},
+ * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}.
+ *
+ */
+ @Override
+ public RDF4JDataset createDataset() {
+ Sail sail = new MemoryStore();
+ Repository repository = new SailRepository(sail);
+ return rdf4j.createRepositoryDatasetImpl(repository, true, false);
+ }
+
+ @Override
+ public RDF4JGraph createGraph() {
+ return asGraph(new LinkedHashModel());
+ }
+
+ @Override
+ public RDF4JIRI createIRI(String iri) throws IllegalArgumentException {
+ return (RDF4JIRI) asRDFTerm(getValueFactory().createIRI(iri));
+ }
+
+ @Override
+ public RDF4JLiteral createLiteral(String lexicalForm) throws IllegalArgumentException {
+ org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm);
+ return (RDF4JLiteral) asRDFTerm(lit);
+ }
+
+ @Override
+ public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, org.apache.commons.rdf.api.IRI dataType)
+ throws IllegalArgumentException {
+ org.eclipse.rdf4j.model.IRI iri = getValueFactory().createIRI(dataType.getIRIString());
+ org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, iri);
+ return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit);
+ }
+
+ @Override
+ public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, String languageTag)
+ throws IllegalArgumentException {
+ org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, languageTag);
+ return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit);
+ }
+
+ @Override
+ public RDF4JTriple createTriple(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object)
+ throws IllegalArgumentException {
+ final Statement statement = getValueFactory().createStatement(
+ (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate),
+ asValue(object));
+ return asTriple(statement);
+ }
+
+ @Override
+ public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate,
+ RDFTerm object) throws IllegalArgumentException {
+ final Statement statement = getValueFactory().createStatement(
+ (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate),
+ asValue(object), (org.eclipse.rdf4j.model.Resource) asValue(graphName));
+ return asQuad(statement);
+ }
+
+ public ValueFactory getValueFactory() {
+ return valueFactory;
+ }
+
+ private EnumSet<Option> optionSet(Option... options) {
+ EnumSet<Option> opts = EnumSet.noneOf(Option.class);
+ opts.addAll(Arrays.asList(options));
+ return opts;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java
index 15ca381..14099e0 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java
@@ -21,17 +21,17 @@ import org.apache.commons.rdf.api.BlankNode;
import org.eclipse.rdf4j.model.BNode;
/**
- * Marker interface for RDF4J implementations of
- * Commons RDF {@link org.apache.commons.rdf.api.BlankNode}.
+ * Marker interface for RDF4J implementations of Commons RDF
+ * {@link org.apache.commons.rdf.api.BlankNode}.
* <p>
- * The underlying RDF4J {@link BNode} instance can
- * be retrieved with {@link #asValue()}.
+ * The underlying RDF4J {@link BNode} instance can be retrieved with
+ * {@link #asValue()}.
*
- * @see RDF4J#createBlankNode()
+ * @see RDF4J#createBlankNode()
*/
public interface RDF4JBlankNode extends RDF4JBlankNodeOrIRI, BlankNode {
-
- @Override
- public BNode asValue();
-
+
+ @Override
+ public BNode asValue();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNodeOrIRI.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNodeOrIRI.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNodeOrIRI.java
index 75b5a32..dd7259e 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNodeOrIRI.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNodeOrIRI.java
@@ -31,7 +31,7 @@ import org.eclipse.rdf4j.model.Resource;
*/
public interface RDF4JBlankNodeOrIRI extends RDF4JTerm, BlankNodeOrIRI {
- @Override
- public Resource asValue();
-
+ @Override
+ public Resource asValue();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
index 7b5cbaa..5740f44 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
@@ -27,7 +27,6 @@ import org.apache.commons.rdf.api.Quad;
import org.apache.commons.rdf.api.RDFTerm;
import org.apache.commons.rdf.rdf4j.RDF4J.Option;
-
/**
* Marker interface for RDF4J implementations of Dataset.
*
@@ -35,106 +34,109 @@ import org.apache.commons.rdf.rdf4j.RDF4J.Option;
* @see RDF4J#asDataset(org.eclipse.rdf4j.repository.Repository, Option...)
*/
public interface RDF4JDataset extends Dataset, RDF4JGraphLike<Quad> {
-
- /**
- * {@inheritDoc}
- * <p>
- * Note that for datasets backed by a repository ({@link #asRepository()} is
- * present), the stream <strong>must be closed</strong> with
- * {@link Stream#close()}.
- * <p>
- * This can generally achieved using a try-with-resources block, e.g.:
- * <pre>
- * int subjects;
- * try (Stream<RDF4JQuad> s : graph.stream()) {
- * subjects = s.map(RDF4JQuad::getSubject).distinct().count()
- * }
- * </pre>
- */
- @Override
- Stream<RDF4JQuad> stream();
-
- /**
- * {@inheritDoc}
- * <p>
- * Note that for datasets backed by a repository ({@link #asRepository()} is
- * present), the stream <strong>must be closed</strong> with
- * {@link Stream#close()}.
- * <p>
- * This can generally achieved using a try-with-resources block, e.g.:
- * <pre>
- * int subjects;
- * try (Stream<RDF4JQuad> s : graph.stream()) {
- * subjects = s.map(RDF4JQuad::getSubject).distinct().count()
- * }
- * </pre>
- */
- @Override
- Stream<RDF4JQuad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object);
- /**
- * {@inheritDoc}
- * <p>
- * Note that for datasets backed by a repository ({@link #asRepository()} is
- * present), the stream <strong>must be closed</strong> with
- * {@link Stream#close()}.
- * <p>
- * This can generally achieved using a try-with-resources block, e.g.:
- * <pre>
- * int graphs;
- * try (Stream<BlankNodeOrIRI> s : graph.stream()) {
- * graphs = s.count()
- * }
- * </pre>
- */
- @Override
- Stream<BlankNodeOrIRI> getGraphNames();
-
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Note that for datasets backed by a repository ({@link #asRepository()} is
+ * present), the stream <strong>must be closed</strong> with
+ * {@link Stream#close()}.
+ * <p>
+ * This can generally achieved using a try-with-resources block, e.g.:
+ *
+ * <pre>
+ * int subjects;
+ * try (Stream<RDF4JQuad> s : graph.stream()) {
+ * subjects = s.map(RDF4JQuad::getSubject).distinct().count()
+ * }
+ * </pre>
+ */
+ @Override
+ Stream<RDF4JQuad> stream();
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Note that for datasets backed by a repository ({@link #asRepository()} is
+ * present), the stream <strong>must be closed</strong> with
+ * {@link Stream#close()}.
+ * <p>
+ * This can generally achieved using a try-with-resources block, e.g.:
+ *
+ * <pre>
+ * int subjects;
+ * try (Stream<RDF4JQuad> s : graph.stream()) {
+ * subjects = s.map(RDF4JQuad::getSubject).distinct().count()
+ * }
+ * </pre>
+ */
+ @Override
+ Stream<RDF4JQuad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
- /**
- * {@inheritDoc}
- * <p>
- * Note that for datasets backed by a repository ({@link #asRepository()} is
- * present), the iterable <strong>must be closed</strong> with
- * {@link ClosableIterable#close()}.
- * <p>
- * This can generally achieved using a try-with-resources block, e.g.:
- * <pre>
- * try (ClosableIterable<Quad> s : graph.iterate()) {
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Note that for datasets backed by a repository ({@link #asRepository()} is
+ * present), the stream <strong>must be closed</strong> with
+ * {@link Stream#close()}.
+ * <p>
+ * This can generally achieved using a try-with-resources block, e.g.:
+ *
+ * <pre>
+ * int graphs;
+ * try (Stream<BlankNodeOrIRI> s : graph.stream()) {
+ * graphs = s.count()
+ * }
+ * </pre>
+ */
+ @Override
+ Stream<BlankNodeOrIRI> getGraphNames();
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Note that for datasets backed by a repository ({@link #asRepository()} is
+ * present), the iterable <strong>must be closed</strong> with
+ * {@link ClosableIterable#close()}.
+ * <p>
+ * This can generally achieved using a try-with-resources block, e.g.:
+ *
+ * <pre>
+ * try (ClosableIterable<Quad> s : graph.iterate()) {
* for (Quad q : quads) {
* return q; // OK to terminate for-loop early
* }
- * }
- * </pre>
- * If you don't use a try-with-resources block, the iterator will
- * attempt to close the ClosableIterable
- * when reaching the end of the iteration.
- */
- @Override
- ClosableIterable<Quad> iterate();
-
+ * }
+ * </pre>
+ *
+ * If you don't use a try-with-resources block, the iterator will attempt to
+ * close the ClosableIterable when reaching the end of the iteration.
+ */
+ @Override
+ ClosableIterable<Quad> iterate();
- /**
- * {@inheritDoc}
- * <p>
- * Note that for datasets backed by a repository ({@link #asRepository()} is
- * present), the iterable <strong>must be closed</strong> with
- * {@link ClosableIterable#close()}.
- * <p>
- * This can generally achieved using a try-with-resources block, e.g.:
- * <pre>
- * try (ClosableIterable<Quad> s : graph.iterate(g,s,p,o)) {
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Note that for datasets backed by a repository ({@link #asRepository()} is
+ * present), the iterable <strong>must be closed</strong> with
+ * {@link ClosableIterable#close()}.
+ * <p>
+ * This can generally achieved using a try-with-resources block, e.g.:
+ *
+ * <pre>
+ * try (ClosableIterable<Quad> s : graph.iterate(g,s,p,o)) {
* for (Quad q : quads) {
* return q; // OK to terminate for-loop early
* }
- * }
- * </pre>
- * If you don't use a try-with-resources block, the iterator will
- * attempt to close the ClosableIterable
- * when reaching the end of the iteration.
- */
- @Override
- ClosableIterable<Quad> iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
+ * }
+ * </pre>
+ *
+ * If you don't use a try-with-resources block, the iterator will attempt to
+ * close the ClosableIterable when reaching the end of the iteration.
+ */
+ @Override
+ ClosableIterable<Quad> iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object);
+
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
index 65cdf67..ab52310 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
@@ -30,7 +30,6 @@ import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.repository.Repository;
import org.apache.commons.rdf.rdf4j.RDF4J.Option;
-
/**
* Marker interface for RDF4J implementations of Graph.
*
@@ -42,115 +41,117 @@ import org.apache.commons.rdf.rdf4j.RDF4J.Option;
* @see RDF4JDataset#getGraph(BlankNodeOrIRI)
*/
public interface RDF4JGraph extends Graph, RDF4JGraphLike<Triple> {
-
- /**
- * Return a copy of the context mask as a {@link Set} of
- * {@link RDF4JBlankNodeOrIRI} graph names.
- * <p>
- * If the set is not {@link Set#isEmpty()}, the mask determines which
- * <em>contexts</em> in the corresponding RDF4J {@link Model} or
- * {@link Repository} that this graph reflect. Modifications to the graph
- * (e.g. {@link #add(Triple)} will be performed for all the specified
- * contexts, while retrieval (e.g. {@link #contains(Triple)}) will succeed
- * if the triple is in at least one of the specified contexts.
- * <p>
- * The context mask array may contain <code>null</code>, indicating the
- * default context (the <em>default graph</em> in RDF datasets).
- * <p>
- * If the context mask is {@link Set#isEmpty()}, then this is a <em>union
- * graph</em> which triples reflect statements in any contexts. Triples
- * added to the graph will be added in the default context, e.g. equivalent
- * to <code>new Resource[1]{null}</code>) in RDF4J.
- * <p>
- * Note that the context mask itself cannot be <code>null</code>.
- * <p>
- * The returned set is an immutable copy; to specify a different mask, use
- * {@link RDF4J#asGraph(Repository, Set, Option...)}
- *
- * @return The context mask as a set of {@link BlankNodeOrIRI} graph names, which
- * may contain the value <code>null</code>.
- */
- public Set<RDF4JBlankNodeOrIRI> getContextMask();
-
- /**
- * {@inheritDoc}
- * <p>
- * Note that for graphs backed by a repository ({@link #asRepository()} is
- * present), the stream <strong>must be closed</strong> with
- * {@link Stream#close()}.
- * <p>
- * This can generally achieved using a try-with-resources block, e.g.:
- *
- * <pre>
- * int subjects;
- * try (Stream<RDF4JTriple> s : graph.stream()) {
- * subjects = s.map(RDF4JTriple::getSubject).distinct().count()
- * }
- * </pre>
- */
- @Override
- Stream<RDF4JTriple> stream();
- /**
- * {@inheritDoc}
- * <p>
- * Note that for graphs backed by a repository ({@link #asRepository()} is
- * present), the stream <strong>must be closed</strong> with
- * {@link Stream#close()}.
- * <p>
- * This can generally achieved using a try-with-resources block, e.g.:
- * <pre>
- * int subjects;
- * try (Stream<RDF4JTriple> s : graph.stream(s,p,o)) {
- * subjects = s.map(RDF4JTriple::getSubject).distinct().count()
- * }
- * </pre>
- */
- @Override
- Stream<RDF4JTriple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
-
-
- /**
- * {@inheritDoc}
- * <p>
- * Note that for graphs backed by a repository ({@link #asRepository()} is
- * present), the iterable <strong>must be closed</strong> with
- * {@link ClosableIterable#close()}.
- * <p>
- * This can generally achieved using a try-with-resources block, e.g.:
- * <pre>
- * try (ClosableIterable<Triple> s : graph.iterate()) {
+ /**
+ * Return a copy of the context mask as a {@link Set} of
+ * {@link RDF4JBlankNodeOrIRI} graph names.
+ * <p>
+ * If the set is not {@link Set#isEmpty()}, the mask determines which
+ * <em>contexts</em> in the corresponding RDF4J {@link Model} or
+ * {@link Repository} that this graph reflect. Modifications to the graph
+ * (e.g. {@link #add(Triple)} will be performed for all the specified
+ * contexts, while retrieval (e.g. {@link #contains(Triple)}) will succeed
+ * if the triple is in at least one of the specified contexts.
+ * <p>
+ * The context mask array may contain <code>null</code>, indicating the
+ * default context (the <em>default graph</em> in RDF datasets).
+ * <p>
+ * If the context mask is {@link Set#isEmpty()}, then this is a <em>union
+ * graph</em> which triples reflect statements in any contexts. Triples
+ * added to the graph will be added in the default context, e.g. equivalent
+ * to <code>new Resource[1]{null}</code>) in RDF4J.
+ * <p>
+ * Note that the context mask itself cannot be <code>null</code>.
+ * <p>
+ * The returned set is an immutable copy; to specify a different mask, use
+ * {@link RDF4J#asGraph(Repository, Set, Option...)}
+ *
+ * @return The context mask as a set of {@link BlankNodeOrIRI} graph names,
+ * which may contain the value <code>null</code>.
+ */
+ public Set<RDF4JBlankNodeOrIRI> getContextMask();
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Note that for graphs backed by a repository ({@link #asRepository()} is
+ * present), the stream <strong>must be closed</strong> with
+ * {@link Stream#close()}.
+ * <p>
+ * This can generally achieved using a try-with-resources block, e.g.:
+ *
+ * <pre>
+ * int subjects;
+ * try (Stream<RDF4JTriple> s : graph.stream()) {
+ * subjects = s.map(RDF4JTriple::getSubject).distinct().count()
+ * }
+ * </pre>
+ */
+ @Override
+ Stream<RDF4JTriple> stream();
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Note that for graphs backed by a repository ({@link #asRepository()} is
+ * present), the stream <strong>must be closed</strong> with
+ * {@link Stream#close()}.
+ * <p>
+ * This can generally achieved using a try-with-resources block, e.g.:
+ *
+ * <pre>
+ * int subjects;
+ * try (Stream<RDF4JTriple> s : graph.stream(s,p,o)) {
+ * subjects = s.map(RDF4JTriple::getSubject).distinct().count()
+ * }
+ * </pre>
+ */
+ @Override
+ Stream<RDF4JTriple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Note that for graphs backed by a repository ({@link #asRepository()} is
+ * present), the iterable <strong>must be closed</strong> with
+ * {@link ClosableIterable#close()}.
+ * <p>
+ * This can generally achieved using a try-with-resources block, e.g.:
+ *
+ * <pre>
+ * try (ClosableIterable<Triple> s : graph.iterate()) {
* for (Triple t : triples) {
* return t; // OK to terminate for-loop early
* }
- * }
- * </pre>
- * If you don't use a try-with-resources block, the iterator will
- * attempt to close the ClosableIterable
- * when reaching the end of the iteration.
- */
- @Override
- ClosableIterable<Triple> iterate() throws ConcurrentModificationException, IllegalStateException;
+ * }
+ * </pre>
+ *
+ * If you don't use a try-with-resources block, the iterator will attempt to
+ * close the ClosableIterable when reaching the end of the iteration.
+ */
+ @Override
+ ClosableIterable<Triple> iterate() throws ConcurrentModificationException, IllegalStateException;
- /**
- * {@inheritDoc}
- * <p>
- * Note that for graphs backed by a repository ({@link #asRepository()} is
- * present), the iterable <strong>must be closed</strong> with
- * {@link ClosableIterable#close()}.
- * <p>
- * This can generally achieved using a try-with-resources block, e.g.:
- * <pre>
- * try (ClosableIterable<Triple> s : graph.iterate(s,p,o)) {
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Note that for graphs backed by a repository ({@link #asRepository()} is
+ * present), the iterable <strong>must be closed</strong> with
+ * {@link ClosableIterable#close()}.
+ * <p>
+ * This can generally achieved using a try-with-resources block, e.g.:
+ *
+ * <pre>
+ * try (ClosableIterable<Triple> s : graph.iterate(s,p,o)) {
* for (Triple t : triples) {
* return t; // OK to terminate for-loop early
* }
- * }
- * </pre>
- * If you don't use a try-with-resources block, the iterator will
- * attempt to close the ClosableIterable
- * when reaching the end of the iteration.
- */
- @Override
- ClosableIterable<Triple> iterate(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+ * }
+ * </pre>
+ *
+ * If you don't use a try-with-resources block, the iterator will attempt to
+ * close the ClosableIterable when reaching the end of the iteration.
+ */
+ @Override
+ ClosableIterable<Triple> iterate(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraphLike.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraphLike.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraphLike.java
index 430369a..4b69bee 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraphLike.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraphLike.java
@@ -37,31 +37,30 @@ import org.eclipse.rdf4j.repository.Repository;
* @see RDF4JDataset
* @see RDF4JGraph
*/
-public interface RDF4JGraphLike<T extends TripleLike>
- extends GraphLike<T>, AutoCloseable {
+public interface RDF4JGraphLike<T extends TripleLike> extends GraphLike<T>, AutoCloseable {
- /**
- * Return the corresponding RDF4J {@link Model}, if present.
- * <p>
- * The return value is {@link Optional#isPresent()} if this is backed by a
- * Model.
- * <p>
- * Changes to the Model are reflected in both directions.
- *
- * @return The corresponding RDF4J Model.
- */
- public Optional<Model> asModel();
+ /**
+ * Return the corresponding RDF4J {@link Model}, if present.
+ * <p>
+ * The return value is {@link Optional#isPresent()} if this is backed by a
+ * Model.
+ * <p>
+ * Changes to the Model are reflected in both directions.
+ *
+ * @return The corresponding RDF4J Model.
+ */
+ public Optional<Model> asModel();
- /**
- * Return the corresponding RDF4J {@link Repository}, if present.
- * <p>
- * The return value is {@link Optional#isPresent()} if this is backed by a
- * Repository.
- * <p>
- * Changes to the Repository are reflected in both directions.
- *
- * @return The corresponding RDF4J Repository.
- */
- public Optional<Repository> asRepository();
+ /**
+ * Return the corresponding RDF4J {@link Repository}, if present.
+ * <p>
+ * The return value is {@link Optional#isPresent()} if this is backed by a
+ * Repository.
+ * <p>
+ * Changes to the Repository are reflected in both directions.
+ *
+ * @return The corresponding RDF4J Repository.
+ */
+ public Optional<Repository> asRepository();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java
index 72c83fa..642ed58 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java
@@ -18,18 +18,17 @@
package org.apache.commons.rdf.rdf4j;
/**
- * Marker interface for RDF4J implementations of
- * Commons RDF {@link org.apache.commons.rdf.api.IRI}.
+ * Marker interface for RDF4J implementations of Commons RDF
+ * {@link org.apache.commons.rdf.api.IRI}.
* <p>
- * The underlying RDF4J {@link org.eclipse.rdf4j.model.IRI}
- * instance can be retrieved with {@link #asValue()}.
+ * The underlying RDF4J {@link org.eclipse.rdf4j.model.IRI} instance can be
+ * retrieved with {@link #asValue()}.
*
* @see RDF4J#createIRI(String)
*/
-public interface RDF4JIRI
- extends RDF4JBlankNodeOrIRI, org.apache.commons.rdf.api.IRI {
-
- @Override
- org.eclipse.rdf4j.model.IRI asValue();
-
+public interface RDF4JIRI extends RDF4JBlankNodeOrIRI, org.apache.commons.rdf.api.IRI {
+
+ @Override
+ org.eclipse.rdf4j.model.IRI asValue();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java
index 23b6cdf..7fedfde 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java
@@ -22,8 +22,10 @@ import org.apache.commons.rdf.api.Quad;
/**
* Marker interface for RDF4J implementations of Quad.
*
- * @see RDF4J#createQuad(org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.IRI, org.apache.commons.rdf.api.RDFTerm)
+ * @see RDF4J#createQuad(org.apache.commons.rdf.api.BlankNodeOrIRI,
+ * org.apache.commons.rdf.api.BlankNodeOrIRI,
+ * org.apache.commons.rdf.api.IRI, org.apache.commons.rdf.api.RDFTerm)
*/
public interface RDF4JQuad extends Quad, RDF4JTripleLike {
-
+
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTerm.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTerm.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTerm.java
index e500651..1f7b841 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTerm.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTerm.java
@@ -25,14 +25,15 @@ import org.eclipse.rdf4j.model.Value;
/**
* Marker interface for RDF4J implementations of RDFTerm.
- *
+ *
*/
public interface RDF4JTerm extends RDFTerm {
-
- /**
- * Return the RDF4J {@link Value} that this RDFTerm represents.
- *
- * @return The wrapped {@link Value} (e.g. a {@link Literal}, {@link IRI} or {@link BNode}.
- */
- public Value asValue();
+
+ /**
+ * Return the RDF4J {@link Value} that this RDFTerm represents.
+ *
+ * @return The wrapped {@link Value} (e.g. a {@link Literal}, {@link IRI} or
+ * {@link BNode}.
+ */
+ public Value asValue();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java
index ca32d94..55388ab 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java
@@ -22,8 +22,9 @@ import org.apache.commons.rdf.api.Triple;
/**
* Marker interface for RDF4J implementations of Triple.
*
- * @see RDF4J#createTriple(org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.IRI, org.apache.commons.rdf.api.RDFTerm)
+ * @see RDF4J#createTriple(org.apache.commons.rdf.api.BlankNodeOrIRI,
+ * org.apache.commons.rdf.api.IRI, org.apache.commons.rdf.api.RDFTerm)
*/
public interface RDF4JTriple extends Triple, RDF4JTripleLike {
-
+
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTripleLike.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTripleLike.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTripleLike.java
index e204e77..222c2c8 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTripleLike.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTripleLike.java
@@ -23,20 +23,21 @@ import org.eclipse.rdf4j.model.Statement;
/**
* Marker interface for RDF4J implementations of {@link TripleLike} statements.
* <p>
- * This interface is in common with the more specific {@link RDF4JTriple} or
+ * This interface is in common with the more specific {@link RDF4JTriple} or
* {@link RDF4JQuad}.
* <p>
- * This is backed by a {@link Statement} retrievable with {@link #asStatement()}.
+ * This is backed by a {@link Statement} retrievable with
+ * {@link #asStatement()}.
*
* @see RDF4JTriple
* @see RDF4JQuad
*/
public interface RDF4JTripleLike extends TripleLike {
-
- /**
- * Return the corresponding RDF4J {@link Statement}.
- *
- * @return The corresponding RDF4J Statement.
- */
- public Statement asStatement();
+
+ /**
+ * Return the corresponding RDF4J {@link Statement}.
+ *
+ * @return The corresponding RDF4J Statement.
+ */
+ public Statement asStatement();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
index 26b3647..87328cd 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
@@ -59,174 +59,178 @@ import org.eclipse.rdf4j.rio.helpers.AbstractRDFHandler;
*/
public class RDF4JParser extends AbstractRDFParser<RDF4JParser> implements RDFParser {
- private final class AddToQuadConsumer extends AbstractRDFHandler {
- private final Consumer<Quad> quadTarget;
-
- private AddToQuadConsumer(Consumer<Quad> quadTarget) {
- this.quadTarget = quadTarget;
- }
-
- public void handleStatement(org.eclipse.rdf4j.model.Statement st)
- throws org.eclipse.rdf4j.rio.RDFHandlerException {
- // TODO: if getRdfTermFactory() is a non-rdf4j factory, should
- // we use factory.createQuad() instead?
- // Unsure what is the promise of setting getRdfTermFactory() --
- // does it go all the way down to creating BlankNode, IRI and
- // Literal?
- quadTarget.accept(rdf4jTermFactory.asQuad(st));
- // Performance note:
- // Graph/Quad.add should pick up again our
- // RDF4JGraphLike.asStatement()
- // and avoid double conversion.
- // Additionally the RDF4JQuad and RDF4JTriple implementations
- // are lazily converting subj/obj/pred/graph.s
- }
- }
-
- private final static class AddToModel extends AbstractRDFHandler {
- private final Model model;
-
- public AddToModel(Model model) {
- this.model = model;
- }
-
- public void handleStatement(org.eclipse.rdf4j.model.Statement st)
- throws org.eclipse.rdf4j.rio.RDFHandlerException {
- model.add(st);
- }
-
- @Override
- public void handleNamespace(String prefix, String uri) throws RDFHandlerException {
- model.setNamespace(prefix, uri);
- }
- }
-
- private RDF4J rdf4jTermFactory;
- private ParserConfig parserConfig = new ParserConfig();
-
- @Override
- protected RDF4J createRDFTermFactory() {
- return new RDF4J();
- }
-
- @Override
- protected RDF4JParser prepareForParsing() throws IOException, IllegalStateException {
- RDF4JParser c = super.prepareForParsing();
- // Ensure we have an RDF4J for conversion.
- // We'll make a new one if user has provided a non-RDF4J factory
- c.rdf4jTermFactory = (RDF4J) getRdfTermFactory().filter(RDF4J.class::isInstance)
- .orElseGet(c::createRDFTermFactory);
- return c;
- }
-
- @Override
- protected void parseSynchronusly() throws IOException {
- Optional<RDFFormat> formatByMimeType = getContentType().flatMap(Rio::getParserFormatForMIMEType);
- String base = getBase().map(IRI::getIRIString).orElse(null);
-
- ParserConfig parserConfig = getParserConfig();
- // TODO: Should we need to set anything?
- RDFLoader loader = new RDFLoader(parserConfig, rdf4jTermFactory.getValueFactory());
- RDFHandler rdfHandler = makeRDFHandler();
- if (getSourceFile().isPresent()) {
- // NOTE: While we could have used
- // loader.load(sourcePath.toFile()
- // if the path fs provider == FileSystems.getDefault(),
- // that RDFLoader method does not use absolute path
- // as the base URI, so to be consistent
- // we'll always do it with our own input stream
- //
- // That means we may have to guess format by extensions:
- Optional<RDFFormat> formatByFilename = getSourceFile().map(Path::getFileName).map(Path::toString)
- .flatMap(Rio::getParserFormatForFileName);
- // TODO: for the excited.. what about the extension after following symlinks?
-
- RDFFormat format = formatByMimeType.orElse(formatByFilename.orElse(null));
- try (InputStream in = Files.newInputStream(getSourceFile().get())) {
- loader.load(in, base, format, rdfHandler);
- }
- } else if (getSourceIri().isPresent()) {
- try {
- // TODO: Handle international IRIs properly
- // (Unicode support for for hostname, path and query)
- URL url = new URL(getSourceIri().get().getIRIString());
- // TODO: This probably does not support https:// -> http:// redirections
- loader.load(url, base, formatByMimeType.orElse(null), makeRDFHandler());
- } catch (MalformedURLException ex) {
- throw new IOException("Can't handle source URL: " + getSourceIri().get(), ex);
- }
- }
- // must be getSourceInputStream then, this is guaranteed by super.checkSource();
- loader.load(getSourceInputStream().get(), base, formatByMimeType.orElse(null), rdfHandler);
- }
-
- /**
- * Get the RDF4J {@link ParserConfig} to use.
- * <p>
- * If no parser config is set, the default configuration is provided.
- * <p>
- * <strong>Note:</strong> The parser config is mutable - changes in the
- * returned config is reflected in this instance of the parser.
- * To avoid mutation, create a new {@link ParserConfig} and set
- * {@link #setParserConfig(ParserConfig)}.
- *
- * @return The RDF4J {@link ParserConfig}
- */
- public ParserConfig getParserConfig() {
- return parserConfig;
- }
-
- /**
- * Set an RDF4J {@link ParserConfig} to use
- *
- * @param parserConfig Parser configuration
- */
- public void setParserConfig(ParserConfig parserConfig) {
- this.parserConfig = parserConfig;
- }
-
- protected RDFHandler makeRDFHandler() {
-
- // TODO: Can we join the below DF4JDataset and RDF4JGraph cases
- // using RDF4JGraphLike<TripleLike<BlankNodeOrIRI,IRI,RDFTerm>>
- // or will that need tricky generics types?
-
- if (getTargetDataset().filter(RDF4JDataset.class::isInstance).isPresent()) {
- // One of us, we can add them as Statements directly
- RDF4JDataset dataset = (RDF4JDataset) getTargetDataset().get();
- if (dataset.asRepository().isPresent()) {
- return new RDFInserter(dataset.asRepository().get().getConnection());
- }
- if (dataset.asModel().isPresent()) {
- Model model = dataset.asModel().get();
- return new AddToModel(model);
- }
- // Not backed by Repository or Model?
- // Third-party RDF4JDataset subclass, so we'll fall through to the
- // getTarget() handling further down
- } else if (getTargetGraph().filter(RDF4JGraph.class::isInstance).isPresent()) {
- RDF4JGraph graph = (RDF4JGraph) getTargetGraph().get();
-
- if (graph.asRepository().isPresent()) {
- RDFInserter inserter = new RDFInserter(graph.asRepository().get().getConnection());
- if (! graph.getContextMask().isEmpty()) {
- Stream<RDF4JBlankNodeOrIRI> b = graph.getContextMask().stream();
- Stream<Resource> c = b.map(RDF4JBlankNodeOrIRI::asValue);
- Resource[] contexts = c.toArray(Resource[]::new);
- inserter.enforceContext(contexts);
- }
- return inserter;
- }
- if (graph.asModel().isPresent() && graph.getContextMask().isEmpty()) {
- // the model accepts any quad
- Model model = graph.asModel().get();
- return new AddToModel(model);
- }
- // else - fall through
- }
-
- // Fall thorough: let target() consume our converted quads.
- return new AddToQuadConsumer(getTarget());
- }
+ private final class AddToQuadConsumer extends AbstractRDFHandler {
+ private final Consumer<Quad> quadTarget;
+
+ private AddToQuadConsumer(Consumer<Quad> quadTarget) {
+ this.quadTarget = quadTarget;
+ }
+
+ public void handleStatement(org.eclipse.rdf4j.model.Statement st)
+ throws org.eclipse.rdf4j.rio.RDFHandlerException {
+ // TODO: if getRdfTermFactory() is a non-rdf4j factory, should
+ // we use factory.createQuad() instead?
+ // Unsure what is the promise of setting getRdfTermFactory() --
+ // does it go all the way down to creating BlankNode, IRI and
+ // Literal?
+ quadTarget.accept(rdf4jTermFactory.asQuad(st));
+ // Performance note:
+ // Graph/Quad.add should pick up again our
+ // RDF4JGraphLike.asStatement()
+ // and avoid double conversion.
+ // Additionally the RDF4JQuad and RDF4JTriple implementations
+ // are lazily converting subj/obj/pred/graph.s
+ }
+ }
+
+ private final static class AddToModel extends AbstractRDFHandler {
+ private final Model model;
+
+ public AddToModel(Model model) {
+ this.model = model;
+ }
+
+ public void handleStatement(org.eclipse.rdf4j.model.Statement st)
+ throws org.eclipse.rdf4j.rio.RDFHandlerException {
+ model.add(st);
+ }
+
+ @Override
+ public void handleNamespace(String prefix, String uri) throws RDFHandlerException {
+ model.setNamespace(prefix, uri);
+ }
+ }
+
+ private RDF4J rdf4jTermFactory;
+ private ParserConfig parserConfig = new ParserConfig();
+
+ @Override
+ protected RDF4J createRDFTermFactory() {
+ return new RDF4J();
+ }
+
+ @Override
+ protected RDF4JParser prepareForParsing() throws IOException, IllegalStateException {
+ RDF4JParser c = super.prepareForParsing();
+ // Ensure we have an RDF4J for conversion.
+ // We'll make a new one if user has provided a non-RDF4J factory
+ c.rdf4jTermFactory = (RDF4J) getRdfTermFactory().filter(RDF4J.class::isInstance)
+ .orElseGet(c::createRDFTermFactory);
+ return c;
+ }
+
+ @Override
+ protected void parseSynchronusly() throws IOException {
+ Optional<RDFFormat> formatByMimeType = getContentType().flatMap(Rio::getParserFormatForMIMEType);
+ String base = getBase().map(IRI::getIRIString).orElse(null);
+
+ ParserConfig parserConfig = getParserConfig();
+ // TODO: Should we need to set anything?
+ RDFLoader loader = new RDFLoader(parserConfig, rdf4jTermFactory.getValueFactory());
+ RDFHandler rdfHandler = makeRDFHandler();
+ if (getSourceFile().isPresent()) {
+ // NOTE: While we could have used
+ // loader.load(sourcePath.toFile()
+ // if the path fs provider == FileSystems.getDefault(),
+ // that RDFLoader method does not use absolute path
+ // as the base URI, so to be consistent
+ // we'll always do it with our own input stream
+ //
+ // That means we may have to guess format by extensions:
+ Optional<RDFFormat> formatByFilename = getSourceFile().map(Path::getFileName).map(Path::toString)
+ .flatMap(Rio::getParserFormatForFileName);
+ // TODO: for the excited.. what about the extension after following
+ // symlinks?
+
+ RDFFormat format = formatByMimeType.orElse(formatByFilename.orElse(null));
+ try (InputStream in = Files.newInputStream(getSourceFile().get())) {
+ loader.load(in, base, format, rdfHandler);
+ }
+ } else if (getSourceIri().isPresent()) {
+ try {
+ // TODO: Handle international IRIs properly
+ // (Unicode support for for hostname, path and query)
+ URL url = new URL(getSourceIri().get().getIRIString());
+ // TODO: This probably does not support https:// -> http://
+ // redirections
+ loader.load(url, base, formatByMimeType.orElse(null), makeRDFHandler());
+ } catch (MalformedURLException ex) {
+ throw new IOException("Can't handle source URL: " + getSourceIri().get(), ex);
+ }
+ }
+ // must be getSourceInputStream then, this is guaranteed by
+ // super.checkSource();
+ loader.load(getSourceInputStream().get(), base, formatByMimeType.orElse(null), rdfHandler);
+ }
+
+ /**
+ * Get the RDF4J {@link ParserConfig} to use.
+ * <p>
+ * If no parser config is set, the default configuration is provided.
+ * <p>
+ * <strong>Note:</strong> The parser config is mutable - changes in the
+ * returned config is reflected in this instance of the parser. To avoid
+ * mutation, create a new {@link ParserConfig} and set
+ * {@link #setParserConfig(ParserConfig)}.
+ *
+ * @return The RDF4J {@link ParserConfig}
+ */
+ public ParserConfig getParserConfig() {
+ return parserConfig;
+ }
+
+ /**
+ * Set an RDF4J {@link ParserConfig} to use
+ *
+ * @param parserConfig
+ * Parser configuration
+ */
+ public void setParserConfig(ParserConfig parserConfig) {
+ this.parserConfig = parserConfig;
+ }
+
+ protected RDFHandler makeRDFHandler() {
+
+ // TODO: Can we join the below DF4JDataset and RDF4JGraph cases
+ // using RDF4JGraphLike<TripleLike<BlankNodeOrIRI,IRI,RDFTerm>>
+ // or will that need tricky generics types?
+
+ if (getTargetDataset().filter(RDF4JDataset.class::isInstance).isPresent()) {
+ // One of us, we can add them as Statements directly
+ RDF4JDataset dataset = (RDF4JDataset) getTargetDataset().get();
+ if (dataset.asRepository().isPresent()) {
+ return new RDFInserter(dataset.asRepository().get().getConnection());
+ }
+ if (dataset.asModel().isPresent()) {
+ Model model = dataset.asModel().get();
+ return new AddToModel(model);
+ }
+ // Not backed by Repository or Model?
+ // Third-party RDF4JDataset subclass, so we'll fall through to the
+ // getTarget() handling further down
+ } else if (getTargetGraph().filter(RDF4JGraph.class::isInstance).isPresent()) {
+ RDF4JGraph graph = (RDF4JGraph) getTargetGraph().get();
+
+ if (graph.asRepository().isPresent()) {
+ RDFInserter inserter = new RDFInserter(graph.asRepository().get().getConnection());
+ if (!graph.getContextMask().isEmpty()) {
+ Stream<RDF4JBlankNodeOrIRI> b = graph.getContextMask().stream();
+ Stream<Resource> c = b.map(RDF4JBlankNodeOrIRI::asValue);
+ Resource[] contexts = c.toArray(Resource[]::new);
+ inserter.enforceContext(contexts);
+ }
+ return inserter;
+ }
+ if (graph.asModel().isPresent() && graph.getContextMask().isEmpty()) {
+ // the model accepts any quad
+ Model model = graph.asModel().get();
+ return new AddToModel(model);
+ }
+ // else - fall through
+ }
+
+ // Fall thorough: let target() consume our converted quads.
+ return new AddToQuadConsumer(getTarget());
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/package-info.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/package-info.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/package-info.java
index 217d003..4f5b070 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/package-info.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/package-info.java
@@ -18,15 +18,13 @@
/**
* Experimental Commons RDF RDF4J implementations.
* <p>
- * Classes in this package should be considered <strong>at
- * risk</strong>; they might change or be removed in the next minor update of
- * Commons RDF.
+ * Classes in this package should be considered <strong>at risk</strong>; they
+ * might change or be removed in the next minor update of Commons RDF.
* <p>
* When a class has stabilized, it will move to the
* {@link org.apache.commons.rdf.rdf4j} package.
* <ul>
- * <li>{@link RDF4JParser} - an RDF4J-backed
- * implementations of
+ * <li>{@link RDF4JParser} - an RDF4J-backed implementations of
* {@link org.apache.commons.rdf.experimental.RDFParser}.</li>
* </ul>
*/
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRDFTerm.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRDFTerm.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRDFTerm.java
index b54c715..7fce346 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRDFTerm.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRDFTerm.java
@@ -21,13 +21,13 @@ import org.apache.commons.rdf.rdf4j.RDF4JTerm;
import org.eclipse.rdf4j.model.Value;
abstract class AbstractRDFTerm<T extends Value> implements RDF4JTerm {
- T value;
+ T value;
- AbstractRDFTerm(T value) {
- this.value = value;
- }
-
- public T asValue() {
- return value;
- }
+ AbstractRDFTerm(T value) {
+ this.value = value;
+ }
+
+ public T asValue() {
+ return value;
+ }
}
\ No newline at end of file
[24/50] [abbrv] incubator-commonsrdf git commit: Travis Travis..
Posted by st...@apache.org.
Travis Travis..
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/96ca8ac2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/96ca8ac2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/96ca8ac2
Branch: refs/heads/COMMONSRDF-7
Commit: 96ca8ac2ef28fec96360079b877c9e6a6d124b95
Parents: 13e692c
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 14:01:07 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 14:01:07 2016 +0100
----------------------------------------------------------------------
.travis.yml | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/96ca8ac2/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index 283b9c3..9262dcf 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,8 +4,15 @@ sudo: required
dist: trusty
language: java
-jdk:
- - oraclejdk8
+
+# Workaround for travis-ci/travis-ci#4042
+addons:
+ apt:
+ packages:
+ - oracle-java8-installer
+#jdk:
+# - oraclejdk8
+
cache:
directories:
[39/50] [abbrv] incubator-commonsrdf git commit: Reformat tab ->
spaces
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
index 7e43068..35a7071 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
@@ -40,125 +40,135 @@ import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.Timeout;
-
/**
* Test a graph within a file-based RDF4J {@link SailRepository}.
* <p>
- * TIP: If the {@link #shutdownAndDelete()} take about 20 seconds
- * this is a hint that a {@link RepositoryConnection} or
- * {@link RepositoryResult} was not closed correctly.
+ * TIP: If the {@link #shutdownAndDelete()} take about 20 seconds this is a hint
+ * that a {@link RepositoryConnection} or {@link RepositoryResult} was not
+ * closed correctly.
*
*/
public class NativeStoreGraphTest extends AbstractGraphTest {
- public final class NativeStoreRDF implements RDF {
-
- RDF4J rdf4jFactory = new RDF4J(getRepository().getValueFactory());
-
- @Override
- public RDF4JGraph createGraph() {
- // We re-use the repository connection, but use a different context every time
- Set<RDF4JBlankNode> context = Collections.singleton(rdf4jFactory.createBlankNode());
- return rdf4jFactory.asGraph(getRepository(), context);
- }
- @Override
- public Dataset createDataset() {
- throw new UnsupportedOperationException("Can't create more than one Dataset in this test");
- // ...as the below would re-use the same repository:
- //return rdf4jFactory.asRDFTermDataset(getRepository());
- }
-
- // Delegate methods
- public RDF4JBlankNode createBlankNode() {
- return rdf4jFactory.createBlankNode();
- }
- public RDF4JBlankNode createBlankNode(String name) {
- return rdf4jFactory.createBlankNode(name);
- }
- public RDF4JIRI createIRI(String iri) throws IllegalArgumentException, UnsupportedOperationException {
- return rdf4jFactory.createIRI(iri);
- }
- public RDF4JLiteral createLiteral(String lexicalForm) {
- return rdf4jFactory.createLiteral(lexicalForm);
- }
- public Literal createLiteral(String lexicalForm, IRI dataType) {
- return rdf4jFactory.createLiteral(lexicalForm, dataType);
- }
- public Literal createLiteral(String lexicalForm, String languageTag) {
- return rdf4jFactory.createLiteral(lexicalForm, languageTag);
- }
- public RDF4JTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return rdf4jFactory.createTriple(subject, predicate, object);
- }
- public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
- throws IllegalArgumentException {
- return rdf4jFactory.createQuad(graphName, subject, predicate, object);
- }
- }
-
-
- @Rule
- public TemporaryFolder tempDir = new TemporaryFolder();
-
- private SailRepository repository;
-
- public void createRepository() throws IOException {
- Sail sail = new NativeStore(tempDir.newFolder());
- repository = new SailRepository(sail);
- repository.initialize();
- }
-
- public synchronized SailRepository getRepository() {
- if (repository == null) {
- try {
- createRepository();
- } catch (IOException e) {
- throw new UncheckedIOException(e);
- }
- }
- return repository;
- }
-
- @Rule
- /**
- * A timeout of more than 15 seconds pr test indicates typically that
- * shutdownAndDelete failed.
- */
- public Timeout globalTimeout = Timeout.seconds(15);
-
- @After
- public void shutdownAndDelete() throws IOException {
- // must shutdown before we delete
- if (repository != null) {
- System.out.print("Shutting down rdf4j repository " + repository + "...");
- // NOTE:
- // If this takes about 20 seconds it means the code forgot to close a
- // RepositoryConnection or RespositoryResult
- // e.g. missing a try-with-resources block
- repository.shutDown();
- System.out.println("OK");
- }
- }
-
-// private static void deleteAll(Path dir) throws IOException {
-// Files.walkFileTree(dir, new SimpleFileVisitor<Path>(){
-// @Override
-// public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
-// Files.delete(file);
-// return FileVisitResult.CONTINUE;
-// }
-// @Override
-// public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
-// FileVisitResult r = super.postVisitDirectory(dir, exc);
-// Files.delete(dir);
-// return r;
-// }
-// });
-// }
-
- @Override
- public RDF createFactory() {
- return new NativeStoreRDF();
- }
+ public final class NativeStoreRDF implements RDF {
+
+ RDF4J rdf4jFactory = new RDF4J(getRepository().getValueFactory());
+
+ @Override
+ public RDF4JGraph createGraph() {
+ // We re-use the repository connection, but use a different context
+ // every time
+ Set<RDF4JBlankNode> context = Collections.singleton(rdf4jFactory.createBlankNode());
+ return rdf4jFactory.asGraph(getRepository(), context);
+ }
+
+ @Override
+ public Dataset createDataset() {
+ throw new UnsupportedOperationException("Can't create more than one Dataset in this test");
+ // ...as the below would re-use the same repository:
+ // return rdf4jFactory.asRDFTermDataset(getRepository());
+ }
+
+ // Delegate methods
+ public RDF4JBlankNode createBlankNode() {
+ return rdf4jFactory.createBlankNode();
+ }
+
+ public RDF4JBlankNode createBlankNode(String name) {
+ return rdf4jFactory.createBlankNode(name);
+ }
+
+ public RDF4JIRI createIRI(String iri) throws IllegalArgumentException, UnsupportedOperationException {
+ return rdf4jFactory.createIRI(iri);
+ }
+
+ public RDF4JLiteral createLiteral(String lexicalForm) {
+ return rdf4jFactory.createLiteral(lexicalForm);
+ }
+
+ public Literal createLiteral(String lexicalForm, IRI dataType) {
+ return rdf4jFactory.createLiteral(lexicalForm, dataType);
+ }
+
+ public Literal createLiteral(String lexicalForm, String languageTag) {
+ return rdf4jFactory.createLiteral(lexicalForm, languageTag);
+ }
+
+ public RDF4JTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return rdf4jFactory.createTriple(subject, predicate, object);
+ }
+
+ public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws IllegalArgumentException {
+ return rdf4jFactory.createQuad(graphName, subject, predicate, object);
+ }
+ }
+
+ @Rule
+ public TemporaryFolder tempDir = new TemporaryFolder();
+
+ private SailRepository repository;
+
+ public void createRepository() throws IOException {
+ Sail sail = new NativeStore(tempDir.newFolder());
+ repository = new SailRepository(sail);
+ repository.initialize();
+ }
+
+ public synchronized SailRepository getRepository() {
+ if (repository == null) {
+ try {
+ createRepository();
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+ return repository;
+ }
+
+ @Rule
+ /**
+ * A timeout of more than 15 seconds pr test indicates typically that
+ * shutdownAndDelete failed.
+ */
+ public Timeout globalTimeout = Timeout.seconds(15);
+
+ @After
+ public void shutdownAndDelete() throws IOException {
+ // must shutdown before we delete
+ if (repository != null) {
+ System.out.print("Shutting down rdf4j repository " + repository + "...");
+ // NOTE:
+ // If this takes about 20 seconds it means the code forgot to close
+ // a
+ // RepositoryConnection or RespositoryResult
+ // e.g. missing a try-with-resources block
+ repository.shutDown();
+ System.out.println("OK");
+ }
+ }
+
+ // private static void deleteAll(Path dir) throws IOException {
+ // Files.walkFileTree(dir, new SimpleFileVisitor<Path>(){
+ // @Override
+ // public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
+ // throws IOException {
+ // Files.delete(file);
+ // return FileVisitResult.CONTINUE;
+ // }
+ // @Override
+ // public FileVisitResult postVisitDirectory(Path dir, IOException exc)
+ // throws IOException {
+ // FileVisitResult r = super.postVisitDirectory(dir, exc);
+ // Files.delete(dir);
+ // return r;
+ // }
+ // });
+ // }
+
+ @Override
+ public RDF createFactory() {
+ return new NativeStoreRDF();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
index cbd85f1..fffa134 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
@@ -31,10 +31,10 @@ public class RDF4JServiceLoaderTest {
public void testServiceLoaderLookup() {
ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class);
for (RDF impl : loader) {
- if (impl instanceof RDF4J) {
- return; // yay
- }
+ if (impl instanceof RDF4J) {
+ return; // yay
+ }
}
- fail("RDF4J not found in ServiceLoader");
+ fail("RDF4J not found in ServiceLoader");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JTest.java
index c10ea9a..29674ae 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JTest.java
@@ -23,15 +23,15 @@ import org.junit.Assume;
public class RDF4JTest extends AbstractRDFTest {
- @Override
- public RDF createFactory() {
- return new RDF4J();
- }
-
- @Override
- public void testInvalidLiteralLang() throws Exception {
- Assume.assumeTrue("RDF4J doesn't check Lang strings",false);
- super.testInvalidLiteralLang();
- }
-
+ @Override
+ public RDF createFactory() {
+ return new RDF4J();
+ }
+
+ @Override
+ public void testInvalidLiteralLang() throws Exception {
+ Assume.assumeTrue("RDF4J doesn't check Lang strings", false);
+ super.testInvalidLiteralLang();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
index 4b20618..1e2dfca 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/BlankNodeImpl.java
@@ -55,7 +55,6 @@ final class BlankNodeImpl implements BlankNode, SimpleRDFTerm {
// ntriplesString() (there are no restrictions on
// RDF.createBlankNode(String) ).
-
// Rather than implement ntriples escaping here, and knowing
// our uniqueReference() contain a UUID anyway, we simply
// create another name-based UUID, and use it within both
@@ -65,8 +64,7 @@ final class BlankNodeImpl implements BlankNode, SimpleRDFTerm {
// is not preserved or shown in ntriplesString. In a way
// this is a feature, not a bug. as the contract for RDF
// has no such requirement.
- this.uniqueReference = UUID.nameUUIDFromBytes(
- uuidInput.getBytes(StandardCharsets.UTF_8)).toString();
+ this.uniqueReference = UUID.nameUUIDFromBytes(uuidInput.getBytes(StandardCharsets.UTF_8)).toString();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
index d578a40..cc6f4b4 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/DatasetGraphView.java
@@ -40,99 +40,100 @@ import org.apache.commons.rdf.api.Triple;
* {@link Quad}s of the Dataset is represented as a {@link Triple}. Adding
* triples will add them to the <em>default graph</em>, while removing triples
* will remove from all graphs.</dd>
-*
+ *
* <dt>{@link #DatasetGraphView(Dataset, BlankNodeOrIRI)}</dt>
- * <dd>Expose a particular graph of the Dataset, either named by an {@link IRI}, a
- * {@link BlankNode}, or <code>null</code> for the <em>default graph</em>.</dd>
+ * <dd>Expose a particular graph of the Dataset, either named by an {@link IRI},
+ * a {@link BlankNode}, or <code>null</code> for the <em>default
+ * graph</em>.</dd>
* </dl>
* <p>
- * Changes in the Graph are reflected directly in the Dataset and vice versa.
+ * Changes in the Graph are reflected directly in the Dataset and vice versa.
* This class is thread-safe is the underlying Dataset is thread-safe.
*/
public class DatasetGraphView implements Graph {
- private final boolean unionGraph;
- private final BlankNodeOrIRI namedGraph;
- private final Dataset dataset;
-
- public DatasetGraphView(Dataset dataset) {
- this.dataset = dataset;
- this.namedGraph = null;
- this.unionGraph = true;
- }
-
- public DatasetGraphView(Dataset dataset, BlankNodeOrIRI namedGraph) {
- this.dataset = dataset;
- this.namedGraph = namedGraph;
- this.unionGraph = false;
- }
-
- @Override
- public void close() throws Exception {
- dataset.close();
-
- }
-
- @Override
- public void add(Triple triple) {
- dataset.add(namedGraph, triple.getSubject(), triple.getPredicate(), triple.getObject());
- }
-
- @Override
- public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- dataset.add(namedGraph, subject, predicate, object);
- }
-
- @Override
- public boolean contains(Triple triple) {
- return dataset.contains(unionOrNamedGraph(), triple.getSubject(), triple.getPredicate(), triple.getObject());
- }
-
- private Optional<BlankNodeOrIRI> unionOrNamedGraph() {
- if (unionGraph) {
- return null;
- }
- return Optional.ofNullable(namedGraph);
- }
-
- @Override
- public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return dataset.contains(unionOrNamedGraph(), subject, predicate, object);
- }
-
- @Override
- public void remove(Triple triple) {
- dataset.remove(unionOrNamedGraph(), triple.getSubject(), triple.getPredicate(), triple.getObject());
- }
-
- @Override
- public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- dataset.remove(unionOrNamedGraph(), subject, predicate, object);
- }
-
- @Override
- public void clear() {
- dataset.remove(unionOrNamedGraph(), null, null, null);
- }
-
- @Override
- public long size() {
- return stream().count();
- }
-
- @Override
- public Stream<? extends Triple> stream() {
- return stream(null, null, null);
- }
-
- @Override
- public Stream<? extends Triple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- Stream<Triple> stream = dataset.stream(unionOrNamedGraph(), subject, predicate, object).map(Quad::asTriple);
- if (unionGraph) {
- // remove duplicates
- return stream.distinct();
- }
- return stream;
- }
+ private final boolean unionGraph;
+ private final BlankNodeOrIRI namedGraph;
+ private final Dataset dataset;
+
+ public DatasetGraphView(Dataset dataset) {
+ this.dataset = dataset;
+ this.namedGraph = null;
+ this.unionGraph = true;
+ }
+
+ public DatasetGraphView(Dataset dataset, BlankNodeOrIRI namedGraph) {
+ this.dataset = dataset;
+ this.namedGraph = namedGraph;
+ this.unionGraph = false;
+ }
+
+ @Override
+ public void close() throws Exception {
+ dataset.close();
+
+ }
+
+ @Override
+ public void add(Triple triple) {
+ dataset.add(namedGraph, triple.getSubject(), triple.getPredicate(), triple.getObject());
+ }
+
+ @Override
+ public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ dataset.add(namedGraph, subject, predicate, object);
+ }
+
+ @Override
+ public boolean contains(Triple triple) {
+ return dataset.contains(unionOrNamedGraph(), triple.getSubject(), triple.getPredicate(), triple.getObject());
+ }
+
+ private Optional<BlankNodeOrIRI> unionOrNamedGraph() {
+ if (unionGraph) {
+ return null;
+ }
+ return Optional.ofNullable(namedGraph);
+ }
+
+ @Override
+ public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return dataset.contains(unionOrNamedGraph(), subject, predicate, object);
+ }
+
+ @Override
+ public void remove(Triple triple) {
+ dataset.remove(unionOrNamedGraph(), triple.getSubject(), triple.getPredicate(), triple.getObject());
+ }
+
+ @Override
+ public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ dataset.remove(unionOrNamedGraph(), subject, predicate, object);
+ }
+
+ @Override
+ public void clear() {
+ dataset.remove(unionOrNamedGraph(), null, null, null);
+ }
+
+ @Override
+ public long size() {
+ return stream().count();
+ }
+
+ @Override
+ public Stream<? extends Triple> stream() {
+ return stream(null, null, null);
+ }
+
+ @Override
+ public Stream<? extends Triple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ Stream<Triple> stream = dataset.stream(unionOrNamedGraph(), subject, predicate, object).map(Quad::asTriple);
+ if (unionGraph) {
+ // remove duplicates
+ return stream.distinct();
+ }
+ return stream;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/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 a23f27e..974122d 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
@@ -43,7 +43,7 @@ import org.apache.commons.rdf.simple.SimpleRDF.SimpleRDFTerm;
* All Stream operations are performed using parallel and unordered directives.
*/
final class DatasetImpl implements Dataset {
-
+
private static final int TO_STRING_MAX = 10;
private final Set<Quad> quads = new HashSet<Quad>();
private final SimpleRDF factory;
@@ -51,43 +51,39 @@ final class DatasetImpl implements Dataset {
DatasetImpl(SimpleRDF simpleRDF) {
this.factory = simpleRDF;
}
-
- @Override
- public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- BlankNodeOrIRI newGraphName = (BlankNodeOrIRI) internallyMap(graphName);
- BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
+
+ @Override
+ public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ BlankNodeOrIRI newGraphName = (BlankNodeOrIRI) internallyMap(graphName);
+ BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
IRI newPredicate = (IRI) internallyMap(predicate);
RDFTerm newObject = internallyMap(object);
Quad result = factory.createQuad(newGraphName, newSubject, newPredicate, newObject);
quads.add(result);
- }
+ }
@Override
- public void add(Quad quad) {
- BlankNodeOrIRI newGraph = (BlankNodeOrIRI) internallyMap(quad.getGraphName().orElse(null));
- BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(quad
- .getSubject());
+ public void add(Quad quad) {
+ BlankNodeOrIRI newGraph = (BlankNodeOrIRI) internallyMap(quad.getGraphName().orElse(null));
+ BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(quad.getSubject());
IRI newPredicate = (IRI) internallyMap(quad.getPredicate());
RDFTerm newObject = internallyMap(quad.getObject());
// Check if any of the object references changed during the mapping, to
// avoid creating a new Quad object if possible
- if (newGraph == quad.getGraphName().orElse(null)
- && newSubject == quad.getSubject()
- && newPredicate == quad.getPredicate()
- && newObject == quad.getObject()) {
+ if (newGraph == quad.getGraphName().orElse(null) && newSubject == quad.getSubject()
+ && newPredicate == quad.getPredicate() && newObject == quad.getObject()) {
quads.add(quad);
} else {
- // Make a new Quad with our mapped instances
- Quad result = factory.createQuad(newGraph, newSubject, newPredicate,
- newObject);
+ // Make a new Quad with our mapped instances
+ Quad result = factory.createQuad(newGraph, newSubject, newPredicate, newObject);
quads.add(result);
}
}
private <T extends RDFTerm> RDFTerm internallyMap(T object) {
- if (object == null || object instanceof SimpleRDFTerm) {
- return object;
- }
+ if (object == null || object instanceof SimpleRDFTerm) {
+ return object;
+ }
if (object instanceof BlankNode && !(object instanceof BlankNodeImpl)) {
BlankNode blankNode = (BlankNode) object;
// This guarantees that adding the same BlankNode multiple times to
@@ -98,18 +94,15 @@ final class DatasetImpl implements Dataset {
} else if (object instanceof IRI && !(object instanceof IRIImpl)) {
IRI iri = (IRI) object;
return factory.createIRI(iri.getIRIString());
- } else if (object instanceof Literal
- && !(object instanceof LiteralImpl)) {
+ } else if (object instanceof Literal && !(object instanceof LiteralImpl)) {
Literal literal = (Literal) object;
if (literal.getLanguageTag().isPresent()) {
- return factory.createLiteral(literal.getLexicalForm(), literal
- .getLanguageTag().get());
+ return factory.createLiteral(literal.getLexicalForm(), literal.getLanguageTag().get());
} else {
- return factory.createLiteral(literal.getLexicalForm(),
- (IRI) internallyMap(literal.getDatatype()));
+ return factory.createLiteral(literal.getLexicalForm(), (IRI) internallyMap(literal.getDatatype()));
}
} else {
- throw new IllegalArgumentException("Not a BlankNode, IRI or Literal: " + object);
+ throw new IllegalArgumentException("Not a BlankNode, IRI or Literal: " + object);
}
}
@@ -118,34 +111,34 @@ final class DatasetImpl implements Dataset {
quads.clear();
}
- @Override
- public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return stream(graphName, subject, predicate, object).findAny().isPresent();
- }
-
+ @Override
+ public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return stream(graphName, subject, predicate, object).findAny().isPresent();
+ }
+
@Override
public boolean contains(Quad quad) {
return quads.contains(Objects.requireNonNull(quad));
}
-
- @Override
- public Stream<Quad> stream() {
+
+ @Override
+ public Stream<Quad> stream() {
return quads.parallelStream().unordered();
- }
+ }
- @Override
- public Stream<Quad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) {
- final Optional<BlankNodeOrIRI> newGraphName = graphName.map(g -> (BlankNodeOrIRI)internallyMap(g));
+ @Override
+ public Stream<Quad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) {
+ final Optional<BlankNodeOrIRI> newGraphName = graphName.map(g -> (BlankNodeOrIRI) internallyMap(g));
final BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
final IRI newPredicate = (IRI) internallyMap(predicate);
final RDFTerm newObject = internallyMap(object);
return getQuads(t -> {
if (newGraphName != null && !t.getGraphName().equals(newGraphName)) {
- // This would check Optional.empty() == Optional.empty()
+ // This would check Optional.empty() == Optional.empty()
return false;
- }
+ }
if (subject != null && !t.getSubject().equals(newSubject)) {
return false;
}
@@ -157,20 +150,20 @@ final class DatasetImpl implements Dataset {
}
return true;
});
- }
+ }
private Stream<Quad> getQuads(final Predicate<Quad> filter) {
return stream().filter(filter);
}
- @Override
- public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ @Override
+ public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
Stream<Quad> toRemove = stream(graphName, subject, predicate, object);
for (Quad t : toRemove.collect(Collectors.toList())) {
// Avoid ConcurrentModificationException in ArrayList
remove(t);
}
- }
+ }
@Override
public void remove(Quad quad) {
@@ -184,8 +177,7 @@ final class DatasetImpl implements Dataset {
@Override
public String toString() {
- String s = stream().limit(TO_STRING_MAX).map(Object::toString)
- .collect(Collectors.joining("\n"));
+ String s = stream().limit(TO_STRING_MAX).map(Object::toString).collect(Collectors.joining("\n"));
if (size() > TO_STRING_MAX) {
return s + "\n# ... +" + (size() - TO_STRING_MAX) + " more";
} else {
@@ -193,29 +185,24 @@ final class DatasetImpl implements Dataset {
}
}
- @Override
- public void close() {
- }
-
- @Override
- public Graph getGraph() {
- return getGraph(null).get();
- }
-
- @Override
- public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
- return Optional.of(new DatasetGraphView(this, graphName));
- }
+ @Override
+ public void close() {
+ }
- @Override
- public Stream<BlankNodeOrIRI> getGraphNames() {
- // Not very efficient..
- return stream()
- .map(Quad::getGraphName)
- .filter(Optional::isPresent).map(Optional::get)
- .distinct();
- }
+ @Override
+ public Graph getGraph() {
+ return getGraph(null).get();
+ }
+ @Override
+ public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
+ return Optional.of(new DatasetGraphView(this, graphName));
+ }
+ @Override
+ public Stream<BlankNodeOrIRI> getGraphNames() {
+ // Not very efficient..
+ return stream().map(Quad::getGraphName).filter(Optional::isPresent).map(Optional::get).distinct();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index b9221d5..84ac9a6 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -55,16 +55,17 @@ final class GraphImpl implements Graph {
@Override
public void add(Triple triple) {
- triples.add(internallyMap(triple));
+ triples.add(internallyMap(triple));
}
private <T extends RDFTerm> RDFTerm internallyMap(T object) {
- if (object == null || object instanceof SimpleRDFTerm) {
- // No need to re-map our own objects.
- // We support null as internallyMap() is also used by the filters, and the
- // factory constructors later do null checks
- return object;
- }
+ if (object == null || object instanceof SimpleRDFTerm) {
+ // No need to re-map our own objects.
+ // We support null as internallyMap() is also used by the filters,
+ // and the
+ // factory constructors later do null checks
+ return object;
+ }
if (object instanceof BlankNode) {
BlankNode blankNode = (BlankNode) object;
// This guarantees that adding the same BlankNode multiple times to
@@ -78,31 +79,26 @@ final class GraphImpl implements Graph {
} else if (object instanceof Literal) {
Literal literal = (Literal) object;
if (literal.getLanguageTag().isPresent()) {
- return factory.createLiteral(literal.getLexicalForm(), literal
- .getLanguageTag().get());
+ return factory.createLiteral(literal.getLexicalForm(), literal.getLanguageTag().get());
} else {
- return factory.createLiteral(literal.getLexicalForm(),
- (IRI) internallyMap(literal.getDatatype()));
+ return factory.createLiteral(literal.getLexicalForm(), (IRI) internallyMap(literal.getDatatype()));
}
} else {
- throw new IllegalArgumentException("RDFTerm was neither a BlankNode, IRI nor Literal: " + object);
+ throw new IllegalArgumentException("RDFTerm was neither a BlankNode, IRI nor Literal: " + object);
}
}
private Triple internallyMap(Triple triple) {
- BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(triple
- .getSubject());
+ BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(triple.getSubject());
IRI newPredicate = (IRI) internallyMap(triple.getPredicate());
RDFTerm newObject = internallyMap(triple.getObject());
// Check if any of the object references changed during the mapping, to
// avoid creating a new Triple object if possible
- if (newSubject == triple.getSubject()
- && newPredicate == triple.getPredicate()
+ if (newSubject == triple.getSubject() && newPredicate == triple.getPredicate()
&& newObject == triple.getObject()) {
return triple;
} else {
- return factory.createTriple(newSubject, newPredicate,
- newObject);
+ return factory.createTriple(newSubject, newPredicate, newObject);
}
}
@@ -112,24 +108,22 @@ final class GraphImpl implements Graph {
}
@Override
- public boolean contains(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) {
+ public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
return stream(subject, predicate, object).findFirst().isPresent();
}
@Override
public boolean contains(Triple triple) {
- return triples.contains(internallyMap(triple));
+ return triples.contains(internallyMap(triple));
}
-
- @Override
+
+ @Override
public Stream<Triple> stream() {
return triples.parallelStream().unordered();
}
@Override
- public Stream<Triple> stream(final BlankNodeOrIRI subject,
- final IRI predicate, final RDFTerm object) {
+ public Stream<Triple> stream(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
final BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
final IRI newPredicate = (IRI) internallyMap(predicate);
final RDFTerm newObject = internallyMap(object);
@@ -175,8 +169,7 @@ final class GraphImpl implements Graph {
@Override
public String toString() {
- String s = stream().limit(TO_STRING_MAX).map(Object::toString)
- .collect(Collectors.joining("\n"));
+ String s = stream().limit(TO_STRING_MAX).map(Object::toString).collect(Collectors.joining("\n"));
if (size() > TO_STRING_MAX) {
return s + "\n# ... +" + (size() - TO_STRING_MAX) + " more";
} else {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
index d477e43..4d3bf31 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/LiteralImpl.java
@@ -42,20 +42,17 @@ final class LiteralImpl implements Literal, SimpleRDF.SimpleRDFTerm {
public LiteralImpl(String lexicalForm, IRI dataType) {
this.lexicalForm = Objects.requireNonNull(lexicalForm);
- this.dataType = Types.get(Objects.requireNonNull(dataType)).orElse(
- dataType);
+ this.dataType = Types.get(Objects.requireNonNull(dataType)).orElse(dataType);
if (Types.RDF_LANGSTRING.equals(this.dataType)) {
throw new IllegalArgumentException(
- "Cannot create a non-language literal with type "
- + Types.RDF_LANGSTRING);
+ "Cannot create a non-language literal with type " + Types.RDF_LANGSTRING);
}
this.languageTag = null;
}
public LiteralImpl(String literal, String languageTag) {
this.lexicalForm = Objects.requireNonNull(literal);
- this.languageTag = Objects.requireNonNull(languageTag).toLowerCase(
- Locale.ENGLISH);
+ this.languageTag = Objects.requireNonNull(languageTag).toLowerCase(Locale.ENGLISH);
if (languageTag.isEmpty()) {
// TODO: Check against
// http://www.w3.org/TR/n-triples/#n-triples-grammar
@@ -64,8 +61,7 @@ final class LiteralImpl implements Literal, SimpleRDF.SimpleRDFTerm {
try {
new Locale.Builder().setLanguageTag(languageTag);
} catch (IllformedLocaleException ex) {
- throw new IllegalArgumentException("Invalid languageTag: "
- + languageTag, ex);
+ throw new IllegalArgumentException("Invalid languageTag: " + languageTag, ex);
}
// System.out.println(aLocale);
@@ -129,8 +125,7 @@ final class LiteralImpl implements Literal, SimpleRDF.SimpleRDFTerm {
return false;
}
Literal literal = (Literal) obj;
- return getDatatype().equals(literal.getDatatype())
- && getLexicalForm().equals(literal.getLexicalForm())
+ return getDatatype().equals(literal.getDatatype()) && getLexicalForm().equals(literal.getLexicalForm())
&& getLanguageTag().equals(literal.getLanguageTag());
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
index 00f8fa8..5092a56 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/QuadImpl.java
@@ -31,7 +31,7 @@ import java.util.Optional;
*/
final class QuadImpl implements Quad {
- private final BlankNodeOrIRI graphName;
+ private final BlankNodeOrIRI graphName;
private final BlankNodeOrIRI subject;
private final IRI predicate;
private final RDFTerm object;
@@ -42,13 +42,17 @@ final class QuadImpl implements Quad {
* The objects are not changed. All mapping of BNode objects is done in
* {@link SimpleRDF#createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)}.
*
- * @param graphName graphName of triple
- * @param subject subject of triple
- * @param predicate predicate of triple
- * @param object object of triple
+ * @param graphName
+ * graphName of triple
+ * @param subject
+ * subject of triple
+ * @param predicate
+ * predicate of triple
+ * @param object
+ * object of triple
*/
public QuadImpl(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- this.graphName = graphName; // possibly null
+ this.graphName = graphName; // possibly null
this.subject = Objects.requireNonNull(subject);
this.predicate = Objects.requireNonNull(predicate);
this.object = Objects.requireNonNull(object);
@@ -56,9 +60,9 @@ final class QuadImpl implements Quad {
@Override
public Optional<BlankNodeOrIRI> getGraphName() {
- return Optional.ofNullable(graphName);
+ return Optional.ofNullable(graphName);
}
-
+
@Override
public BlankNodeOrIRI getSubject() {
return subject;
@@ -75,13 +79,10 @@ final class QuadImpl implements Quad {
}
@Override
- public String toString() {
- return
- getSubject().ntriplesString() + " "
- + getPredicate().ntriplesString() + " "
- + getObject().ntriplesString() + " "
- + getGraphName().map(g -> g.ntriplesString() + " ").orElse("")
- + ".";
+ public String toString() {
+ return getSubject().ntriplesString() + " " + getPredicate().ntriplesString() + " "
+ + getObject().ntriplesString() + " " + getGraphName().map(g -> g.ntriplesString() + " ").orElse("")
+ + ".";
}
@Override
@@ -95,15 +96,13 @@ final class QuadImpl implements Quad {
return false;
}
Quad other = (Quad) obj;
- return getGraphName().equals(other.getGraphName())
- && getSubject().equals(other.getSubject())
- && getPredicate().equals(other.getPredicate())
- && getObject().equals(other.getObject());
+ return getGraphName().equals(other.getGraphName()) && getSubject().equals(other.getSubject())
+ && getPredicate().equals(other.getPredicate()) && getObject().equals(other.getObject());
}
-
+
@Override
public Triple asTriple() {
- return new TripleImpl(getSubject(), getPredicate(), getObject());
+ return new TripleImpl(getSubject(), getPredicate(), getObject());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
index 1698955..1292dc7 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
@@ -33,26 +33,25 @@ import org.apache.commons.rdf.api.Triple;
/**
* Simple RDF implementation.
* <p>
- * The {@link RDFTerm}, {@link Triple}, {@link Quad}, {@link Graph}
- * and {@link Dataset} instances created by SimpleRDF are
- * simple in-memory Implementations that are not thread-safe or efficient, but
- * which may be useful for testing and prototyping purposes.
+ * The {@link RDFTerm}, {@link Triple}, {@link Quad}, {@link Graph} and
+ * {@link Dataset} instances created by SimpleRDF are simple in-memory
+ * Implementations that are not thread-safe or efficient, but which may be
+ * useful for testing and prototyping purposes.
*/
public class SimpleRDF implements RDF {
- /**
- * Marker interface to say that this RDFTerm is part of the
- * Simple implementation. Used by {@link GraphImpl} to avoid
- * double remapping.
- * <p>
- * This method is package protected to avoid any third-party
- * subclasses.
- *
- */
- static interface SimpleRDFTerm extends RDFTerm {
- }
-
- /** Unique salt per instance, for {@link #createBlankNode(String)}
+ /**
+ * Marker interface to say that this RDFTerm is part of the Simple
+ * implementation. Used by {@link GraphImpl} to avoid double remapping.
+ * <p>
+ * This method is package protected to avoid any third-party subclasses.
+ *
+ */
+ static interface SimpleRDFTerm extends RDFTerm {
+ }
+
+ /**
+ * Unique salt per instance, for {@link #createBlankNode(String)}
*/
private final UUID SALT = UUID.randomUUID();
@@ -75,9 +74,9 @@ public class SimpleRDF implements RDF {
@Override
public Dataset createDataset() throws UnsupportedOperationException {
- return new DatasetImpl(this);
+ return new DatasetImpl(this);
}
-
+
@Override
public IRI createIRI(String iri) {
IRI result = new IRIImpl(iri);
@@ -101,14 +100,13 @@ public class SimpleRDF implements RDF {
}
@Override
- public Triple createTriple(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) {
+ public Triple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
return new TripleImpl(subject, predicate, object);
}
-
+
@Override
public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
- throws IllegalArgumentException {
- return new QuadImpl(graphName, subject, predicate, object);
+ throws IllegalArgumentException {
+ return new QuadImpl(graphName, subject, predicate, object);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
index fa242b1..144cfe5 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDFTermFactory.java
@@ -34,37 +34,37 @@ import org.apache.commons.rdf.api.Triple;
@Deprecated
public class SimpleRDFTermFactory implements RDFTermFactory {
- private SimpleRDF factory = new SimpleRDF();
+ private SimpleRDF factory = new SimpleRDF();
- public BlankNode createBlankNode() {
- return factory.createBlankNode();
- }
+ public BlankNode createBlankNode() {
+ return factory.createBlankNode();
+ }
- public BlankNode createBlankNode(String name) {
- return factory.createBlankNode(name);
- }
+ public BlankNode createBlankNode(String name) {
+ return factory.createBlankNode(name);
+ }
- public Graph createGraph() {
- return factory.createGraph();
- }
+ public Graph createGraph() {
+ return factory.createGraph();
+ }
- public IRI createIRI(String iri) {
- return factory.createIRI(iri);
- }
+ public IRI createIRI(String iri) {
+ return factory.createIRI(iri);
+ }
- public Literal createLiteral(String literal) {
- return factory.createLiteral(literal);
- }
+ public Literal createLiteral(String literal) {
+ return factory.createLiteral(literal);
+ }
- public Literal createLiteral(String literal, IRI dataType) {
- return factory.createLiteral(literal, dataType);
- }
+ public Literal createLiteral(String literal, IRI dataType) {
+ return factory.createLiteral(literal, dataType);
+ }
- public Literal createLiteral(String literal, String language) {
- return factory.createLiteral(literal, language);
- }
+ public Literal createLiteral(String literal, String language) {
+ return factory.createLiteral(literal, language);
+ }
- public Triple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return factory.createTriple(subject, predicate, object);
- }
+ public Triple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return factory.createTriple(subject, predicate, object);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
index 1abd905..35ce1cc 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/TripleImpl.java
@@ -39,9 +39,12 @@ final class TripleImpl implements Triple {
* The objects are not changed. All mapping of BNode objects is done in
* {@link SimpleRDF#createTriple(BlankNodeOrIRI, IRI, RDFTerm)}.
*
- * @param subject subject of triple
- * @param predicate predicate of triple
- * @param object object of triple
+ * @param subject
+ * subject of triple
+ * @param predicate
+ * predicate of triple
+ * @param object
+ * object of triple
*/
public TripleImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
this.subject = Objects.requireNonNull(subject);
@@ -66,8 +69,7 @@ final class TripleImpl implements Triple {
@Override
public String toString() {
- return getSubject().ntriplesString() + " "
- + getPredicate().ntriplesString() + " "
+ return getSubject().ntriplesString() + " " + getPredicate().ntriplesString() + " "
+ getObject().ntriplesString() + " .";
}
@@ -82,8 +84,7 @@ final class TripleImpl implements Triple {
return false;
}
Triple other = (Triple) obj;
- return getSubject().equals(other.getSubject())
- && getPredicate().equals(other.getPredicate())
+ return getSubject().equals(other.getSubject()) && getPredicate().equals(other.getPredicate())
&& getObject().equals(other.getObject());
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
index b6dd8ee..cf4d2e1 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
@@ -32,14 +32,12 @@ public final class Types implements IRI, SimpleRDF.SimpleRDFTerm {
/**
* <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML</tt>
*/
- public static final Types RDF_HTML = new Types(
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML");
+ public static final Types RDF_HTML = new Types("http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML");
/**
* <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</tt>
*/
- public static final Types RDF_LANGSTRING = new Types(
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
+ public static final Types RDF_LANGSTRING = new Types("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
/**
* <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral</tt>
@@ -47,236 +45,197 @@ public final class Types implements IRI, SimpleRDF.SimpleRDFTerm {
* @deprecated Not used in RDF-1.1
*/
@Deprecated
- public static final Types RDF_PLAINLITERAL = new Types(
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral");
+ public static final Types RDF_PLAINLITERAL = new Types("http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral");
/**
* <tt>http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral</tt>
*/
- public static final Types RDF_XMLLITERAL = new Types(
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral");
+ public static final Types RDF_XMLLITERAL = new Types("http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral");
/**
* <tt>http://www.w3.org/2001/XMLSchema#anyURI</tt>
*/
- public static final Types XSD_ANYURI = new Types(
- "http://www.w3.org/2001/XMLSchema#anyURI");
+ public static final Types XSD_ANYURI = new Types("http://www.w3.org/2001/XMLSchema#anyURI");
/**
* <tt>http://www.w3.org/2001/XMLSchema#base64Binary</tt>
*/
- public static final Types XSD_BASE64BINARY = new Types(
- "http://www.w3.org/2001/XMLSchema#base64Binary");
+ public static final Types XSD_BASE64BINARY = new Types("http://www.w3.org/2001/XMLSchema#base64Binary");
/**
* <tt>http://www.w3.org/2001/XMLSchema#boolean</tt>
*/
- public static final Types XSD_BOOLEAN = new Types(
- "http://www.w3.org/2001/XMLSchema#boolean");
+ public static final Types XSD_BOOLEAN = new Types("http://www.w3.org/2001/XMLSchema#boolean");
/**
* <tt>http://www.w3.org/2001/XMLSchema#byte</tt>
*/
- public static final Types XSD_BYTE = new Types(
- "http://www.w3.org/2001/XMLSchema#byte");
+ public static final Types XSD_BYTE = new Types("http://www.w3.org/2001/XMLSchema#byte");
/**
* <tt>http://www.w3.org/2001/XMLSchema#date</tt>
*/
- public static final Types XSD_DATE = new Types(
- "http://www.w3.org/2001/XMLSchema#date");
+ public static final Types XSD_DATE = new Types("http://www.w3.org/2001/XMLSchema#date");
/**
* <tt>http://www.w3.org/2001/XMLSchema#dateTime</tt>
*/
- public static final Types XSD_DATETIME = new Types(
- "http://www.w3.org/2001/XMLSchema#dateTime");
+ public static final Types XSD_DATETIME = new Types("http://www.w3.org/2001/XMLSchema#dateTime");
/**
* <tt>http://www.w3.org/2001/XMLSchema#dayTimeDuration</tt>
*/
- public static final Types XSD_DAYTIMEDURATION = new Types(
- "http://www.w3.org/2001/XMLSchema#dayTimeDuration");
+ public static final Types XSD_DAYTIMEDURATION = new Types("http://www.w3.org/2001/XMLSchema#dayTimeDuration");
/**
* <tt>http://www.w3.org/2001/XMLSchema#decimal</tt>
*/
- public static final Types XSD_DECIMAL = new Types(
- "http://www.w3.org/2001/XMLSchema#decimal");
+ public static final Types XSD_DECIMAL = new Types("http://www.w3.org/2001/XMLSchema#decimal");
/**
* <tt>http://www.w3.org/2001/XMLSchema#double</tt>
*/
- public static final Types XSD_DOUBLE = new Types(
- "http://www.w3.org/2001/XMLSchema#double");
+ public static final Types XSD_DOUBLE = new Types("http://www.w3.org/2001/XMLSchema#double");
/**
* <tt>http://www.w3.org/2001/XMLSchema#duration</tt>
*/
- public static final Types XSD_DURATION = new Types(
- "http://www.w3.org/2001/XMLSchema#duration");
+ public static final Types XSD_DURATION = new Types("http://www.w3.org/2001/XMLSchema#duration");
/**
* <tt>http://www.w3.org/2001/XMLSchema#float</tt>
*/
- public static final Types XSD_FLOAT = new Types(
- "http://www.w3.org/2001/XMLSchema#float");
+ public static final Types XSD_FLOAT = new Types("http://www.w3.org/2001/XMLSchema#float");
/**
* <tt>http://www.w3.org/2001/XMLSchema#gDay</tt>
*/
- public static final Types XSD_GDAY = new Types(
- "http://www.w3.org/2001/XMLSchema#gDay");
+ public static final Types XSD_GDAY = new Types("http://www.w3.org/2001/XMLSchema#gDay");
/**
* <tt>http://www.w3.org/2001/XMLSchema#gMonth</tt>
*/
- public static final Types XSD_GMONTH = new Types(
- "http://www.w3.org/2001/XMLSchema#gMonth");
+ public static final Types XSD_GMONTH = new Types("http://www.w3.org/2001/XMLSchema#gMonth");
/**
* <tt>http://www.w3.org/2001/XMLSchema#gMonthDay</tt>
*/
- public static final Types XSD_GMONTHDAY = new Types(
- "http://www.w3.org/2001/XMLSchema#gMonthDay");
+ public static final Types XSD_GMONTHDAY = new Types("http://www.w3.org/2001/XMLSchema#gMonthDay");
/**
* <tt>http://www.w3.org/2001/XMLSchema#gYear</tt>
*/
- public static final Types XSD_GYEAR = new Types(
- "http://www.w3.org/2001/XMLSchema#gYear");
+ public static final Types XSD_GYEAR = new Types("http://www.w3.org/2001/XMLSchema#gYear");
/**
* <tt>http://www.w3.org/2001/XMLSchema#gYearMonth</tt>
*/
- public static final Types XSD_GYEARMONTH = new Types(
- "http://www.w3.org/2001/XMLSchema#gYearMonth");
+ public static final Types XSD_GYEARMONTH = new Types("http://www.w3.org/2001/XMLSchema#gYearMonth");
/**
* <tt>http://www.w3.org/2001/XMLSchema#hexBinary</tt>
*/
- public static final Types XSD_HEXBINARY = new Types(
- "http://www.w3.org/2001/XMLSchema#hexBinary");
+ public static final Types XSD_HEXBINARY = new Types("http://www.w3.org/2001/XMLSchema#hexBinary");
/**
* <tt>http://www.w3.org/2001/XMLSchema#int</tt>
*/
- public static final Types XSD_INT = new Types(
- "http://www.w3.org/2001/XMLSchema#int");
+ public static final Types XSD_INT = new Types("http://www.w3.org/2001/XMLSchema#int");
/**
* <tt>http://www.w3.org/2001/XMLSchema#integer</tt>
*/
- public static final Types XSD_INTEGER = new Types(
- "http://www.w3.org/2001/XMLSchema#integer");
+ public static final Types XSD_INTEGER = new Types("http://www.w3.org/2001/XMLSchema#integer");
/**
* <tt>http://www.w3.org/2001/XMLSchema#language</tt>
*/
- public static final Types XSD_LANGUAGE = new Types(
- "http://www.w3.org/2001/XMLSchema#language");
+ public static final Types XSD_LANGUAGE = new Types("http://www.w3.org/2001/XMLSchema#language");
/**
* <tt>http://www.w3.org/2001/XMLSchema#long</tt>
*/
- public static final Types XSD_LONG = new Types(
- "http://www.w3.org/2001/XMLSchema#long");
+ public static final Types XSD_LONG = new Types("http://www.w3.org/2001/XMLSchema#long");
/**
* <tt>http://www.w3.org/2001/XMLSchema#Name</tt>
*/
- public static final Types XSD_NAME = new Types(
- "http://www.w3.org/2001/XMLSchema#Name");
+ public static final Types XSD_NAME = new Types("http://www.w3.org/2001/XMLSchema#Name");
/**
* <tt>http://www.w3.org/2001/XMLSchema#NCName</tt>
*/
- public static final Types XSD_NCNAME = new Types(
- "http://www.w3.org/2001/XMLSchema#NCName");
+ public static final Types XSD_NCNAME = new Types("http://www.w3.org/2001/XMLSchema#NCName");
/**
* <tt>http://www.w3.org/2001/XMLSchema#negativeInteger</tt>
*/
- public static final Types XSD_NEGATIVEINTEGER = new Types(
- "http://www.w3.org/2001/XMLSchema#negativeInteger");
+ public static final Types XSD_NEGATIVEINTEGER = new Types("http://www.w3.org/2001/XMLSchema#negativeInteger");
/**
* <tt>http://www.w3.org/2001/XMLSchema#NMTOKEN</tt>
*/
- public static final Types XSD_NMTOKEN = new Types(
- "http://www.w3.org/2001/XMLSchema#NMTOKEN");
+ public static final Types XSD_NMTOKEN = new Types("http://www.w3.org/2001/XMLSchema#NMTOKEN");
/**
* <tt>http://www.w3.org/2001/XMLSchema#nonNegativeInteger</tt>
*/
- public static final Types XSD_NONNEGATIVEINTEGER = new Types(
- "http://www.w3.org/2001/XMLSchema#nonNegativeInteger");
+ public static final Types XSD_NONNEGATIVEINTEGER = new Types("http://www.w3.org/2001/XMLSchema#nonNegativeInteger");
/**
* <tt>http://www.w3.org/2001/XMLSchema#nonPositiveInteger</tt>
*/
- public static final Types XSD_NONPOSITIVEINTEGER = new Types(
- "http://www.w3.org/2001/XMLSchema#nonPositiveInteger");
+ public static final Types XSD_NONPOSITIVEINTEGER = new Types("http://www.w3.org/2001/XMLSchema#nonPositiveInteger");
/**
* <tt>http://www.w3.org/2001/XMLSchema#normalizedString</tt>
*/
- public static final Types XSD_NORMALIZEDSTRING = new Types(
- "http://www.w3.org/2001/XMLSchema#normalizedString");
+ public static final Types XSD_NORMALIZEDSTRING = new Types("http://www.w3.org/2001/XMLSchema#normalizedString");
/**
* <tt>http://www.w3.org/2001/XMLSchema#positiveInteger</tt>
*/
- public static final Types XSD_POSITIVEINTEGER = new Types(
- "http://www.w3.org/2001/XMLSchema#positiveInteger");
+ public static final Types XSD_POSITIVEINTEGER = new Types("http://www.w3.org/2001/XMLSchema#positiveInteger");
/**
* <tt>http://www.w3.org/2001/XMLSchema#short</tt>
*/
- public static final Types XSD_SHORT = new Types(
- "http://www.w3.org/2001/XMLSchema#short");
+ public static final Types XSD_SHORT = new Types("http://www.w3.org/2001/XMLSchema#short");
/**
* <tt>http://www.w3.org/2001/XMLSchema#string</tt>
*/
- public static final Types XSD_STRING = new Types(
- "http://www.w3.org/2001/XMLSchema#string");
+ public static final Types XSD_STRING = new Types("http://www.w3.org/2001/XMLSchema#string");
/**
* <tt>http://www.w3.org/2001/XMLSchema#time</tt>
*/
- public static final Types XSD_TIME = new Types(
- "http://www.w3.org/2001/XMLSchema#time");
+ public static final Types XSD_TIME = new Types("http://www.w3.org/2001/XMLSchema#time");
/**
* <tt>http://www.w3.org/2001/XMLSchema#token</tt>
*/
- public static final Types XSD_TOKEN = new Types(
- "http://www.w3.org/2001/XMLSchema#token");
+ public static final Types XSD_TOKEN = new Types("http://www.w3.org/2001/XMLSchema#token");
/**
* <tt>http://www.w3.org/2001/XMLSchema#unsignedByte</tt>
*/
- public static final Types XSD_UNSIGNEDBYTE = new Types(
- "http://www.w3.org/2001/XMLSchema#unsignedByte");
+ public static final Types XSD_UNSIGNEDBYTE = new Types("http://www.w3.org/2001/XMLSchema#unsignedByte");
/**
* <tt>http://www.w3.org/2001/XMLSchema#unsignedInt</tt>
*/
- public static final Types XSD_UNSIGNEDINT = new Types(
- "http://www.w3.org/2001/XMLSchema#unsignedInt");
+ public static final Types XSD_UNSIGNEDINT = new Types("http://www.w3.org/2001/XMLSchema#unsignedInt");
/**
* <tt>http://www.w3.org/2001/XMLSchema#unsignedLong</tt>
*/
- public static final Types XSD_UNSIGNEDLONG = new Types(
- "http://www.w3.org/2001/XMLSchema#unsignedLong");
+ public static final Types XSD_UNSIGNEDLONG = new Types("http://www.w3.org/2001/XMLSchema#unsignedLong");
/**
* <tt>http://www.w3.org/2001/XMLSchema#unsignedShort</tt>
*/
- public static final Types XSD_UNSIGNEDSHORT = new Types(
- "http://www.w3.org/2001/XMLSchema#unsignedShort");
+ public static final Types XSD_UNSIGNEDSHORT = new Types("http://www.w3.org/2001/XMLSchema#unsignedShort");
private static final Set<IRI> ALL_TYPES;
@@ -371,9 +330,10 @@ public final class Types implements IRI, SimpleRDF.SimpleRDFTerm {
* Get the IRI from this collection if it is present, or return
* {@link Optional#empty()} otherwise.
*
- * @param nextIRI The IRI to look for.
+ * @param nextIRI
+ * The IRI to look for.
* @return An {@link Optional} containing the IRI from this collection or
- * {@link Optional#empty()} if it is not present here.
+ * {@link Optional#empty()} if it is not present here.
*/
public static Optional<IRI> get(IRI nextIRI) {
if (ALL_TYPES.contains(nextIRI)) {
[17/50] [abbrv] incubator-commonsrdf git commit: Merge branch
'avoid-unsupported' into COMMONSRDF-46
Posted by st...@apache.org.
Merge branch 'avoid-unsupported' into COMMONSRDF-46
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/fa27a178
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/fa27a178
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/fa27a178
Branch: refs/heads/COMMONSRDF-7
Commit: fa27a178994bbe718bf8bff5a8bf405df39e4de7
Parents: 3ed4272 17c0d27
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Oct 23 01:42:03 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Oct 23 01:42:03 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/api/RDF.java | 2 -
.../rdf/api/AbstractRDFTermFactoryTest.java | 235 ++++---------------
.../commons/rdf/jsonldjava/JsonLdBlankNode.java | 1 +
.../rdf/jsonldjava/JsonLdFactoryTest.java | 6 +-
.../rdf/rdf4j/MemoryRDFTermFactoryTest.java | 2 +-
.../commons/rdf/rdf4j/NativeStoreGraphTest.java | 2 -
.../rdf/rdf4j/Rdf4JRDFTermFactoryTest.java | 2 +-
7 files changed, 52 insertions(+), 198 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fa27a178/api/src/main/java/org/apache/commons/rdf/api/RDF.java
----------------------------------------------------------------------
diff --cc api/src/main/java/org/apache/commons/rdf/api/RDF.java
index 0565ba4,0000000..32b7f66
mode 100644,000000..100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDF.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDF.java
@@@ -1,246 -1,0 +1,244 @@@
+/**
+ * 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.io.Serializable;
+import java.util.Locale;
+
+/**
+ * A RDF implementation.
+ * <p>
+ * A <code>RDF</code> implementation can create instances of
+ * the {@link RDFTerm} types
+ * {@link IRI}, {@link BlankNode} and {@link Literal}, as well as creating
+ * instances of the types {@link Triple}, {@link Quad}, {@link Graph} or
+ * {@link Dataset}.
+ * <p>
+ * A <em>partial RDF implementation</em>
+ * should be clearly documented as such, and may throw
+ * {@link UnsupportedOperationException} where applicable, e.g. if it
+ * does not support creating {@link Dataset}s or {@link Quad}s.
+ * <p>
+ * Instances of <code>RDF</code> work like a factory for
+ * creating Commons RDF instances.
+ * spezializations of this interface may also provide methods
+ * for conversions from/to their underlying RDF framework.
+ * <p>
+ * If a factory method of a particular implementation does not allow or support
+ * a provided parameter, e.g. because an IRI is considered invalid, then it
+ * SHOULD throw {@link IllegalArgumentException}.
+ *
+ * @since 0.3.0-incubating
+ * @see RDFTerm
+ * @see Graph
+ * @see Quad
+ */
+public interface RDF {
+
+ /**
+ * Create a new blank node.
+ * <p>
+ * The returned blank node MUST NOT be equal to any existing
+ * {@link BlankNode} instances according to {@link BlankNode#equals(Object)}.
+ *
+ * @return A new, unique {@link BlankNode}
- * @throws UnsupportedOperationException
- * If the operation is not supported.
+ */
+ public BlankNode createBlankNode();
+
+ /**
+ * Create a blank node based on the given name.
+ * <p>
+ * All {@link BlankNode}s created with the given <code>name</code>
+ * <em>on a particular instance</em> of <code>RDF</code> MUST be
+ * equivalent according to {@link BlankNode#equals(Object)},
+ * <p>
+ * The returned BlankNode MUST NOT be equal to <code>BlankNode</code>
+ * instances returned for any other <code>name</code> or those returned from
+ * {@link #createBlankNode()}.
+ * <p>
+ * The returned BlankNode SHOULD NOT be equivalent to any BlankNodes created
+ * on a <em>different</em> <code>RDF</code> instance, e.g.
+ * different instances of <code>RDF</code> should produce
+ * different blank nodes for the same <code>name</code> unless they
+ * purposely are intending to create equivalent {@link BlankNode}
+ * instances (e.g. a reinstated {@link Serializable} factory).
+ *
+ * @param name
+ * A non-empty, non-null, String that is unique to this blank
+ * node in the context of this {@link RDF}.
+ * @return A BlankNode for the given name
+ */
+ public BlankNode createBlankNode(String name);
+
+ /**
+ * Create a new graph.
+ *
+ * It is undefined if the graph will be persisted by any underlying storage
+ * mechanism.
+ *
+ * @return A new Graph
+ */
+ public Graph createGraph();
+
+ /**
+ * Create a new dataset.
+ *
+ * It is undefined if the dataset will be persisted by any underlying storage
+ * mechanism.
+ *
+ * @return A new Dataset
+ */
+ public Dataset createDataset();
+
+ /**
+ * Create an IRI from a (possibly escaped) String.
+ *
+ * The provided iri string MUST be valid according to the <a
+ * href="http://www.w3.org/TR/rdf11-concepts/#dfn-iri">W3C RDF-1.1 IRI</a>
+ * definition.
+ *
+ * @param iri Internationalized Resource Identifier
+ * @return A new IRI
+ * @throws IllegalArgumentException If the provided string is not acceptable, e.g. does not
+ * conform to the RFC3987 syntax.
+ */
+ public IRI createIRI(String iri) throws IllegalArgumentException;
+
+ /**
+ * Create a simple literal.
+ *
+ * The provided lexical form should not be escaped in any sense, e.g. should
+ * not include "quotes" unless those are part of the literal value.
+ *
+ * The returned Literal MUST have a {@link Literal#getLexicalForm()} that is
+ * equal to the provided lexical form, MUST NOT have a
+ * {@link Literal#getLanguageTag()} present, and SHOULD return a
+ * {@link Literal#getDatatype()} that is equal to the IRI
+ * <code>http://www.w3.org/2001/XMLSchema#string</code>.
+ *
+ * @param lexicalForm The literal value in plain text
+ * @return The created Literal
+ * @throws IllegalArgumentException If the provided lexicalForm is not acceptable, e.g. because
+ * it is too large for an underlying storage.
+ */
+ public Literal createLiteral(String lexicalForm)
+ throws IllegalArgumentException;
+
+ /**
+ * Create a literal with the specified data type.
+ *
+ * The provided lexical form should not be escaped in any sense, e.g. should
+ * not include "quotes" unless those are part of the literal value.
+ *
+ * It is RECOMMENDED that the provided dataType is one of the <a
+ * href="http://www.w3.org/TR/rdf11-concepts/#xsd-datatypes">RDF-compatible
+ * XSD types</a>.
+ *
+ * The provided lexical form SHOULD be in the <a
+ * href="http://www.w3.org/TR/rdf11-concepts/#dfn-lexical-space">lexical
+ * space</a> of the provided dataType.
+ *
+ * The returned Literal SHOULD have a {@link Literal#getLexicalForm()} that
+ * is equal to the provided lexicalForm, MUST NOT have a
+ * {@link Literal#getLanguageTag()} present, and MUST return a
+ * {@link Literal#getDatatype()} that is equivalent to the provided dataType
+ * IRI.
+ *
+ * @param lexicalForm The literal value
+ * @param dataType The data type IRI for the literal value, e.g.
+ * <code>http://www.w3.org/2001/XMLSchema#integer</code>
+ * @return The created Literal
+ * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
+ * because the provided dataType is not permitted.
+ */
+ public Literal createLiteral(String lexicalForm, IRI dataType)
+ throws IllegalArgumentException;
+
+ /**
+ * Create a language-tagged literal.
+ *
+ * The provided lexical form should not be escaped in any sense, e.g. should
+ * not include "quotes" unless those are part of the literal value.
+ *
+ * The provided language tag MUST be valid according to <a
+ * href="http://tools.ietf.org/html/bcp47">BCP47</a>, e.g. <code>en</code>.
+ *
+ * The provided language tag <a
+ * href="http://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string"
+ * >MAY be converted to lower case</a>.
+ *
+ * The returned Literal SHOULD have a {@link Literal#getLexicalForm()} which
+ * is equal to the provided lexicalForm, MUST return a
+ * {@link Literal#getDatatype()} that is equal to the IRI
+ * <code>http://www.w3.org/1999/02/22-rdf-syntax-ns#langString</code>, and
+ * MUST have a {@link Literal#getLanguageTag()} present which SHOULD be
+ * equal to the provided language tag (compared as
+ * {@link String#toLowerCase(Locale)} using {@link Locale#ENGLISH}).
+ *
+ * @param lexicalForm The literal value
+ * @param languageTag The non-empty language tag as defined by <a
+ * href="http://tools.ietf.org/html/bcp47">BCP47</a>
+ * @return The created Literal
+ * @throws IllegalArgumentException If the provided values are not acceptable, e.g. because the
+ * languageTag was syntactically invalid.
+ */
+ public Literal createLiteral(String lexicalForm, String languageTag)
+ throws IllegalArgumentException;
+
+ /**
+ * Create a triple.
+ *
+ * The returned Triple SHOULD have a {@link Triple#getSubject()} that is
+ * equal to the provided subject, a {@link Triple#getPredicate()} that is
+ * equal to the provided predicate, and a {@link Triple#getObject()} that is
+ * equal to the provided object.
+ *
+ * @param subject The IRI or BlankNode that is the subject of the triple
+ * @param predicate The IRI that is the predicate of the triple
+ * @param object The IRI, BlankNode or Literal that is the object of the triple
+ * @return The created Triple
+ * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
+ * because a Literal has a lexicalForm that is too large for an
+ * underlying storage.
+ */
+ public Triple createTriple(BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) throws IllegalArgumentException;
+
+ /**
+ * Create a quad.
+ * <p>
+ * The returned Quad SHOULD have a
+ * {@link Quad#getGraphName()} that is equal to the provided graphName, a
+ * {@link Quad#getSubject()} that is
+ * equal to the provided subject, a {@link Quad#getPredicate()} that is
+ * equal to the provided predicate, and a {@link Quad#getObject()} that is
+ * equal to the provided object.
+ *
+ * @param graphName The IRI or BlankNode that this quad belongs to, or <code>null</code> for the public graph
+ * @param subject The IRI or BlankNode that is the subject of the quad
+ * @param predicate The IRI that is the predicate of the quad
+ * @param object The IRI, BlankNode or Literal that is the object of the quad
+ * @return The created Quad
+ * @throws IllegalArgumentException If any of the provided arguments are not acceptable, e.g.
+ * because a Literal has a lexicalForm that is too large for an
+ * underlying storage.
+ */
+ public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) throws IllegalArgumentException;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fa27a178/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fa27a178/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
----------------------------------------------------------------------
diff --cc jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
index 81fb532,fd65c2a..22010f7
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
@@@ -18,7 -18,8 +18,8 @@@
package org.apache.commons.rdf.jsonldjava;
import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
-import org.apache.commons.rdf.api.RDFFactory;
+import org.apache.commons.rdf.api.RDF;
+ import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fa27a178/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fa27a178/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
----------------------------------------------------------------------
diff --cc rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
index e5a9772,91a0b14..3697069
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
@@@ -61,13 -61,9 +61,12 @@@ public class NativeStoreGraphTest exten
Set<RDF4JBlankNode> context = Collections.singleton(rdf4jFactory.createBlankNode());
return rdf4jFactory.asRDFTermGraph(getRepository(), context);
}
+ @Override
public Dataset createDataset() {
- return rdf4jFactory.asRDFTermDataset(getRepository());
+ throw new UnsupportedOperationException("Can't create more than one Dataset in this test");
+ // ...as the below would re-use the same repository:
+ //return rdf4jFactory.asRDFTermDataset(getRepository());
}
-
// Delegate methods
public RDF4JBlankNode createBlankNode() {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fa27a178/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
----------------------------------------------------------------------
[31/50] [abbrv] incubator-commonsrdf git commit: Avoid space at end
of line - " ; " -> "; "
Posted by st...@apache.org.
Avoid space at end of line - " ;" -> ";"
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/b7016f02
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/b7016f02
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/b7016f02
Branch: refs/heads/COMMONSRDF-7
Commit: b7016f020c468cf696be0435fca58ad8cd7c2bb1
Parents: 2e160b5
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 28 11:02:48 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 28 11:02:48 2016 +0100
----------------------------------------------------------------------
.../rdf/jena/impl/AbstractJenaRDFTerm.java | 2 +-
.../commons/rdf/jena/TestBlankNodeJena.java | 8 +++---
.../apache/commons/rdf/jena/TestGraphJena.java | 6 ++---
.../jena/TestJenaGraphToCommonsRDFGraph.java | 26 ++++++++++----------
.../rdf/jena/TestRDFTermFactoryJena.java | 6 ++---
5 files changed, 24 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b7016f02/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java
index 9c0d7ec..fd117a2 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractJenaRDFTerm.java
@@ -25,7 +25,7 @@ import org.apache.jena.riot.out.NodeFmtLib;
class AbstractJenaRDFTerm implements JenaRDFTerm, RDFTerm {
private Node node;
- // static private PrefixMapping empty = new PrefixMappingImpl() ;
+ // static private PrefixMapping empty = new PrefixMappingImpl();
protected AbstractJenaRDFTerm(Node node) {
this.node = node;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b7016f02/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java
index a3db975..abe8080 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java
@@ -20,8 +20,8 @@ package org.apache.commons.rdf.jena;
import java.util.UUID;
-import org.apache.commons.rdf.api.AbstractBlankNodeTest ;
-import org.apache.commons.rdf.api.BlankNode ;
+import org.apache.commons.rdf.api.AbstractBlankNodeTest;
+import org.apache.commons.rdf.api.BlankNode;
import org.apache.commons.rdf.jena.impl.InternalJenaFactory;
public class TestBlankNodeJena extends AbstractBlankNodeTest {
@@ -35,12 +35,12 @@ public class TestBlankNodeJena extends AbstractBlankNodeTest {
@Override
protected BlankNode getBlankNode() {
- return internalJenaFactory.createBlankNode(SALT) ;
+ return internalJenaFactory.createBlankNode(SALT);
}
@Override
protected BlankNode getBlankNode(String identifier) {
- return internalJenaFactory.createBlankNode(identifier, SALT) ;
+ return internalJenaFactory.createBlankNode(identifier, SALT);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b7016f02/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
index a11fdc6..296c42d 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
@@ -18,14 +18,14 @@
package org.apache.commons.rdf.jena;
-import org.apache.commons.rdf.api.AbstractGraphTest ;
-import org.apache.commons.rdf.api.RDF ;
+import org.apache.commons.rdf.api.AbstractGraphTest;
+import org.apache.commons.rdf.api.RDF;
public class TestGraphJena extends AbstractGraphTest {
@Override
public RDF createFactory() {
- return new JenaRDF() ;
+ return new JenaRDF();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b7016f02/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
index 51cfa4c..50bb1ff 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
@@ -28,13 +28,13 @@ import java.nio.file.StandardCopyOption;
import org.apache.commons.rdf.api.BlankNode;
import org.apache.commons.rdf.api.BlankNodeOrIRI;
-import org.apache.commons.rdf.api.Graph ;
+import org.apache.commons.rdf.api.Graph;
import org.apache.commons.rdf.api.RDFTerm;
import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.simple.Types;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.sparql.graph.GraphFactory ;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFDataMgr;
+import org.apache.jena.sparql.graph.GraphFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -60,13 +60,13 @@ public class TestJenaGraphToCommonsRDFGraph {
@Test
public void jenaToCommonsRDF() throws Exception {
- org.apache.jena.graph.Graph jGraph = GraphFactory.createGraphMem() ;
- RDFDataMgr.read(jGraph, turtleFile.toUri().toString()) ;
+ org.apache.jena.graph.Graph jGraph = GraphFactory.createGraphMem();
+ RDFDataMgr.read(jGraph, turtleFile.toUri().toString());
- JenaRDF factory = new JenaRDF() ;
+ JenaRDF factory = new JenaRDF();
// "graph" is a CommonsRDF graph
- Graph graph = factory.asGraph(jGraph) ;
+ Graph graph = factory.asGraph(jGraph);
@@ -115,7 +115,7 @@ public class TestJenaGraphToCommonsRDFGraph {
JenaLiteral foo = factory.createLiteral("foo");
graph.add(s2,
p2,
- foo) ;
+ foo);
assertEquals(4, graph.size());
assertTrue(graph.contains(s2,p2,foo));
@@ -123,11 +123,11 @@ public class TestJenaGraphToCommonsRDFGraph {
assertTrue(jGraph.contains(s2.asJenaNode(), p2.asJenaNode(), foo.asJenaNode()));
if (DEBUG) {
- System.out.println("==== Write CommonsRDF graph\n") ;
- graph.stream().forEach(System.out::println) ;
+ System.out.println("==== Write CommonsRDF graph\n");
+ graph.stream().forEach(System.out::println);
// And its in the Jena graph
- System.out.println("\n==== Write Jena graph directly\n") ;
- RDFDataMgr.write(System.out, jGraph, Lang.TTL) ;
+ System.out.println("\n==== Write Jena graph directly\n");
+ RDFDataMgr.write(System.out, jGraph, Lang.TTL);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b7016f02/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
index 327f218..870546a 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
@@ -18,14 +18,14 @@
package org.apache.commons.rdf.jena;
-import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest ;
-import org.apache.commons.rdf.api.RDF ;
+import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
+import org.apache.commons.rdf.api.RDF;
public class TestRDFTermFactoryJena extends AbstractRDFTermFactoryTest {
@Override
public RDF createFactory() {
- return new JenaRDF() ;
+ return new JenaRDF();
}
}
[23/50] [abbrv] incubator-commonsrdf git commit: Is travis happy with
dist: trusty?
Posted by st...@apache.org.
Is travis happy with dist: trusty?
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/13e692cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/13e692cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/13e692cd
Branch: refs/heads/COMMONSRDF-7
Commit: 13e692cd0e892ab04f827da1c5c4f682ab0235e8
Parents: 400d1e7
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 13:48:11 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 13:48:11 2016 +0100
----------------------------------------------------------------------
.travis.yml | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/13e692cd/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index f356e54..283b9c3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,7 @@
-# Use docker-based build environment
-sudo: false
+# Attempt to get a newer oraclejdk8..
+# See https://docs.travis-ci.com/user/ci-environment/
+sudo: required
+dist: trusty
language: java
jdk:
[21/50] [abbrv] incubator-commonsrdf git commit: Merge branch
'master' into COMMONSRDF-46
Posted by st...@apache.org.
Merge branch 'master' into COMMONSRDF-46
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/46e159db
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/46e159db
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/46e159db
Branch: refs/heads/COMMONSRDF-7
Commit: 46e159db15c8290820e0abebe6bf61ed9c250c3d
Parents: d6306ad 9f73a14
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 12:58:47 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 12:58:47 2016 +0100
----------------------------------------------------------------------
.../main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java | 3 ++-
.../main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java | 7 ++++---
2 files changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/46e159db/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
----------------------------------------------------------------------
diff --cc rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
index fb54a09,e5edde7..7b5cbaa
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
@@@ -25,13 -25,14 +25,14 @@@ import org.apache.commons.rdf.api.Datas
import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.Quad;
import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.rdf4j.RDF4JFactory.Option;
++import org.apache.commons.rdf.rdf4j.RDF4J.Option;
/**
* Marker interface for RDF4J implementations of Dataset.
*
- * @see RDF4JFactory#createDataset()
- * @see RDF4JFactory#asDataset(org.eclipse.rdf4j.repository.Repository, Option...)
+ * @see RDF4J#createDataset()
- * @see RDF4J#asDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)
++ * @see RDF4J#asDataset(org.eclipse.rdf4j.repository.Repository, Option...)
*/
public interface RDF4JDataset extends Dataset, RDF4JGraphLike<Quad> {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/46e159db/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
----------------------------------------------------------------------
diff --cc rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
index d1ab485,4968b99..65cdf67
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
@@@ -28,15 -28,16 +28,16 @@@ import org.apache.commons.rdf.api.RDFTe
import org.apache.commons.rdf.api.Triple;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.repository.Repository;
-import org.apache.commons.rdf.rdf4j.RDF4JFactory.Option;
++import org.apache.commons.rdf.rdf4j.RDF4J.Option;
/**
* Marker interface for RDF4J implementations of Graph.
*
- * @see RDF4JFactory#createGraph()
- * @see RDF4JFactory#asGraph(Model)
- * @see RDF4JFactory#asGraph(Repository, Option...)
- * @see RDF4JFactory#asGraphUnion(Repository, Option...)
+ * @see RDF4J#createGraph()
+ * @see RDF4J#asGraph(Model)
- * @see RDF4J#asGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)
- * @see RDF4J#asGraphUnion(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)
++ * @see RDF4J#asGraph(Repository, Option...)
++ * @see RDF4J#asGraphUnion(Repository, Option...)
* @see RDF4JDataset#getGraph()
* @see RDF4JDataset#getGraph(BlankNodeOrIRI)
*/
@@@ -64,7 -65,7 +65,7 @@@ public interface RDF4JGraph extends Gra
* Note that the context mask itself cannot be <code>null</code>.
* <p>
* The returned set is an immutable copy; to specify a different mask, use
- * {@link RDF4J#asGraph(Repository, Set, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)}
- * {@link RDF4JFactory#asGraph(Repository, Set, Option...)}
++ * {@link RDF4J#asGraph(Repository, Set, Option...)}
*
* @return The context mask as a set of {@link BlankNodeOrIRI} graph names, which
* may contain the value <code>null</code>.
[25/50] [abbrv] incubator-commonsrdf git commit: Merge branch
'master' into COMMONSRDF-46
Posted by st...@apache.org.
Merge branch 'master' into COMMONSRDF-46
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/7779fca8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/7779fca8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/7779fca8
Branch: refs/heads/COMMONSRDF-7
Commit: 7779fca802793eabb0f3153e6780152825c7b23b
Parents: 96ca8ac 4f243b3
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 16:49:26 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 16:49:41 2016 +0100
----------------------------------------------------------------------
.travis.yml | 17 +++++++++--------
.../commons/rdf/integrationtests/AllToAllTest.java | 16 +++++++---------
.../commons/rdf/jsonldjava/JsonLdTripleLike.java | 17 +++++++++++++++++
.../rdf/jsonldjava/JsonLdBlankNodeTest.java | 17 +++++++++++++++++
.../apache/commons/rdf/rdf4j/ClosableIterable.java | 17 +++++++++++++++++
5 files changed, 67 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/7779fca8/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
----------------------------------------------------------------------
[06/50] [abbrv] incubator-commonsrdf git commit: Javadoc: @see
RDFFactory for making IRI etc
Posted by st...@apache.org.
Javadoc: @see RDFFactory for making IRI etc
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/9addc8c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/9addc8c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/9addc8c0
Branch: refs/heads/COMMONSRDF-7
Commit: 9addc8c08c991198c2736a8d1f89ddd37fe341e7
Parents: f229c17
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 19 18:07:23 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 19 18:07:23 2016 +0100
----------------------------------------------------------------------
api/src/main/java/org/apache/commons/rdf/api/BlankNodeOrIRI.java | 2 +-
api/src/main/java/org/apache/commons/rdf/api/Dataset.java | 3 +++
api/src/main/java/org/apache/commons/rdf/api/Graph.java | 2 ++
api/src/main/java/org/apache/commons/rdf/api/IRI.java | 2 ++
api/src/main/java/org/apache/commons/rdf/api/Literal.java | 4 ++++
api/src/main/java/org/apache/commons/rdf/api/RDFFactory.java | 1 +
api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java | 2 +-
api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java | 2 +-
8 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9addc8c0/api/src/main/java/org/apache/commons/rdf/api/BlankNodeOrIRI.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/BlankNodeOrIRI.java b/api/src/main/java/org/apache/commons/rdf/api/BlankNodeOrIRI.java
index c15c77d..8999c6f 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/BlankNodeOrIRI.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/BlankNodeOrIRI.java
@@ -19,7 +19,7 @@ package org.apache.commons.rdf.api;
/**
* This interface represents the {@link RDFTerm}s that may be used in the
- * subject position of an RDF-1.1 {@link Triple}, including {@link BlankNode}
+ * subject position of an RDF-1.1 {@link Triple}, that is {@link BlankNode}
* and {@link IRI}.
*/
public interface BlankNodeOrIRI extends RDFTerm {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9addc8c0/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 3b602d3..9e6f6d7 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
@@ -27,6 +27,9 @@ import java.util.stream.Stream;
* 1.1 dataset</a>, a set of RDF quads, as defined by
* <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.
+ *
+ * @since 0.3.0-incubating
+ * @see RDFFactory#createDataset()
*/
public interface Dataset extends AutoCloseable, GraphLike<Quad> {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9addc8c0/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 ff78ec3..ccf9c9d 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
@@ -26,6 +26,8 @@ import java.util.stream.Stream;
* Graph</a>, a set of RDF triples, as defined by <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.
+ *
+ * @see RDFFactory#createGraph()
*/
public interface Graph extends AutoCloseable,GraphLike<Triple> {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9addc8c0/api/src/main/java/org/apache/commons/rdf/api/IRI.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/IRI.java b/api/src/main/java/org/apache/commons/rdf/api/IRI.java
index 76a1407..f3588cb 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/IRI.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/IRI.java
@@ -22,6 +22,8 @@ package org.apache.commons.rdf.api;
* as defined by <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.
+ *
+ * @see RDFFactory#createIRI(String)
*/
public interface IRI extends BlankNodeOrIRI {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9addc8c0/api/src/main/java/org/apache/commons/rdf/api/Literal.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Literal.java b/api/src/main/java/org/apache/commons/rdf/api/Literal.java
index 4c83784..29b7f77 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Literal.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Literal.java
@@ -26,6 +26,10 @@ import java.util.Optional;
* "http://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal" >RDF-1.1
* Concepts and Abstract Syntax</a>, a W3C Recommendation published on 25
* February 2014
+ *
+ * @see RDFFactory#createLiteral(String)
+ * @see RDFFactory#createLiteral(String, IRI)
+ * @see RDFFactory#createLiteral(String, String)
*/
public interface Literal extends RDFTerm {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9addc8c0/api/src/main/java/org/apache/commons/rdf/api/RDFFactory.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFFactory.java b/api/src/main/java/org/apache/commons/rdf/api/RDFFactory.java
index 2e97a03..a116153 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFFactory.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFFactory.java
@@ -34,6 +34,7 @@ import java.util.Locale;
* because an IRI is considered invalid, then it SHOULD throw
* {@link IllegalArgumentException}.
*
+ * @since 0.3.0-incubating
* @see RDFTerm
* @see Graph
* @see Quad
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9addc8c0/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java b/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
index 84e1ca7..541469f 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
@@ -31,7 +31,7 @@ import java.util.Optional;
* and <a href="https://en.wikipedia.org/wiki/TriX_%28syntax%29">TriX</a>.
*
* @see <a href="https://www.w3.org/TR/rdf11-primer/#section-graph-syntax">RDF 1.1 Primer</a>
- *
+ * @see org.apache.commons.rdf.experimental.RDFParser
*/
public enum RDFSyntax {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9addc8c0/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
index 731d7cc..9488338 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
@@ -22,7 +22,7 @@ package org.apache.commons.rdf.api;
* Term</a>, as defined by <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.<br>
- *
+ *
* @see <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-term" >RDF-1.1
* Term</a>
*/
[37/50] [abbrv] incubator-commonsrdf git commit: COMMONSRDF-46 Rename
RDFTermFactory to RDF
Posted by st...@apache.org.
COMMONSRDF-46 Rename RDFTermFactory to RDF
This closes #25
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/f1ea9cd0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/f1ea9cd0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/f1ea9cd0
Branch: refs/heads/COMMONSRDF-7
Commit: f1ea9cd093d7c4cdbbf211dfa99a267e257fbca5
Parents: 6aa5a5d 2d4b5d3
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 28 11:39:57 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 28 11:39:57 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/api/BlankNode.java | 6 +-
.../apache/commons/rdf/api/BlankNodeOrIRI.java | 6 +-
.../org/apache/commons/rdf/api/Dataset.java | 3 +
.../java/org/apache/commons/rdf/api/Graph.java | 2 +
.../java/org/apache/commons/rdf/api/IRI.java | 2 +
.../org/apache/commons/rdf/api/Literal.java | 4 +
.../java/org/apache/commons/rdf/api/Quad.java | 2 +-
.../java/org/apache/commons/rdf/api/RDF.java | 244 ++++++
.../org/apache/commons/rdf/api/RDFSyntax.java | 2 +-
.../org/apache/commons/rdf/api/RDFTerm.java | 13 +-
.../apache/commons/rdf/api/RDFTermFactory.java | 213 +-----
.../java/org/apache/commons/rdf/api/Triple.java | 2 +-
.../apache/commons/rdf/api/package-info.java | 2 +-
.../commons/rdf/experimental/RDFParser.java | 12 +-
.../commons/rdf/api/AbstractBlankNodeTest.java | 8 +
.../commons/rdf/api/AbstractGraphTest.java | 21 +-
.../rdf/api/AbstractRDFTermFactoryTest.java | 505 -------------
.../apache/commons/rdf/api/AbstractRDFTest.java | 334 +++++++++
.../rdf/api/DefaultRDFTermFactoryTest.java | 33 -
examples/src/example/UserGuideTest.java | 10 +-
.../rdf/integrationtests/AllToAllTest.java | 26 +-
.../apache/commons/rdf/jena/JenaFactory.java | 741 ------------------
.../org/apache/commons/rdf/jena/JenaRDF.java | 742 +++++++++++++++++++
.../rdf/jena/experimental/JenaRDFParser.java | 24 +-
.../rdf/jena/impl/AbstractJenaRDFTerm.java | 2 +-
.../commons/rdf/jena/impl/AbstractQuadLike.java | 6 +-
.../rdf/jena/impl/InternalJenaFactory.java | 4 +-
.../commons/rdf/jena/impl/JenaDatasetImpl.java | 14 +-
.../commons/rdf/jena/impl/JenaGraphImpl.java | 12 +-
.../services/org.apache.commons.rdf.api.RDF | 1 +
.../org.apache.commons.rdf.api.RDFTermFactory | 1 -
.../apache/commons/rdf/jena/JenaRDFTest.java | 32 +
.../commons/rdf/jena/JenaServiceLoaderTest.java | 40 +
.../commons/rdf/jena/TestBlankNodeJena.java | 8 +-
.../apache/commons/rdf/jena/TestGraphJena.java | 8 +-
.../jena/TestJenaGraphToCommonsRDFGraph.java | 25 +-
.../commons/rdf/jena/TestRDFParserBuilder.java | 2 +-
.../rdf/jena/TestRDFTermFactoryJena.java | 32 -
.../commons/rdf/jsonldjava/JsonLdBlankNode.java | 1 +
.../commons/rdf/jsonldjava/JsonLdFactory.java | 306 --------
.../commons/rdf/jsonldjava/JsonLdGraphLike.java | 8 +-
.../commons/rdf/jsonldjava/JsonLdQuadLike.java | 2 +-
.../commons/rdf/jsonldjava/JsonLdRDF.java | 309 ++++++++
.../jsonldjava/experimental/JsonLdParser.java | 12 +-
.../commons/rdf/jsonldjava/package-info.java | 2 +-
.../services/org.apache.commons.rdf.api.RDF | 1 +
.../org.apache.commons.rdf.api.RDFTermFactory | 1 -
.../rdf/jsonldjava/JsonLdFactoryTest.java | 54 --
.../commons/rdf/jsonldjava/JsonLdGraphTest.java | 6 +-
.../rdf/jsonldjava/JsonLdParserBuilderTest.java | 2 +-
.../commons/rdf/jsonldjava/JsonLdRDFTest.java | 54 ++
.../rdf/jsonldjava/JsonLdServiceLoaderTest.java | 40 +
.../org/apache/commons/rdf/rdf4j/RDF4J.java | 603 +++++++++++++++
.../commons/rdf/rdf4j/RDF4JBlankNode.java | 2 +-
.../apache/commons/rdf/rdf4j/RDF4JDataset.java | 6 +-
.../apache/commons/rdf/rdf4j/RDF4JFactory.java | 601 ---------------
.../apache/commons/rdf/rdf4j/RDF4JGraph.java | 12 +-
.../org/apache/commons/rdf/rdf4j/RDF4JIRI.java | 2 +-
.../apache/commons/rdf/rdf4j/RDF4JLiteral.java | 2 +-
.../org/apache/commons/rdf/rdf4j/RDF4JQuad.java | 2 +-
.../apache/commons/rdf/rdf4j/RDF4JTriple.java | 2 +-
.../rdf/rdf4j/experimental/RDF4JParser.java | 12 +-
.../rdf4j/impl/AbstractRepositoryGraphLike.java | 6 +-
.../rdf/rdf4j/impl/InternalRDF4JFactory.java | 15 +-
.../commons/rdf/rdf4j/impl/ModelGraphImpl.java | 6 +-
.../apache/commons/rdf/rdf4j/impl/QuadImpl.java | 10 +-
.../commons/rdf/rdf4j/impl/TripleImpl.java | 8 +-
.../apache/commons/rdf/rdf4j/package-info.java | 36 +-
.../services/org.apache.commons.rdf.api.RDF | 1 +
.../apache/commons/rdf/rdf4j/BlankNodeTest.java | 2 +-
.../org/apache/commons/rdf/rdf4j/GraphTest.java | 6 +-
.../commons/rdf/rdf4j/MemoryGraphTest.java | 10 +-
.../rdf/rdf4j/MemoryRDFTermFactoryTest.java | 37 -
.../commons/rdf/rdf4j/MemoryStoreRDFTest.java | 37 +
.../commons/rdf/rdf4j/NativeStoreGraphTest.java | 24 +-
.../rdf/rdf4j/RDF4JServiceLoaderTest.java | 40 +
.../org/apache/commons/rdf/rdf4j/RDF4JTest.java | 37 +
.../rdf/rdf4j/Rdf4JRDFTermFactoryTest.java | 37 -
.../commons/rdf/simple/BlankNodeImpl.java | 8 +-
.../apache/commons/rdf/simple/DatasetImpl.java | 8 +-
.../apache/commons/rdf/simple/GraphImpl.java | 8 +-
.../org/apache/commons/rdf/simple/IRIImpl.java | 2 +-
.../apache/commons/rdf/simple/LiteralImpl.java | 2 +-
.../org/apache/commons/rdf/simple/QuadImpl.java | 2 +-
.../apache/commons/rdf/simple/SimpleRDF.java | 114 +++
.../rdf/simple/SimpleRDFTermFactory.java | 99 +--
.../apache/commons/rdf/simple/TripleImpl.java | 2 +-
.../org/apache/commons/rdf/simple/Types.java | 2 +-
.../simple/experimental/AbstractRDFParser.java | 32 +-
.../apache/commons/rdf/simple/package-info.java | 6 +-
.../services/org.apache.commons.rdf.api.RDF | 1 +
.../org.apache.commons.rdf.api.RDFTermFactory | 2 +-
.../commons/rdf/simple/DefaultGraphTest.java | 51 --
.../rdf/simple/DummyRDFParserBuilder.java | 4 +-
.../commons/rdf/simple/SimpleGraphTest.java | 8 +-
.../SimpleNoRelativeIRIRDFTermFactoryTest.java | 46 --
.../rdf/simple/SimpleNoRelativeIRIRDTest.java | 46 ++
.../simple/SimpleRDFTermFactoryLookupTest.java | 42 --
.../rdf/simple/SimpleRDFTermFactoryTest.java | 33 -
.../commons/rdf/simple/SimpleRDFTest.java | 33 +
.../rdf/simple/SimpleServiceLoaderTest.java | 40 +
.../commons/rdf/simple/TestWritingGraph.java | 6 +-
.../experimental/AbstractRDFParserTest.java | 6 +-
src/site/markdown/userguide.md | 257 ++++---
104 files changed, 3202 insertions(+), 3156 deletions(-)
----------------------------------------------------------------------
[29/50] [abbrv] incubator-commonsrdf git commit: JavaDoc and
'protected' for abstract test methods
Posted by st...@apache.org.
JavaDoc and 'protected' for abstract test methods
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/e340604b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/e340604b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/e340604b
Branch: refs/heads/COMMONSRDF-7
Commit: e340604bb4bd00665494706c7535a34fba59f51e
Parents: 7779fca
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 28 10:55:40 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 28 10:55:40 2016 +0100
----------------------------------------------------------------------
.../apache/commons/rdf/api/AbstractBlankNodeTest.java | 8 ++++++++
.../org/apache/commons/rdf/api/AbstractGraphTest.java | 9 ++++++++-
.../commons/rdf/api/AbstractRDFTermFactoryTest.java | 12 ++++++------
3 files changed, 22 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/e340604b/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java
index 1556a03..b61c64a 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractBlankNodeTest.java
@@ -27,6 +27,14 @@ import static org.junit.Assert.assertNotEquals;
*/
public abstract class AbstractBlankNodeTest {
+ /**
+ * This method must be overridden by the implementing test to
+ * create a {@link BlankNode} to be tested.
+ * <p>
+ * Each call to this method must provide a new, unique BlankNode.
+ *
+ * @return {@link RDF} instance to be tested.
+ */
protected abstract BlankNode getBlankNode();
/**
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/e340604b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
index ba930eb..422e97b 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
@@ -67,7 +67,14 @@ public abstract class AbstractGraphTest {
protected Literal companyName;
protected Triple bobNameTriple;
- public abstract RDF createFactory();
+ /**
+ *
+ * This method must be overridden by the implementing test to provide a
+ * factory for the test to create {@link Graph}, {@link IRI} etc.
+ *
+ * @return {@link RDF} instance to be tested.
+ */
+ protected abstract RDF createFactory();
@Before
public void createGraphAndAdd() {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/e340604b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
index 35eb764..1ef5b6c 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
@@ -42,13 +42,13 @@ public abstract class AbstractRDFTermFactoryTest {
private RDF factory;
/**
- * testCreate a new, distinct {@link RDF} object using the
- * implementation being tested here.
- *
- * @return a new, distinct {@link RDF} object using the
- * implementation being tested here
+ *
+ * This method must be overridden by the implementing test to provide a
+ * factory for the test to create {@link Literal}, {@link IRI} etc.
+ *
+ * @return {@link RDF} instance to be tested.
*/
- public abstract RDF createFactory();
+ protected abstract RDF createFactory();
@Before
public void setUp() {
[05/50] [abbrv] incubator-commonsrdf git commit: RDFFactory
documentation
Posted by st...@apache.org.
RDFFactory documentation
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/f229c171
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/f229c171
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/f229c171
Branch: refs/heads/COMMONSRDF-7
Commit: f229c1711fb70ad934d24b1d7530ecfd5cac5ba3
Parents: 102a9fc
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 19 18:03:24 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 19 18:03:24 2016 +0100
----------------------------------------------------------------------
src/site/markdown/userguide.md | 74 ++++++++++++++++++-------------------
1 file changed, 37 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f229c171/src/site/markdown/userguide.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md
index a18436d..8451ab9 100644
--- a/src/site/markdown/userguide.md
+++ b/src/site/markdown/userguide.md
@@ -28,8 +28,8 @@ Commons RDF [API](apidocs/).
* [RDF concepts](#RDF_concepts)
* [Using Commons RDF from Maven](#Using_Commons_RDF_from_Maven)
* [Creating Commons RDF instances](#Creating_Commons_RDF_instances)
- * [Creating a RDFTermFactory](#Creating_a_RDFTermFactory)
- * [Using a RDFTermFactory](#Using_a_RDFTermFactory)
+ * [Creating a RDFFactory](#Creating_a_RDFFactory)
+ * [Using a RDFFactory](#Using_a_RDFFactory)
* [RDF terms](#RDF_terms)
* [N-Triples string](#N-Triples_string)
* [IRI](#IRI)
@@ -146,25 +146,25 @@ see the [download page](download.html) for the latest version._
To create instances of Commons RDF interfaces like
[`Graph`](apidocs/org/apache/commons/rdf/api/Graph.html) and
[`IRI`](apidocs/org/apache/commons/rdf/api/IRI.html) you will need a
-[RDFTermFactory](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html).
+[RDFFactory](apidocs/org/apache/commons/rdf/api/RDFFactory.html).
-### Creating a RDFTermFactory
+### Creating a RDFFactory
How to get an instance of this factory is implementation-specific, for the
_simple_ implementation, you can construct the
-[SimpleRDFTermFactory](apidocs/org/apache/commons/rdf/simple/SimpleRDFTermFactory.html):
+[SimpleRDFFactory](apidocs/org/apache/commons/rdf/simple/SimpleRDFFactory.html):
```java
import org.apache.commons.rdf.api.*;
-import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
+import org.apache.commons.rdf.simple.SimpleRDFFactory;
// ...
-RDFTermFactory factory = new SimpleRDFTermFactory();
+RDFFactory factory = new SimpleRDFFactory();
```
If you don't want to depend on instantiating a concrete implementation,
you can alternatively use the
[ServiceLoader](http://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html)
-to lookup any `RDFTermFactory` implementations found on the classpath:
+to lookup any `RDFFactory` implementations found on the classpath:
```java
import java.util.Iterator;
@@ -172,16 +172,16 @@ import java.util.ServiceLoader;
import org.apache.commons.rdf.api.*;
// ...
-ServiceLoader<RDFTermFactory> loader = ServiceLoader.load(RDFTermFactory.class);
-Iterator<RDFTermFactory> iterator = loader.iterator();
-RDFTermFactory factory = iterator.next();
+ServiceLoader<RDFFactory> loader = ServiceLoader.load(RDFFactory.class);
+Iterator<RDFFactory> iterator = loader.iterator();
+RDFFactory factory = iterator.next();
```
Note that the `ServiceLoader` approach above might not work well within
split classloader systems like OSGi.
-### Using a RDFTermFactory
+### Using a RDFFactory
Using the factory you can construct
any [RDFTerm](apidocs/org/apache/commons/rdf/api/RDFTerm.html), e.g. to create a
@@ -201,12 +201,12 @@ You can also create a stand-alone [Triple](apidocs/org/apache/commons/rdf/api/Tr
Triple triple = factory.createTriple(aliceBlankNode, nameIri, aliceLiteral);
```
-The [RDFTermFactory](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html) also
+The [RDFFactory](apidocs/org/apache/commons/rdf/api/RDFFactory.html) also
contains more specific variants of some of the methods above, e.g. to create a
typed literal.
Note that for any given implementation, `RDFTerm` instances need not be created
-using a `RDFTermFactory`. More likely, implementation-specific methods might create these
+using a `RDFFactory`. More likely, implementation-specific methods might create these
objects as part of data parsing, storage lookup and queries.
@@ -292,7 +292,7 @@ _predicate_ or _object_ of a [Triple](apidocs/org/apache/commons/rdf/api/Triple.
[Quad](apidocs/org/apache/commons/rdf/api/Quad.html),
where it can also be used a _graph name_.
-To create an `IRI` instance from a `RDFTermFactory`, use [createIRI](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html#createIRI-java.lang.String-):
+To create an `IRI` instance from a `RDFFactory`, use [createIRI](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createIRI-java.lang.String-):
```java
IRI iri = factory.createIRI("http://example.com/alice");
@@ -353,8 +353,8 @@ where it can also be used a _graph name_.
To create a new
[BlankNode](apidocs/org/apache/commons/rdf/api/BlankNode.html) instance from a
-`RDFTermFactory`, use
-[createBlankNode](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html#createBlankNode--):
+`RDFFactory`, use
+[createBlankNode](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createBlankNode--):
```java
BlankNode bnode = factory.createBlankNode();
@@ -377,9 +377,9 @@ System.out.println(bnode.equals(factory.createBlankNode()));
Sometimes it can be beneficial to create a blank node based on a
localized _name_, without needing to keep object references
-to earlier `BlankNode` instances. For that purpose, `RDFTermFactory`
+to earlier `BlankNode` instances. For that purpose, `RDFFactory`
may support the
-[expanded createBlankNode](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html#createBlankNode-java.lang.String-)
+[expanded createBlankNode](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createBlankNode-java.lang.String-)
method:
```java
@@ -408,12 +408,12 @@ System.out.println(b1.equals(factory.createBlankNode("b1")));
```
> `true`
-That means that care should be taken to create a new `RDFTermFactory` if making
+That means that care should be taken to create a new `RDFFactory` if making
"different" blank nodes (e.g. parsed from a different RDF file)
which accidfentally might have the same name:
```java
-System.out.println(b1.equals(new SimpleRDFTermFactory().createBlankNode("b1")));
+System.out.println(b1.equals(new SimpleRDFFactory().createBlankNode("b1")));
```
> `false`
@@ -455,8 +455,8 @@ an _object_ of a [Triple](apidocs/org/apache/commons/rdf/api/Triple.html#getObje
or [Quad](apidocs/org/apache/commons/rdf/api/Quad.html#getObject--)
To create a [Literal](apidocs/org/apache/commons/rdf/api/Literal.html) instance
-from an `RDFTermFactory`, use
-[createLiteral](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html#createLiteral-java.lang.String-):
+from an `RDFFactory`, use
+[createLiteral](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createLiteral-java.lang.String-):
```java
Literal literal = factory.createLiteral("Hello world!");
@@ -515,7 +515,7 @@ literal</a> data type.
To create a literal with any other
[datatype](http://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri) (e.g. `xsd:double`),
then create the datatype `IRI` and pass it to the expanded
-[createLiteral](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html#createLiteral-java.lang.String-org.apache.commons.rdf.api.IRI-):
+[createLiteral](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createLiteral-java.lang.String-org.apache.commons.rdf.api.IRI-):
```java
IRI xsdDouble = factory.createIRI("http://www.w3.org/2001/XMLSchema#double");
@@ -552,7 +552,7 @@ System.out.println(Types.XSD_STRING.equals(literal.getDatatype()));
Literals may be created with an associated
[language tag](http://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string)
-using the expanded [createLiteral](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html#createLiteral-java.lang.String-java.lang.String-):
+using the expanded [createLiteral](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createLiteral-java.lang.String-java.lang.String-):
```java
Literal inSpanish = factory.createLiteral("�Hola, Mundo!", "es");
@@ -610,8 +610,8 @@ RDF 1.1 consists of:
To construct a [Triple](apidocs/org/apache/commons/rdf/api/Triple.html) from a
-`RDFTermFactory`, use
-[createTriple](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html#createTriple-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-):
+`RDFFactory`, use
+[createTriple](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createTriple-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-):
```java
BlankNodeOrIRI subject = factory.createBlankNode();
@@ -700,7 +700,7 @@ Commons RDF represents such statements using the class [Quad](apidocs/org/apache
* The [graph name](apidocs/org/apache/commons/rdf/api/Quad.html#getGraphName--), which is an [IRI](apidocs/org/apache/commons/rdf/api/IRI.html) or a [BlankNode](apidocs/org/apache/commons/rdf/api/BlankNode.html); wrapped as an `java.util.Optional`
-To create a `Quad`, use [createQuad](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html#createQuad-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-):
+To create a `Quad`, use [createQuad](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createQuad-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-):
```
BlankNodeOrIRI graph = factory.createIRI("http://example.com/graph");
@@ -810,7 +810,7 @@ System.out.println(quadAsTriple.equals(otherQuad.asTriple());
> `true`
To create a triple from a quad, you will need to use
-[RDFTermFactory.createQuad](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html#createQuad-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-)
+[RDFFactory.createQuad](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createQuad-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-)
providing the desired graph name:
```
@@ -867,8 +867,8 @@ A [graph](http://www.w3.org/TR/rdf11-concepts/#section-rdf-graph)
is a collection of triples.
To create a [Graph](apidocs/org/apache/commons/rdf/api/Graph.html) instance
-from a `RDFTermFactory`, use
-[createGraph()](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html#createGraph--):
+from a `RDFFactory`, use
+[createGraph()](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createGraph--):
```java
Graph graph = factory.createGraph();
@@ -1037,8 +1037,8 @@ A [dataset](https://www.w3.org/TR/rdf11-concepts/#section-dataset)
is a collection of quads, or if you like, a collection of `Graph`s.
To create a [Dataset](apidocs/org/apache/commons/rdf/api/Dataset.html) instance
-from a `RDFTermFactory`, use
-[createDataset()](apidocs/org/apache/commons/rdf/api/RDFTermFactory.html#createDataset--):
+from a `RDFFactory`, use
+[createDataset()](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createDataset--):
```java
Dataset dataset = factory.createDataset();
@@ -1065,7 +1065,7 @@ dataset.remove(quad);
The convenience method [add(g,s,p,o)](apidocs/org/apache/commons/rdf/api/Dataset.html#add-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-) take an additional `BlankNodeOrIRI` parameter for the
-graph name - matching `RDFTermFactory.createQuad(g,s,p,o)`.
+graph name - matching `RDFFactory.createQuad(g,s,p,o)`.
Note that the expanded pattern methods like [contains(g,s,p,o)](apidocs/org/apache/commons/rdf/api/Dataset.html#contains-java.util.Optional-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-) and
[stream(g,s,p,o)](apidocs/org/apache/commons/rdf/api/Dataset.html#stream-java.util.Optional-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-) uses `null` as a wildcard pattern, and
@@ -1206,7 +1206,7 @@ implementations provided by Commons RDF
Different RDF frameworks might have different mechanisms to retrieve a Commons
RDF objects like `Graph` or `Triple` (e.g. returned from a query).
-Commons RDF provides a `RDFTermFactory` interface as an interoperable
+Commons RDF provides a `RDFFactory` interface as an interoperable
way to create new instances, but does not mandate how the factory
itself should be instantiated (e.g. a factory might be returned for an
open network connection).
@@ -1219,10 +1219,10 @@ RDF interfaces, Commons RDF objects are intended to be cross-compatible. Thus a
client would be able to mix and match objects from multiple implementations:
```java
-import com.example.foo.FooRDFTermFactory;
+import com.example.foo.FooRDFFactory;
import net.example.bar.BarGraph;
-RDFTermFactory fooFactory = new FooRDFTermFactory();
+RDFFactory fooFactory = new FooRDFFactory();
FooGraph g1 = (FooGraph) fooFactory.createGraph();
// Foo-specific load method
g1.load("dataset.ttl");
[19/50] [abbrv] incubator-commonsrdf git commit: Merge branch
'master' into a
Posted by st...@apache.org.
Merge branch 'master' into a
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/44b4b680
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/44b4b680
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/44b4b680
Branch: refs/heads/COMMONSRDF-7
Commit: 44b4b6808d19715006adcc075f749fd57345b965
Parents: 9c191fc 351c296
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Oct 23 03:16:39 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Oct 23 03:16:39 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/rdf4j/RDF4J.java | 22 ++++++++++----------
.../apache/commons/rdf/rdf4j/RDF4JDataset.java | 2 +-
.../apache/commons/rdf/rdf4j/RDF4JGraph.java | 8 +++----
.../rdf/rdf4j/impl/InternalRDF4JFactory.java | 2 +-
.../apache/commons/rdf/rdf4j/package-info.java | 4 ++--
.../commons/rdf/rdf4j/MemoryGraphTest.java | 2 +-
.../commons/rdf/rdf4j/NativeStoreGraphTest.java | 2 +-
7 files changed, 21 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/44b4b680/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
----------------------------------------------------------------------
diff --cc rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
index fb5743b,0000000..7f70c75
mode 100644,000000..100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
@@@ -1,603 -1,0 +1,603 @@@
+/**
+ * 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.rdf4j;
+
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+
+// To avoid confusion, avoid importing
+// classes that are in both
+// commons.rdf and openrdf.model (e.g. IRI, Literal)
+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.Quad;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.RDF;
+import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.api.TripleLike;
+import org.apache.commons.rdf.rdf4j.impl.InternalRDF4JFactory;
+import org.eclipse.rdf4j.model.BNode;
+import org.eclipse.rdf4j.model.Model;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.Statement;
+import org.eclipse.rdf4j.model.Value;
+import org.eclipse.rdf4j.model.ValueFactory;
+import org.eclipse.rdf4j.model.impl.LinkedHashModel;
+import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
+import org.eclipse.rdf4j.repository.Repository;
+import org.eclipse.rdf4j.repository.RepositoryConnection;
+import org.eclipse.rdf4j.repository.sail.SailRepository;
+import org.eclipse.rdf4j.sail.Sail;
+import org.eclipse.rdf4j.sail.memory.MemoryStore;
+
+/**
+ * RDF4J implementation of RDF.
+ * <p>
+ * The {@link #RDF4J()} constructor uses a {@link SimpleValueFactory}
+ * to create corresponding RDF4J {@link Value} instances. Alternatively, this
+ * factory can be constructed with a different {@link ValueFactory} using
+ * {@link #RDF4J(ValueFactory)}.
+ * <p>
+ * {@link #asRDFTerm(Value)} can be used to convert any RDF4J {@link Value} to
+ * an RDFTerm. Note that adapted {@link BNode}s are considered equal if they are
+ * converted with the same {@link RDF4J} instance and have the same
+ * {@link BNode#getID()}.
+ * <p>
+ * {@link #createGraph()} creates a new Graph backed by {@link LinkedHashModel}.
- * To use other models, see {@link #asRDFTermGraph(Model)}.
++ * To use other models, see {@link #asGraph(Model)}.
+ * <p>
+ * To adapt a RDF4J {@link Repository} as a {@link Dataset} or {@link Graph},
- * use {@link #asRDFTermDataset(Repository, Option...)}
++ * use {@link #asDataset(Repository, Option...)}
+ * or
- * {@link #asRDFTermGraph(Repository, Option...)}.
++ * {@link #asGraph(Repository, Option...)}.
+ * <p>
+ * {@link #asTriple(Statement)} can be used to convert a RDF4J {@link Statement}
+ * to a Commons RDF {@link Triple}, and equivalent {@link #asQuad(Statement)} to
+ * convert a {@link Quad}.
+ * <p>
+ * To convert any {@link Triple} or {@link Quad} to to RDF4J {@link Statement},
+ * use {@link #asStatement(TripleLike)}. This recognises previously converted
+ * {@link RDF4JTriple}s and {@link RDF4JQuad}s without re-converting their
+ * {@link RDF4JTripleLike#asStatement()}.
+ * <p>
+ * Likewise, {@link #asValue(RDFTerm)} can be used to convert any Commons RDF
+ * {@link RDFTerm} to a corresponding RDF4J {@link Value}. This recognises
+ * previously converted {@link RDF4JTerm}s without re-converting their
+ * {@link RDF4JTerm#asValue()}.
+ * <p>
+ * For the purpose of {@link BlankNode} equivalence, this factory contains an
+ * internal {@link UUID} salt that is used by adapter methods like
+ * {@link #asQuad(Statement)}, {@link #asTriple(Statement)},
+ * {@link #asRDFTerm(Value)} as well as {@link #createBlankNode(String)}. As
+ * RDF4J {@link BNode} instances from multiple repositories or models may have
+ * the same {@link BNode#getID()}, converting them with the above methods might
+ * cause accidental {@link BlankNode} equivalence. Note that the {@link Graph}
+ * and {@link Dataset} adapter methods like
- * {@link #asRDFTermDataset(Repository, Option...)}
++ * {@link #asDataset(Repository, Option...)}
+ * and
- * {@link #asRDFTermGraph(Repository, Option...)}
++ * {@link #asGraph(Repository, Option...)}
+ * therefore uses a unique {@link RDF4J} internally.
+ *
+ * @see RDF
+ *
+ */
+public final class RDF4J implements RDF {
+
+ /**
+ * InternalRDF4JFactory is deliberately abstract
+ */
+ private static InternalRDF4JFactory rdf4j = new InternalRDF4JFactory() {
+ };
+
+ public enum Option {
+ /**
+ * The Graph/Dataset should include any inferred statements
+ */
+ includeInferred,
+ /**
+ * The graph/dataset should handle {@link Repository#initialize()} (if
+ * needed) and {@link Repository#shutDown()} on {@link Graph#close()} /
+ * {@link Dataset#close()}.
+ */
+ handleInitAndShutdown
+ }
+
+ private final UUID salt;
+
+ private final ValueFactory valueFactory;
+
+ /**
+ * Construct an {@link RDF4J}.
+ *
+ */
+ public RDF4J() {
+ this(SimpleValueFactory.getInstance(), UUID.randomUUID());
+ }
+
+ /**
+ * Construct an {@link RDF4J}.
+ * <p>
+ * This constructor is intended for use with the value factory from
+ * {@link Repository#getValueFactory()} when using
+ * Repository-based graphs and datasets.
+ *
+ * @param valueFactory
+ * The RDF4J {@link ValueFactory} to use
+ */
+ public RDF4J(ValueFactory valueFactory) {
+ this(valueFactory, UUID.randomUUID());
+ }
+
+ /**
+ * Construct an {@link RDF4J}.
+ * <p>
+ * This constructor may be used if reproducible
+ * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable.
+ *
+ * @param salt
+ * An {@link UUID} salt to be used by any created
+ * {@link BlankNode}s for the purpose of
+ * {@link BlankNode#uniqueReference()}
+ */
+ public RDF4J(UUID salt) {
+ this(SimpleValueFactory.getInstance(), salt);
+ }
+ /**
+ * Construct an {@link RDF4J}.
+ * <p>
+ * This constructor may be used if reproducible
+ * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable.
+ *
+ * @param valueFactory
+ * The RDF4J {@link ValueFactory} to use
+ * @param salt
+ * An {@link UUID} salt to be used by any created
+ * {@link BlankNode}s for the purpose of
+ * {@link BlankNode#uniqueReference()}
+ */
+ public RDF4J(ValueFactory valueFactory, UUID salt) {
+ this.valueFactory = valueFactory;
+ this.salt = salt;
+ }
+
+ /**
+ * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Quad}.
+ * <p>
+ * For the purpose of {@link BlankNode} equivalence, this method will use an
+ * internal salt UUID that is unique per instance of
+ * {@link RDF4J}.
+ * <p>
+ * <strong>NOTE:</strong> If combining RDF4J {@link Statement}s multiple
+ * repositories or models, then their {@link BNode}s may have the same
+ * {@link BNode#getID()}, which with this method would become equivalent
+ * according to {@link BlankNode#equals(Object)} and
+ * {@link BlankNode#uniqueReference()}, unless a separate
+ * {@link RDF4J} instance is used per RDF4J repository/model.
+ *
+ * @param statement
+ * The statement to convert
+ * @return A {@link RDF4JQuad} that is equivalent to the statement
+ */
+ public RDF4JQuad asQuad(final Statement statement) {
+ return rdf4j.createQuadImpl(statement, salt);
+ }
+
+ /**
+ *
+ * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
+ * <p>
+ * The value will be of the same kind as the term, e.g. a
+ * {@link org.eclipse.rdf4j.model.BNode} is converted to a
+ * {@link org.apache.commons.rdf.api.BlankNode}, a
+ * {@link org.eclipse.rdf4j.model.IRI} is converted to a
+ * {@link org.apache.commons.rdf.api.IRI} and a
+ * {@link org.eclipse.rdf4j.model.Literal}. is converted to a
+ * {@link org.apache.commons.rdf.api.Literal}
+ * <p>
+ * For the purpose of {@link BlankNode} equivalence, this method will use an
+ * internal salt UUID that is unique per instance of
+ * {@link RDF4J}.
+ * <p>
+ * <strong>NOTE:</strong> If combining RDF4J values from multiple
+ * repositories or models, then their {@link BNode}s may have the same
+ * {@link BNode#getID()}, which with this method would become equivalent
+ * according to {@link BlankNode#equals(Object)} and
+ * {@link BlankNode#uniqueReference()}, unless a separate
+ * {@link RDF4J} instance is used per RDF4J repository/model.
+ *
+ * @param value
+ * The RDF4J {@link Value} to convert.
+ * @return A {@link RDFTerm} that corresponds to the RDF4J value
+ * @throws IllegalArgumentException
+ * if the value is not a BNode, Literal or IRI
+ */
+ public RDF4JTerm asRDFTerm(Value value) {
+ return asRDFTerm(value, salt);
+ }
+
+ /**
+ * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
+ * <p>
+ * The value will be of the same kind as the term, e.g. a
+ * {@link org.eclipse.rdf4j.model.BNode} is converted to a
+ * {@link org.apache.commons.rdf.api.BlankNode}, a
+ * {@link org.eclipse.rdf4j.model.IRI} is converted to a
+ * {@link org.apache.commons.rdf.api.IRI} and a
+ * {@link org.eclipse.rdf4j.model.Literal}. is converted to a
+ * {@link org.apache.commons.rdf.api.Literal}
+ *
+ * @param value
+ * The RDF4J {@link Value} to convert.
+ * @param salt
+ * A {@link UUID} salt to use for uniquely mapping any
+ * {@link BNode}s. The salt should typically be the same for
+ * multiple statements in the same {@link Repository} or
+ * {@link Model} to ensure {@link BlankNode#equals(Object)} and
+ * {@link BlankNode#uniqueReference()} works as intended.
+ * @return A {@link RDFTerm} that corresponds to the RDF4J value
+ * @throws IllegalArgumentException
+ * if the value is not a BNode, Literal or IRI
+ */
+ public static RDF4JTerm asRDFTerm(final Value value, UUID salt) {
+ if (value instanceof BNode) {
+ return rdf4j.createBlankNodeImpl((BNode) value, salt);
+ }
+ if (value instanceof org.eclipse.rdf4j.model.Literal) {
+ return rdf4j.createLiteralImpl((org.eclipse.rdf4j.model.Literal) value);
+ }
+ if (value instanceof org.eclipse.rdf4j.model.IRI) {
+ return rdf4j.createIRIImpl((org.eclipse.rdf4j.model.IRI) value);
+ }
+ throw new IllegalArgumentException("Value is not a BNode, Literal or IRI: " + value.getClass());
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Dataset}.
+ * <p>
+ * Changes to the dataset are reflected in the repository, and vice versa.
+ * <p>
+ * <strong>Note:</strong> Some operations on the {@link RDF4JDataset}
+ * requires the use of try-with-resources to close underlying
+ * {@link RepositoryConnection}s, including
+ * {@link RDF4JDataset#iterate()},
+ * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param options
+ * Zero or more {@link Option}
+ * @return A {@link Dataset} backed by the RDF4J repository.
+ */
- public RDF4JDataset asRDFTermDataset(Repository repository, Option... options) {
++ public RDF4JDataset asDataset(Repository repository, Option... options) {
+ EnumSet<Option> opts = optionSet(options);
+ return rdf4j.createRepositoryDatasetImpl(repository,
+ opts.contains(Option.handleInitAndShutdown),
+ opts.contains(Option.includeInferred));
+ }
+
+ /**
+ * Adapt an RDF4J {@link Model} as a Commons RDF {@link Graph}.
+ * <p>
+ * Changes to the graph are reflected in the model, and vice versa.
+ *
+ * @param model
+ * RDF4J {@link Model} to adapt.
+ * @return Adapted {@link Graph}.
+ */
- public RDF4JGraph asRDFTermGraph(Model model) {
++ public RDF4JGraph asGraph(Model model) {
+ return rdf4j.createModelGraphImpl(model, this);
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
+ * <p>
+ * The graph will only include triples in the default graph (equivalent to
+ * context <code>new Resource[0]{null})</code> in RDF4J).
+ * <p>
+ * Changes to the graph are reflected in the repository, and vice versa.
+ * <p>
+ * <strong>Note:</strong> Some operations on the {@link RDF4JGraph}
+ * requires the use of try-with-resources to close underlying
+ * {@link RepositoryConnection}s, including
+ * {@link RDF4JGraph#iterate()} and
+ * {@link RDF4JGraph#stream()}.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param options
+ * Zero or more {@link Option}
+ * @return A {@link Graph} backed by the RDF4J repository.
+ */
- public RDF4JGraph asRDFTermGraph(Repository repository, Option... options) {
++ public RDF4JGraph asGraph(Repository repository, Option... options) {
+ EnumSet<Option> opts = optionSet(options);
+ return rdf4j.createRepositoryGraphImpl(repository,
+ opts.contains(Option.handleInitAndShutdown),
+ opts.contains(Option.includeInferred),
+ new Resource[]{null}); // default graph
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
+ * <p>
+ * The graph will include triples in any contexts (e.g. the union graph).
+ * <p>
+ * Changes to the graph are reflected in the repository, and vice versa.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param options
+ * Zero or more {@link Option}
+ * @return A union {@link Graph} backed by the RDF4J repository.
+ */
- public RDF4JGraph asRDFTermGraphUnion(Repository repository, Option... options) {
++ public RDF4JGraph asGraphUnion(Repository repository, Option... options) {
+ EnumSet<Option> opts = optionSet(options);
+ return rdf4j.createRepositoryGraphImpl(repository,
+ opts.contains(Option.handleInitAndShutdown),
+ opts.contains(Option.includeInferred),
+ new Resource[]{}); // union graph
+
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
+ * <p>
+ * The graph will include triples in the specified contexts.
+ * <p>
+ * Changes to the graph are reflected in the repository, and vice versa.
+ * Triples added/removed to the graph are reflected in all the specified
+ * contexts.
+ * <p>
+ * <strong>Note:</strong> Some operations on the {@link RDF4JGraph}
+ * requires the use of try-with-resources to close underlying
+ * {@link RepositoryConnection}s, including
+ * {@link RDF4JGraph#iterate()} and
+ * {@link RDF4JGraph#stream()}.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param contexts
+ * A {@link Set} of {@link BlankNodeOrIRI} specifying the graph
+ * names to use as a context. The set may include the value
+ * <code>null</code> to indicate the default graph. The empty set
+ * indicates any context, e.g. the <em>union graph</em>.
+ * @param option
+ * Zero or more {@link Option}s
+ * @return A {@link Graph} backed by the RDF4J repository.
+ */
- public RDF4JGraph asRDFTermGraph(Repository repository, Set<? extends BlankNodeOrIRI> contexts,
++ public RDF4JGraph asGraph(Repository repository, Set<? extends BlankNodeOrIRI> contexts,
+ Option... option) {
+ EnumSet<Option> opts = optionSet(option);
+ /** NOTE: asValue() deliberately CAN handle <code>null</code> */
+ Resource[] resources = contexts.stream().map(g -> (Resource) asValue(g)).toArray(Resource[]::new);
+ return rdf4j.createRepositoryGraphImpl(Objects.requireNonNull(repository),
+ opts.contains(Option.handleInitAndShutdown),
+ opts.contains(Option.includeInferred),
+ resources);
+ }
+
+ /**
+ * Adapt a Commons RDF {@link Triple} or {@link Quad} as a RDF4J
+ * {@link Statement}.
+ * <p>
+ * If the <code>tripleLike</code> argument is an {@link RDF4JTriple} or a
+ * {@link RDF4JQuad}, then its {@link RDF4JTripleLike#asStatement()} is
+ * returned as-is. Note that this means that a {@link RDF4JTriple} would
+ * preserve its {@link Statement#getContext()}, and that any
+ * {@link BlankNode}s would be deemed equivalent in RDF4J if they have the
+ * same {@link BNode#getID()}.
+ *
+ * @param tripleLike
+ * A {@link Triple} or {@link Quad} to adapt
+ * @return A corresponding {@link Statement}
+ */
+ public Statement asStatement(TripleLike tripleLike) {
+ if (tripleLike instanceof RDF4JTripleLike) {
+ // Return original statement - this covers both RDF4JQuad and
+ // RDF4JTriple
+ return ((RDF4JTripleLike) tripleLike).asStatement();
+ }
+
+ org.eclipse.rdf4j.model.Resource subject = (org.eclipse.rdf4j.model.Resource) asValue(tripleLike.getSubject());
+ org.eclipse.rdf4j.model.IRI predicate = (org.eclipse.rdf4j.model.IRI) asValue(tripleLike.getPredicate());
+ Value object = asValue(tripleLike.getObject());
+
+ org.eclipse.rdf4j.model.Resource context = null;
+ if (tripleLike instanceof Quad) {
+ Quad quad = (Quad) tripleLike;
+ context = (org.eclipse.rdf4j.model.Resource) asValue(quad.getGraphName().orElse(null));
+ }
+
+ return getValueFactory().createStatement(subject, predicate, object, context);
+ }
+
+ /**
+ * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Triple}.
+ * <p>
+ * For the purpose of {@link BlankNode} equivalence, this method will use an
+ * internal salt UUID that is unique per instance of
+ * {@link RDF4J}.
+ * <p>
+ * <strong>NOTE:</strong> If combining RDF4J statements from multiple
+ * repositories or models, then their {@link BNode}s may have the same
+ * {@link BNode#getID()}, which with this method would become equivalent
+ * according to {@link BlankNode#equals(Object)} and
+ * {@link BlankNode#uniqueReference()}, unless a separate
+ * {@link RDF4J} instance is used per RDF4J repository/model.
+ *
+ * @param statement
+ * The RDF4J {@link Statement} to adapt.
+ * @return A {@link RDF4JTriple} that is equivalent to the statement
+ */
+ public RDF4JTriple asTriple(final Statement statement) {
+ return rdf4j.createTripleImpl(statement, salt);
+ }
+
+ /**
+ * Adapt a Commons RDF {@link RDFTerm} as a RDF4J {@link Value}.
+ * <p>
+ * The value will be of the same kind as the term, e.g. a
+ * {@link org.apache.commons.rdf.api.BlankNode} is converted to a
+ * {@link org.eclipse.rdf4j.model.BNode}, a
+ * {@link org.apache.commons.rdf.api.IRI} is converted to a
+ * {@link org.eclipse.rdf4j.model.IRI} and a
+ * {@link org.apache.commons.rdf.api.Literal} is converted to a
+ * {@link org.eclipse.rdf4j.model.Literal}.
+ * <p>
+ * If the provided {@link RDFTerm} is <code>null</code>, then the returned
+ * value is <code>null</code>.
+ * <p>
+ * If the provided term is an instance of {@link RDF4JTerm}, then the
+ * {@link RDF4JTerm#asValue()} is returned without any conversion. Note that
+ * this could mean that a {@link Value} from a different kind of
+ * {@link ValueFactory} could be returned.
+ *
+ * @param term
+ * RDFTerm to adapt to RDF4J Value
+ * @return Adapted RDF4J {@link Value}
+ */
+ public Value asValue(RDFTerm term) {
+ if (term == null) {
+ return null;
+ }
+ if (term instanceof RDF4JTerm) {
+ // One of our own - avoid converting again.
+ // (This is crucial to avoid double-escaping in BlankNode)
+ return ((RDF4JTerm) term).asValue();
+ }
+ if (term instanceof org.apache.commons.rdf.api.IRI) {
+ org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) term;
+ return getValueFactory().createIRI(iri.getIRIString());
+ }
+ if (term instanceof org.apache.commons.rdf.api.Literal) {
+ org.apache.commons.rdf.api.Literal literal = (org.apache.commons.rdf.api.Literal) term;
+ String label = literal.getLexicalForm();
+ if (literal.getLanguageTag().isPresent()) {
+ String lang = literal.getLanguageTag().get();
+ return getValueFactory().createLiteral(label, lang);
+ }
+ org.eclipse.rdf4j.model.IRI dataType = (org.eclipse.rdf4j.model.IRI) asValue(literal.getDatatype());
+ return getValueFactory().createLiteral(label, dataType);
+ }
+ if (term instanceof BlankNode) {
+ // This is where it gets tricky to support round trips!
+ BlankNode blankNode = (BlankNode) term;
+ // FIXME: The uniqueReference might not be a valid BlankNode
+ // identifier..
+ // does it have to be in RDF4J?
+ return getValueFactory().createBNode(blankNode.uniqueReference());
+ }
+ throw new IllegalArgumentException("RDFTerm was not an IRI, Literal or BlankNode: " + term.getClass());
+ }
+
+ @Override
+ public RDF4JBlankNode createBlankNode() {
+ BNode bnode = getValueFactory().createBNode();
+ return (RDF4JBlankNode) asRDFTerm(bnode);
+ }
+
+ @Override
+ public RDF4JBlankNode createBlankNode(String name) {
+ BNode bnode = getValueFactory().createBNode(name);
+ return (RDF4JBlankNode) asRDFTerm(bnode);
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * <strong>Note:</strong> Some operations on the {@link RDF4JDataset}
+ * requires the use of try-with-resources to close underlying
+ * {@link RepositoryConnection}s, including
+ * {@link RDF4JDataset#iterate()},
+ * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}.
+ *
+ */
+ @Override
+ public RDF4JDataset createDataset() {
+ Sail sail = new MemoryStore();
+ Repository repository = new SailRepository(sail);
+ return rdf4j.createRepositoryDatasetImpl(repository, true, false);
+ }
+
+ @Override
+ public RDF4JGraph createGraph() {
- return asRDFTermGraph(new LinkedHashModel());
++ return asGraph(new LinkedHashModel());
+ }
+
+ @Override
+ public RDF4JIRI createIRI(String iri) throws IllegalArgumentException {
+ return (RDF4JIRI) asRDFTerm(getValueFactory().createIRI(iri));
+ }
+
+ @Override
+ public RDF4JLiteral createLiteral(String lexicalForm)
+ throws IllegalArgumentException {
+ org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm);
+ return (RDF4JLiteral) asRDFTerm(lit);
+ }
+
+ @Override
+ public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, org.apache.commons.rdf.api.IRI dataType)
+ throws IllegalArgumentException {
+ org.eclipse.rdf4j.model.IRI iri = getValueFactory().createIRI(dataType.getIRIString());
+ org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, iri);
+ return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit);
+ }
+
+ @Override
+ public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, String languageTag)
+ throws IllegalArgumentException {
+ org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, languageTag);
+ return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit);
+ }
+
+ @Override
+ public RDF4JTriple createTriple(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object)
+ throws IllegalArgumentException {
+ final Statement statement = getValueFactory().createStatement(
+ (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate),
+ asValue(object));
+ return asTriple(statement);
+ }
+
+ @Override
+ public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate,
+ RDFTerm object) throws IllegalArgumentException {
+ final Statement statement = getValueFactory().createStatement(
+ (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate),
+ asValue(object), (org.eclipse.rdf4j.model.Resource) asValue(graphName));
+ return asQuad(statement);
+ }
+
+ public ValueFactory getValueFactory() {
+ return valueFactory;
+ }
+
+ private EnumSet<Option> optionSet(Option... options) {
+ EnumSet<Option> opts = EnumSet.noneOf(Option.class);
+ opts.addAll(Arrays.asList(options));
+ return opts;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/44b4b680/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
----------------------------------------------------------------------
diff --cc rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
index 28c2659,87803fa..fb54a09
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
@@@ -30,8 -30,8 +30,8 @@@ import org.apache.commons.rdf.api.RDFTe
/**
* Marker interface for RDF4J implementations of Dataset.
*
- * @see RDF4JFactory#createDataset()
- * @see RDF4JFactory#asDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)
+ * @see RDF4J#createDataset()
- * @see RDF4J#asRDFTermDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...)
++ * @see RDF4J#asDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)
*/
public interface RDF4JDataset extends Dataset, RDF4JGraphLike<Quad> {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/44b4b680/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
----------------------------------------------------------------------
diff --cc rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
index 68978ce,70edd3f..d1ab485
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
@@@ -33,10 -33,10 +33,10 @@@ import org.eclipse.rdf4j.repository.Rep
/**
* Marker interface for RDF4J implementations of Graph.
*
- * @see RDF4JFactory#createGraph()
- * @see RDF4JFactory#asGraph(Model)
- * @see RDF4JFactory#asGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)
- * @see RDF4JFactory#asGraphUnion(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)
+ * @see RDF4J#createGraph()
- * @see RDF4J#asRDFTermGraph(Model)
- * @see RDF4J#asRDFTermGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...)
- * @see RDF4J#asRDFTermGraphUnion(Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...)
++ * @see RDF4J#asGraph(Model)
++ * @see RDF4J#asGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)
++ * @see RDF4J#asGraphUnion(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)
* @see RDF4JDataset#getGraph()
* @see RDF4JDataset#getGraph(BlankNodeOrIRI)
*/
@@@ -64,7 -64,7 +64,7 @@@ public interface RDF4JGraph extends Gra
* Note that the context mask itself cannot be <code>null</code>.
* <p>
* The returned set is an immutable copy; to specify a different mask, use
- * {@link RDF4J#asRDFTermGraph(Repository, Set, org.apache.commons.rdf.rdf4j.RDF4J.Option...)}
- * {@link RDF4JFactory#asGraph(Repository, Set, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)}
++ * {@link RDF4J#asGraph(Repository, Set, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)}
*
* @return The context mask as a set of {@link BlankNodeOrIRI} graph names, which
* may contain the value <code>null</code>.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/44b4b680/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
----------------------------------------------------------------------
diff --cc rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
index b1cd419,b43c15f..ca97472
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
@@@ -42,10 -42,10 +42,10 @@@ import org.eclipse.rdf4j.repository.Rep
* <p>
* <strong>Internal class:</strong> This "abstract" class is intended for
* internal use by Commons RDF and may change in any minor update. Use instead
- * {@link RDF4JFactory} methods like
- * {@link RDF4JFactory#createBlankNode()},
- * {@link RDF4JFactory#asRDFTerm(org.eclipse.rdf4j.model.Value)} and
- * {@link RDF4JFactory#asGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)}
+ * {@link RDF4J} methods like
+ * {@link RDF4J#createBlankNode()},
+ * {@link RDF4J#asRDFTerm(org.eclipse.rdf4j.model.Value)} and
- * {@link RDF4J#asRDFTermGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...)}
++ * {@link RDF4J#asGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)}
* <p>
* This class exists as a <code>public</code> bridge between the packages
* {@link org.apache.commons.rdf.rdf4j} and
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/44b4b680/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
----------------------------------------------------------------------
diff --cc rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
index 51556bc,1d5e677..dbccdb3
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
@@@ -32,9 -32,9 +32,9 @@@
* {@link org.eclipse.rdf4j.repository.Repository} instances can be adapted to
* Commons RDF {@link org.apache.commons.rdf.api.Graph} and
* {@link org.apache.commons.rdf.api.Dataset}, e.g. using
- * {@link org.apache.commons.rdf.rdf4j.RDF4J#asRDFTermGraph(org.eclipse.rdf4j.model.Model)}
- * {@link org.apache.commons.rdf.rdf4j.RDF4JFactory#asGraph(org.eclipse.rdf4j.model.Model)}
++ * {@link org.apache.commons.rdf.rdf4j.RDF4J#asGraph(org.eclipse.rdf4j.model.Model)}
* or
- * {@link org.apache.commons.rdf.rdf4j.RDF4J#asRDFTermDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...)}
- * {@link org.apache.commons.rdf.rdf4j.RDF4JFactory#asDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)}
++ * {@link org.apache.commons.rdf.rdf4j.RDF4J#asDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)}
* The returned adapted graph/dataset is directly mapped, so changes are
* propagated both ways. For convenience, the marker interface
* {@link org.apache.commons.rdf.rdf4j.RDF4JGraph} and
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/44b4b680/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/44b4b680/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
----------------------------------------------------------------------
diff --cc rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
index 3697069,ccabf72..7e43068
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
@@@ -59,15 -57,9 +59,15 @@@ public class NativeStoreGraphTest exten
public RDF4JGraph createGraph() {
// We re-use the repository connection, but use a different context every time
Set<RDF4JBlankNode> context = Collections.singleton(rdf4jFactory.createBlankNode());
- return rdf4jFactory.asRDFTermGraph(getRepository(), context);
+ return rdf4jFactory.asGraph(getRepository(), context);
}
-
+ @Override
+ public Dataset createDataset() {
+ throw new UnsupportedOperationException("Can't create more than one Dataset in this test");
+ // ...as the below would re-use the same repository:
+ //return rdf4jFactory.asRDFTermDataset(getRepository());
+ }
+
// Delegate methods
public RDF4JBlankNode createBlankNode() {
return rdf4jFactory.createBlankNode();
[42/50] [abbrv] incubator-commonsrdf git commit: Reformat tab ->
spaces
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
index 64f877a..213f412 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
@@ -40,270 +40,280 @@ import com.github.jsonldjava.core.RDFDataset.Node;
*/
public final class JsonLdRDF implements RDF {
- final String bnodePrefix;
+ final String bnodePrefix;
- public JsonLdRDF() {
- // An "outside Graph" bnodePrefix
- this("urn:uuid:" + UUID.randomUUID() + "#b");
- }
+ public JsonLdRDF() {
+ // An "outside Graph" bnodePrefix
+ this("urn:uuid:" + UUID.randomUUID() + "#b");
+ }
- JsonLdRDF(String bnodePrefix) {
- this.bnodePrefix = Objects.requireNonNull(bnodePrefix);
- }
+ JsonLdRDF(String bnodePrefix) {
+ this.bnodePrefix = Objects.requireNonNull(bnodePrefix);
+ }
- /**
- * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Dataset}.
- * <p>
- * Changes to the Commons RDF {@link Dataset} are reflected in the JsonLd
- * {@link RDFDataset} and vice versa.
- *
- * @see #asGraph(RDFDataset)
- * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
- * @return Adapted {@link Dataset}
- */
- public JsonLdDataset asDataset(RDFDataset rdfDataSet) {
- return new JsonLdDatasetImpl(rdfDataSet);
- }
+ /**
+ * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Dataset}.
+ * <p>
+ * Changes to the Commons RDF {@link Dataset} are reflected in the JsonLd
+ * {@link RDFDataset} and vice versa.
+ *
+ * @see #asGraph(RDFDataset)
+ * @param rdfDataSet
+ * JsonLd {@link RDFDataset} to adapt
+ * @return Adapted {@link Dataset}
+ */
+ public JsonLdDataset asDataset(RDFDataset rdfDataSet) {
+ return new JsonLdDatasetImpl(rdfDataSet);
+ }
- /**
- * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Graph}.
- * <p>
- * Only triples in the <em>default graph</em> are included. To retrieve
- * any other graph, {@link #asDataset(RDFDataset)} together with
- * {@link Dataset#getGraph(BlankNodeOrIRI)}.
- * <p>
- * Changes to the Commons RDF {@link Graph} are reflected in the JsonLd
- * {@link RDFDataset} and vice versa.
- *
- * @see #asDataset(RDFDataset)
- * @see #asUnionGraph(RDFDataset)
- * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
- * @return Adapted {@link Graph} covering the <em>default graph</em>
- */
- public JsonLdGraph asGraph(RDFDataset rdfDataSet) {
- return new JsonLdGraphImpl(rdfDataSet);
- }
+ /**
+ * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Graph}.
+ * <p>
+ * Only triples in the <em>default graph</em> are included. To retrieve any
+ * other graph, {@link #asDataset(RDFDataset)} together with
+ * {@link Dataset#getGraph(BlankNodeOrIRI)}.
+ * <p>
+ * Changes to the Commons RDF {@link Graph} are reflected in the JsonLd
+ * {@link RDFDataset} and vice versa.
+ *
+ * @see #asDataset(RDFDataset)
+ * @see #asUnionGraph(RDFDataset)
+ * @param rdfDataSet
+ * JsonLd {@link RDFDataset} to adapt
+ * @return Adapted {@link Graph} covering the <em>default graph</em>
+ */
+ public JsonLdGraph asGraph(RDFDataset rdfDataSet) {
+ return new JsonLdGraphImpl(rdfDataSet);
+ }
- public Node asJsonLdNode(RDFTerm term) {
- if (term instanceof JsonLdBlankNode) {
- JsonLdBlankNode jsonLdBlankNode = (JsonLdBlankNode) term;
- if (jsonLdBlankNode.uniqueReference().startsWith(bnodePrefix)) {
- // Only return blank nodes 'as is' if they have the same prefix
- return jsonLdBlankNode.asJsonLdNode();
- }
- } else if (term instanceof JsonLdTerm) {
- // non-Bnodes can always be return as-is
- return ((JsonLdTerm) term).asJsonLdNode();
- }
- if (term instanceof IRI) {
- return new RDFDataset.IRI(((IRI) term).getIRIString());
- }
- if (term instanceof BlankNode) {
- String ref = ((BlankNode) term).uniqueReference();
- if (ref.startsWith(bnodePrefix)) {
- // one of our own (but no longer a JsonLdBlankNode),
- // we can recover the label after our unique prefix
- return new RDFDataset.BlankNode(ref.replace(bnodePrefix, ""));
- }
- // The "foreign" unique reference might not be a valid bnode string,
- // we'll convert to a UUID
- UUID uuid = UUID.nameUUIDFromBytes(ref.getBytes(StandardCharsets.UTF_8));
- return new RDFDataset.BlankNode("_:" + uuid);
- }
- if (term instanceof Literal) {
- Literal literal = (Literal) term;
- return new RDFDataset.Literal(literal.getLexicalForm(), literal.getDatatype().getIRIString(),
- literal.getLanguageTag().orElse(null));
- }
- throw new IllegalArgumentException("RDFTerm not instanceof IRI, BlankNode or Literal: " + term);
- }
+ public Node asJsonLdNode(RDFTerm term) {
+ if (term instanceof JsonLdBlankNode) {
+ JsonLdBlankNode jsonLdBlankNode = (JsonLdBlankNode) term;
+ if (jsonLdBlankNode.uniqueReference().startsWith(bnodePrefix)) {
+ // Only return blank nodes 'as is' if they have the same prefix
+ return jsonLdBlankNode.asJsonLdNode();
+ }
+ } else if (term instanceof JsonLdTerm) {
+ // non-Bnodes can always be return as-is
+ return ((JsonLdTerm) term).asJsonLdNode();
+ }
+ if (term instanceof IRI) {
+ return new RDFDataset.IRI(((IRI) term).getIRIString());
+ }
+ if (term instanceof BlankNode) {
+ String ref = ((BlankNode) term).uniqueReference();
+ if (ref.startsWith(bnodePrefix)) {
+ // one of our own (but no longer a JsonLdBlankNode),
+ // we can recover the label after our unique prefix
+ return new RDFDataset.BlankNode(ref.replace(bnodePrefix, ""));
+ }
+ // The "foreign" unique reference might not be a valid bnode string,
+ // we'll convert to a UUID
+ UUID uuid = UUID.nameUUIDFromBytes(ref.getBytes(StandardCharsets.UTF_8));
+ return new RDFDataset.BlankNode("_:" + uuid);
+ }
+ if (term instanceof Literal) {
+ Literal literal = (Literal) term;
+ return new RDFDataset.Literal(literal.getLexicalForm(), literal.getDatatype().getIRIString(),
+ literal.getLanguageTag().orElse(null));
+ }
+ throw new IllegalArgumentException("RDFTerm not instanceof IRI, BlankNode or Literal: " + term);
+ }
- /**
- * Adapt a Commons RDF {@link org.apache.commons.rdf.api.Quad} as a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}.
- *
- * @param quad Commons RDF {@link org.apache.commons.rdf.api.Quad} to adapt
- * @return Adapted JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}
- */
- public RDFDataset.Quad asJsonLdQuad(org.apache.commons.rdf.api.Quad quad) {
- BlankNodeOrIRI g = quad.getGraphName().orElse(null);
- return createJsonLdQuad(g, quad.getSubject(), quad.getPredicate(), quad.getObject());
- }
-
- /**
- * Adapt a Commons RDF {@link Triple} as a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}.
- *
- * @param triple Commons RDF {@link Triple} to adapt
- * @return Adapted JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}
- */
- public RDFDataset.Quad asJsonLdQuad(Triple triple) {
- return createJsonLdQuad(null, triple.getSubject(), triple.getPredicate(), triple.getObject());
- }
+ /**
+ * Adapt a Commons RDF {@link org.apache.commons.rdf.api.Quad} as a JsonLd
+ * {@link com.github.jsonldjava.core.RDFDataset.Quad}.
+ *
+ * @param quad
+ * Commons RDF {@link org.apache.commons.rdf.api.Quad} to adapt
+ * @return Adapted JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}
+ */
+ public RDFDataset.Quad asJsonLdQuad(org.apache.commons.rdf.api.Quad quad) {
+ BlankNodeOrIRI g = quad.getGraphName().orElse(null);
+ return createJsonLdQuad(g, quad.getSubject(), quad.getPredicate(), quad.getObject());
+ }
- /**
- * Adapt a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} as a Commons RDF
- * {@link org.apache.commons.rdf.api.Quad}.
- * <p>
- * The underlying JsonLd quad can be retrieved with
- * {@link JsonLdQuad#asJsonLdQuad()}.
- *
- * @param quad
- * A JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} to adapt
- * @return Adapted {@link JsonLdQuad}
- */
- public JsonLdQuad asQuad(final RDFDataset.Quad quad) {
- return new JsonLdQuadImpl(quad, bnodePrefix);
- }
+ /**
+ * Adapt a Commons RDF {@link Triple} as a JsonLd
+ * {@link com.github.jsonldjava.core.RDFDataset.Quad}.
+ *
+ * @param triple
+ * Commons RDF {@link Triple} to adapt
+ * @return Adapted JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad}
+ */
+ public RDFDataset.Quad asJsonLdQuad(Triple triple) {
+ return createJsonLdQuad(null, triple.getSubject(), triple.getPredicate(), triple.getObject());
+ }
- /**
- * Adapt a JsonLd {@link Node} as a Commons RDF {@link RDFTerm}.
- * <p>
- * The underlying node can be retrieved with
- * {@link JsonLdTerm#asJsonLdNode()}.
- *
- * @param node
- * A JsonLd {@link Node} to adapt
- * @return Adapted {@link JsonLdTerm}
- */
- public JsonLdTerm asRDFTerm(final Node node) {
- return asRDFTerm(node, bnodePrefix);
- }
+ /**
+ * Adapt a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} as a
+ * Commons RDF {@link org.apache.commons.rdf.api.Quad}.
+ * <p>
+ * The underlying JsonLd quad can be retrieved with
+ * {@link JsonLdQuad#asJsonLdQuad()}.
+ *
+ * @param quad
+ * A JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} to
+ * adapt
+ * @return Adapted {@link JsonLdQuad}
+ */
+ public JsonLdQuad asQuad(final RDFDataset.Quad quad) {
+ return new JsonLdQuadImpl(quad, bnodePrefix);
+ }
- /**
- * Adapt a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} as a Commons RDF
- * {@link org.apache.commons.rdf.api.Triple}.
- * <p>
- * The underlying JsonLd quad can be retrieved with
- * {@link JsonLdTriple#asJsonLdQuad()}.
- *
- * @param quad
- * A JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} to adapt
- * @return Adapted {@link JsonLdTriple}
- */
- public JsonLdTriple asTriple(final RDFDataset.Quad quad) {
- return new JsonLdTripleImpl(quad, bnodePrefix);
- }
+ /**
+ * Adapt a JsonLd {@link Node} as a Commons RDF {@link RDFTerm}.
+ * <p>
+ * The underlying node can be retrieved with
+ * {@link JsonLdTerm#asJsonLdNode()}.
+ *
+ * @param node
+ * A JsonLd {@link Node} to adapt
+ * @return Adapted {@link JsonLdTerm}
+ */
+ public JsonLdTerm asRDFTerm(final Node node) {
+ return asRDFTerm(node, bnodePrefix);
+ }
- /**
- * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Graph}.
- * <p>
- * The graph can be seen as a <em>union graph</em> as it will contains all the
- * triples across all the graphs of the underlying {@link RDFDataset}.
- * <p>
- * Note that some triple operations on a union graph
- * can be inefficient as they need to remove any duplicate
- * triples across the graphs.
- * <p>
- * Changes to the Commons RDF {@link Graph} are reflected in the JsonLd
- * {@link RDFDataset} and vice versa. Triples removed from the graph are
- * removed from <strong>all</strong> graphs, while triples added
- * are added to the <em>default graph</em>.
- *
- * @param rdfDataSet JsonLd {@link RDFDataset} to adapt
- * @return Adapted {@link Dataset}
- */
- public JsonLdUnionGraph asUnionGraph(RDFDataset rdfDataSet) {
- return new JsonLdUnionGraphImpl(rdfDataSet);
- }
+ /**
+ * Adapt a JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} as a
+ * Commons RDF {@link org.apache.commons.rdf.api.Triple}.
+ * <p>
+ * The underlying JsonLd quad can be retrieved with
+ * {@link JsonLdTriple#asJsonLdQuad()}.
+ *
+ * @param quad
+ * A JsonLd {@link com.github.jsonldjava.core.RDFDataset.Quad} to
+ * adapt
+ * @return Adapted {@link JsonLdTriple}
+ */
+ public JsonLdTriple asTriple(final RDFDataset.Quad quad) {
+ return new JsonLdTripleImpl(quad, bnodePrefix);
+ }
- @Override
- public JsonLdBlankNode createBlankNode() {
- String id = "_:" + UUID.randomUUID().toString();
- return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
- }
+ /**
+ * Adapt a JsonLd {@link RDFDataset} as a Commons RDF {@link Graph}.
+ * <p>
+ * The graph can be seen as a <em>union graph</em> as it will contains all
+ * the triples across all the graphs of the underlying {@link RDFDataset}.
+ * <p>
+ * Note that some triple operations on a union graph can be inefficient as
+ * they need to remove any duplicate triples across the graphs.
+ * <p>
+ * Changes to the Commons RDF {@link Graph} are reflected in the JsonLd
+ * {@link RDFDataset} and vice versa. Triples removed from the graph are
+ * removed from <strong>all</strong> graphs, while triples added are added
+ * to the <em>default graph</em>.
+ *
+ * @param rdfDataSet
+ * JsonLd {@link RDFDataset} to adapt
+ * @return Adapted {@link Dataset}
+ */
+ public JsonLdUnionGraph asUnionGraph(RDFDataset rdfDataSet) {
+ return new JsonLdUnionGraphImpl(rdfDataSet);
+ }
- @Override
- public JsonLdBlankNode createBlankNode(String name) {
- String id = "_:" + name;
- // TODO: Check if name is valid JSON-LD BlankNode identifier
- return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
- }
+ @Override
+ public JsonLdBlankNode createBlankNode() {
+ String id = "_:" + UUID.randomUUID().toString();
+ return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
+ }
- @Override
- public JsonLdDataset createDataset() {
- return new JsonLdDatasetImpl(bnodePrefix);
- }
+ @Override
+ public JsonLdBlankNode createBlankNode(String name) {
+ String id = "_:" + name;
+ // TODO: Check if name is valid JSON-LD BlankNode identifier
+ return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
+ }
- @Override
- public JsonLdGraph createGraph() {
- return new JsonLdGraphImpl(bnodePrefix);
- }
+ @Override
+ public JsonLdDataset createDataset() {
+ return new JsonLdDatasetImpl(bnodePrefix);
+ }
- @Override
- public JsonLdIRI createIRI(String iri) {
- return new JsonLdIRIImpl(iri);
- }
+ @Override
+ public JsonLdGraph createGraph() {
+ return new JsonLdGraphImpl(bnodePrefix);
+ }
- @Override
- public JsonLdLiteral createLiteral(String literal) {
- return new JsonLdLiteralImpl(new RDFDataset.Literal(literal, null, null));
- }
+ @Override
+ public JsonLdIRI createIRI(String iri) {
+ return new JsonLdIRIImpl(iri);
+ }
- @Override
- public JsonLdLiteral createLiteral(String literal, IRI dataType) {
- return new JsonLdLiteralImpl(new RDFDataset.Literal(literal, dataType.getIRIString(), null));
- }
+ @Override
+ public JsonLdLiteral createLiteral(String literal) {
+ return new JsonLdLiteralImpl(new RDFDataset.Literal(literal, null, null));
+ }
- @Override
- public JsonLdLiteral createLiteral(String literal, String language) {
- return new JsonLdLiteralImpl(new RDFDataset.Literal(literal, Types.RDF_LANGSTRING.getIRIString(), language));
- }
+ @Override
+ public JsonLdLiteral createLiteral(String literal, IRI dataType) {
+ return new JsonLdLiteralImpl(new RDFDataset.Literal(literal, dataType.getIRIString(), null));
+ }
- @Override
- public JsonLdQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
- throws IllegalArgumentException, UnsupportedOperationException {
- return new JsonLdQuadImpl(createJsonLdQuad(graphName, subject, predicate, object), bnodePrefix);
- }
+ @Override
+ public JsonLdLiteral createLiteral(String literal, String language) {
+ return new JsonLdLiteralImpl(new RDFDataset.Literal(literal, Types.RDF_LANGSTRING.getIRIString(), language));
+ }
- @Override
- public JsonLdTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return new JsonLdTripleImpl(createJsonLdQuad(null, subject, predicate, object), bnodePrefix);
- }
+ @Override
+ public JsonLdQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws IllegalArgumentException, UnsupportedOperationException {
+ return new JsonLdQuadImpl(createJsonLdQuad(graphName, subject, predicate, object), bnodePrefix);
+ }
- String asJsonLdString(BlankNodeOrIRI blankNodeOrIRI) {
- if (blankNodeOrIRI == null) {
- return null;
- }
- if (blankNodeOrIRI instanceof IRI) {
- return ((IRI)blankNodeOrIRI).getIRIString();
- } else if (blankNodeOrIRI instanceof BlankNode) {
- BlankNode blankNode = (BlankNode) blankNodeOrIRI;
- String ref = blankNode.uniqueReference();
- if (ref.startsWith(bnodePrefix)) {
- // One of ours (but possibly not a JsonLdBlankNode) -
- // we can use the suffix directly
- return ref.replace(bnodePrefix, "_:");
- } else {
- // Map to unique bnode identifier, e.g. _:0dbd92ee-ab1a-45e7-bba2-7ade54f87ec5
- UUID uuid = UUID.nameUUIDFromBytes(ref.getBytes(StandardCharsets.UTF_8));
- return "_:"+ uuid;
- }
- } else {
- throw new IllegalArgumentException("Expected a BlankNode or IRI, not: " + blankNodeOrIRI);
- }
- }
+ @Override
+ public JsonLdTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return new JsonLdTripleImpl(createJsonLdQuad(null, subject, predicate, object), bnodePrefix);
+ }
- JsonLdTerm asRDFTerm(final Node node, String blankNodePrefix) {
- if (node == null) {
- return null; // e.g. default graph
- }
- if (node.isIRI()) {
- return new JsonLdIRIImpl(node);
- } else if (node.isBlankNode()) {
- return new JsonLdBlankNodeImpl(node, blankNodePrefix);
- } else if (node.isLiteral()) {
- // TODO: Our own JsonLdLiteral
- if (node.getLanguage() != null) {
- return createLiteral(node.getValue(), node.getLanguage());
- } else {
- return createLiteral(node.getValue(), createIRI(node.getDatatype()));
- }
- } else {
- throw new IllegalArgumentException("Node is neither IRI, BlankNode nor Literal: " + node);
- }
- }
+ String asJsonLdString(BlankNodeOrIRI blankNodeOrIRI) {
+ if (blankNodeOrIRI == null) {
+ return null;
+ }
+ if (blankNodeOrIRI instanceof IRI) {
+ return ((IRI) blankNodeOrIRI).getIRIString();
+ } else if (blankNodeOrIRI instanceof BlankNode) {
+ BlankNode blankNode = (BlankNode) blankNodeOrIRI;
+ String ref = blankNode.uniqueReference();
+ if (ref.startsWith(bnodePrefix)) {
+ // One of ours (but possibly not a JsonLdBlankNode) -
+ // we can use the suffix directly
+ return ref.replace(bnodePrefix, "_:");
+ } else {
+ // Map to unique bnode identifier, e.g.
+ // _:0dbd92ee-ab1a-45e7-bba2-7ade54f87ec5
+ UUID uuid = UUID.nameUUIDFromBytes(ref.getBytes(StandardCharsets.UTF_8));
+ return "_:" + uuid;
+ }
+ } else {
+ throw new IllegalArgumentException("Expected a BlankNode or IRI, not: " + blankNodeOrIRI);
+ }
+ }
- RDFDataset.Quad createJsonLdQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return new RDFDataset.Quad(asJsonLdNode(subject), asJsonLdNode(predicate), asJsonLdNode(object), asJsonLdString(graphName));
- }
+ JsonLdTerm asRDFTerm(final Node node, String blankNodePrefix) {
+ if (node == null) {
+ return null; // e.g. default graph
+ }
+ if (node.isIRI()) {
+ return new JsonLdIRIImpl(node);
+ } else if (node.isBlankNode()) {
+ return new JsonLdBlankNodeImpl(node, blankNodePrefix);
+ } else if (node.isLiteral()) {
+ // TODO: Our own JsonLdLiteral
+ if (node.getLanguage() != null) {
+ return createLiteral(node.getValue(), node.getLanguage());
+ } else {
+ return createLiteral(node.getValue(), createIRI(node.getDatatype()));
+ }
+ } else {
+ throw new IllegalArgumentException("Node is neither IRI, BlankNode nor Literal: " + node);
+ }
+ }
+
+ RDFDataset.Quad createJsonLdQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return new RDFDataset.Quad(asJsonLdNode(subject), asJsonLdNode(predicate), asJsonLdNode(object),
+ asJsonLdString(graphName));
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTerm.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTerm.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTerm.java
index 62138d2..722f440 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTerm.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTerm.java
@@ -22,23 +22,23 @@ import org.apache.commons.rdf.api.RDFTerm;
import com.github.jsonldjava.core.RDFDataset.Node;
public interface JsonLdTerm extends RDFTerm {
-
- /**
- * Return the underlying JsonLd {@link Node}.
- *
- * @return JsonLd {@link Node}
- */
- Node asJsonLdNode();
+
+ /**
+ * Return the underlying JsonLd {@link Node}.
+ *
+ * @return JsonLd {@link Node}
+ */
+ Node asJsonLdNode();
}
-
- abstract class JsonLdTermImpl implements JsonLdTerm {
- final Node node;
- JsonLdTermImpl(Node node) {
- this.node = node;
- }
- public Node asJsonLdNode() {
- return node;
- }
- }
-
+abstract class JsonLdTermImpl implements JsonLdTerm {
+ final Node node;
+
+ JsonLdTermImpl(Node node) {
+ this.node = node;
+ }
+
+ public Node asJsonLdNode() {
+ return node;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTriple.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTriple.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTriple.java
index 906e240..de880a8 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTriple.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTriple.java
@@ -28,29 +28,26 @@ import com.github.jsonldjava.core.RDFDataset.Quad;
public interface JsonLdTriple extends Triple, JsonLdTripleLike {
+}
+
+final class JsonLdTripleImpl extends JsonLdQuadLikeImpl<BlankNodeOrIRI, IRI, RDFTerm, RDFTerm> implements JsonLdTriple {
+
+ JsonLdTripleImpl(Quad quad, String blankNodePrefix) {
+ super(quad, blankNodePrefix);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Triple)) {
+ return false;
+ }
+ Triple other = (Triple) obj;
+ return getSubject().equals(other.getSubject()) && getPredicate().equals(other.getPredicate())
+ && getObject().equals(other.getObject());
+ }
+ @Override
+ public int hashCode() {
+ return Objects.hash(getSubject(), getPredicate(), getObject());
+ }
}
-
- final class JsonLdTripleImpl extends JsonLdQuadLikeImpl<BlankNodeOrIRI, IRI, RDFTerm, RDFTerm>
- implements JsonLdTriple {
-
- JsonLdTripleImpl(Quad quad, String blankNodePrefix) {
- super(quad, blankNodePrefix);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (! (obj instanceof Triple)) {
- return false;
- }
- Triple other = (Triple) obj;
- return getSubject().equals(other.getSubject()) &&
- getPredicate().equals(other.getPredicate()) &&
- getObject().equals(other.getObject());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(getSubject(), getPredicate(), getObject());
- }
- }
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTripleLike.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTripleLike.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTripleLike.java
index 8004a02..521beb1 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTripleLike.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdTripleLike.java
@@ -21,11 +21,12 @@ import org.apache.commons.rdf.api.TripleLike;
public interface JsonLdTripleLike extends TripleLike {
- /**
- * Return the underlying JsonLD {@link com.github.jsonldjava.core.RDFDataset.Quad}
- *
- * @return The JsonLD {@link com.github.jsonldjava.core.RDFDataset.Quad}
- */
- public com.github.jsonldjava.core.RDFDataset.Quad asJsonLdQuad();
+ /**
+ * Return the underlying JsonLD
+ * {@link com.github.jsonldjava.core.RDFDataset.Quad}
+ *
+ * @return The JsonLD {@link com.github.jsonldjava.core.RDFDataset.Quad}
+ */
+ public com.github.jsonldjava.core.RDFDataset.Quad asJsonLdQuad();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java
index b27e66a..5fafefd 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdUnionGraph.java
@@ -34,85 +34,80 @@ import com.github.jsonldjava.core.RDFDataset;
* A union graph contains all the triples of the dataset, irregardless of their
* graph names.
* <p>
- * {@link #add(Triple)} and {@link #add(BlankNodeOrIRI, IRI, RDFTerm)}
- * will add the triple to the default graph
- * (e.g. <code>@default</code> in JSON-LD), while
- * the remaining methods (including
- * {@link #remove(Triple)} or {@link #remove(BlankNodeOrIRI, IRI, RDFTerm)})
- * relate to triples from <strong>all</strong> graphs.
+ * {@link #add(Triple)} and {@link #add(BlankNodeOrIRI, IRI, RDFTerm)} will add
+ * the triple to the default graph (e.g. <code>@default</code> in JSON-LD),
+ * while the remaining methods (including {@link #remove(Triple)} or
+ * {@link #remove(BlankNodeOrIRI, IRI, RDFTerm)}) relate to triples from
+ * <strong>all</strong> graphs.
* <p>
- * <strong>Note:</strong>
- * Some operations like {@link #stream()} and {@link #size()} are
- * inefficient as they skip any duplicate triples from multiple
- * graphs.
+ * <strong>Note:</strong> Some operations like {@link #stream()} and
+ * {@link #size()} are inefficient as they skip any duplicate triples from
+ * multiple graphs.
*/
public interface JsonLdUnionGraph extends JsonLdGraphLike<org.apache.commons.rdf.api.Triple>, Graph {
}
-class JsonLdUnionGraphImpl extends AbstractJsonLdGraphLike<org.apache.commons.rdf.api.Triple> implements JsonLdUnionGraph {
-
- JsonLdUnionGraphImpl(String bnodePrefix) {
- super(bnodePrefix);
- }
-
- JsonLdUnionGraphImpl(RDFDataset rdfDataSet) {
- super(rdfDataSet);
- }
-
- JsonLdUnionGraphImpl(RDFDataset rdfDataSet, String bnodePrefix) {
- super(rdfDataSet, bnodePrefix);
- }
-
-
- @Override
- public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- super.add(null, subject, predicate, object);
- }
-
- @Override
- public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return super.contains(null, subject, predicate, object);
- }
-
- @Override
- public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- super.remove(null, subject, predicate, object);
- }
-
- @Override
- public void remove(Triple t) {
- // Remove from ALL graphs, not just default graph
- super.remove(null, t.getSubject(), t.getPredicate(), t.getObject());
- }
-
- @Override
- public Stream<JsonLdTriple> stream(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) {
- return filteredGraphs(null)
- .flatMap(List::stream)
- .filter(quadFilter(subject, predicate, object))
- .map(factory::asTriple)
- // Make sure we don't have duplicate triples
- // NOTE: This can be quite inefficient
- .distinct();
- }
-
- @Override
- public Stream<? extends Triple> stream() {
- // NOTE: inefficient as we have to remove duplicate triples
- // in different graphs :-(
- return super.stream().distinct();
- }
-
- @Override
- JsonLdTriple asTripleOrQuad(com.github.jsonldjava.core.RDFDataset.Quad jsonldQuad) {
- return factory.asTriple(jsonldQuad);
- }
-
- @Override
- public long size() {
- // Note: Our specialized stream() already removes duplicates using .distinct()
- return stream().count();
- }
-}
+class JsonLdUnionGraphImpl extends AbstractJsonLdGraphLike<org.apache.commons.rdf.api.Triple>
+ implements JsonLdUnionGraph {
+
+ JsonLdUnionGraphImpl(String bnodePrefix) {
+ super(bnodePrefix);
+ }
+
+ JsonLdUnionGraphImpl(RDFDataset rdfDataSet) {
+ super(rdfDataSet);
+ }
+
+ JsonLdUnionGraphImpl(RDFDataset rdfDataSet, String bnodePrefix) {
+ super(rdfDataSet, bnodePrefix);
+ }
+
+ @Override
+ public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ super.add(null, subject, predicate, object);
+ }
+
+ @Override
+ public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return super.contains(null, subject, predicate, object);
+ }
+ @Override
+ public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ super.remove(null, subject, predicate, object);
+ }
+
+ @Override
+ public void remove(Triple t) {
+ // Remove from ALL graphs, not just default graph
+ super.remove(null, t.getSubject(), t.getPredicate(), t.getObject());
+ }
+
+ @Override
+ public Stream<JsonLdTriple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return filteredGraphs(null).flatMap(List::stream).filter(quadFilter(subject, predicate, object))
+ .map(factory::asTriple)
+ // Make sure we don't have duplicate triples
+ // NOTE: This can be quite inefficient
+ .distinct();
+ }
+
+ @Override
+ public Stream<? extends Triple> stream() {
+ // NOTE: inefficient as we have to remove duplicate triples
+ // in different graphs :-(
+ return super.stream().distinct();
+ }
+
+ @Override
+ JsonLdTriple asTripleOrQuad(com.github.jsonldjava.core.RDFDataset.Quad jsonldQuad) {
+ return factory.asTriple(jsonldQuad);
+ }
+
+ @Override
+ public long size() {
+ // Note: Our specialized stream() already removes duplicates using
+ // .distinct()
+ return stream().count();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java
index ff3ffe8..1e6d3ec 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java
@@ -43,118 +43,118 @@ import com.github.jsonldjava.utils.JsonUtils;
public class JsonLdParser extends AbstractRDFParser<JsonLdParser> {
- @Override
- protected JsonLdRDF createRDFTermFactory() {
- return new JsonLdRDF();
- }
+ @Override
+ protected JsonLdRDF createRDFTermFactory() {
+ return new JsonLdRDF();
+ }
- @Override
- public JsonLdParser contentType(RDFSyntax rdfSyntax) throws IllegalArgumentException {
- if (rdfSyntax != null && rdfSyntax != RDFSyntax.JSONLD) {
- throw new IllegalArgumentException("Unsupported contentType: " + rdfSyntax);
- }
- return super.contentType(rdfSyntax);
- }
-
- @Override
- public JsonLdParser contentType(String contentType) throws IllegalArgumentException {
- JsonLdParser c = (JsonLdParser) super.contentType(contentType);
- if (c.getContentType().filter(Predicate.isEqual(RDFSyntax.JSONLD).negate()).isPresent()) {
- throw new IllegalArgumentException("Unsupported contentType: " + contentType);
- }
- return c;
- }
+ @Override
+ public JsonLdParser contentType(RDFSyntax rdfSyntax) throws IllegalArgumentException {
+ if (rdfSyntax != null && rdfSyntax != RDFSyntax.JSONLD) {
+ throw new IllegalArgumentException("Unsupported contentType: " + rdfSyntax);
+ }
+ return super.contentType(rdfSyntax);
+ }
- private static URL asURL(IRI iri) throws IllegalStateException {
- try {
- return new URI(iri.getIRIString()).toURL();
- } catch (MalformedURLException | URISyntaxException e) {
- throw new IllegalStateException("Invalid URL: " + iri.getIRIString());
- }
- }
-
- @Override
- protected void checkSource() throws IOException {
- super.checkSource();
- // Might throw IllegalStateException if invalid
- getSourceIri().map(JsonLdParser::asURL);
- }
-
- @Override
- protected void parseSynchronusly() throws IOException {
- Object json = readSource();
- JsonLdOptions options = new JsonLdOptions();
- getBase().map(IRI::getIRIString).ifPresent(options::setBase);
- // TODO: base from readSource() (after redirection and Content-Location header)
- // should be forwarded
+ @Override
+ public JsonLdParser contentType(String contentType) throws IllegalArgumentException {
+ JsonLdParser c = (JsonLdParser) super.contentType(contentType);
+ if (c.getContentType().filter(Predicate.isEqual(RDFSyntax.JSONLD).negate()).isPresent()) {
+ throw new IllegalArgumentException("Unsupported contentType: " + contentType);
+ }
+ return c;
+ }
- // TODO: Modify JsonLdProcessor to accept the target RDFDataset
- RDFDataset rdfDataset;
- try {
- rdfDataset = (RDFDataset) JsonLdProcessor.toRDF(json, options);
- } catch (JsonLdError e) {
- throw new IOException("Could not parse Json-LD", e);
- }
- if (getTargetGraph().isPresent()) {
- Graph intoGraph = getTargetGraph().get();
- if (intoGraph instanceof JsonLdGraph && ! intoGraph.contains(null, null, null)) {
- // Empty graph, we can just move over the map content directly:
- JsonLdGraph jsonLdGraph = (JsonLdGraph) intoGraph;
- jsonLdGraph.getRdfDataSet().putAll(rdfDataset);
- return;
- // otherwise we have to merge as normal
- }
- // TODO: Modify JsonLdProcessor to have an actual triple callback
- Graph parsedGraph = getJsonLdFactory().asGraph(rdfDataset);
- // sequential() as we don't know if destination is thread safe :-/
- parsedGraph.stream().sequential().forEach(intoGraph::add);
- } else if (getTargetDataset().isPresent()) {
- Dataset intoDataset = getTargetDataset().get();
- if (intoDataset instanceof JsonLdDataset &&
- ! intoDataset.contains(null, null, null, null)) {
- JsonLdDataset jsonLdDataset = (JsonLdDataset) intoDataset;
- // Empty - we can just do a brave replace!
- jsonLdDataset.getRdfDataSet().putAll(rdfDataset);
- return;
- // otherwise we have to merge.. but also avoid duplicate triples,
- // map blank nodes etc, so we'll fall back to normal Dataset appending.
- }
- Dataset fromDataset = getJsonLdFactory().asDataset(rdfDataset);
- // .sequential() as we don't know if destination is thread-safe :-/
- fromDataset.stream().sequential().forEach(intoDataset::add);
- } else {
- Dataset fromDataset = getJsonLdFactory().asDataset(rdfDataset);
- // No need for .sequential() here
- fromDataset.stream().forEach(getTarget());
- }
- }
-
- private JsonLdRDF getJsonLdFactory() {
- if (getRdfTermFactory().isPresent() && getRdfTermFactory().get() instanceof JsonLdRDF) {
- return (JsonLdRDF) getRdfTermFactory().get();
- }
- return createRDFTermFactory();
- }
+ private static URL asURL(IRI iri) throws IllegalStateException {
+ try {
+ return new URI(iri.getIRIString()).toURL();
+ } catch (MalformedURLException | URISyntaxException e) {
+ throw new IllegalStateException("Invalid URL: " + iri.getIRIString());
+ }
+ }
- private Object readSource() throws IOException {
- // Due to checked IOException we can't easily
- // do this with .map and .orElseGet()
-
- if (getSourceInputStream().isPresent()) {
- return JsonUtils.fromInputStream(getSourceInputStream().get());
- }
- if (getSourceIri().isPresent()) {
- // TODO: propagate @base from content
- return JsonUtils.fromURL(asURL(getSourceIri().get()),
- JsonUtils.getDefaultHttpClient());
- }
- if (getSourceFile().isPresent()) {
- try (InputStream inputStream = Files.newInputStream(getSourceFile().get())){
- return JsonUtils.fromInputStream(inputStream);
- }
- }
- throw new IllegalStateException("No known source found");
- }
+ @Override
+ protected void checkSource() throws IOException {
+ super.checkSource();
+ // Might throw IllegalStateException if invalid
+ getSourceIri().map(JsonLdParser::asURL);
+ }
-}
+ @Override
+ protected void parseSynchronusly() throws IOException {
+ Object json = readSource();
+ JsonLdOptions options = new JsonLdOptions();
+ getBase().map(IRI::getIRIString).ifPresent(options::setBase);
+ // TODO: base from readSource() (after redirection and Content-Location
+ // header)
+ // should be forwarded
+
+ // TODO: Modify JsonLdProcessor to accept the target RDFDataset
+ RDFDataset rdfDataset;
+ try {
+ rdfDataset = (RDFDataset) JsonLdProcessor.toRDF(json, options);
+ } catch (JsonLdError e) {
+ throw new IOException("Could not parse Json-LD", e);
+ }
+ if (getTargetGraph().isPresent()) {
+ Graph intoGraph = getTargetGraph().get();
+ if (intoGraph instanceof JsonLdGraph && !intoGraph.contains(null, null, null)) {
+ // Empty graph, we can just move over the map content directly:
+ JsonLdGraph jsonLdGraph = (JsonLdGraph) intoGraph;
+ jsonLdGraph.getRdfDataSet().putAll(rdfDataset);
+ return;
+ // otherwise we have to merge as normal
+ }
+ // TODO: Modify JsonLdProcessor to have an actual triple callback
+ Graph parsedGraph = getJsonLdFactory().asGraph(rdfDataset);
+ // sequential() as we don't know if destination is thread safe :-/
+ parsedGraph.stream().sequential().forEach(intoGraph::add);
+ } else if (getTargetDataset().isPresent()) {
+ Dataset intoDataset = getTargetDataset().get();
+ if (intoDataset instanceof JsonLdDataset && !intoDataset.contains(null, null, null, null)) {
+ JsonLdDataset jsonLdDataset = (JsonLdDataset) intoDataset;
+ // Empty - we can just do a brave replace!
+ jsonLdDataset.getRdfDataSet().putAll(rdfDataset);
+ return;
+ // otherwise we have to merge.. but also avoid duplicate
+ // triples,
+ // map blank nodes etc, so we'll fall back to normal Dataset
+ // appending.
+ }
+ Dataset fromDataset = getJsonLdFactory().asDataset(rdfDataset);
+ // .sequential() as we don't know if destination is thread-safe :-/
+ fromDataset.stream().sequential().forEach(intoDataset::add);
+ } else {
+ Dataset fromDataset = getJsonLdFactory().asDataset(rdfDataset);
+ // No need for .sequential() here
+ fromDataset.stream().forEach(getTarget());
+ }
+ }
+
+ private JsonLdRDF getJsonLdFactory() {
+ if (getRdfTermFactory().isPresent() && getRdfTermFactory().get() instanceof JsonLdRDF) {
+ return (JsonLdRDF) getRdfTermFactory().get();
+ }
+ return createRDFTermFactory();
+ }
+ private Object readSource() throws IOException {
+ // Due to checked IOException we can't easily
+ // do this with .map and .orElseGet()
+
+ if (getSourceInputStream().isPresent()) {
+ return JsonUtils.fromInputStream(getSourceInputStream().get());
+ }
+ if (getSourceIri().isPresent()) {
+ // TODO: propagate @base from content
+ return JsonUtils.fromURL(asURL(getSourceIri().get()), JsonUtils.getDefaultHttpClient());
+ }
+ if (getSourceFile().isPresent()) {
+ try (InputStream inputStream = Files.newInputStream(getSourceFile().get())) {
+ return JsonUtils.fromInputStream(inputStream);
+ }
+ }
+ throw new IllegalStateException("No known source found");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/package-info.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/package-info.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/package-info.java
index 67de964..e0a587e 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/package-info.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/package-info.java
@@ -18,17 +18,14 @@
/**
* Experimental Commons RDF JSONLD-Java implementations.
* <p>
- * Classes in this package should be considered <strong>at
- * risk</strong>; they might change or be removed in the next minor update of
- * Commons RDF.
+ * Classes in this package should be considered <strong>at risk</strong>; they
+ * might change or be removed in the next minor update of Commons RDF.
* <p>
* When a class has stabilized, it will move to the
* {@link org.apache.commons.rdf.jsonldjava} package.
* <ul>
- * <li>{@link JsonLdParser} - an JSONLD-Java-backed
- * implementations of
- * {@link org.apache.commons.rdf.experimental.RDFParser}.
- * </li>
+ * <li>{@link JsonLdParser} - an JSONLD-Java-backed implementations of
+ * {@link org.apache.commons.rdf.experimental.RDFParser}.</li>
* </ul>
*/
package org.apache.commons.rdf.jsonldjava.experimental;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/resources/test.jsonld
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/resources/test.jsonld b/jsonld-java/src/main/resources/test.jsonld
index cc10bdb..f5227d7 100644
--- a/jsonld-java/src/main/resources/test.jsonld
+++ b/jsonld-java/src/main/resources/test.jsonld
@@ -17,10 +17,10 @@
"pred3": 1337,
"pred4": { "@id": "http://example.com/graph",
"@graph": [
- { "@id": "http://example.com/test",
- "pred1": "Other value",
- "pred2": "http://example.com/graph"
- }
+ { "@id": "http://example.com/test",
+ "pred1": "Other value",
+ "pred2": "http://example.com/graph"
+ }
]
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNodeTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNodeTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNodeTest.java
index 1af375a..fce0893 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNodeTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNodeTest.java
@@ -26,16 +26,16 @@ import com.github.jsonldjava.core.RDFDataset;
public class JsonLdBlankNodeTest extends AbstractBlankNodeTest {
- String fixedPrefix = "urn:uuid:d028ca89-8b2f-4e18-90a0-8959f955038d#";
-
- @Override
- protected BlankNode getBlankNode() {
- return getBlankNode(UUID.randomUUID().toString());
- }
-
- @Override
- protected BlankNode getBlankNode(String identifier) {
- return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode("_:" + identifier), fixedPrefix);
- }
+ String fixedPrefix = "urn:uuid:d028ca89-8b2f-4e18-90a0-8959f955038d#";
+
+ @Override
+ protected BlankNode getBlankNode() {
+ return getBlankNode(UUID.randomUUID().toString());
+ }
+
+ @Override
+ protected BlankNode getBlankNode(String identifier) {
+ return new JsonLdBlankNodeImpl(new RDFDataset.BlankNode("_:" + identifier), fixedPrefix);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java
index 64e94e5..e63e43d 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java
@@ -22,10 +22,9 @@ import org.apache.commons.rdf.api.RDF;
public class JsonLdGraphTest extends AbstractGraphTest {
- @Override
- public RDF createFactory() {
- return new JsonLdRDF();
- }
-
+ @Override
+ public RDF createFactory() {
+ return new JsonLdRDF();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java
index 6cdb841..d6cda65 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java
@@ -36,92 +36,70 @@ import org.apache.commons.rdf.jsonldjava.experimental.JsonLdParser;
import org.apache.commons.rdf.simple.Types;
import org.junit.Test;
-public class JsonLdParserBuilderTest {
- private static final String TEST_JSONLD = "/test.jsonld";
-
- static JsonLdRDF factory = new JsonLdRDF();
- IRI test = factory.createIRI("http://example.com/test");
- IRI Type = factory.createIRI("http://example.com/Type");
- IRI type = factory.createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
- IRI pred1 = factory.createIRI("http://example.com/pred1");
- IRI pred2 = factory.createIRI("http://example.com/pred2");
- IRI pred3 = factory.createIRI("http://example.com/pred3");
- IRI pred4 = factory.createIRI("http://example.com/pred4");
- IRI other = factory.createIRI("http://example.com/other");
- IRI graph = factory.createIRI("http://example.com/graph");
+public class JsonLdParserBuilderTest {
+ private static final String TEST_JSONLD = "/test.jsonld";
-
-
- @Test
- public void parseByUrl() throws Exception {
- URL url = getClass().getResource(TEST_JSONLD);
- assertNotNull("Test resource not found: " + TEST_JSONLD, url);
- IRI iri = factory.createIRI(url.toString());
- Graph g = factory.createGraph();
- new JsonLdParser()
- .contentType(RDFSyntax.JSONLD)
- .source(iri)
- .target(g)
- .parse()
- .get(10, TimeUnit.SECONDS);
- checkGraph(g);
- }
+ static JsonLdRDF factory = new JsonLdRDF();
+ IRI test = factory.createIRI("http://example.com/test");
+ IRI Type = factory.createIRI("http://example.com/Type");
+ IRI type = factory.createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
+ IRI pred1 = factory.createIRI("http://example.com/pred1");
+ IRI pred2 = factory.createIRI("http://example.com/pred2");
+ IRI pred3 = factory.createIRI("http://example.com/pred3");
+ IRI pred4 = factory.createIRI("http://example.com/pred4");
+ IRI other = factory.createIRI("http://example.com/other");
+ IRI graph = factory.createIRI("http://example.com/graph");
- @Test
- public void parseByPath() throws Exception {
- Path path = Files.createTempFile("test", ".jsonld");
- path.toFile().deleteOnExit();
- try (InputStream is = getClass().getResourceAsStream(TEST_JSONLD)) {
- assertNotNull("Test resource not found: " + TEST_JSONLD, is);
- Files.copy(is, path, StandardCopyOption.REPLACE_EXISTING);
- }
- Graph g = factory.createGraph();
- new JsonLdParser()
- .contentType(RDFSyntax.JSONLD)
- .source(path)
- .target(g)
- .parse()
- .get(10, TimeUnit.SECONDS);
- checkGraph(g);
- }
-
- @Test
- public void parseByStream() throws Exception {
- Graph g = factory.createGraph();
- try (InputStream is = getClass().getResourceAsStream(TEST_JSONLD)) {
- assertNotNull("Test resource not found: " + TEST_JSONLD, is);
- new JsonLdParser()
- .base("http://example.com/base/")
- .contentType(RDFSyntax.JSONLD).source(is)
- .target(g)
- .parse()
- .get(10, TimeUnit.SECONDS);
- }
- checkGraph(g);
- }
-
-
- private void checkGraph(Graph g) {
- assertTrue(g.contains(test, type, Type));
- // Should not include statements from the named graph
-
- assertEquals(1, g.stream(test, pred1, null).count());
- assertEquals(1, g.stream(test, pred2, null).count());
-
- assertEquals("Hello",
- ((Literal) g.stream(test, pred1, null)
- .findFirst().get().getObject() ).getLexicalForm());
- assertTrue(g.contains(test, pred2, other));
-
- assertEquals("1337",
- ((Literal) g.stream(test, pred3, null)
- .findFirst().get().getObject() ).getLexicalForm());
- assertEquals(Types.XSD_INTEGER,
- ((Literal) g.stream(test, pred3, null)
- .findFirst().get().getObject() ).getDatatype());
-
- // While the named graph 'graph' is not included, the relationship
- // to that @id is included.
- assertTrue(g.contains(test, pred4, graph));
- }
+ @Test
+ public void parseByUrl() throws Exception {
+ URL url = getClass().getResource(TEST_JSONLD);
+ assertNotNull("Test resource not found: " + TEST_JSONLD, url);
+ IRI iri = factory.createIRI(url.toString());
+ Graph g = factory.createGraph();
+ new JsonLdParser().contentType(RDFSyntax.JSONLD).source(iri).target(g).parse().get(10, TimeUnit.SECONDS);
+ checkGraph(g);
+ }
+
+ @Test
+ public void parseByPath() throws Exception {
+ Path path = Files.createTempFile("test", ".jsonld");
+ path.toFile().deleteOnExit();
+ try (InputStream is = getClass().getResourceAsStream(TEST_JSONLD)) {
+ assertNotNull("Test resource not found: " + TEST_JSONLD, is);
+ Files.copy(is, path, StandardCopyOption.REPLACE_EXISTING);
+ }
+ Graph g = factory.createGraph();
+ new JsonLdParser().contentType(RDFSyntax.JSONLD).source(path).target(g).parse().get(10, TimeUnit.SECONDS);
+ checkGraph(g);
+ }
+
+ @Test
+ public void parseByStream() throws Exception {
+ Graph g = factory.createGraph();
+ try (InputStream is = getClass().getResourceAsStream(TEST_JSONLD)) {
+ assertNotNull("Test resource not found: " + TEST_JSONLD, is);
+ new JsonLdParser().base("http://example.com/base/").contentType(RDFSyntax.JSONLD).source(is).target(g)
+ .parse().get(10, TimeUnit.SECONDS);
+ }
+ checkGraph(g);
+ }
+
+ private void checkGraph(Graph g) {
+ assertTrue(g.contains(test, type, Type));
+ // Should not include statements from the named graph
+
+ assertEquals(1, g.stream(test, pred1, null).count());
+ assertEquals(1, g.stream(test, pred2, null).count());
+
+ assertEquals("Hello", ((Literal) g.stream(test, pred1, null).findFirst().get().getObject()).getLexicalForm());
+ assertTrue(g.contains(test, pred2, other));
+
+ assertEquals("1337", ((Literal) g.stream(test, pred3, null).findFirst().get().getObject()).getLexicalForm());
+ assertEquals(Types.XSD_INTEGER,
+ ((Literal) g.stream(test, pred3, null).findFirst().get().getObject()).getDatatype());
+
+ // While the named graph 'graph' is not included, the relationship
+ // to that @id is included.
+ assertTrue(g.contains(test, pred4, graph));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java
index 99c0771..b5e8a0b 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java
@@ -24,31 +24,31 @@ import org.junit.Test;
public class JsonLdRDFTest extends AbstractRDFTest {
- @Override
- public RDF createFactory() {
- return new JsonLdRDF();
- }
-
- // TODO: Add support for checking for invalid lang/iri/blanknode IDs
- @Ignore("JSONLD-Java does not validate lang strings")
- @Test
- @Override
- public void testInvalidLiteralLang() throws Exception {
- super.testInvalidLiteralLang();
- }
-
- @Ignore("JSONLD-Java does not validate IRIs")
- @Test
- @Override
- public void testInvalidIRI() throws Exception {
- super.testInvalidIRI();
- }
-
- @Ignore("JSONLD-Java does not validate blanknode identifiers")
- @Test
- @Override
- public void testPossiblyInvalidBlankNode() throws Exception {
- // TODO: Fix blank node in ntriplesString()
- super.testPossiblyInvalidBlankNode();
- }
+ @Override
+ public RDF createFactory() {
+ return new JsonLdRDF();
+ }
+
+ // TODO: Add support for checking for invalid lang/iri/blanknode IDs
+ @Ignore("JSONLD-Java does not validate lang strings")
+ @Test
+ @Override
+ public void testInvalidLiteralLang() throws Exception {
+ super.testInvalidLiteralLang();
+ }
+
+ @Ignore("JSONLD-Java does not validate IRIs")
+ @Test
+ @Override
+ public void testInvalidIRI() throws Exception {
+ super.testInvalidIRI();
+ }
+
+ @Ignore("JSONLD-Java does not validate blanknode identifiers")
+ @Test
+ @Override
+ public void testPossiblyInvalidBlankNode() throws Exception {
+ // TODO: Fix blank node in ntriplesString()
+ super.testPossiblyInvalidBlankNode();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
index dd44586..e23fc3d 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
@@ -31,10 +31,10 @@ public class JsonLdServiceLoaderTest {
public void testServiceLoaderLookup() {
ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class);
for (RDF impl : loader) {
- if (impl instanceof JsonLdRDF) {
- return; // yay
- }
+ if (impl instanceof JsonLdRDF) {
+ return; // yay
+ }
}
- fail("JsonLdRDF not found in ServiceLoader");
+ fail("JsonLdRDF not found in ServiceLoader");
}
- }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/ClosableIterable.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/ClosableIterable.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/ClosableIterable.java
index e8c6ad5..d888b0a 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/ClosableIterable.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/ClosableIterable.java
@@ -21,18 +21,17 @@ package org.apache.commons.rdf.rdf4j;
* An {@link Iterable} which should be {@link #close()}d after use.
* <p>
* A good pattern to use this iterator is with an outer try-with-resources
- * block:
- * <code>
+ * block: <code>
* for (ClosableIterable<Triple> triples : graph.iterate()) {
* for (Triple t : triples) {
* return t; // OK to terminate for-loop early
* }
* }
- * </code>
- * The above will ensure that underlying resources are closed even if
+ * </code> The above will ensure that underlying resources are closed even if
* the iteration does not exhaust all triples.
*
- * @param <T> type of elements returned by the iterator
+ * @param <T>
+ * type of elements returned by the iterator
*/
public interface ClosableIterable<T> extends Iterable<T>, AutoCloseable {
[09/50] [abbrv] incubator-commonsrdf git commit: JenaFactory ->
JenaRDF
Posted by st...@apache.org.
JenaFactory -> JenaRDF
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/384a8337
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/384a8337
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/384a8337
Branch: refs/heads/COMMONSRDF-7
Commit: 384a83377e8f643d61ffc91d202e84053450fa55
Parents: ff94b9d
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Oct 23 00:44:43 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Oct 23 00:44:43 2016 +0100
----------------------------------------------------------------------
.../apache/commons/rdf/jena/JenaFactory.java | 727 -------------------
.../org/apache/commons/rdf/jena/JenaRDF.java | 727 +++++++++++++++++++
.../rdf/jena/experimental/JenaRDFParser.java | 20 +-
.../commons/rdf/jena/impl/AbstractQuadLike.java | 6 +-
.../rdf/jena/impl/InternalJenaFactory.java | 4 +-
.../commons/rdf/jena/impl/JenaDatasetImpl.java | 14 +-
.../commons/rdf/jena/impl/JenaGraphImpl.java | 12 +-
.../org.apache.commons.rdf.api.RDFFactory | 2 +-
.../commons/rdf/jena/JenaServiceLoaderTest.java | 4 +-
.../apache/commons/rdf/jena/TestGraphJena.java | 2 +-
.../jena/TestJenaGraphToCommonsRDFGraph.java | 4 +-
.../commons/rdf/jena/TestRDFParserBuilder.java | 2 +-
.../rdf/jena/TestRDFTermFactoryJena.java | 2 +-
13 files changed, 763 insertions(+), 763 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/384a8337/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java
deleted file mode 100644
index 4832e44..0000000
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaFactory.java
+++ /dev/null
@@ -1,727 +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.jena;
-
-import java.util.Optional;
-import java.util.UUID;
-import java.util.function.Consumer;
-
-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;
-import org.apache.commons.rdf.api.QuadLike;
-import org.apache.commons.rdf.api.RDFSyntax;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.api.Triple;
-import org.apache.commons.rdf.api.TripleLike;
-import org.apache.commons.rdf.jena.impl.InternalJenaFactory;
-import org.apache.jena.datatypes.RDFDatatype;
-import org.apache.jena.datatypes.xsd.XSDDatatype;
-import org.apache.jena.graph.Node;
-import org.apache.jena.graph.NodeFactory;
-import org.apache.jena.riot.Lang;
-import org.apache.jena.riot.RDFDataMgr;
-import org.apache.jena.riot.RDFLanguages;
-import org.apache.jena.riot.system.StreamRDF;
-import org.apache.jena.riot.system.StreamRDFBase;
-import org.apache.jena.sparql.core.DatasetGraph;
-import org.apache.jena.sparql.graph.GraphFactory;
-
-/**
- * RDF with Jena-backed objects.
- * <p>
- * This factory can also convert existing objects from/to Jena with methods like
- * {@link #fromJena(org.apache.jena.graph.Graph)} and {@link #toJena(Graph)}.
- * <p>
- * For the purpose of {@link BlankNode} identity, this factory will use an internal
- * {@link UUID} as a salt. See {@link BlankNode#uniqueReference()} for details.
- *
- * @see RDF
- */
-public final class JenaFactory implements RDF {
-
- private static InternalJenaFactory internalJenaFactory = new InternalJenaFactory(){};
-
- private final UUID salt;
-
- /**
- * Create a JenaFactory.
- * <p>
- * This constructor will use a randomly generated {@link UUID} as a salt
- * for the purposes of {@link BlankNode} identity, see {@link #getSalt()}.
- */
- public JenaFactory() {
- this.salt = UUID.randomUUID();
- }
-
- /**
- * Create a JenaFactory.
- * <p>
- * This constructor will use the specified {@link UUID} as a salt for
- * the purposes of {@link BlankNode} identity, and should only be used in
- * cases where predictable and consistent
- * {@link BlankNode#uniqueReference()} are important.
- *
- * @param salt
- * {@link UUID} to use as salt for {@link BlankNode} equality
- */
- public JenaFactory(UUID salt) {
- this.salt = salt;
- }
-
- @Override
- public JenaBlankNode createBlankNode() {
- return internalJenaFactory.createBlankNode(getSalt());
- }
-
- @Override
- public JenaBlankNode createBlankNode(String name) {
- return internalJenaFactory.createBlankNode(name, getSalt());
- }
-
- @Override
- public JenaDataset createDataset() {
- return internalJenaFactory.createDataset(getSalt());
- }
-
- @Override
- public JenaGraph createGraph() {
- return internalJenaFactory.createGraph(getSalt());
- }
-
- @Override
- public JenaIRI createIRI(String iri) {
- validateIRI(iri);
- return internalJenaFactory.createIRI(iri);
- }
-
- @Override
- public JenaLiteral createLiteral(String lexicalForm) {
- return internalJenaFactory.createLiteral(lexicalForm);
- }
-
- @Override
- public JenaLiteral createLiteral(String lexicalForm, IRI dataType) {
- return internalJenaFactory.createLiteralDT(lexicalForm, dataType.getIRIString());
- }
-
- @Override
- public JenaLiteral createLiteral(String lexicalForm, String languageTag) {
- validateLang(languageTag);
- return internalJenaFactory.createLiteralLang(lexicalForm, languageTag);
- }
-
- @Override
- public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return internalJenaFactory.createTriple(subject, predicate, object);
- }
-
- @Override
- public JenaQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
- throws IllegalArgumentException, UnsupportedOperationException {
- return internalJenaFactory.createQuad(subject, predicate, object, graphName);
- }
-
- /**
- * Create a generalized Jena triple.
- * <p>
- * The <em>generalized triple</em> supports any {@link RDFTerm} as its
- * {@link TripleLike#getSubject()} {@link TripleLike#getPredicate()} or
- * {@link TripleLike#getObject()}.
- *
- * @see #createTriple(BlankNodeOrIRI, IRI, RDFTerm)
- * @see #createGeneralizedQuad(RDFTerm, RDFTerm, RDFTerm, RDFTerm)
- *
- * @param subject
- * The subject of the statement
- * @param predicate
- * The predicate of the statement
- * @param object
- * The object of the statement
- * @return Generalized {@link TripleLike}. Note that the generalized triple
- * does <strong>not</strong> implement {@link Triple#equals(Object)}
- * or {@link Triple#hashCode()}.
- */
- public JenaGeneralizedTripleLike createGeneralizedTriple(
- RDFTerm subject, RDFTerm predicate, RDFTerm object) {
- return internalJenaFactory.createGeneralizedTriple(subject, predicate, object);
- }
-
- /**
- * Create a generalized Jena quad.
- * <p>
- * The <em>generalized quad</em> supports any {@link RDFTerm} as its
- * {@link QuadLike#getSubject()} {@link QuadLike#getPredicate()},
- * {@link QuadLike#getObject()} or {@link QuadLike#getObject()}.
- *
- * @see #createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)
- * @see #createGeneralizedTriple(RDFTerm, RDFTerm, RDFTerm)
- *
- * @param subject
- * The subject of the statement
- * @param predicate
- * The predicate of the statement
- * @param object
- * The object of the statement
- * @param graphName
- * The graph name of the statement
- * @return Generalized {@link QuadLike}. Note that the generalized quad does
- * <strong>not</strong> implement {@link Quad#equals(Object)} or
- * {@link Quad#hashCode()}.
- */
- public JenaGeneralizedQuadLike createGeneralizedQuad(
- RDFTerm subject, RDFTerm predicate, RDFTerm object, RDFTerm graphName) {
- return internalJenaFactory.createGeneralizedQuad(subject, predicate, object, graphName);
- }
- /**
- * Adapt an existing Jena Node to CommonsRDF {@link RDFTerm}.
- * <p>
- * If {@link Node#isLiteral()}, then the returned value is a {@link Literal}.
- * If {@link Node#isURI()}, the returned value is a IRI. If {$@link Node#isBlank()},
- * the returned value is a {@link BlankNode}, which will use a {@link UUID}
- * salt from this {@link JenaFactory} instance in combination with
- * {@link Node#getBlankNodeId()} for the purpose of its
- * {@link BlankNode#uniqueReference()}.
- *
- * @see #fromJena(RDF, Node)
- *
- * @param node
- * The Jena Node to adapt. It's {@link Node#isConcrete()} must be
- * <code>true</code>.
- * @return Adapted {@link JenaRDFTerm}
- * @throws ConversionException If the {@link Node} can't be represented as an {@link RDFTerm}, e.g.
- * if the node is not concrete or represents a variable in Jena.
- */
- public JenaRDFTerm fromJena(Node node) throws ConversionException {
- return internalJenaFactory.fromJena(node, getSalt());
- }
-
- /**
- * Convert from Jena {@link Node} to any Commons RDF implementation.
- * <p>
- * Note that if the {@link Node#isBlank()}, then the factory's
- * {@link RDF#createBlankNode(String)} will be used, meaning
- * that care should be taken if reusing an {@link RDF} instance
- * for multiple conversion sessions.
- *
- * @see #fromJena(Node)
- *
- * @param factory {@link RDF} to use for creating {@link RDFTerm}.
- * @param node
- * The Jena Node to adapt. It's {@link Node#isConcrete()} must be
- * <code>true</code>.
- * @return Adapted {@link RDFTerm}
- * @throws ConversionException If the {@link Node} can't be represented as an {@link RDFTerm}, e.g.
- * if the node is not concrete or represents a variable in Jena.
- */
- public static RDFTerm fromJena(RDF factory, Node node) {
- if (node == null) {
- return null;
- }
- if (factory instanceof JenaFactory) {
- // No need to convert, just wrap
- return ((JenaFactory) factory).fromJena(node);
- }
- if (node.isURI())
- return factory.createIRI(node.getURI());
- if (node.isLiteral()) {
- String lang = node.getLiteralLanguage();
- if (lang != null && !lang.isEmpty())
- return factory.createLiteral(node.getLiteralLexicalForm(), lang);
- if (node.getLiteralDatatype().equals(XSDDatatype.XSDstring))
- return factory.createLiteral(node.getLiteralLexicalForm());
- IRI dt = factory.createIRI(node.getLiteralDatatype().getURI());
- return factory.createLiteral(node.getLiteralLexicalForm(), dt);
- }
- if (node.isBlank())
- // The factory
- return factory.createBlankNode(node.getBlankNodeLabel());
- throw new ConversionException("Node is not a concrete RDF Term: " + node);
- }
-
- /**
- * Adapt an existing Jena Triple to CommonsRDF {@link Triple}.
- * <p>
- * If the triple contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaFactory} instance in combination with
- * {@link Node#getBlankNodeId()} for the purpose of its
- * {@link BlankNode#uniqueReference()}.
- *
- * @see #fromJena(RDF, org.apache.jena.graph.Triple)
- *
- * @param triple
- * Jena {@link org.apache.jena.graph.Triple} to adapt
- * @return Adapted {@link JenaTriple}
- * @throws ConversionException
- * if any of the triple's nodes are not concrete or the triple
- * is a generalized triple
- */
- public JenaTriple fromJena(org.apache.jena.graph.Triple triple) throws ConversionException {
- return internalJenaFactory.fromJena(triple, getSalt());
- }
-
- /**
- * Adapt a generalized Jena {@link org.apache.jena.graph.Triple} to a CommonsRDF {@link TripleLike}.
- * <p>
- * The generalized triple supports any {@link RDFTerm} as its {@link TripleLike#getSubject()}
- * {@link TripleLike#getPredicate()} or {@link TripleLike#getObject()}.
- * <p>
- * If the Jena triple contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaFactory} instance in combination with
- * {@link Node#getBlankNodeId()} for the purpose of its
- * {@link BlankNode#uniqueReference()}.
- *
- * @see #fromJena(RDF, org.apache.jena.graph.Triple)
- *
- * @param triple
- * Jena triple
- * @return Adapted {@link TripleLike}. Note that the generalized triple does
- * <strong>not</strong> implement {@link Triple#equals(Object)} or
- * {@link Triple#hashCode()}.
- * @throws ConversionException
- * if any of the triple's nodes are not concrete
- */
- public JenaTripleLike fromJenaGeneralized(org.apache.jena.graph.Triple triple) throws ConversionException {
- return internalJenaFactory.fromJenaGeneralized(triple, getSalt());
- }
-
- /**
- * Adapt a generalized Jena {@link org.apache.jena.sparql.core.Quad} to a CommonsRDF {@link QuadLike}.
- * <p>
- * The generalized quad supports any {@link RDFTerm} as its
- * {@link QuadLike#getGraphName()},
- * {@link QuadLike#getSubject()}
- * {@link QuadLike#getPredicate()} or
- * {@link QuadLike#getObject()}.
- * <p>
- * If the Jena quad contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaFactory} instance in combination with
- * {@link Node#getBlankNodeId()} for the purpose of its
- * {@link BlankNode#uniqueReference()}.
- *
- * @see #fromJena(org.apache.jena.sparql.core.Quad)
- * @see #fromJenaGeneralized(org.apache.jena.graph.Triple)
- *
- * @param quad
- * Jena quad
- * @return Adapted {@link QuadLike}. Note that the generalized quad does
- * <strong>not</strong> implement {@link Quad#equals(Object)} or
- * {@link Quad#hashCode()}.
- * @throws ConversionException
- * if any of the quad nodes are not concrete
- */
- public JenaQuadLike<RDFTerm> fromJenaGeneralized(org.apache.jena.sparql.core.Quad quad) throws ConversionException {
- return internalJenaFactory.fromJenaGeneralized(quad, getSalt());
- }
-
- /**
- * Convert from Jena {@link org.apache.jena.graph.Triple} to a Commons RDF
- * {@link Triple}.
- * <p>
- * Note that if any of the triple's nodes {@link Node#isBlank()}, then the factory's
- * {@link RDF#createBlankNode(String)} will be used, meaning
- * that care should be taken if reusing an {@link RDF} instance
- * for multiple conversion sessions.
- *
- * @see #fromJena(org.apache.jena.graph.Triple)
- *
- * @param factory {@link RDF} to use for creating the {@link Triple} and its
- * {@link RDFTerm}s.
- * @param triple
- * Jena triple
- * @return Converted triple
- * @throws ConversionException
- * if any of the triple's nodes are not concrete or the triple
- * is a generalized triple
- */
- public static Triple fromJena(RDF factory, org.apache.jena.graph.Triple triple)
- throws ConversionException{
- if (factory instanceof JenaFactory) {
- // No need to convert, just wrap
- return ((JenaFactory) factory).fromJena(triple);
- }
- final BlankNodeOrIRI subject;
- final IRI predicate;
- try {
- subject = (BlankNodeOrIRI) fromJena(factory, triple.getSubject());
- predicate = (IRI) fromJena(factory, triple.getPredicate());
- } catch (ClassCastException ex) {
- throw new ConversionException("Can't convert generalized triple: " + triple, ex);
- }
- RDFTerm object = fromJena(factory, triple.getObject());
- return factory.createTriple(subject, predicate, object);
- }
-
- /**
- * Adapt an existing Jena {@link org.apache.jena.sparql.core.Quad} to CommonsRDF {@link Quad}.
- * <p>
- * If the quad contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaFactory} instance
- * in combination with {@link Node#getBlankNodeId()}
- * for the purpose of its {@link BlankNode#uniqueReference()}.
- *
- * @param quad
- * Jena quad
- * @return Adapted quad
- */
- public JenaQuad fromJena(org.apache.jena.sparql.core.Quad quad) {
- return internalJenaFactory.fromJena(quad, getSalt());
- }
-
- /**
- * Adapt an existing Jena {@link org.apache.jena.graph.Graph} to CommonsRDF
- * {@link Graph}.
- * <p>
- * This does not take a copy, changes to the CommonsRDF Graph are reflected
- * in the jena graph, which is accessible from
- * {@link JenaGraph#asJenaGraph()}.
- * <p>
- * If the graph contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaFactory} instance in combination with
- * {@link Node#getBlankNodeId()} for the purpose of its
- * {@link BlankNode#uniqueReference()}.
- *
- * @param graph
- * Jena {@link org.apache.jena.graph.Graph} to adapt
- * @return Adapted {@link JenaGraph}
- */
- public JenaGraph fromJena(org.apache.jena.graph.Graph graph) {
- return internalJenaFactory.fromJena(graph, getSalt());
- }
-
- /**
- * Adapt an existing Jena {@link org.apache.jena.rdf.model.Model} to CommonsRDF {@link Graph}.
- * <p>
- * This does not ake a copy, changes to the CommonsRDF Graph are reflected in the jena
- * graph, which is accessible from {@link JenaGraph#asJenaGraph()}.
- * <p>
- * If the graph contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaFactory} instance
- * in combination with {@link Node#getBlankNodeId()}
- * for the purpose of its {@link BlankNode#uniqueReference()}.
- * @param model
- * Jena {@link org.apache.jena.rdf.model.Model} to adapt
- * @return Adapted {@link JenaGraph}
- */
- public JenaGraph fromJena(org.apache.jena.rdf.model.Model model) {
- return internalJenaFactory.fromJena(model, getSalt());
- }
-
- /**
- * Adapt an existing Jena {@link DatasetGraph} to CommonsRDF {@link Dataset}.
- * <p>
- * This does not
- * take a copy, changes to the CommonsRDF Dataset are reflected in the jena
- * dataset graph, which is accessible from {@link JenaDataset#asJenaDatasetGraph()}.
- * <p>
- * If the dataset contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaFactory} instance
- * in combination with {@link Node#getBlankNodeId()}
- * for the purpose of its {@link BlankNode#uniqueReference()}.
- *
- * @param datasetGraph Jena {@link DatasetGraph} to adapt
- * @return Adapted {@link JenaDataset}
- */
- public JenaDataset fromJena(DatasetGraph datasetGraph) {
- return internalJenaFactory.fromJena(datasetGraph, getSalt());
- }
-
- /**
- * Adapt an existing Jena {@link org.apache.jena.query.Dataset} to CommonsRDF {@link Dataset}.
- * <p>
- * This does not
- * take a copy, changes to the CommonsRDF Dataset are reflected in the jena
- * dataset graph, which is accessible from {@link JenaDataset#asJenaDatasetGraph()}.
- * <p>
- * If the dataset contains any {@link Node#isBlank()}, then any corresponding
- * {@link BlankNode} will use a {@link UUID} salt from this
- * {@link JenaFactory} instance
- * in combination with {@link Node#getBlankNodeId()}
- * for the purpose of its {@link BlankNode#uniqueReference()}.
- *
- * @param datasetGraph Jena {@link org.apache.jena.query.Dataset} to adapt
- * @return Adapted {@link JenaDataset}
- */
- public JenaDataset fromJena(org.apache.jena.query.Dataset datasetGraph) {
- return internalJenaFactory.fromJena(datasetGraph.asDatasetGraph(), getSalt());
- }
-
- /**
- * Convert from Jena {@link org.apache.jena.sparql.core.Quad} to a Commons
- * RDF {@link Quad}.
- * <p>
- * Note that if any of the quad's nodes {@link Node#isBlank()}, then the
- * factory's {@link RDF#createBlankNode(String)} will be used,
- * meaning that care should be taken if reusing an {@link RDF}
- * instance for multiple conversion sessions.
- *
- * @see #fromJena(org.apache.jena.sparql.core.Quad)
- * @see #fromJenaGeneralized(org.apache.jena.sparql.core.Quad)
- *
- * @param factory
- * {@link RDF} to use for creating the {@link Triple}
- * and its {@link RDFTerm}s.
- * @param quad
- * Jena {@link org.apache.jena.sparql.core.Quad} to adapt
- * @return Converted {@link Quad}
- * @throws ConversionException
- * if any of the quad's nodes are not concrete or the quad
- * is a generalized quad
- */
- public static Quad fromJena(RDF factory, org.apache.jena.sparql.core.Quad quad) {
- if (factory instanceof JenaFactory) {
- // No need to convert, just wrap
- return ((JenaFactory) factory).fromJena(quad);
- }
- BlankNodeOrIRI graphName = (BlankNodeOrIRI) (fromJena(factory, quad.getGraph()));
- BlankNodeOrIRI subject = (BlankNodeOrIRI) (fromJena(factory, quad.getSubject()));
- IRI predicate = (IRI) (fromJena(factory, quad.getPredicate()));
- RDFTerm object = fromJena(factory, quad.getObject());
- return factory.createQuad(graphName, subject, predicate, object);
- }
-
- /**
- * Return {@link RDFSyntax} corresponding to a Jena {@link Lang}.
- *
- * @param lang {@link Lang} to convert
- * @return Matched {@link RDFSyntax}, otherwise {@link Optional#empty()}
- */
- public Optional<RDFSyntax> langToRdfSyntax(Lang lang) {
- return RDFSyntax.byMediaType(lang.getContentType().getContentType());
- }
-
- /**
- * Return Jena {@link Lang} corresponding to a {@link RDFSyntax}.
- *
- * @param rdfSyntax {@link RDFSyntax} to convert
- * @return Matched {@link Lang}, otherwise {@link Optional#empty()}
- */
- public Optional<Lang> rdfSyntaxToLang(RDFSyntax rdfSyntax) {
- return Optional.ofNullable(RDFLanguages.contentTypeToLang(rdfSyntax.mediaType));
- }
-
- /**
- * Create a {@link StreamRDF} instance that inserts the converted
- * {@link Quad}s. into a the provided {@link Consumer}.
- * <p>
- * The returned {@link StreamRDF} can be used for instance with Jena's
- * {@link RDFDataMgr#parse(StreamRDF, String)}.
- *
- * @param factory
- * {@link RDF} to use for creating {@link RDFTerm}s
- * and {@link Quad}s.
- * @param consumer
- * A {@link Consumer} of {@link Quad}s
- * @return A {@link StreamRDF} that will stream converted quads to the
- * consumer
- */
- public static StreamRDF streamJenaToCommonsRDF(RDF factory, Consumer<Quad> consumer) {
- return new StreamRDFBase() {
- @Override
- public void quad(org.apache.jena.sparql.core.Quad quad) {
- consumer.accept(fromJena(factory, quad));
- }
- };
- }
-
- /**
- * Create a {@link StreamRDF} instance that inserts generalized
- * {@link TripleLike}s. into a the provided {@link Consumer}.
- * <p>
- * A generalized triple allows any {@link RDFTerm} for
- * {@link TripleLike#getSubject()}, {@link TripleLike#getPredicate()} and
- * {@link TripleLike#getObject()}.
- * <p>
- * The returned {@link StreamRDF} can be used for instance with Jena's
- * {@link RDFDataMgr#parse(StreamRDF, String)}.
- *
- * @param generalizedConsumer
- * A {@link Consumer} of generalized {@link TripleLike}s
- * @return A {@link StreamRDF} that will stream generalized triples to the
- * consumer
- */
- public StreamRDF streamJenaToGeneralizedTriple(Consumer<TripleLike> generalizedConsumer) {
- return new StreamRDFBase() {
- @Override
- public void triple(org.apache.jena.graph.Triple triple) {
- generalizedConsumer.accept(fromJenaGeneralized(triple));
- }
- };
- }
-
- /**
- * Create a {@link StreamRDF} instance that inserts generalized
- * {@link QuadLike}s. into a the provided {@link Consumer}.
- * <p>
- * A generalized quad allows any {@link RDFTerm} for
- * {@link QuadLike#getSubject()}, {@link TripleLike#getPredicate()},
- * {@link QuadLike#getObject()} and {@link QuadLike#getGraphName()} .
- * <p>
- * The returned {@link StreamRDF} can be used for instance with Jena's
- * {@link RDFDataMgr#parse(StreamRDF, String)}.
- *
- * @param generalizedConsumer
- * A {@link Consumer} of generalized {@link QuadLike}s
- * @return A {@link StreamRDF} that will stream generalized quads to the
- * consumer
- */
- public StreamRDF streamJenaToGeneralizedQuad(Consumer<QuadLike<RDFTerm>> generalizedConsumer) {
- return new StreamRDFBase() {
- @Override
- public void quad(org.apache.jena.sparql.core.Quad quad) {
- generalizedConsumer.accept(fromJenaGeneralized(quad));
- }
- };
- }
-
- /**
- * Convert a CommonsRDF Graph to a Jena Graph. If the Graph was from Jena
- * originally, return that original object else create a copy using Jena
- * objects.
- *
- * @param graph Commons RDF {@link Graph} to convert
- * @return Converted Jena {@link org.apache.jena.graph.Graph}
- */
- public org.apache.jena.graph.Graph toJena(Graph graph) {
- if (graph instanceof JenaGraph)
- return ((JenaGraph) graph).asJenaGraph();
- org.apache.jena.graph.Graph g = GraphFactory.createGraphMem();
- graph.stream().forEach(t -> g.add(toJena(t)));
- return g;
- }
-
- /**
- * Convert a CommonsRDF RDFTerm to a Jena Node. If the RDFTerm was from Jena
- * originally, return that original object, else create a copy using Jena
- * objects.
- *
- * @param term Commons RDF {@link RDFTerm} to convert
- * @return Converted Jena {@link Node}
- */
- public Node toJena(RDFTerm term) {
- if (term == null) {
- return null;
- }
- if (term instanceof JenaRDFTerm)
- // TODO: What if it's a JenaBlankNodeImpl with
- // a different salt? Do we need to rewrite the
- // jena blanknode identifier?
- return ((JenaRDFTerm) term).asJenaNode();
-
- if (term instanceof IRI)
- return NodeFactory.createURI(((IRI) term).getIRIString());
-
- if (term instanceof Literal) {
- Literal lit = (Literal) term;
- RDFDatatype dt = NodeFactory.getType(lit.getDatatype().getIRIString());
- String lang = lit.getLanguageTag().orElse("");
- return NodeFactory.createLiteral(lit.getLexicalForm(), lang, dt);
- }
-
- if (term instanceof BlankNode) {
- String id = ((BlankNode) term).uniqueReference();
- return NodeFactory.createBlankNode(id);
- }
- throw new ConversionException("Not a concrete RDF Term: " + term);
- }
-
- /**
- * Convert a CommonsRDF {@link Triple} to a Jena
- * {@link org.apache.jena.graph.Triple}.
- * <p>
- * If the triple was from Jena originally, return that original object, else
- * create a copy using Jena objects.
- *
- * @param triple Commons RDF {@link Triple} to convert
- * @return Converted Jena {@link org.apache.jena.graph.Triple}
- */
- public org.apache.jena.graph.Triple toJena(Triple triple) {
- if (triple instanceof JenaTriple)
- return ((JenaTriple) triple).asJenaTriple();
- return org.apache.jena.graph.Triple.create(
- toJena(triple.getSubject()),
- toJena(triple.getPredicate()),
- toJena(triple.getObject()));
- }
-
-
- /**
- * Convert a CommonsRDF {@link Quad} to a Jena
- * {@link org.apache.jena.sparql.core.Quad}.
- * <p>
- * If the quad was from Jena originally, return that original object,
- * otherwise create a copy using Jena objects.
- *
- * @param quad Commons RDF {@link Quad} to convert
- * @return Converted Jena {@link org.apache.jena.sparql.core.Quad}
- */
- public org.apache.jena.sparql.core.Quad toJena(Quad quad) {
- if (quad instanceof JenaQuad) {
- return ((JenaQuad) quad).asJenaQuad();
- }
- return org.apache.jena.sparql.core.Quad.create(
- toJena(quad.getGraphName().orElse(null)),
- toJena(quad.getSubject()),
- toJena(quad.getPredicate()),
- toJena(quad.getObject()));
- }
-
- // Some simple validations - full IRI parsing is not cheap.
- private void validateIRI(String iri) {
- if (iri.contains(" "))
- throw new IllegalArgumentException();
- if (iri.contains("<"))
- throw new IllegalArgumentException();
- if (iri.contains(">"))
- throw new IllegalArgumentException();
- }
-
- private static void validateLang(String languageTag) {
- if (languageTag.contains(" "))
- throw new IllegalArgumentException("Invalid language tag: " + languageTag);
- }
-
- /**
- * Return the {@link UUID} salt used by this factory.
- * <p>
- * The salt is used for the purposes of {@link BlankNode} identity, see
- * {@link BlankNode#uniqueReference()} for details.
- * <p>
- * This salt can be used with the constructor
- * {@link JenaFactory#JenaFactory(UUID)}
- * if consistent or reproducible {@link BlankNode}s are desirable.
- *
- * @return The {@link UUID} used as salt
- */
- public UUID getSalt() {
- return salt;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/384a8337/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
new file mode 100644
index 0000000..e3c2a86
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
@@ -0,0 +1,727 @@
+/**
+ * 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.jena;
+
+import java.util.Optional;
+import java.util.UUID;
+import java.util.function.Consumer;
+
+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;
+import org.apache.commons.rdf.api.QuadLike;
+import org.apache.commons.rdf.api.RDFSyntax;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.RDF;
+import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.api.TripleLike;
+import org.apache.commons.rdf.jena.impl.InternalJenaFactory;
+import org.apache.jena.datatypes.RDFDatatype;
+import org.apache.jena.datatypes.xsd.XSDDatatype;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFDataMgr;
+import org.apache.jena.riot.RDFLanguages;
+import org.apache.jena.riot.system.StreamRDF;
+import org.apache.jena.riot.system.StreamRDFBase;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.graph.GraphFactory;
+
+/**
+ * RDF with Jena-backed objects.
+ * <p>
+ * This factory can also convert existing objects from/to Jena with methods like
+ * {@link #fromJena(org.apache.jena.graph.Graph)} and {@link #toJena(Graph)}.
+ * <p>
+ * For the purpose of {@link BlankNode} identity, this factory will use an internal
+ * {@link UUID} as a salt. See {@link BlankNode#uniqueReference()} for details.
+ *
+ * @see RDF
+ */
+public final class JenaRDF implements RDF {
+
+ private static InternalJenaFactory internalJenaFactory = new InternalJenaFactory(){};
+
+ private final UUID salt;
+
+ /**
+ * Create a JenaRDF.
+ * <p>
+ * This constructor will use a randomly generated {@link UUID} as a salt
+ * for the purposes of {@link BlankNode} identity, see {@link #getSalt()}.
+ */
+ public JenaRDF() {
+ this.salt = UUID.randomUUID();
+ }
+
+ /**
+ * Create a JenaRDF.
+ * <p>
+ * This constructor will use the specified {@link UUID} as a salt for
+ * the purposes of {@link BlankNode} identity, and should only be used in
+ * cases where predictable and consistent
+ * {@link BlankNode#uniqueReference()} are important.
+ *
+ * @param salt
+ * {@link UUID} to use as salt for {@link BlankNode} equality
+ */
+ public JenaRDF(UUID salt) {
+ this.salt = salt;
+ }
+
+ @Override
+ public JenaBlankNode createBlankNode() {
+ return internalJenaFactory.createBlankNode(getSalt());
+ }
+
+ @Override
+ public JenaBlankNode createBlankNode(String name) {
+ return internalJenaFactory.createBlankNode(name, getSalt());
+ }
+
+ @Override
+ public JenaDataset createDataset() {
+ return internalJenaFactory.createDataset(getSalt());
+ }
+
+ @Override
+ public JenaGraph createGraph() {
+ return internalJenaFactory.createGraph(getSalt());
+ }
+
+ @Override
+ public JenaIRI createIRI(String iri) {
+ validateIRI(iri);
+ return internalJenaFactory.createIRI(iri);
+ }
+
+ @Override
+ public JenaLiteral createLiteral(String lexicalForm) {
+ return internalJenaFactory.createLiteral(lexicalForm);
+ }
+
+ @Override
+ public JenaLiteral createLiteral(String lexicalForm, IRI dataType) {
+ return internalJenaFactory.createLiteralDT(lexicalForm, dataType.getIRIString());
+ }
+
+ @Override
+ public JenaLiteral createLiteral(String lexicalForm, String languageTag) {
+ validateLang(languageTag);
+ return internalJenaFactory.createLiteralLang(lexicalForm, languageTag);
+ }
+
+ @Override
+ public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return internalJenaFactory.createTriple(subject, predicate, object);
+ }
+
+ @Override
+ public JenaQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws IllegalArgumentException, UnsupportedOperationException {
+ return internalJenaFactory.createQuad(subject, predicate, object, graphName);
+ }
+
+ /**
+ * Create a generalized Jena triple.
+ * <p>
+ * The <em>generalized triple</em> supports any {@link RDFTerm} as its
+ * {@link TripleLike#getSubject()} {@link TripleLike#getPredicate()} or
+ * {@link TripleLike#getObject()}.
+ *
+ * @see #createTriple(BlankNodeOrIRI, IRI, RDFTerm)
+ * @see #createGeneralizedQuad(RDFTerm, RDFTerm, RDFTerm, RDFTerm)
+ *
+ * @param subject
+ * The subject of the statement
+ * @param predicate
+ * The predicate of the statement
+ * @param object
+ * The object of the statement
+ * @return Generalized {@link TripleLike}. Note that the generalized triple
+ * does <strong>not</strong> implement {@link Triple#equals(Object)}
+ * or {@link Triple#hashCode()}.
+ */
+ public JenaGeneralizedTripleLike createGeneralizedTriple(
+ RDFTerm subject, RDFTerm predicate, RDFTerm object) {
+ return internalJenaFactory.createGeneralizedTriple(subject, predicate, object);
+ }
+
+ /**
+ * Create a generalized Jena quad.
+ * <p>
+ * The <em>generalized quad</em> supports any {@link RDFTerm} as its
+ * {@link QuadLike#getSubject()} {@link QuadLike#getPredicate()},
+ * {@link QuadLike#getObject()} or {@link QuadLike#getObject()}.
+ *
+ * @see #createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)
+ * @see #createGeneralizedTriple(RDFTerm, RDFTerm, RDFTerm)
+ *
+ * @param subject
+ * The subject of the statement
+ * @param predicate
+ * The predicate of the statement
+ * @param object
+ * The object of the statement
+ * @param graphName
+ * The graph name of the statement
+ * @return Generalized {@link QuadLike}. Note that the generalized quad does
+ * <strong>not</strong> implement {@link Quad#equals(Object)} or
+ * {@link Quad#hashCode()}.
+ */
+ public JenaGeneralizedQuadLike createGeneralizedQuad(
+ RDFTerm subject, RDFTerm predicate, RDFTerm object, RDFTerm graphName) {
+ return internalJenaFactory.createGeneralizedQuad(subject, predicate, object, graphName);
+ }
+ /**
+ * Adapt an existing Jena Node to CommonsRDF {@link RDFTerm}.
+ * <p>
+ * If {@link Node#isLiteral()}, then the returned value is a {@link Literal}.
+ * If {@link Node#isURI()}, the returned value is a IRI. If {$@link Node#isBlank()},
+ * the returned value is a {@link BlankNode}, which will use a {@link UUID}
+ * salt from this {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
+ * @see #fromJena(RDF, Node)
+ *
+ * @param node
+ * The Jena Node to adapt. It's {@link Node#isConcrete()} must be
+ * <code>true</code>.
+ * @return Adapted {@link JenaRDFTerm}
+ * @throws ConversionException If the {@link Node} can't be represented as an {@link RDFTerm}, e.g.
+ * if the node is not concrete or represents a variable in Jena.
+ */
+ public JenaRDFTerm fromJena(Node node) throws ConversionException {
+ return internalJenaFactory.fromJena(node, getSalt());
+ }
+
+ /**
+ * Convert from Jena {@link Node} to any Commons RDF implementation.
+ * <p>
+ * Note that if the {@link Node#isBlank()}, then the factory's
+ * {@link RDF#createBlankNode(String)} will be used, meaning
+ * that care should be taken if reusing an {@link RDF} instance
+ * for multiple conversion sessions.
+ *
+ * @see #fromJena(Node)
+ *
+ * @param factory {@link RDF} to use for creating {@link RDFTerm}.
+ * @param node
+ * The Jena Node to adapt. It's {@link Node#isConcrete()} must be
+ * <code>true</code>.
+ * @return Adapted {@link RDFTerm}
+ * @throws ConversionException If the {@link Node} can't be represented as an {@link RDFTerm}, e.g.
+ * if the node is not concrete or represents a variable in Jena.
+ */
+ public static RDFTerm fromJena(RDF factory, Node node) {
+ if (node == null) {
+ return null;
+ }
+ if (factory instanceof JenaRDF) {
+ // No need to convert, just wrap
+ return ((JenaRDF) factory).fromJena(node);
+ }
+ if (node.isURI())
+ return factory.createIRI(node.getURI());
+ if (node.isLiteral()) {
+ String lang = node.getLiteralLanguage();
+ if (lang != null && !lang.isEmpty())
+ return factory.createLiteral(node.getLiteralLexicalForm(), lang);
+ if (node.getLiteralDatatype().equals(XSDDatatype.XSDstring))
+ return factory.createLiteral(node.getLiteralLexicalForm());
+ IRI dt = factory.createIRI(node.getLiteralDatatype().getURI());
+ return factory.createLiteral(node.getLiteralLexicalForm(), dt);
+ }
+ if (node.isBlank())
+ // The factory
+ return factory.createBlankNode(node.getBlankNodeLabel());
+ throw new ConversionException("Node is not a concrete RDF Term: " + node);
+ }
+
+ /**
+ * Adapt an existing Jena Triple to CommonsRDF {@link Triple}.
+ * <p>
+ * If the triple contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
+ * @see #fromJena(RDF, org.apache.jena.graph.Triple)
+ *
+ * @param triple
+ * Jena {@link org.apache.jena.graph.Triple} to adapt
+ * @return Adapted {@link JenaTriple}
+ * @throws ConversionException
+ * if any of the triple's nodes are not concrete or the triple
+ * is a generalized triple
+ */
+ public JenaTriple fromJena(org.apache.jena.graph.Triple triple) throws ConversionException {
+ return internalJenaFactory.fromJena(triple, getSalt());
+ }
+
+ /**
+ * Adapt a generalized Jena {@link org.apache.jena.graph.Triple} to a CommonsRDF {@link TripleLike}.
+ * <p>
+ * The generalized triple supports any {@link RDFTerm} as its {@link TripleLike#getSubject()}
+ * {@link TripleLike#getPredicate()} or {@link TripleLike#getObject()}.
+ * <p>
+ * If the Jena triple contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
+ * @see #fromJena(RDF, org.apache.jena.graph.Triple)
+ *
+ * @param triple
+ * Jena triple
+ * @return Adapted {@link TripleLike}. Note that the generalized triple does
+ * <strong>not</strong> implement {@link Triple#equals(Object)} or
+ * {@link Triple#hashCode()}.
+ * @throws ConversionException
+ * if any of the triple's nodes are not concrete
+ */
+ public JenaTripleLike fromJenaGeneralized(org.apache.jena.graph.Triple triple) throws ConversionException {
+ return internalJenaFactory.fromJenaGeneralized(triple, getSalt());
+ }
+
+ /**
+ * Adapt a generalized Jena {@link org.apache.jena.sparql.core.Quad} to a CommonsRDF {@link QuadLike}.
+ * <p>
+ * The generalized quad supports any {@link RDFTerm} as its
+ * {@link QuadLike#getGraphName()},
+ * {@link QuadLike#getSubject()}
+ * {@link QuadLike#getPredicate()} or
+ * {@link QuadLike#getObject()}.
+ * <p>
+ * If the Jena quad contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
+ * @see #fromJena(org.apache.jena.sparql.core.Quad)
+ * @see #fromJenaGeneralized(org.apache.jena.graph.Triple)
+ *
+ * @param quad
+ * Jena quad
+ * @return Adapted {@link QuadLike}. Note that the generalized quad does
+ * <strong>not</strong> implement {@link Quad#equals(Object)} or
+ * {@link Quad#hashCode()}.
+ * @throws ConversionException
+ * if any of the quad nodes are not concrete
+ */
+ public JenaQuadLike<RDFTerm> fromJenaGeneralized(org.apache.jena.sparql.core.Quad quad) throws ConversionException {
+ return internalJenaFactory.fromJenaGeneralized(quad, getSalt());
+ }
+
+ /**
+ * Convert from Jena {@link org.apache.jena.graph.Triple} to a Commons RDF
+ * {@link Triple}.
+ * <p>
+ * Note that if any of the triple's nodes {@link Node#isBlank()}, then the factory's
+ * {@link RDF#createBlankNode(String)} will be used, meaning
+ * that care should be taken if reusing an {@link RDF} instance
+ * for multiple conversion sessions.
+ *
+ * @see #fromJena(org.apache.jena.graph.Triple)
+ *
+ * @param factory {@link RDF} to use for creating the {@link Triple} and its
+ * {@link RDFTerm}s.
+ * @param triple
+ * Jena triple
+ * @return Converted triple
+ * @throws ConversionException
+ * if any of the triple's nodes are not concrete or the triple
+ * is a generalized triple
+ */
+ public static Triple fromJena(RDF factory, org.apache.jena.graph.Triple triple)
+ throws ConversionException{
+ if (factory instanceof JenaRDF) {
+ // No need to convert, just wrap
+ return ((JenaRDF) factory).fromJena(triple);
+ }
+ final BlankNodeOrIRI subject;
+ final IRI predicate;
+ try {
+ subject = (BlankNodeOrIRI) fromJena(factory, triple.getSubject());
+ predicate = (IRI) fromJena(factory, triple.getPredicate());
+ } catch (ClassCastException ex) {
+ throw new ConversionException("Can't convert generalized triple: " + triple, ex);
+ }
+ RDFTerm object = fromJena(factory, triple.getObject());
+ return factory.createTriple(subject, predicate, object);
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.sparql.core.Quad} to CommonsRDF {@link Quad}.
+ * <p>
+ * If the quad contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance
+ * in combination with {@link Node#getBlankNodeId()}
+ * for the purpose of its {@link BlankNode#uniqueReference()}.
+ *
+ * @param quad
+ * Jena quad
+ * @return Adapted quad
+ */
+ public JenaQuad fromJena(org.apache.jena.sparql.core.Quad quad) {
+ return internalJenaFactory.fromJena(quad, getSalt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.graph.Graph} to CommonsRDF
+ * {@link Graph}.
+ * <p>
+ * This does not take a copy, changes to the CommonsRDF Graph are reflected
+ * in the jena graph, which is accessible from
+ * {@link JenaGraph#asJenaGraph()}.
+ * <p>
+ * If the graph contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
+ * @param graph
+ * Jena {@link org.apache.jena.graph.Graph} to adapt
+ * @return Adapted {@link JenaGraph}
+ */
+ public JenaGraph fromJena(org.apache.jena.graph.Graph graph) {
+ return internalJenaFactory.fromJena(graph, getSalt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.rdf.model.Model} to CommonsRDF {@link Graph}.
+ * <p>
+ * This does not ake a copy, changes to the CommonsRDF Graph are reflected in the jena
+ * graph, which is accessible from {@link JenaGraph#asJenaGraph()}.
+ * <p>
+ * If the graph contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance
+ * in combination with {@link Node#getBlankNodeId()}
+ * for the purpose of its {@link BlankNode#uniqueReference()}.
+ * @param model
+ * Jena {@link org.apache.jena.rdf.model.Model} to adapt
+ * @return Adapted {@link JenaGraph}
+ */
+ public JenaGraph fromJena(org.apache.jena.rdf.model.Model model) {
+ return internalJenaFactory.fromJena(model, getSalt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link DatasetGraph} to CommonsRDF {@link Dataset}.
+ * <p>
+ * This does not
+ * take a copy, changes to the CommonsRDF Dataset are reflected in the jena
+ * dataset graph, which is accessible from {@link JenaDataset#asJenaDatasetGraph()}.
+ * <p>
+ * If the dataset contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance
+ * in combination with {@link Node#getBlankNodeId()}
+ * for the purpose of its {@link BlankNode#uniqueReference()}.
+ *
+ * @param datasetGraph Jena {@link DatasetGraph} to adapt
+ * @return Adapted {@link JenaDataset}
+ */
+ public JenaDataset fromJena(DatasetGraph datasetGraph) {
+ return internalJenaFactory.fromJena(datasetGraph, getSalt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.query.Dataset} to CommonsRDF {@link Dataset}.
+ * <p>
+ * This does not
+ * take a copy, changes to the CommonsRDF Dataset are reflected in the jena
+ * dataset graph, which is accessible from {@link JenaDataset#asJenaDatasetGraph()}.
+ * <p>
+ * If the dataset contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance
+ * in combination with {@link Node#getBlankNodeId()}
+ * for the purpose of its {@link BlankNode#uniqueReference()}.
+ *
+ * @param datasetGraph Jena {@link org.apache.jena.query.Dataset} to adapt
+ * @return Adapted {@link JenaDataset}
+ */
+ public JenaDataset fromJena(org.apache.jena.query.Dataset datasetGraph) {
+ return internalJenaFactory.fromJena(datasetGraph.asDatasetGraph(), getSalt());
+ }
+
+ /**
+ * Convert from Jena {@link org.apache.jena.sparql.core.Quad} to a Commons
+ * RDF {@link Quad}.
+ * <p>
+ * Note that if any of the quad's nodes {@link Node#isBlank()}, then the
+ * factory's {@link RDF#createBlankNode(String)} will be used,
+ * meaning that care should be taken if reusing an {@link RDF}
+ * instance for multiple conversion sessions.
+ *
+ * @see #fromJena(org.apache.jena.sparql.core.Quad)
+ * @see #fromJenaGeneralized(org.apache.jena.sparql.core.Quad)
+ *
+ * @param factory
+ * {@link RDF} to use for creating the {@link Triple}
+ * and its {@link RDFTerm}s.
+ * @param quad
+ * Jena {@link org.apache.jena.sparql.core.Quad} to adapt
+ * @return Converted {@link Quad}
+ * @throws ConversionException
+ * if any of the quad's nodes are not concrete or the quad
+ * is a generalized quad
+ */
+ public static Quad fromJena(RDF factory, org.apache.jena.sparql.core.Quad quad) {
+ if (factory instanceof JenaRDF) {
+ // No need to convert, just wrap
+ return ((JenaRDF) factory).fromJena(quad);
+ }
+ BlankNodeOrIRI graphName = (BlankNodeOrIRI) (fromJena(factory, quad.getGraph()));
+ BlankNodeOrIRI subject = (BlankNodeOrIRI) (fromJena(factory, quad.getSubject()));
+ IRI predicate = (IRI) (fromJena(factory, quad.getPredicate()));
+ RDFTerm object = fromJena(factory, quad.getObject());
+ return factory.createQuad(graphName, subject, predicate, object);
+ }
+
+ /**
+ * Return {@link RDFSyntax} corresponding to a Jena {@link Lang}.
+ *
+ * @param lang {@link Lang} to convert
+ * @return Matched {@link RDFSyntax}, otherwise {@link Optional#empty()}
+ */
+ public Optional<RDFSyntax> langToRdfSyntax(Lang lang) {
+ return RDFSyntax.byMediaType(lang.getContentType().getContentType());
+ }
+
+ /**
+ * Return Jena {@link Lang} corresponding to a {@link RDFSyntax}.
+ *
+ * @param rdfSyntax {@link RDFSyntax} to convert
+ * @return Matched {@link Lang}, otherwise {@link Optional#empty()}
+ */
+ public Optional<Lang> rdfSyntaxToLang(RDFSyntax rdfSyntax) {
+ return Optional.ofNullable(RDFLanguages.contentTypeToLang(rdfSyntax.mediaType));
+ }
+
+ /**
+ * Create a {@link StreamRDF} instance that inserts the converted
+ * {@link Quad}s. into a the provided {@link Consumer}.
+ * <p>
+ * The returned {@link StreamRDF} can be used for instance with Jena's
+ * {@link RDFDataMgr#parse(StreamRDF, String)}.
+ *
+ * @param factory
+ * {@link RDF} to use for creating {@link RDFTerm}s
+ * and {@link Quad}s.
+ * @param consumer
+ * A {@link Consumer} of {@link Quad}s
+ * @return A {@link StreamRDF} that will stream converted quads to the
+ * consumer
+ */
+ public static StreamRDF streamJenaToCommonsRDF(RDF factory, Consumer<Quad> consumer) {
+ return new StreamRDFBase() {
+ @Override
+ public void quad(org.apache.jena.sparql.core.Quad quad) {
+ consumer.accept(fromJena(factory, quad));
+ }
+ };
+ }
+
+ /**
+ * Create a {@link StreamRDF} instance that inserts generalized
+ * {@link TripleLike}s. into a the provided {@link Consumer}.
+ * <p>
+ * A generalized triple allows any {@link RDFTerm} for
+ * {@link TripleLike#getSubject()}, {@link TripleLike#getPredicate()} and
+ * {@link TripleLike#getObject()}.
+ * <p>
+ * The returned {@link StreamRDF} can be used for instance with Jena's
+ * {@link RDFDataMgr#parse(StreamRDF, String)}.
+ *
+ * @param generalizedConsumer
+ * A {@link Consumer} of generalized {@link TripleLike}s
+ * @return A {@link StreamRDF} that will stream generalized triples to the
+ * consumer
+ */
+ public StreamRDF streamJenaToGeneralizedTriple(Consumer<TripleLike> generalizedConsumer) {
+ return new StreamRDFBase() {
+ @Override
+ public void triple(org.apache.jena.graph.Triple triple) {
+ generalizedConsumer.accept(fromJenaGeneralized(triple));
+ }
+ };
+ }
+
+ /**
+ * Create a {@link StreamRDF} instance that inserts generalized
+ * {@link QuadLike}s. into a the provided {@link Consumer}.
+ * <p>
+ * A generalized quad allows any {@link RDFTerm} for
+ * {@link QuadLike#getSubject()}, {@link TripleLike#getPredicate()},
+ * {@link QuadLike#getObject()} and {@link QuadLike#getGraphName()} .
+ * <p>
+ * The returned {@link StreamRDF} can be used for instance with Jena's
+ * {@link RDFDataMgr#parse(StreamRDF, String)}.
+ *
+ * @param generalizedConsumer
+ * A {@link Consumer} of generalized {@link QuadLike}s
+ * @return A {@link StreamRDF} that will stream generalized quads to the
+ * consumer
+ */
+ public StreamRDF streamJenaToGeneralizedQuad(Consumer<QuadLike<RDFTerm>> generalizedConsumer) {
+ return new StreamRDFBase() {
+ @Override
+ public void quad(org.apache.jena.sparql.core.Quad quad) {
+ generalizedConsumer.accept(fromJenaGeneralized(quad));
+ }
+ };
+ }
+
+ /**
+ * Convert a CommonsRDF Graph to a Jena Graph. If the Graph was from Jena
+ * originally, return that original object else create a copy using Jena
+ * objects.
+ *
+ * @param graph Commons RDF {@link Graph} to convert
+ * @return Converted Jena {@link org.apache.jena.graph.Graph}
+ */
+ public org.apache.jena.graph.Graph toJena(Graph graph) {
+ if (graph instanceof JenaGraph)
+ return ((JenaGraph) graph).asJenaGraph();
+ org.apache.jena.graph.Graph g = GraphFactory.createGraphMem();
+ graph.stream().forEach(t -> g.add(toJena(t)));
+ return g;
+ }
+
+ /**
+ * Convert a CommonsRDF RDFTerm to a Jena Node. If the RDFTerm was from Jena
+ * originally, return that original object, else create a copy using Jena
+ * objects.
+ *
+ * @param term Commons RDF {@link RDFTerm} to convert
+ * @return Converted Jena {@link Node}
+ */
+ public Node toJena(RDFTerm term) {
+ if (term == null) {
+ return null;
+ }
+ if (term instanceof JenaRDFTerm)
+ // TODO: What if it's a JenaBlankNodeImpl with
+ // a different salt? Do we need to rewrite the
+ // jena blanknode identifier?
+ return ((JenaRDFTerm) term).asJenaNode();
+
+ if (term instanceof IRI)
+ return NodeFactory.createURI(((IRI) term).getIRIString());
+
+ if (term instanceof Literal) {
+ Literal lit = (Literal) term;
+ RDFDatatype dt = NodeFactory.getType(lit.getDatatype().getIRIString());
+ String lang = lit.getLanguageTag().orElse("");
+ return NodeFactory.createLiteral(lit.getLexicalForm(), lang, dt);
+ }
+
+ if (term instanceof BlankNode) {
+ String id = ((BlankNode) term).uniqueReference();
+ return NodeFactory.createBlankNode(id);
+ }
+ throw new ConversionException("Not a concrete RDF Term: " + term);
+ }
+
+ /**
+ * Convert a CommonsRDF {@link Triple} to a Jena
+ * {@link org.apache.jena.graph.Triple}.
+ * <p>
+ * If the triple was from Jena originally, return that original object, else
+ * create a copy using Jena objects.
+ *
+ * @param triple Commons RDF {@link Triple} to convert
+ * @return Converted Jena {@link org.apache.jena.graph.Triple}
+ */
+ public org.apache.jena.graph.Triple toJena(Triple triple) {
+ if (triple instanceof JenaTriple)
+ return ((JenaTriple) triple).asJenaTriple();
+ return org.apache.jena.graph.Triple.create(
+ toJena(triple.getSubject()),
+ toJena(triple.getPredicate()),
+ toJena(triple.getObject()));
+ }
+
+
+ /**
+ * Convert a CommonsRDF {@link Quad} to a Jena
+ * {@link org.apache.jena.sparql.core.Quad}.
+ * <p>
+ * If the quad was from Jena originally, return that original object,
+ * otherwise create a copy using Jena objects.
+ *
+ * @param quad Commons RDF {@link Quad} to convert
+ * @return Converted Jena {@link org.apache.jena.sparql.core.Quad}
+ */
+ public org.apache.jena.sparql.core.Quad toJena(Quad quad) {
+ if (quad instanceof JenaQuad) {
+ return ((JenaQuad) quad).asJenaQuad();
+ }
+ return org.apache.jena.sparql.core.Quad.create(
+ toJena(quad.getGraphName().orElse(null)),
+ toJena(quad.getSubject()),
+ toJena(quad.getPredicate()),
+ toJena(quad.getObject()));
+ }
+
+ // Some simple validations - full IRI parsing is not cheap.
+ private void validateIRI(String iri) {
+ if (iri.contains(" "))
+ throw new IllegalArgumentException();
+ if (iri.contains("<"))
+ throw new IllegalArgumentException();
+ if (iri.contains(">"))
+ throw new IllegalArgumentException();
+ }
+
+ private static void validateLang(String languageTag) {
+ if (languageTag.contains(" "))
+ throw new IllegalArgumentException("Invalid language tag: " + languageTag);
+ }
+
+ /**
+ * Return the {@link UUID} salt used by this factory.
+ * <p>
+ * The salt is used for the purposes of {@link BlankNode} identity, see
+ * {@link BlankNode#uniqueReference()} for details.
+ * <p>
+ * This salt can be used with the constructor
+ * {@link JenaRDF#JenaFactory(UUID)}
+ * if consistent or reproducible {@link BlankNode}s are desirable.
+ *
+ * @return The {@link UUID} used as salt
+ */
+ public UUID getSalt() {
+ return salt;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/384a8337/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java b/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
index ffbb61c..d78870c 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
@@ -30,7 +30,7 @@ import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.TripleLike;
import org.apache.commons.rdf.experimental.RDFParser;
import org.apache.commons.rdf.jena.JenaGraph;
-import org.apache.commons.rdf.jena.JenaFactory;
+import org.apache.commons.rdf.jena.JenaRDF;
import org.apache.commons.rdf.simple.experimental.AbstractRDFParser;
import org.apache.jena.graph.Graph;
import org.apache.jena.riot.Lang;
@@ -44,7 +44,7 @@ public class JenaRDFParser extends AbstractRDFParser<JenaRDFParser> implements R
private Consumer<QuadLike<RDFTerm>> generalizedConsumerQuad;
protected RDF createRDFTermFactory() {
- return new JenaFactory();
+ return new JenaRDF();
}
public JenaRDFParser targetGeneralizedTriple(Consumer<TripleLike> consumer) {
@@ -71,21 +71,21 @@ public class JenaRDFParser extends AbstractRDFParser<JenaRDFParser> implements R
@Override
protected void parseSynchronusly() throws IOException {
StreamRDF dest;
- JenaFactory jenaFactory = getJenaFactory();
+ JenaRDF jenaRDF = getJenaFactory();
if (getTargetGraph().isPresent() && getTargetGraph().get() instanceof JenaGraph) {
Graph jenaGraph = ((JenaGraph) getTargetGraph().get()).asJenaGraph();
dest = StreamRDFLib.graph(jenaGraph);
} else {
if (generalizedConsumerQuad != null) {
- dest = jenaFactory.streamJenaToGeneralizedQuad(generalizedConsumerQuad);
+ dest = jenaRDF.streamJenaToGeneralizedQuad(generalizedConsumerQuad);
} else if (generalizedConsumerTriple != null) {
- dest = jenaFactory.streamJenaToGeneralizedTriple(generalizedConsumerTriple);
+ dest = jenaRDF.streamJenaToGeneralizedTriple(generalizedConsumerTriple);
} else {
- dest = JenaFactory.streamJenaToCommonsRDF(getRdfTermFactory().get(), getTarget());
+ dest = JenaRDF.streamJenaToCommonsRDF(getRdfTermFactory().get(), getTarget());
}
}
- Lang lang = getContentTypeSyntax().flatMap(jenaFactory::rdfSyntaxToLang).orElse(null);
+ Lang lang = getContentTypeSyntax().flatMap(jenaRDF::rdfSyntaxToLang).orElse(null);
String baseStr = getBase().map(IRI::getIRIString).orElse(null);
if (getSourceIri().isPresent()) {
@@ -99,9 +99,9 @@ public class JenaRDFParser extends AbstractRDFParser<JenaRDFParser> implements R
}
}
- private JenaFactory getJenaFactory() {
- return (JenaFactory) getRdfTermFactory()
- .filter(JenaFactory.class::isInstance)
+ private JenaRDF getJenaFactory() {
+ return (JenaRDF) getRdfTermFactory()
+ .filter(JenaRDF.class::isInstance)
.orElseGet(this::createRDFTermFactory);
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/384a8337/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
index c66a1da..d538076 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
@@ -26,7 +26,7 @@ import org.apache.commons.rdf.api.QuadLike;
import org.apache.commons.rdf.api.RDFTerm;
import org.apache.commons.rdf.jena.JenaQuad;
import org.apache.commons.rdf.jena.JenaQuadLike;
-import org.apache.commons.rdf.jena.JenaFactory;
+import org.apache.commons.rdf.jena.JenaRDF;
import org.apache.commons.rdf.jena.JenaTriple;
import org.apache.jena.graph.Triple;
import org.apache.jena.sparql.core.Quad;
@@ -86,7 +86,7 @@ abstract class AbstractQuadLike<S extends RDFTerm, P extends RDFTerm, O extends
@Override
public org.apache.jena.sparql.core.Quad asJenaQuad() {
- JenaFactory factory = new JenaFactory();
+ JenaRDF factory = new JenaRDF();
if (quad == null) {
quad = org.apache.jena.sparql.core.Quad.create(
factory.toJena(graphName.orElse(null)),
@@ -99,7 +99,7 @@ abstract class AbstractQuadLike<S extends RDFTerm, P extends RDFTerm, O extends
@Override
public org.apache.jena.graph.Triple asJenaTriple() {
- JenaFactory factory = new JenaFactory();
+ JenaRDF factory = new JenaRDF();
if (triple == null) {
triple = org.apache.jena.graph.Triple.create(
factory.toJena(subject),
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/384a8337/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
index 67fccb7..66ef867 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
@@ -35,7 +35,7 @@ import org.apache.commons.rdf.jena.JenaIRI;
import org.apache.commons.rdf.jena.JenaLiteral;
import org.apache.commons.rdf.jena.JenaQuad;
import org.apache.commons.rdf.jena.JenaRDFTerm;
-import org.apache.commons.rdf.jena.JenaFactory;
+import org.apache.commons.rdf.jena.JenaRDF;
import org.apache.commons.rdf.jena.JenaTriple;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.NodeFactory;
@@ -49,7 +49,7 @@ import org.apache.jena.sparql.graph.GraphFactory;
* <p>
* This class is deliberately an abstract class, as it is an internal helper
* which <strong>may change</strong> in any minor version update; users should
- * instead use {@link JenaFactory}.
+ * instead use {@link JenaRDF}.
* <p>
* For the purpose of blank node identity, some of these methods require a
* {@link UUID} to use as a salt. See {@link BlankNode#uniqueReference()} for
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/384a8337/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
index 67b2988..81c9a07 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
@@ -32,7 +32,7 @@ import org.apache.commons.rdf.api.Quad;
import org.apache.commons.rdf.api.RDFTerm;
import org.apache.commons.rdf.jena.JenaDataset;
import org.apache.commons.rdf.jena.JenaGraph;
-import org.apache.commons.rdf.jena.JenaFactory;
+import org.apache.commons.rdf.jena.JenaRDF;
import org.apache.jena.atlas.iterator.Iter;
import org.apache.jena.graph.Node;
import org.apache.jena.riot.Lang;
@@ -44,12 +44,12 @@ class JenaDatasetImpl implements JenaDataset {
private DatasetGraph graph;
private UUID salt;
- private JenaFactory factory;
+ private JenaRDF factory;
JenaDatasetImpl(DatasetGraph graph, UUID salt) {
this.graph = graph;
this.salt = salt;
- this.factory = new JenaFactory(salt);
+ this.factory = new JenaRDF(salt);
}
@Override
@@ -136,14 +136,14 @@ class JenaDatasetImpl implements JenaDataset {
@Override
public Stream<? extends Quad> stream() {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.find(ANY, ANY, ANY, ANY), true)
.map(factory::fromJena);
}
@Override
public Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> g, BlankNodeOrIRI s, IRI p, RDFTerm o) {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.find(toJenaPattern(g), toJenaPattern(s), toJenaPattern(p), toJenaPattern(o)), true)
.map(factory::fromJena);
}
@@ -175,14 +175,14 @@ class JenaDatasetImpl implements JenaDataset {
@Override
public Stream<BlankNodeOrIRI> getGraphNames() {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.listGraphNodes()).map(node ->
(BlankNodeOrIRI) factory.fromJena(node));
}
@Override
public Iterable<Quad> iterate() {
- final JenaFactory factory = new JenaFactory(salt);
+ final JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.find(), false)
.map(q -> (Quad) factory.fromJena(q))
::iterator;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/384a8337/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
index bad996a..eab4089 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
@@ -27,7 +27,7 @@ import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.RDFTerm;
import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.jena.JenaGraph;
-import org.apache.commons.rdf.jena.JenaFactory;
+import org.apache.commons.rdf.jena.JenaRDF;
import org.apache.jena.atlas.iterator.Iter;
import org.apache.jena.graph.Node;
import org.apache.jena.rdf.model.Model;
@@ -39,20 +39,20 @@ class JenaGraphImpl implements JenaGraph {
private final org.apache.jena.graph.Graph graph;
private final UUID salt;
- private final transient JenaFactory factory;
+ private final transient JenaRDF factory;
private Model model;
JenaGraphImpl(org.apache.jena.graph.Graph graph, UUID salt) {
this.graph = graph;
this.salt = salt;
- this.factory = new JenaFactory(salt);
+ this.factory = new JenaRDF(salt);
}
JenaGraphImpl(Model model, UUID salt) {
this.model = model;
this.graph = model.getGraph();
this.salt = salt;
- this.factory = new JenaFactory(salt);
+ this.factory = new JenaRDF(salt);
}
@Override
@@ -116,13 +116,13 @@ class JenaGraphImpl implements JenaGraph {
@Override
public Stream<? extends Triple> stream() {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.find(null, null, null), true).map(factory::fromJena);
}
@Override
public Stream<? extends Triple> stream(BlankNodeOrIRI s, IRI p, RDFTerm o) {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.find(toJenaAny(s), toJenaAny(p), toJenaAny(o)), true)
.map(factory::fromJena);
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/384a8337/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
----------------------------------------------------------------------
diff --git a/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory b/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
index f39e71d..afe6af3 100644
--- a/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
+++ b/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
@@ -1 +1 @@
-org.apache.commons.rdf.jena.JenaFactory
+org.apache.commons.rdf.jena.JenaRDF
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/384a8337/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java b/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
index 87ce543..836e2ec 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
@@ -31,10 +31,10 @@ public class JenaServiceLoaderTest {
public void testServiceLoaderLookup() {
ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class);
for (RDF impl : loader) {
- if (impl instanceof JenaFactory) {
+ if (impl instanceof JenaRDF) {
return; // yay
}
}
- fail("JenaFactory not found in ServiceLoader");
+ fail("JenaRDF not found in ServiceLoader");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/384a8337/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
index 3c7caa8..a11fdc6 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
@@ -25,7 +25,7 @@ public class TestGraphJena extends AbstractGraphTest {
@Override
public RDF createFactory() {
- return new JenaFactory() ;
+ return new JenaRDF() ;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/384a8337/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
index ad71a58..16e3e67 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
@@ -56,10 +56,10 @@ public class TestJenaGraphToCommonsRDFGraph {
RDFDataMgr.read(jGraph, turtleFile.toUri().toString()) ;
// "graph" is a CommonsRDF graph
- Graph graph = new JenaFactory().fromJena(jGraph) ;
+ Graph graph = new JenaRDF().fromJena(jGraph) ;
// Add to CommonsRDF Graph
- RDF rft = new JenaFactory() ;
+ RDF rft = new JenaRDF() ;
graph.add(rft.createIRI("http://example/s2"),
rft.createIRI("http://example/p2"),
rft.createLiteral("foo")) ;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/384a8337/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
index b5b3363..7760e1f 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
@@ -54,7 +54,7 @@ public class TestRDFParserBuilder {
@Test
public void parseTurtle() throws Exception {
- Graph g = new JenaFactory().createGraph();
+ Graph g = new JenaRDF().createGraph();
Future<ParseResult> gFuture = new JenaRDFParser().contentType(RDFSyntax.TURTLE).source(turtleFile)
.target(g).parse();
gFuture.get(5, TimeUnit.SECONDS);
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/384a8337/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
index f917a68..327f218 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
@@ -25,7 +25,7 @@ public class TestRDFTermFactoryJena extends AbstractRDFTermFactoryTest {
@Override
public RDF createFactory() {
- return new JenaFactory() ;
+ return new JenaRDF() ;
}
}
[50/50] [abbrv] incubator-commonsrdf git commit: COMMONSRDF-7 clarify
immutability and hashcode
Posted by st...@apache.org.
COMMONSRDF-7 clarify immutability and hashcode
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/797a4cd5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/797a4cd5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/797a4cd5
Branch: refs/heads/COMMONSRDF-7
Commit: 797a4cd53f62585ecff7f49864f3cd75a55ba0f9
Parents: e0dc34a
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 28 13:52:49 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 28 14:06:58 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/api/Quad.java | 55 ++++++++++++--------
.../org/apache/commons/rdf/api/RDFTerm.java | 37 ++++++++-----
.../java/org/apache/commons/rdf/api/Triple.java | 29 +++++++----
3 files changed, 74 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/797a4cd5/api/src/main/java/org/apache/commons/rdf/api/Quad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Quad.java b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
index a242ae3..0b19ec1 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Quad.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
@@ -17,31 +17,40 @@
*/
package org.apache.commons.rdf.api;
-import java.util.List;
-import java.util.Map;
import java.util.Objects;
import java.util.Optional;
-import java.util.Set;
/**
* A Quad is a statement in a
* <a href= "http://www.w3.org/TR/rdf11-concepts/#section-dataset" >RDF-1.1
- * Dataset</a>, as defined by
- * <a href= "https://www.w3.org/TR/2014/NOTE-rdf11-datasets-20140225/#quad-semantics" >RDF-1.1
- * Concepts and Abstract Syntax</a>, a W3C Working Group Note published on 25
- * February 2014.
+ * Dataset</a>, as defined by <a href=
+ * "https://www.w3.org/TR/2014/NOTE-rdf11-datasets-20140225/#quad-semantics"
+ * >RDF-1.1 Concepts and Abstract Syntax</a>, a W3C Working Group Note published
+ * on 25 February 2014.
* <p>
- * A {@link Quad} object in Commons RDF is considered <em>immutable</em>, that
- * is, over its life time it will have consistent behaviour for its
- * {@link #equals(Object)} and {@link #hashCode()}, and the instances returned
- * from {@link #getGraphName()}, {@link #getSubject()}, {@link #getPredicate()}
- * and {@link #getObject()} will have consistent {@link Object#equals(Object)}
- * behaviour.
+ * A <code>Quad</code> object in Commons RDF is considered
+ * <strong>immutable</strong>, that is, over its life time it will have
+ * consistent behaviour for its {@link #equals(Object)}, and the instances
+ * returned from {@link #getGraphName()}, {@link #getSubject()},
+ * {@link #getPredicate()} and {@link #getObject()} will have consistent
+ * {@link Object#equals(Object)} behaviour.
* <p>
- * Thus, a {@link Quad} is thread-safe and can be safely used in collections
- * like {@link List}, {@link Map} or {@link Set}, and a {@link Quad} can be
- * used interchangeably across Commons RDF implementations.
- *
+ * Note that <code>Quad</code> methods are not required to return object
+ * identical (<code>==</code>) instances as long as they are equivalent
+ * according to their {@link RDFTerm#equals(Object)} and/or
+ * {@link Optional#equals(Object)}. Specialisations of <code>Quad</code> may
+ * provide additional methods that are documented to be mutable.
+ * <p>
+ * <code>Quad</code> methods are <strong>thread-safe</strong>, however
+ * specialisations may provide additional methods that are documented to not be
+ * thread-safe.
+ * <p>
+ * <code>Quad</code>s can be safely used in hashing collections like
+ * {@link java.util.HashSet} and {@link java.util.HashMap}.
+ * <p>
+ * Any <code>Quad</code> can be used interchangeably across Commons RDF
+ * implementations.
+ *
* @since 0.3.0-incubating
* @see Dataset
* @see RDF#createQuad(BlankNodeOrIRI,BlankNodeOrIRI,IRI,RDFTerm)
@@ -53,7 +62,7 @@ public interface Quad extends QuadLike<BlankNodeOrIRI> {
/**
* The graph name (graph label) of this quad, if present.
- *
+ *
* If {@link Optional#isPresent()}, then the {@link Optional#get()} is
* either a {@link BlankNode} or an {@link IRI}, indicating the
* <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-named-graph">graph
@@ -65,7 +74,7 @@ public interface Quad extends QuadLike<BlankNodeOrIRI> {
* @return If {@link Optional#isPresent()}, the graph name
* {@link BlankNodeOrIRI} of this quad, otherwise
* {@link Optional#empty()}, indicating the default graph.
- *
+ *
* @see <a href="https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset">RDF-
* 1.1 Dataset</a>
*/
@@ -114,7 +123,7 @@ public interface Quad extends QuadLike<BlankNodeOrIRI> {
* {@link #getGraphName()} value of {@link Optional#empty()}, but MUST
* follow the {@link Triple#equals(Object)} semantics. This means that the
* following MUST be true:
- *
+ *
* <pre>
* Quad q1, q2;
* if (q1.equals(q2)) {
@@ -126,14 +135,14 @@ public interface Quad extends QuadLike<BlankNodeOrIRI> {
* assert (!q1.getGraphName().equals(q2.getGraphName()));
* }
* </pre>
- *
+ *
* The <code>default</code> implementation of this method return a proxy
* {@link Triple} instance that keeps a reference to this {@link Quad} to
* call the underlying {@link TripleLike} methods, but supplies a
* {@link Triple} compatible implementation of {@link Triple#equals(Object)}
* and {@link Triple#hashCode()}. Implementations may override this method,
* e.g. for a more efficient solution.
- *
+ *
* @return A {@link Triple} that contains the same {@link TripleLike}
* properties as this Quad.
*/
@@ -191,7 +200,7 @@ public interface Quad extends QuadLike<BlankNodeOrIRI> {
* this Quad's {@link #getGraphName()} is {@link Optional#empty()}. To test
* triple-like equivalence, callers can use:
* </p>
- *
+ *
* <pre>
* Quad q1;
* Triple t2;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/797a4cd5/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
index 47fd432..dc095b7 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
@@ -17,26 +17,35 @@
*/
package org.apache.commons.rdf.api;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* An <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-term" >RDF-1.1
* Term</a>, as defined by
* <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.
* <p>
- * A {@link RDFTerm} object in Commons RDF is considered <em>immutable</em>,
- * that is, over its life time it will have consistent behaviour for its
- * {@link #equals(Object)} and {@link #hashCode()}, and objects returned from
- * its getter methods (e.g. {@link IRI#getIRIString()} and
- * {@link Literal#getLanguageTag()}) will have consistent
+ * A {@link RDFTerm} object in Commons RDF is considered
+ * <strong>immutable</strong>, that is, over its life time it will have
+ * consistent behaviour for its {@link #equals(Object)} and {@link #hashCode()},
+ * and objects returned from its getter methods (e.g. {@link IRI#getIRIString()}
+ * and {@link Literal#getLanguageTag()}) will have consistent
* {@link #equals(Object)} behaviour.
* <p>
- * Thus, an {@link RDFTerm} is thread-safe and can be safely used in collections
- * like {@link List}, {@link Map} or {@link Set}, and a {@link RDFTerm} can be
- * used interchangeably across Commons RDF implementations.
+ * Note that methods in <code>RDFTerm</code> and its Commons RDF specialisations
+ * {@link IRI}, {@link BlankNode} and {@link Literal} are not required to return
+ * object identical (<code>==</code>) instances as long as they are equivalent
+ * according to their {@link Object#equals(Object)}. Further specialisations may
+ * provide additional methods that are documented to be mutable.
+ * <p>
+ * Methods in <code>RDFTerm</code> and its Commons RDF specialisations
+ * {@link IRI}, {@link BlankNode} and {@link Literal} are
+ * <strong>thread-safe</strong>, however further specialisations may add
+ * additional methods that are documented to not be thread-safe.
+ * <p>
+ * <code>RDFTerm</code>s can be safely used in hashing collections like
+ * {@link java.util.HashSet} and {@link java.util.HashMap}.
+ * <p>
+ * Any <code>RDFTerm</code> can be used interchangeably across Commons RDF
+ * implementations.
*
* @see <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-term" >RDF-1.1
* Term</a>
@@ -68,7 +77,7 @@ public interface RDFTerm {
* @see IRI#equals(Object)
* @see BlankNode#equals(Object)
* @see Literal#equals(Object)
- *
+ *
* @param other
* Another object
* @return true if other is a RDFTerm and is equal to this
@@ -85,7 +94,7 @@ public interface RDFTerm {
* This method MUST be implemented in conjunction with
* {@link #equals(Object)} so that two equal RDFTerm produce the same hash
* code.
- *
+ *
* @see IRI#hashCode()
* @see Literal#hashCode()
* @see BlankNode#hashCode()
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/797a4cd5/api/src/main/java/org/apache/commons/rdf/api/Triple.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Triple.java b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
index 51c4a39..7772851 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Triple.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
@@ -17,27 +17,36 @@
*/
package org.apache.commons.rdf.api;
-import java.util.List;
-import java.util.Map;
import java.util.Objects;
-import java.util.Set;
/**
* An <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple" >RDF-1.1
* Triple</a>, as defined by
* <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.<br>
+ * Abstract Syntax</a>, a W3C Recommendation published on 25 February 2014.
* <p>
- * A {@link Triple} object in Commons RDF is considered <em>immutable</em>, that
- * is, over its life time it will have consistent behaviour for its
- * {@link #equals(Object)} and {@link #hashCode()}, and the {@link RDFTerm}
+ * A <code>Triple</code> object in Commons RDF is considered
+ * <strong>immutable</strong>, that is, over its life time it will have
+ * consistent behaviour for its {@link #equals(Object)}, and the {@link RDFTerm}
* instances returned from {@link #getSubject()}, {@link #getPredicate()} and
* {@link #getObject()} will have consistent {@link RDFTerm#equals(Object)}
* behaviour.
* <p>
- * Thus, a {@link Triple} is thread-safe and can be safely used in collections
- * like {@link List}, {@link Map} or {@link Set}, and a {@link Triple} can be
- * used interchangeably across Commons RDF implementations.
+ * Note that <code>Triple</code> methods are not required to return object
+ * identical (<code>==</code>) instances as long as they are equivalent
+ * according to {@link RDFTerm#equals(Object)}. Specialisations of
+ * <code>Triple</code> may provide additional methods that are documented to be
+ * mutable.
+ * <p>
+ * <code>Triple</code> methods are <strong>thread-safe</strong>, however
+ * specialisations may provide additional methods that are documented to not be
+ * thread-safe.
+ * <p>
+ * <code>Triple</code>s can be safely used in hashing collections like
+ * {@link java.util.HashSet} and {@link java.util.HashMap}.
+ * <p>
+ * Any <code>Triple</code> can be used interchangeably across Commons RDF
+ * implementations.
*
* @see Quad
* @see RDF#createTriple(BlankNodeOrIRI,IRI,RDFTerm)
[20/50] [abbrv] incubator-commonsrdf git commit: Merge branch
'master' into COMMONSRDF-46
Posted by st...@apache.org.
Merge branch 'master' into COMMONSRDF-46
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/d6306ad4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/d6306ad4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/d6306ad4
Branch: refs/heads/COMMONSRDF-7
Commit: d6306ad47b151b20bde77a9bff70532f614f9285
Parents: 44b4b68 2a5dbf9
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 26 12:50:50 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 26 12:50:50 2016 +0100
----------------------------------------------------------------------
api/pom.xml | 7 -
integration-tests/pom.xml | 60 +++++++
.../rdf/integrationtests/AllToAllTest.java | 178 +++++++++++++++++++
jena/pom.xml | 9 +-
.../org/apache/commons/rdf/jena/JenaRDF.java | 153 ++++++++--------
.../rdf/jena/experimental/JenaRDFParser.java | 4 +-
.../commons/rdf/jena/impl/AbstractQuadLike.java | 28 +--
.../rdf/jena/impl/InternalJenaFactory.java | 72 ++++----
.../commons/rdf/jena/impl/JenaDatasetImpl.java | 28 +--
.../commons/rdf/jena/impl/JenaGraphImpl.java | 30 ++--
.../services/org.apache.commons.rdf.api.RDF | 1 +
.../org.apache.commons.rdf.api.RDFFactory | 1 -
.../jena/TestJenaGraphToCommonsRDFGraph.java | 86 +++++++--
jena/src/test/resources/log4j.properties | 33 ----
jsonld-java/pom.xml | 7 +-
.../services/org.apache.commons.rdf.api.RDF | 1 +
.../org.apache.commons.rdf.api.RDFFactory | 1 -
pom.xml | 40 ++++-
rdf4j/pom.xml | 10 +-
.../services/org.apache.commons.rdf.api.RDF | 1 +
.../org.apache.commons.rdf.api.RDFFactory | 1 -
simple/pom.xml | 5 -
.../services/org.apache.commons.rdf.api.RDF | 1 +
.../org.apache.commons.rdf.api.RDFFactory | 1 -
.../commons/rdf/simple/SimpleGraphTest.java | 2 +-
25 files changed, 517 insertions(+), 243 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
----------------------------------------------------------------------
diff --cc integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
index 0000000,1b32e35..e90ea47
mode 000000,100644..100644
--- a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
+++ b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
@@@ -1,0 -1,178 +1,178 @@@
+ /**
+ * 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.integrationtests;
+
+ import static org.junit.Assert.assertEquals;
+ import static org.junit.Assert.assertTrue;
+
+ import java.util.ArrayList;
+ import java.util.Arrays;
+ import java.util.Collection;
+ import java.util.List;
+
+ import org.apache.commons.rdf.api.BlankNode;
+ 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.RDF;
+ import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDFTermFactory;
+ import org.apache.commons.rdf.api.Triple;
-import org.apache.commons.rdf.jena.JenaFactory;
-import org.apache.commons.rdf.jsonldjava.JsonLdFactory;
-import org.apache.commons.rdf.rdf4j.RDF4JFactory;
-import org.apache.commons.rdf.simple.SimpleRDFTermFactory;
++import org.apache.commons.rdf.jena.JenaRDF;
++import org.apache.commons.rdf.jsonldjava.JsonLdRDF;
++import org.apache.commons.rdf.rdf4j.RDF4J;
++import org.apache.commons.rdf.simple.SimpleRDF;
+ import org.junit.Test;
+ import org.junit.runner.RunWith;
+ import org.junit.runners.Parameterized;
+ import org.junit.runners.Parameterized.Parameters;
+
+ @RunWith(Parameterized.class)
+ public class AllToAllTest {
+
- private RDFTermFactory nodeFactory;
- private RDFTermFactory graphFactory;
++ private RDF nodeFactory;
++ private RDF graphFactory;
+
+
+ public AllToAllTest(
- Class<? extends RDFTermFactory> from,
- Class<? extends RDFTermFactory> to) throws InstantiationException, IllegalAccessException {
++ Class<? extends RDF> from,
++ Class<? extends RDF> to) throws InstantiationException, IllegalAccessException {
+ this.nodeFactory = from.newInstance();
+ this.graphFactory = to.newInstance();
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Parameters(name = "{index}: {0}->{1}")
+ public static Collection<Object[]> data() {
+ List<Class> factories = Arrays.asList(
- SimpleRDFTermFactory.class,
- JenaFactory.class,
- RDF4JFactory.class,
- JsonLdFactory.class);
++ SimpleRDF.class,
++ JenaRDF.class,
++ RDF4J.class,
++ JsonLdRDF.class);
+ Collection<Object[]> allToAll = new ArrayList<>();
+ for (Class from : factories) {
+ for (Class to : factories) {
+ // NOTE: we deliberately include self-to-self here
+ // to test two instances of the same implementation
+ allToAll.add(new Object[]{from, to});
+ }
+ }
+ return allToAll;
+ }
+
+ /**
+ * This test creates a {@link Graph} with the first
+ * {@link RDFTermFactory}, then inserts/queries with
+ * triples using {@link RDFTerm}s created with the second factory.
+ *
+ * @param nodeFactory Factory to create {@link RDFTerm} instances
+ * @param graphFactory Factory to create {@link Graph}
+ * @throws Exception
+ */
+ @Test
+ public void addTermsFromOtherFactory() throws Exception {
+ Graph g = graphFactory.createGraph();
+ BlankNode s = nodeFactory.createBlankNode();
+ IRI p = nodeFactory.createIRI("http://example.com/p");
+ Literal o = nodeFactory.createLiteral("Hello");
+
+ g.add(s, p, o);
+
+ // blankNode should still work with g.contains()
+ assertTrue(g.contains(s, p, o));
+ Triple t1 = g.stream().findAny().get();
+
+ // Can't make assumptions about BlankNode equality - it might
+ // have been mapped to a different BlankNode.uniqueReference()
+ // assertEquals(s, t.getSubject());
+
+ assertEquals(p, t1.getPredicate());
+ assertEquals(o, t1.getObject());
+
+ IRI s2 = nodeFactory.createIRI("http://example.com/s2");
+ g.add(s2, p, s);
+ assertTrue(g.contains(s2, p, s));
+
+ // This should be mapped to the same BlankNode
+ // (even if it has a different identifier), e.g.
+ // we should be able to do:
+
+ Triple t2 = g.stream(s2, p, null).findAny().get();
+
+ BlankNode bnode = (BlankNode) t2.getObject();
+ // And that (possibly adapted) BlankNode object should
+ // match the subject of t1 statement
+ assertEquals(bnode, t1.getSubject());
+ // And can be used as a key:
+ Triple t3 = g.stream(bnode, p, null).findAny().get();
+ assertEquals(t1, t3);
+ }
+
+
+ /**
+ * This is a variation of {@link #addTermsFromOtherFactory(RDFTermFactory, RDFTermFactory)},
+ * but here {@link Triple} is created in the "foreign" nodeFactory before adding to the graph.
+ *
+ * @param nodeFactory Factory to create {@link RDFTerm} and {@link Triple}s
+ * @param graphFactory Factory to create {@link Graph}
+ * @throws Exception
+ */
+ @Test
+ public void addTriplesFromOtherFactory() throws Exception {
+ Graph g = graphFactory.createGraph();
+ BlankNode s = nodeFactory.createBlankNode();
+ IRI p = nodeFactory.createIRI("http://example.com/p");
+ Literal o = nodeFactory.createLiteral("Hello");
+
+ Triple srcT1 = nodeFactory.createTriple(s, p, o);
+ // This should work even with BlankNode as they are from the same factory
+ assertEquals(s, srcT1.getSubject());
+ assertEquals(p, srcT1.getPredicate());
+ assertEquals(o, srcT1.getObject());
+ g.add(srcT1);
+
+ // what about the blankNode within?
+ assertTrue(g.contains(srcT1));
+ Triple t1 = g.stream().findAny().get();
+
+ // Can't make assumptions about BlankNode equality - it might
+ // have been mapped to a different BlankNode.uniqueReference()
+ //assertEquals(srcT1, t1);
+ //assertEquals(s, t1.getSubject());
+ assertEquals(p, t1.getPredicate());
+ assertEquals(o, t1.getObject());
+
+ IRI s2 = nodeFactory.createIRI("http://example.com/s2");
+ Triple srcT2 = nodeFactory.createTriple(s2, p, s);
+ g.add(srcT2);
+ assertTrue(g.contains(srcT2));
+
+ // This should be mapped to the same BlankNode
+ // (even if it has a different identifier), e.g.
+ // we should be able to do:
+
+ Triple t2 = g.stream(s2, p, null).findAny().get();
+
+ BlankNode bnode = (BlankNode) t2.getObject();
+ // And that (possibly adapted) BlankNode object should
+ // match the subject of t1 statement
+ assertEquals(bnode, t1.getSubject());
+ // And can be used as a key:
+ Triple t3 = g.stream(bnode, p, null).findAny().get();
+ assertEquals(t1, t3);
+ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
----------------------------------------------------------------------
diff --cc jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
index 0a3f1b0,0000000..22db284
mode 100644,000000..100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
@@@ -1,729 -1,0 +1,742 @@@
+/**
+ * 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.jena;
+
+import java.util.Optional;
+import java.util.UUID;
+import java.util.function.Consumer;
+
+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;
+import org.apache.commons.rdf.api.QuadLike;
+import org.apache.commons.rdf.api.RDFSyntax;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.RDF;
+import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.api.TripleLike;
+import org.apache.commons.rdf.jena.impl.InternalJenaFactory;
+import org.apache.jena.datatypes.RDFDatatype;
+import org.apache.jena.datatypes.xsd.XSDDatatype;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFDataMgr;
+import org.apache.jena.riot.RDFLanguages;
+import org.apache.jena.riot.system.StreamRDF;
+import org.apache.jena.riot.system.StreamRDFBase;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.graph.GraphFactory;
+
+/**
+ * Apache Jena RDF implementation.
+ * <p>
- * Instances of JenaRDF can also convert existing objects from/to
- * <code>org.apache.jena</code> types with methods like
- * {@link #fromJena(org.apache.jena.graph.Graph)} and {@link #toJena(Graph)}.
++ * Instances of JenaRDF can also
++ * convert existing objects from Jena with methods like
++ * {@link #asRDFTerm(Node)} and {@link #asGraph(org.apache.jena.graph.Graph)},
++ * and vice versa from any Commons RDF object to Jena with the
++ * <code>asJena*</code> methods like {@link #asJenaNode(RDFTerm)} and
++ * {@link #asJenaGraph(Graph)}.
+ * <p>
- * For the purpose of {@link BlankNode} identity, JenaRDF instances use an
- * internal {@link UUID} as a salt. See {@link BlankNode#uniqueReference()} for
- * details.
++ * Note that Commons RDF objects created by this class implement the
++ * specializations interfaces like {@link JenaRDFTerm}, {@link JenaGraph} and
++ * {@link JenaTriple}, which provide access to the underlying Jena objects, e.g.
++ * with {@link JenaRDFTerm#asJenaNode()}.
++ * <p>
++ * For the purpose of {@link BlankNode} identity when using
++ * {@link #createBlankNode(String)} (see {@link BlankNode#equals(Object)} and
++ * {@link BlankNode#uniqueReference()}), each instance of JenaRDF uses an
++ * internal random state. If for some reason consistent/reproducible BlankNode
++ * identity is desired, it is possible to retrieve the state as a UUID using
++ * {@link #salt} for subsequent use with {@link JenaFactory#JenaFactory(UUID)} -
++ * note that such consistency is only guaranteed within the same minor version
++ * of Commons RDF.
+ *
+ * @see RDF
+ */
+public final class JenaRDF implements RDF {
+
+ private static InternalJenaFactory internalJenaFactory = new InternalJenaFactory(){};
+
+ private final UUID salt;
+
+ /**
+ * Create a JenaRDF.
+ * <p>
+ * This constructor will use a randomly generated {@link UUID} as a salt
- * for the purposes of {@link BlankNode} identity, see {@link #getSalt()}.
++ * for the purposes of {@link BlankNode} identity, see {@link #salt()}.
+ */
+ public JenaRDF() {
+ this.salt = UUID.randomUUID();
+ }
+
+ /**
+ * Create a JenaRDF.
+ * <p>
+ * This constructor will use the specified {@link UUID} as a salt for
+ * the purposes of {@link BlankNode} identity, and should only be used in
+ * cases where predictable and consistent
+ * {@link BlankNode#uniqueReference()} are important.
+ *
+ * @param salt
+ * {@link UUID} to use as salt for {@link BlankNode} equality
+ */
+ public JenaRDF(UUID salt) {
+ this.salt = salt;
+ }
+
+ @Override
+ public JenaBlankNode createBlankNode() {
- return internalJenaFactory.createBlankNode(getSalt());
++ return internalJenaFactory.createBlankNode(salt());
+ }
+
+ @Override
+ public JenaBlankNode createBlankNode(String name) {
- return internalJenaFactory.createBlankNode(name, getSalt());
++ return internalJenaFactory.createBlankNode(name, salt());
+ }
+
+ @Override
+ public JenaDataset createDataset() {
- return internalJenaFactory.createDataset(getSalt());
++ return internalJenaFactory.createDataset(salt());
+ }
+
+ @Override
+ public JenaGraph createGraph() {
- return internalJenaFactory.createGraph(getSalt());
++ return internalJenaFactory.createGraph(salt());
+ }
+
+ @Override
+ public JenaIRI createIRI(String iri) {
+ validateIRI(iri);
+ return internalJenaFactory.createIRI(iri);
+ }
+
+ @Override
+ public JenaLiteral createLiteral(String lexicalForm) {
+ return internalJenaFactory.createLiteral(lexicalForm);
+ }
+
+ @Override
+ public JenaLiteral createLiteral(String lexicalForm, IRI dataType) {
+ return internalJenaFactory.createLiteralDT(lexicalForm, dataType.getIRIString());
+ }
+
+ @Override
+ public JenaLiteral createLiteral(String lexicalForm, String languageTag) {
+ validateLang(languageTag);
+ return internalJenaFactory.createLiteralLang(lexicalForm, languageTag);
+ }
+
+ @Override
+ public JenaTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return internalJenaFactory.createTriple(subject, predicate, object);
+ }
+
+ @Override
+ public JenaQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws IllegalArgumentException, UnsupportedOperationException {
+ return internalJenaFactory.createQuad(subject, predicate, object, graphName);
+ }
+
+ /**
+ * Create a generalized Jena triple.
+ * <p>
+ * The <em>generalized triple</em> supports any {@link RDFTerm} as its
+ * {@link TripleLike#getSubject()} {@link TripleLike#getPredicate()} or
+ * {@link TripleLike#getObject()}.
+ *
+ * @see #createTriple(BlankNodeOrIRI, IRI, RDFTerm)
+ * @see #createGeneralizedQuad(RDFTerm, RDFTerm, RDFTerm, RDFTerm)
+ *
+ * @param subject
+ * The subject of the statement
+ * @param predicate
+ * The predicate of the statement
+ * @param object
+ * The object of the statement
+ * @return Generalized {@link TripleLike}. Note that the generalized triple
+ * does <strong>not</strong> implement {@link Triple#equals(Object)}
+ * or {@link Triple#hashCode()}.
+ */
+ public JenaGeneralizedTripleLike createGeneralizedTriple(
+ RDFTerm subject, RDFTerm predicate, RDFTerm object) {
+ return internalJenaFactory.createGeneralizedTriple(subject, predicate, object);
+ }
+
+ /**
+ * Create a generalized Jena quad.
+ * <p>
+ * The <em>generalized quad</em> supports any {@link RDFTerm} as its
+ * {@link QuadLike#getSubject()} {@link QuadLike#getPredicate()},
+ * {@link QuadLike#getObject()} or {@link QuadLike#getObject()}.
+ *
+ * @see #createQuad(BlankNodeOrIRI, BlankNodeOrIRI, IRI, RDFTerm)
+ * @see #createGeneralizedTriple(RDFTerm, RDFTerm, RDFTerm)
+ *
+ * @param subject
+ * The subject of the statement
+ * @param predicate
+ * The predicate of the statement
+ * @param object
+ * The object of the statement
+ * @param graphName
+ * The graph name of the statement
+ * @return Generalized {@link QuadLike}. Note that the generalized quad does
+ * <strong>not</strong> implement {@link Quad#equals(Object)} or
+ * {@link Quad#hashCode()}.
+ */
+ public JenaGeneralizedQuadLike createGeneralizedQuad(
+ RDFTerm subject, RDFTerm predicate, RDFTerm object, RDFTerm graphName) {
+ return internalJenaFactory.createGeneralizedQuad(subject, predicate, object, graphName);
+ }
+ /**
+ * Adapt an existing Jena Node to CommonsRDF {@link RDFTerm}.
+ * <p>
+ * If {@link Node#isLiteral()}, then the returned value is a {@link Literal}.
+ * If {@link Node#isURI()}, the returned value is a IRI. If {$@link Node#isBlank()},
+ * the returned value is a {@link BlankNode}, which will use a {@link UUID}
+ * salt from this {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
- * @see #fromJena(RDF, Node)
++ * @see #asRDFTerm(RDF, Node)
+ *
+ * @param node
+ * The Jena Node to adapt. It's {@link Node#isConcrete()} must be
+ * <code>true</code>.
+ * @return Adapted {@link JenaRDFTerm}
+ * @throws ConversionException If the {@link Node} can't be represented as an {@link RDFTerm}, e.g.
+ * if the node is not concrete or represents a variable in Jena.
+ */
- public JenaRDFTerm fromJena(Node node) throws ConversionException {
- return internalJenaFactory.fromJena(node, getSalt());
++ public JenaRDFTerm asRDFTerm(Node node) throws ConversionException {
++ return internalJenaFactory.createRDFTerm(node, salt());
+ }
+
+ /**
+ * Convert from Jena {@link Node} to any Commons RDF implementation.
+ * <p>
+ * Note that if the {@link Node#isBlank()}, then the factory's
+ * {@link RDF#createBlankNode(String)} will be used, meaning
+ * that care should be taken if reusing an {@link RDF} instance
+ * for multiple conversion sessions.
+ *
- * @see #fromJena(Node)
++ * @see #asRDFTerm(Node)
+ *
+ * @param factory {@link RDF} to use for creating {@link RDFTerm}.
+ * @param node
+ * The Jena Node to adapt. It's {@link Node#isConcrete()} must be
+ * <code>true</code>.
+ * @return Adapted {@link RDFTerm}
+ * @throws ConversionException If the {@link Node} can't be represented as an {@link RDFTerm}, e.g.
+ * if the node is not concrete or represents a variable in Jena.
+ */
- public static RDFTerm fromJena(RDF factory, Node node) {
++ public static RDFTerm asRDFTerm(RDF factory, Node node) {
+ if (node == null) {
+ return null;
+ }
+ if (factory instanceof JenaRDF) {
+ // No need to convert, just wrap
- return ((JenaRDF) factory).fromJena(node);
++ return ((JenaRDF) factory).asRDFTerm(node);
+ }
+ if (node.isURI())
+ return factory.createIRI(node.getURI());
+ if (node.isLiteral()) {
+ String lang = node.getLiteralLanguage();
+ if (lang != null && !lang.isEmpty())
+ return factory.createLiteral(node.getLiteralLexicalForm(), lang);
+ if (node.getLiteralDatatype().equals(XSDDatatype.XSDstring))
+ return factory.createLiteral(node.getLiteralLexicalForm());
+ IRI dt = factory.createIRI(node.getLiteralDatatype().getURI());
+ return factory.createLiteral(node.getLiteralLexicalForm(), dt);
+ }
+ if (node.isBlank())
+ // The factory
+ return factory.createBlankNode(node.getBlankNodeLabel());
+ throw new ConversionException("Node is not a concrete RDF Term: " + node);
+ }
+
+ /**
+ * Adapt an existing Jena Triple to CommonsRDF {@link Triple}.
+ * <p>
+ * If the triple contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
- * @see #fromJena(RDF, org.apache.jena.graph.Triple)
++ * @see #asTriple(RDF, org.apache.jena.graph.Triple)
+ *
+ * @param triple
+ * Jena {@link org.apache.jena.graph.Triple} to adapt
+ * @return Adapted {@link JenaTriple}
+ * @throws ConversionException
+ * if any of the triple's nodes are not concrete or the triple
+ * is a generalized triple
+ */
- public JenaTriple fromJena(org.apache.jena.graph.Triple triple) throws ConversionException {
- return internalJenaFactory.fromJena(triple, getSalt());
++ public JenaTriple asTriple(org.apache.jena.graph.Triple triple) throws ConversionException {
++ return internalJenaFactory.createTriple(triple, salt());
+ }
+
+ /**
+ * Adapt a generalized Jena {@link org.apache.jena.graph.Triple} to a CommonsRDF {@link TripleLike}.
+ * <p>
+ * The generalized triple supports any {@link RDFTerm} as its {@link TripleLike#getSubject()}
+ * {@link TripleLike#getPredicate()} or {@link TripleLike#getObject()}.
+ * <p>
+ * If the Jena triple contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
- * @see #fromJena(RDF, org.apache.jena.graph.Triple)
++ * @see #asTriple(RDF, org.apache.jena.graph.Triple)
+ *
+ * @param triple
+ * Jena triple
+ * @return Adapted {@link TripleLike}. Note that the generalized triple does
+ * <strong>not</strong> implement {@link Triple#equals(Object)} or
+ * {@link Triple#hashCode()}.
+ * @throws ConversionException
+ * if any of the triple's nodes are not concrete
+ */
- public JenaTripleLike fromJenaGeneralized(org.apache.jena.graph.Triple triple) throws ConversionException {
- return internalJenaFactory.fromJenaGeneralized(triple, getSalt());
++ public JenaTripleLike asGeneralizedTriple(org.apache.jena.graph.Triple triple) throws ConversionException {
++ return internalJenaFactory.createGeneralizedTriple(triple, salt());
+ }
+
+ /**
+ * Adapt a generalized Jena {@link org.apache.jena.sparql.core.Quad} to a CommonsRDF {@link QuadLike}.
+ * <p>
+ * The generalized quad supports any {@link RDFTerm} as its
+ * {@link QuadLike#getGraphName()},
+ * {@link QuadLike#getSubject()}
+ * {@link QuadLike#getPredicate()} or
+ * {@link QuadLike#getObject()}.
+ * <p>
+ * If the Jena quad contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
- * @see #fromJena(org.apache.jena.sparql.core.Quad)
- * @see #fromJenaGeneralized(org.apache.jena.graph.Triple)
++ * @see #asQuad(org.apache.jena.sparql.core.Quad)
++ * @see #asGeneralizedTriple(org.apache.jena.graph.Triple)
+ *
+ * @param quad
+ * Jena quad
+ * @return Adapted {@link QuadLike}. Note that the generalized quad does
+ * <strong>not</strong> implement {@link Quad#equals(Object)} or
+ * {@link Quad#hashCode()}.
+ * @throws ConversionException
+ * if any of the quad nodes are not concrete
+ */
- public JenaQuadLike<RDFTerm> fromJenaGeneralized(org.apache.jena.sparql.core.Quad quad) throws ConversionException {
- return internalJenaFactory.fromJenaGeneralized(quad, getSalt());
++ public JenaQuadLike<RDFTerm> asGeneralizedQuad(org.apache.jena.sparql.core.Quad quad) throws ConversionException {
++ return internalJenaFactory.createGeneralizedQuad(quad, salt());
+ }
+
+ /**
+ * Convert from Jena {@link org.apache.jena.graph.Triple} to a Commons RDF
+ * {@link Triple}.
+ * <p>
+ * Note that if any of the triple's nodes {@link Node#isBlank()}, then the factory's
+ * {@link RDF#createBlankNode(String)} will be used, meaning
+ * that care should be taken if reusing an {@link RDF} instance
+ * for multiple conversion sessions.
+ *
- * @see #fromJena(org.apache.jena.graph.Triple)
++ * @see #asTriple(org.apache.jena.graph.Triple)
+ *
+ * @param factory {@link RDF} to use for creating the {@link Triple} and its
+ * {@link RDFTerm}s.
+ * @param triple
+ * Jena triple
+ * @return Converted triple
+ * @throws ConversionException
+ * if any of the triple's nodes are not concrete or the triple
+ * is a generalized triple
+ */
- public static Triple fromJena(RDF factory, org.apache.jena.graph.Triple triple)
++ public static Triple asTriple(RDF factory, org.apache.jena.graph.Triple triple)
+ throws ConversionException{
+ if (factory instanceof JenaRDF) {
+ // No need to convert, just wrap
- return ((JenaRDF) factory).fromJena(triple);
++ return ((JenaRDF) factory).asTriple(triple);
+ }
+ final BlankNodeOrIRI subject;
+ final IRI predicate;
+ try {
- subject = (BlankNodeOrIRI) fromJena(factory, triple.getSubject());
- predicate = (IRI) fromJena(factory, triple.getPredicate());
++ subject = (BlankNodeOrIRI) asRDFTerm(factory, triple.getSubject());
++ predicate = (IRI) asRDFTerm(factory, triple.getPredicate());
+ } catch (ClassCastException ex) {
+ throw new ConversionException("Can't convert generalized triple: " + triple, ex);
+ }
- RDFTerm object = fromJena(factory, triple.getObject());
++ RDFTerm object = asRDFTerm(factory, triple.getObject());
+ return factory.createTriple(subject, predicate, object);
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.sparql.core.Quad} to CommonsRDF {@link Quad}.
+ * <p>
+ * If the quad contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance
+ * in combination with {@link Node#getBlankNodeId()}
+ * for the purpose of its {@link BlankNode#uniqueReference()}.
+ *
+ * @param quad
+ * Jena quad
+ * @return Adapted quad
+ */
- public JenaQuad fromJena(org.apache.jena.sparql.core.Quad quad) {
- return internalJenaFactory.fromJena(quad, getSalt());
++ public JenaQuad asQuad(org.apache.jena.sparql.core.Quad quad) {
++ return internalJenaFactory.createQuad(quad, salt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.graph.Graph} to CommonsRDF
+ * {@link Graph}.
+ * <p>
+ * This does not take a copy, changes to the CommonsRDF Graph are reflected
+ * in the jena graph, which is accessible from
+ * {@link JenaGraph#asJenaGraph()}.
+ * <p>
+ * If the graph contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance in combination with
+ * {@link Node#getBlankNodeId()} for the purpose of its
+ * {@link BlankNode#uniqueReference()}.
+ *
+ * @param graph
+ * Jena {@link org.apache.jena.graph.Graph} to adapt
+ * @return Adapted {@link JenaGraph}
+ */
- public JenaGraph fromJena(org.apache.jena.graph.Graph graph) {
- return internalJenaFactory.fromJena(graph, getSalt());
++ public JenaGraph asGraph(org.apache.jena.graph.Graph graph) {
++ return internalJenaFactory.createGraph(graph, salt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.rdf.model.Model} to CommonsRDF {@link Graph}.
+ * <p>
+ * This does not ake a copy, changes to the CommonsRDF Graph are reflected in the jena
+ * graph, which is accessible from {@link JenaGraph#asJenaGraph()}.
+ * <p>
+ * If the graph contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance
+ * in combination with {@link Node#getBlankNodeId()}
+ * for the purpose of its {@link BlankNode#uniqueReference()}.
+ * @param model
+ * Jena {@link org.apache.jena.rdf.model.Model} to adapt
+ * @return Adapted {@link JenaGraph}
+ */
- public JenaGraph fromJena(org.apache.jena.rdf.model.Model model) {
- return internalJenaFactory.fromJena(model, getSalt());
++ public JenaGraph asGraph(org.apache.jena.rdf.model.Model model) {
++ return internalJenaFactory.createGraph(model, salt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link DatasetGraph} to CommonsRDF {@link Dataset}.
+ * <p>
+ * This does not
+ * take a copy, changes to the CommonsRDF Dataset are reflected in the jena
+ * dataset graph, which is accessible from {@link JenaDataset#asJenaDatasetGraph()}.
+ * <p>
+ * If the dataset contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance
+ * in combination with {@link Node#getBlankNodeId()}
+ * for the purpose of its {@link BlankNode#uniqueReference()}.
+ *
+ * @param datasetGraph Jena {@link DatasetGraph} to adapt
+ * @return Adapted {@link JenaDataset}
+ */
- public JenaDataset fromJena(DatasetGraph datasetGraph) {
- return internalJenaFactory.fromJena(datasetGraph, getSalt());
++ public JenaDataset asDataset(DatasetGraph datasetGraph) {
++ return internalJenaFactory.createDataset(datasetGraph, salt());
+ }
+
+ /**
+ * Adapt an existing Jena {@link org.apache.jena.query.Dataset} to CommonsRDF {@link Dataset}.
+ * <p>
+ * This does not
+ * take a copy, changes to the CommonsRDF Dataset are reflected in the jena
+ * dataset graph, which is accessible from {@link JenaDataset#asJenaDatasetGraph()}.
+ * <p>
+ * If the dataset contains any {@link Node#isBlank()}, then any corresponding
+ * {@link BlankNode} will use a {@link UUID} salt from this
+ * {@link JenaRDF} instance
+ * in combination with {@link Node#getBlankNodeId()}
+ * for the purpose of its {@link BlankNode#uniqueReference()}.
+ *
+ * @param datasetGraph Jena {@link org.apache.jena.query.Dataset} to adapt
+ * @return Adapted {@link JenaDataset}
+ */
- public JenaDataset fromJena(org.apache.jena.query.Dataset datasetGraph) {
- return internalJenaFactory.fromJena(datasetGraph.asDatasetGraph(), getSalt());
++ public JenaDataset asDataset(org.apache.jena.query.Dataset datasetGraph) {
++ return internalJenaFactory.createDataset(datasetGraph.asDatasetGraph(), salt());
+ }
+
+ /**
+ * Convert from Jena {@link org.apache.jena.sparql.core.Quad} to a Commons
+ * RDF {@link Quad}.
+ * <p>
+ * Note that if any of the quad's nodes {@link Node#isBlank()}, then the
+ * factory's {@link RDF#createBlankNode(String)} will be used,
+ * meaning that care should be taken if reusing an {@link RDF}
+ * instance for multiple conversion sessions.
+ *
- * @see #fromJena(org.apache.jena.sparql.core.Quad)
- * @see #fromJenaGeneralized(org.apache.jena.sparql.core.Quad)
++ * @see #asQuad(org.apache.jena.sparql.core.Quad)
++ * @see #asGeneralizedQuad(org.apache.jena.sparql.core.Quad)
+ *
+ * @param factory
+ * {@link RDF} to use for creating the {@link Triple}
+ * and its {@link RDFTerm}s.
+ * @param quad
+ * Jena {@link org.apache.jena.sparql.core.Quad} to adapt
+ * @return Converted {@link Quad}
+ * @throws ConversionException
+ * if any of the quad's nodes are not concrete or the quad
+ * is a generalized quad
+ */
- public static Quad fromJena(RDF factory, org.apache.jena.sparql.core.Quad quad) {
++ public static Quad asQuad(RDF factory, org.apache.jena.sparql.core.Quad quad) {
+ if (factory instanceof JenaRDF) {
+ // No need to convert, just wrap
- return ((JenaRDF) factory).fromJena(quad);
++ return ((JenaRDF) factory).asQuad(quad);
+ }
- BlankNodeOrIRI graphName = (BlankNodeOrIRI) (fromJena(factory, quad.getGraph()));
- BlankNodeOrIRI subject = (BlankNodeOrIRI) (fromJena(factory, quad.getSubject()));
- IRI predicate = (IRI) (fromJena(factory, quad.getPredicate()));
- RDFTerm object = fromJena(factory, quad.getObject());
++ BlankNodeOrIRI graphName = (BlankNodeOrIRI) (asRDFTerm(factory, quad.getGraph()));
++ BlankNodeOrIRI subject = (BlankNodeOrIRI) (asRDFTerm(factory, quad.getSubject()));
++ IRI predicate = (IRI) (asRDFTerm(factory, quad.getPredicate()));
++ RDFTerm object = asRDFTerm(factory, quad.getObject());
+ return factory.createQuad(graphName, subject, predicate, object);
+ }
+
+ /**
+ * Return {@link RDFSyntax} corresponding to a Jena {@link Lang}.
+ *
+ * @param lang {@link Lang} to convert
+ * @return Matched {@link RDFSyntax}, otherwise {@link Optional#empty()}
+ */
- public Optional<RDFSyntax> langToRdfSyntax(Lang lang) {
++ public Optional<RDFSyntax> asRDFSyntax(Lang lang) {
+ return RDFSyntax.byMediaType(lang.getContentType().getContentType());
+ }
+
+ /**
+ * Return Jena {@link Lang} corresponding to a {@link RDFSyntax}.
+ *
+ * @param rdfSyntax {@link RDFSyntax} to convert
+ * @return Matched {@link Lang}, otherwise {@link Optional#empty()}
+ */
- public Optional<Lang> rdfSyntaxToLang(RDFSyntax rdfSyntax) {
++ public Optional<Lang> asJenaLang(RDFSyntax rdfSyntax) {
+ return Optional.ofNullable(RDFLanguages.contentTypeToLang(rdfSyntax.mediaType));
+ }
+
+ /**
+ * Create a {@link StreamRDF} instance that inserts the converted
+ * {@link Quad}s. into a the provided {@link Consumer}.
+ * <p>
+ * The returned {@link StreamRDF} can be used for instance with Jena's
+ * {@link RDFDataMgr#parse(StreamRDF, String)}.
+ *
+ * @param factory
+ * {@link RDF} to use for creating {@link RDFTerm}s
+ * and {@link Quad}s.
+ * @param consumer
+ * A {@link Consumer} of {@link Quad}s
+ * @return A {@link StreamRDF} that will stream converted quads to the
+ * consumer
+ */
- public static StreamRDF streamJenaToCommonsRDF(RDF factory, Consumer<Quad> consumer) {
++ public static StreamRDF streamJenaToQuad(RDF factory, Consumer<Quad> consumer) {
+ return new StreamRDFBase() {
+ @Override
+ public void quad(org.apache.jena.sparql.core.Quad quad) {
- consumer.accept(fromJena(factory, quad));
++ consumer.accept(asQuad(factory, quad));
+ }
+ };
+ }
+
+ /**
+ * Create a {@link StreamRDF} instance that inserts generalized
+ * {@link TripleLike}s. into a the provided {@link Consumer}.
+ * <p>
+ * A generalized triple allows any {@link RDFTerm} for
+ * {@link TripleLike#getSubject()}, {@link TripleLike#getPredicate()} and
+ * {@link TripleLike#getObject()}.
+ * <p>
+ * The returned {@link StreamRDF} can be used for instance with Jena's
+ * {@link RDFDataMgr#parse(StreamRDF, String)}.
+ *
+ * @param generalizedConsumer
+ * A {@link Consumer} of generalized {@link TripleLike}s
+ * @return A {@link StreamRDF} that will stream generalized triples to the
+ * consumer
+ */
+ public StreamRDF streamJenaToGeneralizedTriple(Consumer<TripleLike> generalizedConsumer) {
+ return new StreamRDFBase() {
+ @Override
+ public void triple(org.apache.jena.graph.Triple triple) {
- generalizedConsumer.accept(fromJenaGeneralized(triple));
++ generalizedConsumer.accept(asGeneralizedTriple(triple));
+ }
+ };
+ }
+
+ /**
+ * Create a {@link StreamRDF} instance that inserts generalized
+ * {@link QuadLike}s. into a the provided {@link Consumer}.
+ * <p>
+ * A generalized quad allows any {@link RDFTerm} for
+ * {@link QuadLike#getSubject()}, {@link TripleLike#getPredicate()},
+ * {@link QuadLike#getObject()} and {@link QuadLike#getGraphName()} .
+ * <p>
+ * The returned {@link StreamRDF} can be used for instance with Jena's
+ * {@link RDFDataMgr#parse(StreamRDF, String)}.
+ *
+ * @param generalizedConsumer
+ * A {@link Consumer} of generalized {@link QuadLike}s
+ * @return A {@link StreamRDF} that will stream generalized quads to the
+ * consumer
+ */
+ public StreamRDF streamJenaToGeneralizedQuad(Consumer<QuadLike<RDFTerm>> generalizedConsumer) {
+ return new StreamRDFBase() {
+ @Override
+ public void quad(org.apache.jena.sparql.core.Quad quad) {
- generalizedConsumer.accept(fromJenaGeneralized(quad));
++ generalizedConsumer.accept(asGeneralizedQuad(quad));
+ }
+ };
+ }
+
+ /**
+ * Convert a CommonsRDF Graph to a Jena Graph. If the Graph was from Jena
+ * originally, return that original object else create a copy using Jena
+ * objects.
+ *
+ * @param graph Commons RDF {@link Graph} to convert
+ * @return Converted Jena {@link org.apache.jena.graph.Graph}
+ */
- public org.apache.jena.graph.Graph toJena(Graph graph) {
++ public org.apache.jena.graph.Graph asJenaGraph(Graph graph) {
+ if (graph instanceof JenaGraph)
+ return ((JenaGraph) graph).asJenaGraph();
+ org.apache.jena.graph.Graph g = GraphFactory.createGraphMem();
- graph.stream().forEach(t -> g.add(toJena(t)));
++ graph.stream().forEach(t -> g.add(asJenaTriple(t)));
+ return g;
+ }
+
+ /**
+ * Convert a CommonsRDF RDFTerm to a Jena Node. If the RDFTerm was from Jena
+ * originally, return that original object, else create a copy using Jena
+ * objects.
+ *
+ * @param term Commons RDF {@link RDFTerm} to convert
+ * @return Converted Jena {@link Node}
+ */
- public Node toJena(RDFTerm term) {
++ public Node asJenaNode(RDFTerm term) {
+ if (term == null) {
+ return null;
+ }
+ if (term instanceof JenaRDFTerm)
+ // TODO: What if it's a JenaBlankNodeImpl with
+ // a different salt? Do we need to rewrite the
+ // jena blanknode identifier?
+ return ((JenaRDFTerm) term).asJenaNode();
+
+ if (term instanceof IRI)
+ return NodeFactory.createURI(((IRI) term).getIRIString());
+
+ if (term instanceof Literal) {
+ Literal lit = (Literal) term;
+ RDFDatatype dt = NodeFactory.getType(lit.getDatatype().getIRIString());
+ String lang = lit.getLanguageTag().orElse("");
+ return NodeFactory.createLiteral(lit.getLexicalForm(), lang, dt);
+ }
+
+ if (term instanceof BlankNode) {
+ String id = ((BlankNode) term).uniqueReference();
+ return NodeFactory.createBlankNode(id);
+ }
+ throw new ConversionException("Not a concrete RDF Term: " + term);
+ }
+
+ /**
+ * Convert a CommonsRDF {@link Triple} to a Jena
+ * {@link org.apache.jena.graph.Triple}.
+ * <p>
+ * If the triple was from Jena originally, return that original object, else
+ * create a copy using Jena objects.
+ *
+ * @param triple Commons RDF {@link Triple} to convert
+ * @return Converted Jena {@link org.apache.jena.graph.Triple}
+ */
- public org.apache.jena.graph.Triple toJena(Triple triple) {
++ public org.apache.jena.graph.Triple asJenaTriple(Triple triple) {
+ if (triple instanceof JenaTriple)
+ return ((JenaTriple) triple).asJenaTriple();
+ return org.apache.jena.graph.Triple.create(
- toJena(triple.getSubject()),
- toJena(triple.getPredicate()),
- toJena(triple.getObject()));
++ asJenaNode(triple.getSubject()),
++ asJenaNode(triple.getPredicate()),
++ asJenaNode(triple.getObject()));
+ }
+
+
+ /**
+ * Convert a CommonsRDF {@link Quad} to a Jena
+ * {@link org.apache.jena.sparql.core.Quad}.
+ * <p>
+ * If the quad was from Jena originally, return that original object,
+ * otherwise create a copy using Jena objects.
+ *
+ * @param quad Commons RDF {@link Quad} to convert
+ * @return Converted Jena {@link org.apache.jena.sparql.core.Quad}
+ */
- public org.apache.jena.sparql.core.Quad toJena(Quad quad) {
++ public org.apache.jena.sparql.core.Quad asJenaQuad(Quad quad) {
+ if (quad instanceof JenaQuad) {
+ return ((JenaQuad) quad).asJenaQuad();
+ }
+ return org.apache.jena.sparql.core.Quad.create(
- toJena(quad.getGraphName().orElse(null)),
- toJena(quad.getSubject()),
- toJena(quad.getPredicate()),
- toJena(quad.getObject()));
++ asJenaNode(quad.getGraphName().orElse(null)),
++ asJenaNode(quad.getSubject()),
++ asJenaNode(quad.getPredicate()),
++ asJenaNode(quad.getObject()));
+ }
+
+ // Some simple validations - full IRI parsing is not cheap.
+ private void validateIRI(String iri) {
+ if (iri.contains(" "))
+ throw new IllegalArgumentException();
+ if (iri.contains("<"))
+ throw new IllegalArgumentException();
+ if (iri.contains(">"))
+ throw new IllegalArgumentException();
+ }
+
+ private static void validateLang(String languageTag) {
+ if (languageTag.contains(" "))
+ throw new IllegalArgumentException("Invalid language tag: " + languageTag);
+ }
+
+ /**
+ * Return the {@link UUID} salt used by this factory.
+ * <p>
+ * The salt is used for the purposes of {@link BlankNode} identity, see
+ * {@link BlankNode#uniqueReference()} for details.
+ * <p>
+ * This salt can be used with the constructor
+ * {@link JenaRDF#JenaRDF(UUID)}
+ * if consistent or reproducible {@link BlankNode}s are desirable.
+ *
+ * @return The {@link UUID} used as salt
+ */
- public UUID getSalt() {
++ public UUID salt() {
+ return salt;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
----------------------------------------------------------------------
diff --cc jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
index d78870c,14d13d9..81069f0
--- a/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/experimental/JenaRDFParser.java
@@@ -77,15 -77,15 +77,15 @@@ public class JenaRDFParser extends Abst
dest = StreamRDFLib.graph(jenaGraph);
} else {
if (generalizedConsumerQuad != null) {
- dest = jenaFactory.streamJenaToGeneralizedQuad(generalizedConsumerQuad);
+ dest = jenaRDF.streamJenaToGeneralizedQuad(generalizedConsumerQuad);
} else if (generalizedConsumerTriple != null) {
- dest = jenaFactory.streamJenaToGeneralizedTriple(generalizedConsumerTriple);
+ dest = jenaRDF.streamJenaToGeneralizedTriple(generalizedConsumerTriple);
} else {
- dest = JenaRDF.streamJenaToCommonsRDF(getRdfTermFactory().get(), getTarget());
- dest = JenaFactory.streamJenaToQuad(getRdfTermFactory().get(), getTarget());
++ dest = JenaRDF.streamJenaToQuad(getRdfTermFactory().get(), getTarget());
}
}
- Lang lang = getContentTypeSyntax().flatMap(jenaRDF::rdfSyntaxToLang).orElse(null);
- Lang lang = getContentTypeSyntax().flatMap(jenaFactory::asJenaLang).orElse(null);
++ Lang lang = getContentTypeSyntax().flatMap(jenaRDF::asJenaLang).orElse(null);
String baseStr = getBase().map(IRI::getIRIString).orElse(null);
if (getSourceIri().isPresent()) {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
----------------------------------------------------------------------
diff --cc jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
index d538076,9166731..10dc069
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/AbstractQuadLike.java
@@@ -86,25 -86,25 +86,25 @@@ abstract class AbstractQuadLike<S exten
@Override
public org.apache.jena.sparql.core.Quad asJenaQuad() {
- JenaFactory factory = new JenaFactory();
+ JenaRDF factory = new JenaRDF();
if (quad == null) {
quad = org.apache.jena.sparql.core.Quad.create(
- factory.toJena(graphName.orElse(null)),
- factory.toJena(subject),
- factory.toJena(predicate),
- factory.toJena(object));
+ factory.asJenaNode(graphName.orElse(null)),
+ factory.asJenaNode(subject),
+ factory.asJenaNode(predicate),
+ factory.asJenaNode(object));
}
return quad;
}
@Override
public org.apache.jena.graph.Triple asJenaTriple() {
- JenaFactory factory = new JenaFactory();
+ JenaRDF factory = new JenaRDF();
if (triple == null) {
triple = org.apache.jena.graph.Triple.create(
- factory.toJena(subject),
- factory.toJena(predicate),
- factory.toJena(object));
+ factory.asJenaNode(subject),
+ factory.asJenaNode(predicate),
+ factory.asJenaNode(object));
}
return triple;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/java/org/apache/commons/rdf/jena/impl/InternalJenaFactory.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
----------------------------------------------------------------------
diff --cc jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
index 81c9a07,17e4e0b..17cb641
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
@@@ -136,16 -136,16 +136,16 @@@ class JenaDatasetImpl implements JenaDa
@Override
public Stream<? extends Quad> stream() {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.find(ANY, ANY, ANY, ANY), true)
- .map(factory::fromJena);
+ .map(factory::asQuad);
}
@Override
public Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> g, BlankNodeOrIRI s, IRI p, RDFTerm o) {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.find(toJenaPattern(g), toJenaPattern(s), toJenaPattern(p), toJenaPattern(o)), true)
- .map(factory::fromJena);
+ .map(factory::asQuad);
}
@Override
@@@ -175,16 -175,16 +175,16 @@@
@Override
public Stream<BlankNodeOrIRI> getGraphNames() {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.listGraphNodes()).map(node ->
- (BlankNodeOrIRI) factory.fromJena(node));
+ (BlankNodeOrIRI) factory.asRDFTerm(node));
}
@Override
public Iterable<Quad> iterate() {
- final JenaFactory factory = new JenaFactory(salt);
+ final JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.find(), false)
- .map(q -> (Quad) factory.fromJena(q))
+ .map(q -> (Quad) factory.asQuad(q))
::iterator;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
----------------------------------------------------------------------
diff --cc jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
index eab4089,ab56505..fd2f6c4
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
@@@ -116,15 -116,15 +116,15 @@@ class JenaGraphImpl implements JenaGrap
@Override
public Stream<? extends Triple> stream() {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
- return Iter.asStream(graph.find(null, null, null), true).map(factory::fromJena);
+ return Iter.asStream(graph.find(null, null, null), true).map(factory::asTriple);
}
@Override
public Stream<? extends Triple> stream(BlankNodeOrIRI s, IRI p, RDFTerm o) {
- JenaFactory factory = new JenaFactory(salt);
+ JenaRDF factory = new JenaRDF(salt);
return Iter.asStream(graph.find(toJenaAny(s), toJenaAny(p), toJenaAny(o)), true)
- .map(factory::fromJena);
+ .map(factory::asTriple);
}
private Node toJenaAny(RDFTerm term) {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
----------------------------------------------------------------------
diff --cc jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
index 0000000,0000000..afe6af3
new file mode 100644
--- /dev/null
+++ b/jena/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
@@@ -1,0 -1,0 +1,1 @@@
++org.apache.commons.rdf.jena.JenaRDF
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
----------------------------------------------------------------------
diff --cc jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
index 16e3e67,728bba2..51cfa4c
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
@@@ -18,14 -18,22 +18,21 @@@
package org.apache.commons.rdf.jena;
+ import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+ import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
+ import org.apache.commons.rdf.api.BlankNode;
+ import org.apache.commons.rdf.api.BlankNodeOrIRI;
import org.apache.commons.rdf.api.Graph ;
- import org.apache.commons.rdf.api.RDF ;
+ import org.apache.commons.rdf.api.RDFTerm;
+ import org.apache.commons.rdf.api.Triple;
+ import org.apache.commons.rdf.simple.Types;
-import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.Lang ;
import org.apache.jena.riot.RDFDataMgr ;
import org.apache.jena.sparql.graph.GraphFactory ;
import org.junit.After;
@@@ -55,20 -64,72 +63,72 @@@ public class TestJenaGraphToCommonsRDFG
org.apache.jena.graph.Graph jGraph = GraphFactory.createGraphMem() ;
RDFDataMgr.read(jGraph, turtleFile.toUri().toString()) ;
- JenaFactory factory = new JenaFactory() ;
++ JenaRDF factory = new JenaRDF() ;
+
// "graph" is a CommonsRDF graph
- Graph graph = new JenaRDF().fromJena(jGraph) ;
+ Graph graph = factory.asGraph(jGraph) ;
+
+
+
+ // The below check expected statements from D.ttl
+
+ JenaIRI p = factory.createIRI("http://example.com/p");
+ JenaIRI s = factory.createIRI("http://example.com/s");
+ JenaLiteral literal123 = factory.createLiteral("123", Types.XSD_INTEGER);
+ assertTrue(graph.contains(s, p, literal123));
+
+ JenaIRI p1 = factory.createIRI("http://example.com/p1");
+ // Let's look up the BlankNode
+ BlankNodeOrIRI bnode1 = graph.stream(null, p1, null)
+ .findFirst().map(Triple::getSubject).get();
+ assertTrue(bnode1 instanceof BlankNode);
+
+ // Verify we can use BlankNode in query again
+ RDFTerm obj = graph.stream(bnode1, p1, null).findFirst().map(Triple::getObject).get();
+ // Let's look up also that nested blank node
+ assertTrue(obj instanceof BlankNode);
+ BlankNode bnode2 = (BlankNode)obj;
+
+
+
+ JenaIRI q = factory.createIRI("http://example.com/q");
+ JenaLiteral literalR = factory.createLiteral("r", "en");
+ assertTrue(graph.contains(bnode2, q, literalR));
+
+
+ // Can we add the same triple again as s/p/o
+ // without affecting graph size?
+ // Just to be evil we add a blanknode-iri-blanknode statement
+ assertEquals(3, graph.size());
+ graph.add(bnode1, p1, bnode2);
+ assertEquals(3, graph.size());
+
+ // Add the same Triple again
+ graph.stream(bnode2,null,null).findFirst().ifPresent(graph::add);
+ assertEquals(3, graph.size());
+
+
// Add to CommonsRDF Graph
- RDF rft = new JenaRDF() ;
- graph.add(rft.createIRI("http://example/s2"),
- rft.createIRI("http://example/p2"),
- rft.createLiteral("foo")) ;
- System.out.println("==== Write CommonsRDF graph\n") ;
- graph.stream().forEach(System.out::println) ;
-
- System.out.println("\n==== Write Jena graph directly\n") ;
- // And its in the Jena graph
- RDFDataMgr.write(System.out, jGraph, Lang.TTL) ;
+ JenaIRI s2 = factory.createIRI("http://example/s2");
+ JenaIRI p2 = factory.createIRI("http://example/p2");
+ JenaLiteral foo = factory.createLiteral("foo");
+ graph.add(s2,
+ p2,
+ foo) ;
+ assertEquals(4, graph.size());
+ assertTrue(graph.contains(s2,p2,foo));
+
+ // Verify the corresponding Jena Nodes are in Jena graph
+ assertTrue(jGraph.contains(s2.asJenaNode(), p2.asJenaNode(), foo.asJenaNode()));
+
+ if (DEBUG) {
+ System.out.println("==== Write CommonsRDF graph\n") ;
+ graph.stream().forEach(System.out::println) ;
+ // And its in the Jena graph
+ System.out.println("\n==== Write Jena graph directly\n") ;
+ RDFDataMgr.write(System.out, jGraph, Lang.TTL) ;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
----------------------------------------------------------------------
diff --cc jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
index 0000000,0000000..2c97ca5
new file mode 100644
--- /dev/null
+++ b/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
@@@ -1,0 -1,0 +1,1 @@@
++org.apache.commons.rdf.jsonldjava.JsonLdRDF
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
----------------------------------------------------------------------
diff --cc rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
index 0000000,0000000..f8a94bb
new file mode 100644
--- /dev/null
+++ b/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
@@@ -1,0 -1,0 +1,1 @@@
++org.apache.commons.rdf.rdf4j.RDF4J
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
----------------------------------------------------------------------
diff --cc simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
index 0000000,0000000..4003034
new file mode 100644
--- /dev/null
+++ b/simple/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDF
@@@ -1,0 -1,0 +1,1 @@@
++org.apache.commons.rdf.simple.SimpleRDF
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/d6306ad4/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
----------------------------------------------------------------------
[15/50] [abbrv] incubator-commonsrdf git commit: javadoc tweaks to
avoid Factory
Posted by st...@apache.org.
javadoc tweaks to avoid Factory
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/417963fe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/417963fe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/417963fe
Branch: refs/heads/COMMONSRDF-7
Commit: 417963fe582804d2d1f3c47a7c0ffd702277b4db
Parents: d261f64
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Oct 23 00:54:59 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Oct 23 01:22:01 2016 +0100
----------------------------------------------------------------------
.../main/java/org/apache/commons/rdf/jena/JenaRDF.java | 12 +++++++-----
.../org/apache/commons/rdf/jsonldjava/JsonLdRDF.java | 3 +++
.../main/java/org/apache/commons/rdf/rdf4j/RDF4J.java | 2 ++
.../java/org/apache/commons/rdf/simple/SimpleRDF.java | 4 ++--
4 files changed, 14 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/417963fe/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
index e3c2a86..0a3f1b0 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaRDF.java
@@ -48,13 +48,15 @@ import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.graph.GraphFactory;
/**
- * RDF with Jena-backed objects.
+ * Apache Jena RDF implementation.
* <p>
- * This factory can also convert existing objects from/to Jena with methods like
+ * Instances of JenaRDF can also convert existing objects from/to
+ * <code>org.apache.jena</code> types with methods like
* {@link #fromJena(org.apache.jena.graph.Graph)} and {@link #toJena(Graph)}.
* <p>
- * For the purpose of {@link BlankNode} identity, this factory will use an internal
- * {@link UUID} as a salt. See {@link BlankNode#uniqueReference()} for details.
+ * For the purpose of {@link BlankNode} identity, JenaRDF instances use an
+ * internal {@link UUID} as a salt. See {@link BlankNode#uniqueReference()} for
+ * details.
*
* @see RDF
*/
@@ -715,7 +717,7 @@ public final class JenaRDF implements RDF {
* {@link BlankNode#uniqueReference()} for details.
* <p>
* This salt can be used with the constructor
- * {@link JenaRDF#JenaFactory(UUID)}
+ * {@link JenaRDF#JenaRDF(UUID)}
* if consistent or reproducible {@link BlankNode}s are desirable.
*
* @return The {@link UUID} used as salt
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/417963fe/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
index bb57b1a..64f877a 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
@@ -35,6 +35,9 @@ import org.apache.commons.rdf.simple.Types;
import com.github.jsonldjava.core.RDFDataset;
import com.github.jsonldjava.core.RDFDataset.Node;
+/**
+ * JSON-LD Java RDF implementation.
+ */
public final class JsonLdRDF implements RDF {
final String bnodePrefix;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/417963fe/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
index 37dd7a2..fb5743b 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
@@ -97,6 +97,8 @@ import org.eclipse.rdf4j.sail.memory.MemoryStore;
* and
* {@link #asRDFTermGraph(Repository, Option...)}
* therefore uses a unique {@link RDF4J} internally.
+ *
+ * @see RDF
*
*/
public final class RDF4J implements RDF {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/417963fe/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
index 91bd7da..1698955 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/SimpleRDF.java
@@ -31,10 +31,10 @@ import org.apache.commons.rdf.api.RDF;
import org.apache.commons.rdf.api.Triple;
/**
- * A simple implementation of RDF.
+ * Simple RDF implementation.
* <p>
* The {@link RDFTerm}, {@link Triple}, {@link Quad}, {@link Graph}
- * and {@link Dataset} instances created by this factory are
+ * and {@link Dataset} instances created by SimpleRDF are
* simple in-memory Implementations that are not thread-safe or efficient, but
* which may be useful for testing and prototyping purposes.
*/
[26/50] [abbrv] incubator-commonsrdf git commit: preparing 0.3.0
release notes
Posted by st...@apache.org.
preparing 0.3.0 release notes
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/98d56f87
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/98d56f87
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/98d56f87
Branch: refs/heads/COMMONSRDF-7
Commit: 98d56f87d671e345eea8642641d427c9df509948
Parents: cb58d56
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Oct 27 10:59:17 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Oct 27 10:59:17 2016 +0100
----------------------------------------------------------------------
RELEASE-NOTES.txt | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/98d56f87/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index e99babd..a04233c 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -1,5 +1,24 @@
# Apache Commons RDF (incubating)
+## 0.3.0-incubating (2016-11)
+
+This release adds RDF implementations based on Apache Jena, Eclipse RDF4J and
+JSONLD-Java. New interfaces include Dataset and Quad. Note that the
+interface RDFTermFactory has been deprecated and been replaced by the interface
+RDF. Graph.getTriples() has been deprecated and replaced by
+Graph.iterate(). This release adds an experimental interface
+RDFParser, note that this may evolve or be removed in the next release.
+
+* [COMMONSRDF-7] - Document that RDFTerm, Triple and Quad are immutable
+* [COMMONSRDF-33] - Jena integration
+* [COMMONSRDF-34] - Add DatasetImpl using Jena
+* [COMMONSRDF-35] - rdf4j integration
+* [COMMONSRDF-36] - jsonld-java integratoin
+* [COMMONSRDF-37] - Quad and Dataset support
+* [COMMONSRDF-38] - simple Graph.contains(Triple) now maps bnodes consistently
+* [COMMONSRDF-39] - Add RDFParser interface (experimental)
+* [COMMONSRDF-46] - Rename RDFTermFactory to RDF
+
## 0.2.0-incubating (2016-04)
This release clarifies .equals() and .hashCode() for RDFTerms so that they can
[27/50] [abbrv] incubator-commonsrdf git commit: avoid infinite loop!
:)
Posted by st...@apache.org.
avoid infinite loop! :)
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/49cba1f9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/49cba1f9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/49cba1f9
Branch: refs/heads/COMMONSRDF-7
Commit: 49cba1f99fc67538c4f24e4e06c7f3a51126a309
Parents: 98d56f8
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Oct 27 16:48:52 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Oct 27 16:48:52 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/49cba1f9/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
index f9a1e74..be37449 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
@@ -111,7 +111,7 @@ public class RDF4JParser extends AbstractRDFParser<RDF4JParser> implements RDFPa
@Override
protected RDF4JParser prepareForParsing() throws IOException, IllegalStateException {
- RDF4JParser c = prepareForParsing();
+ RDF4JParser c = super.prepareForParsing();
// Ensure we have an RDF4JFactory for conversion.
// We'll make a new one if user has provided a non-RDF4J factory
c.rdf4jTermFactory = (RDF4JFactory) getRdfTermFactory().filter(RDF4JFactory.class::isInstance)
[28/50] [abbrv] incubator-commonsrdf git commit: newer jsonld-java
and rdf4j
Posted by st...@apache.org.
newer jsonld-java and rdf4j
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/6aa5a5d0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/6aa5a5d0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/6aa5a5d0
Branch: refs/heads/COMMONSRDF-7
Commit: 6aa5a5d0df961908bf9851582f3a68e44aa403fc
Parents: 49cba1f
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Oct 27 16:51:20 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Thu Oct 27 16:51:20 2016 +0100
----------------------------------------------------------------------
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/6aa5a5d0/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 9ef400a..879b131 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,8 +58,8 @@
<!-- NOTE: jsonldjava is also used by rdf4j and jena, check -->
- <jsonldjava.version>0.8.2</jsonldjava.version>
- <rdf4j.version>2.0</rdf4j.version>
+ <jsonldjava.version>0.8.3</jsonldjava.version>
+ <rdf4j.version>2.1</rdf4j.version>
<jena.version>3.1.0</jena.version>
<!-- NOTE: dexx and xerces versions should match
the versions marked as <optional> in jena-osgi pom
[45/50] [abbrv] incubator-commonsrdf git commit: Reformat tab ->
spaces
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
index 422e97b..7b1310c 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java
@@ -41,8 +41,8 @@ import org.junit.Test;
* <p>
* To add to your implementation's tests, create a subclass with a name ending
* in <code>Test</code> and provide {@link #createFactory()} which minimally
- * must support {@link RDF#createGraph()} and
- * {@link RDF#createIRI(String)}, but ideally support all operations.
+ * must support {@link RDF#createGraph()} and {@link RDF#createIRI(String)}, but
+ * ideally support all operations.
* <p>
* This test uses try-with-resources blocks for calls to {@link Graph#stream()}
* and {@link Graph#iterate()}.
@@ -129,15 +129,13 @@ public abstract class AbstractGraphTest {
graph.add(bnode1, name, secretClubName);
graph.add(bnode2, name, companyName);
}
- }
+ }
}
-
@Test
public void size() throws Exception {
assertTrue(graph.size() > 0);
- Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName,
- companyName, bobNameTriple);
+ Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName, companyName, bobNameTriple);
// Can only reliably predict size if we could create all triples
assertEquals(8, graph.size());
}
@@ -158,18 +156,18 @@ public abstract class AbstractGraphTest {
// aborted iteration
Iterable<Triple> iterate = graph.iterate();
- Iterator<Triple> it = iterate.iterator();
-
+ Iterator<Triple> it = iterate.iterator();
+
assertTrue(it.hasNext());
it.next();
closeIterable(iterate);
-
// second iteration - should start from fresh and
// get the same count
long count = 0;
Iterable<Triple> iterable = graph.iterate();
- for (@SuppressWarnings("unused") Triple t : iterable) {
+ for (@SuppressWarnings("unused")
+ Triple t : iterable) {
count++;
}
assertEquals(graph.size(), count);
@@ -178,11 +176,11 @@ public abstract class AbstractGraphTest {
/**
* Special triple closing for RDF4J.
*/
- private void closeIterable(Iterable<Triple> iterate) throws Exception {
+ private void closeIterable(Iterable<Triple> iterate) throws Exception {
if (iterate instanceof AutoCloseable) {
- ((AutoCloseable) iterate).close();
+ ((AutoCloseable) iterate).close();
}
- }
+ }
@Test
public void iterateFilter() throws Exception {
@@ -197,10 +195,10 @@ public abstract class AbstractGraphTest {
// .. can we iterate over zero hits?
Iterable<Triple> iterate = graph.iterate(bob, knows, alice);
- for (Triple unexpected : iterate) {
- fail("Unexpected triple " + unexpected);
+ for (Triple unexpected : iterate) {
+ fail("Unexpected triple " + unexpected);
}
- //closeIterable(iterate);
+ // closeIterable(iterate);
}
@Test
@@ -210,11 +208,10 @@ public abstract class AbstractGraphTest {
assertTrue(graph.contains(alice, knows, bob));
try (Stream<? extends Triple> stream = graph.stream()) {
- Optional<? extends Triple> first = stream.skip(4)
- .findFirst();
- Assume.assumeTrue(first.isPresent());
- Triple existingTriple = first.get();
- assertTrue(graph.contains(existingTriple));
+ Optional<? extends Triple> first = stream.skip(4).findFirst();
+ Assume.assumeTrue(first.isPresent());
+ Triple existingTriple = first.get();
+ assertTrue(graph.contains(existingTriple));
}
Triple nonExistingTriple = factory.createTriple(bob, knows, alice);
@@ -254,19 +251,19 @@ public abstract class AbstractGraphTest {
Triple otherTriple;
try (Stream<? extends Triple> stream = graph.stream()) {
- Optional<? extends Triple> anyTriple = stream.findAny();
- Assume.assumeTrue(anyTriple.isPresent());
- otherTriple = anyTriple.get();
+ Optional<? extends Triple> anyTriple = stream.findAny();
+ Assume.assumeTrue(anyTriple.isPresent());
+ otherTriple = anyTriple.get();
}
graph.remove(otherTriple);
assertEquals(shrunkSize - 1, graph.size());
graph.remove(otherTriple);
assertEquals(shrunkSize - 1, graph.size()); // no change
-
+
// for some reason in rdf4j this causes duplicates!
graph.add(otherTriple);
- //graph.stream().forEach(System.out::println);
+ // graph.stream().forEach(System.out::println);
// should have increased
assertTrue(graph.size() >= shrunkSize);
}
@@ -282,19 +279,18 @@ public abstract class AbstractGraphTest {
@Test
public void getTriples() throws Exception {
- long tripleCount;
+ long tripleCount;
try (Stream<? extends Triple> stream = graph.stream()) {
- tripleCount = stream.count();
+ tripleCount = stream.count();
}
assertTrue(tripleCount > 0);
try (Stream<? extends Triple> stream = graph.stream()) {
- assertTrue(stream.allMatch(t -> graph.contains(t)));
+ assertTrue(stream.allMatch(t -> graph.contains(t)));
}
-
+
// Check exact count
- Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName,
- companyName, bobNameTriple);
+ Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName, companyName, bobNameTriple);
assertEquals(8, tripleCount);
}
@@ -302,19 +298,19 @@ public abstract class AbstractGraphTest {
public void getTriplesQuery() throws Exception {
try (Stream<? extends Triple> stream = graph.stream(alice, null, null)) {
- long aliceCount = stream.count();
- assertTrue(aliceCount > 0);
- Assume.assumeNotNull(aliceName);
- assertEquals(3, aliceCount);
+ long aliceCount = stream.count();
+ assertTrue(aliceCount > 0);
+ Assume.assumeNotNull(aliceName);
+ assertEquals(3, aliceCount);
}
Assume.assumeNotNull(bnode1, bnode2, bobName, companyName, secretClubName);
try (Stream<? extends Triple> stream = graph.stream(null, name, null)) {
- assertEquals(4, stream.count());
+ assertEquals(4, stream.count());
}
Assume.assumeNotNull(bnode1);
try (Stream<? extends Triple> stream = graph.stream(null, member, null)) {
- assertEquals(3, stream.count());
+ assertEquals(3, stream.count());
}
}
@@ -322,32 +318,31 @@ public abstract class AbstractGraphTest {
public void addBlankNodesFromMultipleGraphs() {
try {
- // Create two separate Graph instances
+ // Create two separate Graph instances
Graph g1 = createGraph1();
Graph g2 = createGraph2();
// and add them to a new Graph g3
- Graph g3 = factory.createGraph();
+ Graph g3 = factory.createGraph();
addAllTriples(g1, g3);
addAllTriples(g2, g3);
-
// Let's make a map to find all those blank nodes after insertion
- // (The Graph implementation is not currently required to
- // keep supporting those BlankNodes with contains() - see COMMONSRDF-15)
+ // (The Graph implementation is not currently required to
+ // keep supporting those BlankNodes with contains() - see
+ // COMMONSRDF-15)
final Map<String, BlankNodeOrIRI> whoIsWho = new ConcurrentHashMap<>();
// ConcurrentHashMap as we will try parallel forEach below,
// which should not give inconsistent results (it does with a
// HashMap!)
-
+
// look up BlankNodes by name
IRI name = factory.createIRI("http://xmlns.com/foaf/0.1/name");
try (Stream<? extends Triple> stream = g3.stream(null, name, null)) {
- stream.parallel().forEach( t ->
- whoIsWho.put( t.getObject().ntriplesString(), t.getSubject()));
- }
-
+ stream.parallel().forEach(t -> whoIsWho.put(t.getObject().ntriplesString(), t.getSubject()));
+ }
+
assertEquals(4, whoIsWho.size());
// and contains 4 unique values
assertEquals(4, new HashSet<BlankNodeOrIRI>(whoIsWho.values()).size());
@@ -400,24 +395,28 @@ public abstract class AbstractGraphTest {
/**
* Add all triples from the source to the target.
* <p>
- * The triples may be copied in any order.
- * No special conversion or adaptation of {@link BlankNode}s are performed.
+ * The triples may be copied in any order. No special conversion or
+ * adaptation of {@link BlankNode}s are performed.
*
- * @param source Source Graph to copy triples from
- * @param target Target Graph where triples will be added
+ * @param source
+ * Source Graph to copy triples from
+ * @param target
+ * Target Graph where triples will be added
*/
private void addAllTriples(Graph source, Graph target) {
// unordered() as we don't need to preserve triple order
- // sequential() as we don't (currently) require target Graph to be thread-safe
-
- try (Stream<? extends Triple> stream = source.stream()) {
- stream.unordered().sequential().forEach(t -> target.add(t));
- }
+ // sequential() as we don't (currently) require target Graph to be
+ // thread-safe
+
+ try (Stream<? extends Triple> stream = source.stream()) {
+ stream.unordered().sequential().forEach(t -> target.add(t));
+ }
}
/**
- * Make a new graph with two BlankNodes - each with a different uniqueReference
+ * Make a new graph with two BlankNodes - each with a different
+ * uniqueReference
*/
private Graph createGraph1() {
RDF factory1 = createFactory();
@@ -426,50 +425,51 @@ public abstract class AbstractGraphTest {
Graph g1 = factory1.createGraph();
BlankNode b1 = createOwnBlankNode("b1", "0240eaaa-d33e-4fc0-a4f1-169d6ced3680");
g1.add(b1, name, factory1.createLiteral("Alice"));
-
-
+
BlankNode b2 = createOwnBlankNode("b2", "9de7db45-0ce7-4b0f-a1ce-c9680ffcfd9f");
g1.add(b2, name, factory1.createLiteral("Bob"));
IRI hasChild = factory1.createIRI("http://example.com/hasChild");
- g1.add(b1, hasChild, b2);
+ g1.add(b1, hasChild, b2);
return g1;
}
- /**
+ /**
* Create a different implementation of BlankNode to be tested with
- * graph.add(a,b,c);
- * (the implementation may or may not then choose to translate such to
- * its own instances)
+ * graph.add(a,b,c); (the implementation may or may not then choose to
+ * translate such to its own instances)
*
* @param name
* @return
*/
- private BlankNode createOwnBlankNode(String name, String uuid) {
- return new BlankNode() {
- @Override
- public String ntriplesString() {
- return "_: " + name;
- }
- @Override
- public String uniqueReference() {
- return uuid;
- }
- @Override
- public int hashCode() {
- return uuid.hashCode();
- }
- @Override
- public boolean equals(Object obj) {
- if (!( obj instanceof BlankNode)) {
- return false;
- }
- BlankNode other = (BlankNode)obj;
- return uuid.equals(other.uniqueReference());
- }
- };
- }
+ private BlankNode createOwnBlankNode(String name, String uuid) {
+ return new BlankNode() {
+ @Override
+ public String ntriplesString() {
+ return "_: " + name;
+ }
+
+ @Override
+ public String uniqueReference() {
+ return uuid;
+ }
+
+ @Override
+ public int hashCode() {
+ return uuid.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof BlankNode)) {
+ return false;
+ }
+ BlankNode other = (BlankNode) obj;
+ return uuid.equals(other.uniqueReference());
+ }
+ };
+ }
private Graph createGraph2() {
RDF factory2 = createFactory();
@@ -485,7 +485,7 @@ public abstract class AbstractGraphTest {
IRI hasChild = factory2.createIRI("http://example.com/hasChild");
// NOTE: Opposite direction of loadGraph1
- g2.add(b2, hasChild, b1);
+ g2.add(b2, hasChild, b1);
return g2;
}
@@ -493,13 +493,14 @@ public abstract class AbstractGraphTest {
* An attempt to use the Java 8 streams to look up a more complicated query.
* <p>
* FYI, the equivalent SPARQL version (untested):
+ *
* <pre>
- * SELECT ?orgName WHERE {
- * ?org foaf:name ?orgName .
- * ?alice foaf:member ?org .
- * ?bob foaf:member ?org .
- * ?alice foaf:knows ?bob .
- * FILTER NOT EXIST { ?bob foaf:knows ?alice }
+ * SELECT ?orgName WHERE {
+ * ?org foaf:name ?orgName .
+ * ?alice foaf:member ?org .
+ * ?bob foaf:member ?org .
+ * ?alice foaf:knows ?bob .
+ * FILTER NOT EXIST { ?bob foaf:knows ?alice }
* }
* </pre>
*
@@ -509,31 +510,31 @@ public abstract class AbstractGraphTest {
public void whyJavaStreamsMightNotTakeOverFromSparql() throws Exception {
Assume.assumeNotNull(bnode1, bnode2, secretClubName);
// Find a secret organizations
- try (Stream<? extends Triple> stream = graph.stream(null, knows, null)) {
- assertEquals("\"The Secret Club\"",
- // Find One-way "knows"
- stream.filter(t -> !graph.contains((BlankNodeOrIRI) t.getObject(), knows, t.getSubject()))
- .map(knowsTriple -> {
- try (Stream<? extends Triple> memberOf = graph
- // and those they know, what are they
- // member of?
- .stream((BlankNodeOrIRI) knowsTriple.getObject(), member, null)) {
- return memberOf
- // keep those which first-guy is a
- // member of
- .filter(memberTriple -> graph.contains(knowsTriple.getSubject(), member,
- // First hit is good enough
- memberTriple.getObject()))
- .findFirst().get().getObject();
- }
- })
- // then look up the name of that org
- .map(org -> {
- try (Stream<? extends Triple> orgName = graph.stream((BlankNodeOrIRI) org, name,
- null)) {
- return orgName.findFirst().get().getObject().ntriplesString();
- }
- }).findFirst().get());
- }
+ try (Stream<? extends Triple> stream = graph.stream(null, knows, null)) {
+ assertEquals("\"The Secret Club\"",
+ // Find One-way "knows"
+ stream.filter(t -> !graph.contains((BlankNodeOrIRI) t.getObject(), knows, t.getSubject()))
+ .map(knowsTriple -> {
+ try (Stream<? extends Triple> memberOf = graph
+ // and those they know, what are they
+ // member of?
+ .stream((BlankNodeOrIRI) knowsTriple.getObject(), member, null)) {
+ return memberOf
+ // keep those which first-guy is a
+ // member of
+ .filter(memberTriple -> graph.contains(knowsTriple.getSubject(), member,
+ // First hit is good enough
+ memberTriple.getObject()))
+ .findFirst().get().getObject();
+ }
+ })
+ // then look up the name of that org
+ .map(org -> {
+ try (Stream<? extends Triple> orgName = graph.stream((BlankNodeOrIRI) org, name,
+ null)) {
+ return orgName.findFirst().get().getObject().ntriplesString();
+ }
+ }).findFirst().get());
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java
index c664da8..e58ede6 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java
@@ -60,9 +60,8 @@ public abstract class AbstractRDFTest {
BlankNode bnode = factory.createBlankNode();
BlankNode bnode2 = factory.createBlankNode();
- assertNotEquals(
- "Second blank node has not got a unique internal identifier",
- bnode.uniqueReference(), bnode2.uniqueReference());
+ assertNotEquals("Second blank node has not got a unique internal identifier", bnode.uniqueReference(),
+ bnode2.uniqueReference());
}
@Test
@@ -90,8 +89,7 @@ public abstract class AbstractRDFTest {
// We don't know what the ntriplesString is, but it MUST be the same
assertEquals(bnode1.ntriplesString(), bnode2.ntriplesString());
// and here it MUST differ
- assertNotEquals(bnode1.uniqueReference(),
- bnode3.uniqueReference());
+ assertNotEquals(bnode1.uniqueReference(), bnode3.uniqueReference());
assertNotEquals(bnode1.ntriplesString(), bnode3.ntriplesString());
}
@@ -101,31 +99,28 @@ public abstract class AbstractRDFTest {
bnode1 = factory.createBlankNode();
// it MUST differ from a second factory
differentFactory = createFactory().createBlankNode();
-
- // NOTE: We can't make similar assumption if we provide a
+
+ // NOTE: We can't make similar assumption if we provide a
// name to createBlankNode(String) as its documentation
// only says:
- //
+ //
// * BlankNodes created using this method with the same parameter, for
// * different instances of RDFFactory, SHOULD NOT be equivalent.
//
// https://github.com/apache/incubator-commonsrdf/pull/7#issuecomment-92312779
assertNotEquals(bnode1, differentFactory);
- assertNotEquals(bnode1.uniqueReference(),
- differentFactory.uniqueReference());
+ assertNotEquals(bnode1.uniqueReference(), differentFactory.uniqueReference());
// but we can't require:
- //assertNotEquals(bnode1.ntriplesString(), differentFactory.ntriplesString());
+ // assertNotEquals(bnode1.ntriplesString(),
+ // differentFactory.ntriplesString());
}
-
@Test
public void testCreateGraph() {
Graph graph = factory.createGraph();
assertEquals("Graph was not empty", 0, graph.size());
- graph.add(factory.createBlankNode(),
- factory.createIRI("http://example.com/"),
- factory.createBlankNode());
+ graph.add(factory.createBlankNode(), factory.createIRI("http://example.com/"), factory.createBlankNode());
Graph graph2 = factory.createGraph();
assertNotSame(graph, graph2);
@@ -147,16 +142,12 @@ public abstract class AbstractRDFTest {
// and now for the international fun!
IRI latin1 = factory.createIRI("http://acc�nt.example.com/premi�re");
- assertEquals("http://acc�nt.example.com/premi�re",
- latin1.getIRIString());
- assertEquals("<http://acc�nt.example.com/premi�re>",
- latin1.ntriplesString());
+ assertEquals("http://acc�nt.example.com/premi�re", latin1.getIRIString());
+ assertEquals("<http://acc�nt.example.com/premi�re>", latin1.ntriplesString());
IRI cyrillic = factory.createIRI("http://example.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435/\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430");
- assertEquals("http://example.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435/\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430",
- cyrillic.getIRIString());
- assertEquals("<http://example.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435/\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430>",
- cyrillic.ntriplesString());
+ assertEquals("http://example.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435/\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430", cyrillic.getIRIString());
+ assertEquals("<http://example.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435/\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430>", cyrillic.ntriplesString());
IRI deseret = factory.createIRI("http://\U00010400.example.com/\U00010400");
assertEquals("http://\U00010400.example.com/\U00010400", deseret.getIRIString());
@@ -168,24 +159,19 @@ public abstract class AbstractRDFTest {
Literal example = factory.createLiteral("Example");
assertEquals("Example", example.getLexicalForm());
assertFalse(example.getLanguageTag().isPresent());
- assertEquals("http://www.w3.org/2001/XMLSchema#string", example
- .getDatatype().getIRIString());
+ assertEquals("http://www.w3.org/2001/XMLSchema#string", example.getDatatype().getIRIString());
// http://lists.w3.org/Archives/Public/public-rdf-comments/2014Dec/0004.html
assertEquals("\"Example\"", example.ntriplesString());
}
@Test
public void testCreateLiteralDateTime() throws Exception {
- Literal dateTime = factory
- .createLiteral(
- "2014-12-27T00:50:00T-0600",
- factory.createIRI("http://www.w3.org/2001/XMLSchema#dateTime"));
+ Literal dateTime = factory.createLiteral("2014-12-27T00:50:00T-0600",
+ factory.createIRI("http://www.w3.org/2001/XMLSchema#dateTime"));
assertEquals("2014-12-27T00:50:00T-0600", dateTime.getLexicalForm());
assertFalse(dateTime.getLanguageTag().isPresent());
- assertEquals("http://www.w3.org/2001/XMLSchema#dateTime", dateTime
- .getDatatype().getIRIString());
- assertEquals(
- "\"2014-12-27T00:50:00T-0600\"^^<http://www.w3.org/2001/XMLSchema#dateTime>",
+ assertEquals("http://www.w3.org/2001/XMLSchema#dateTime", dateTime.getDatatype().getIRIString());
+ assertEquals("\"2014-12-27T00:50:00T-0600\"^^<http://www.w3.org/2001/XMLSchema#dateTime>",
dateTime.ntriplesString());
}
@@ -195,8 +181,7 @@ public abstract class AbstractRDFTest {
assertEquals("Example", example.getLexicalForm());
assertEquals("en", example.getLanguageTag().get());
- assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",
- example.getDatatype().getIRIString());
+ assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", example.getDatatype().getIRIString());
assertEquals("\"Example\"@en", example.ntriplesString());
}
@@ -206,19 +191,17 @@ public abstract class AbstractRDFTest {
Literal vls = factory.createLiteral("Herbert Van de Sompel", "vls"); // JENA-827
assertEquals("vls", vls.getLanguageTag().get());
- assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",
- vls.getDatatype().getIRIString());
+ assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", vls.getDatatype().getIRIString());
assertEquals("\"Herbert Van de Sompel\"@vls", vls.ntriplesString());
}
@Test
public void testCreateLiteralString() throws Exception {
- Literal example = factory.createLiteral("Example", factory
- .createIRI("http://www.w3.org/2001/XMLSchema#string"));
+ Literal example = factory.createLiteral("Example",
+ factory.createIRI("http://www.w3.org/2001/XMLSchema#string"));
assertEquals("Example", example.getLexicalForm());
assertFalse(example.getLanguageTag().isPresent());
- assertEquals("http://www.w3.org/2001/XMLSchema#string", example
- .getDatatype().getIRIString());
+ assertEquals("http://www.w3.org/2001/XMLSchema#string", example.getDatatype().getIRIString());
// http://lists.w3.org/Archives/Public/public-rdf-comments/2014Dec/0004.html
assertEquals("\"Example\"", example.ntriplesString());
}
@@ -239,10 +222,10 @@ public abstract class AbstractRDFTest {
@Test
public void testCreateTripleBnodeIRI() {
- BlankNode subject = factory.createBlankNode("b1");
- IRI predicate = factory.createIRI("http://example.com/pred");
- IRI object = factory.createIRI("http://example.com/obj");
- Triple triple = factory.createTriple(subject, predicate, object);
+ BlankNode subject = factory.createBlankNode("b1");
+ IRI predicate = factory.createIRI("http://example.com/pred");
+ IRI object = factory.createIRI("http://example.com/obj");
+ Triple triple = factory.createTriple(subject, predicate, object);
// bnode equivalence should be OK as we used the same
// factory and have not yet inserted Triple into a Graph
@@ -253,11 +236,11 @@ public abstract class AbstractRDFTest {
@Test
public void testCreateTripleBnodeTriple() {
- BlankNode subject = factory.createBlankNode();
- IRI predicate = factory.createIRI("http://example.com/pred");
- Literal object = factory.createLiteral("Example", "en");
- Triple triple = factory.createTriple(subject, predicate, object);
-
+ BlankNode subject = factory.createBlankNode();
+ IRI predicate = factory.createIRI("http://example.com/pred");
+ Literal object = factory.createLiteral("Example", "en");
+ Triple triple = factory.createTriple(subject, predicate, object);
+
// bnode equivalence should be OK as we used the same
// factory and have not yet inserted Triple into a Graph
assertEquals(subject, triple.getSubject());
@@ -279,8 +262,7 @@ public abstract class AbstractRDFTest {
assertFalse(withColon.ntriplesString().contains("with:colon"));
// and creating it twice gets the same ntriplesString
- assertEquals(withColon.ntriplesString(),
- factory.createBlankNode("with:colon").ntriplesString());
+ assertEquals(withColon.ntriplesString(), factory.createBlankNode("with:colon").ntriplesString());
}
@Test(expected = IllegalArgumentException.class)
@@ -316,11 +298,7 @@ public abstract class AbstractRDFTest {
@Test
public void hashCodeLiteral() throws Exception {
Literal literal = factory.createLiteral("Hello");
- assertEquals(Objects.hash(
- literal.getLexicalForm(),
- literal.getDatatype(),
- literal.getLanguageTag()
- ),
+ assertEquals(Objects.hash(literal.getLexicalForm(), literal.getDatatype(), literal.getLanguageTag()),
literal.hashCode());
}
@@ -328,7 +306,6 @@ public abstract class AbstractRDFTest {
public void hashCodeTriple() throws Exception {
IRI iri = factory.createIRI("http://example.com/");
Triple triple = factory.createTriple(iri, iri, iri);
- assertEquals(Objects.hash(iri, iri, iri),
- triple.hashCode());
+ assertEquals(Objects.hash(iri, iri, iri), triple.hashCode());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java b/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java
index 5781822..a1cb62e 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java
@@ -25,91 +25,91 @@ import org.junit.Test;
public class RDFSyntaxTest {
- @Test
- public void byFileExtension() throws Exception {
- assertEquals(RDFSyntax.JSONLD, RDFSyntax.byFileExtension(".jsonld").get());
- assertEquals(RDFSyntax.NQUADS, RDFSyntax.byFileExtension(".nq").get());
- assertEquals(RDFSyntax.NTRIPLES, RDFSyntax.byFileExtension(".nt").get());
- assertEquals(RDFSyntax.RDFA_HTML, RDFSyntax.byFileExtension(".html").get());
- assertEquals(RDFSyntax.RDFA_XHTML, RDFSyntax.byFileExtension(".xhtml").get());
- assertEquals(RDFSyntax.RDFXML, RDFSyntax.byFileExtension(".rdf").get());
- assertEquals(RDFSyntax.TRIG, RDFSyntax.byFileExtension(".trig").get());
- assertEquals(RDFSyntax.TURTLE, RDFSyntax.byFileExtension(".ttl").get());
- }
-
- @Test
- public void byFileExtensionFailsWithoutDot() throws Exception {
- assertEquals(Optional.empty(), RDFSyntax.byFileExtension("rdf"));
- }
-
- @Test
- public void byFileExtensionLowerCase() throws Exception {
- assertEquals(RDFSyntax.TURTLE, RDFSyntax.byFileExtension(".TtL").get());
- }
-
- @Test
- public void byFileExtensionUnknown() throws Exception {
- assertEquals(Optional.empty(), RDFSyntax.byFileExtension(".tar"));
- }
-
- @Test
- public void byMediaType() throws Exception {
- assertEquals(RDFSyntax.JSONLD, RDFSyntax.byMediaType("application/ld+json").get());
- assertEquals(RDFSyntax.NQUADS, RDFSyntax.byMediaType("application/n-quads").get());
- assertEquals(RDFSyntax.NTRIPLES, RDFSyntax.byMediaType("application/n-triples").get());
- assertEquals(RDFSyntax.RDFA_HTML, RDFSyntax.byMediaType("text/html").get());
- assertEquals(RDFSyntax.RDFA_XHTML, RDFSyntax.byMediaType("application/xhtml+xml").get());
- assertEquals(RDFSyntax.RDFXML, RDFSyntax.byMediaType("application/rdf+xml").get());
- assertEquals(RDFSyntax.TRIG, RDFSyntax.byMediaType("application/trig").get());
- assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle").get());
- }
-
- @Test
- public void byMediaTypeContentType() throws Exception {
- assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle; charset=\"UTF-8\"").get());
- assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle ; charset=\"UTF-8\"").get());
- assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle, text/plain").get());
- assertEquals(Optional.empty(), RDFSyntax.byMediaType(" text/turtle"));
- }
-
- @Test
- public void byMediaTypeLowerCase() throws Exception {
- assertEquals(RDFSyntax.JSONLD, RDFSyntax.byMediaType("APPLICATION/ld+JSON").get());
- }
-
- @Test
- public void byMediaTypeUnknown() throws Exception {
- assertEquals(Optional.empty(), RDFSyntax.byMediaType("application/octet-stream"));
- }
-
- @Test
- public void fileExtension() throws Exception {
- assertEquals(".jsonld", RDFSyntax.JSONLD.fileExtension);
- assertEquals(".nq", RDFSyntax.NQUADS.fileExtension);
- assertEquals(".nt", RDFSyntax.NTRIPLES.fileExtension);
- assertEquals(".html", RDFSyntax.RDFA_HTML.fileExtension);
- assertEquals(".xhtml", RDFSyntax.RDFA_XHTML.fileExtension);
- assertEquals(".rdf", RDFSyntax.RDFXML.fileExtension);
- assertEquals(".trig", RDFSyntax.TRIG.fileExtension);
- assertEquals(".ttl", RDFSyntax.TURTLE.fileExtension);
- }
-
- @Test
- public void mediaType() throws Exception {
- assertEquals("application/ld+json", RDFSyntax.JSONLD.mediaType);
- assertEquals("application/n-quads", RDFSyntax.NQUADS.mediaType);
- assertEquals("application/n-triples", RDFSyntax.NTRIPLES.mediaType);
- assertEquals("text/html", RDFSyntax.RDFA_HTML.mediaType);
- assertEquals("application/xhtml+xml", RDFSyntax.RDFA_XHTML.mediaType);
- assertEquals("application/rdf+xml", RDFSyntax.RDFXML.mediaType);
- assertEquals("application/trig", RDFSyntax.TRIG.mediaType);
- assertEquals("text/turtle", RDFSyntax.TURTLE.mediaType);
- }
-
- @Test
- public void name() throws Exception {
- assertEquals("JSON-LD 1.0", RDFSyntax.JSONLD.toString());
- assertEquals("RDF 1.1 Turtle", RDFSyntax.TURTLE.toString());
- }
+ @Test
+ public void byFileExtension() throws Exception {
+ assertEquals(RDFSyntax.JSONLD, RDFSyntax.byFileExtension(".jsonld").get());
+ assertEquals(RDFSyntax.NQUADS, RDFSyntax.byFileExtension(".nq").get());
+ assertEquals(RDFSyntax.NTRIPLES, RDFSyntax.byFileExtension(".nt").get());
+ assertEquals(RDFSyntax.RDFA_HTML, RDFSyntax.byFileExtension(".html").get());
+ assertEquals(RDFSyntax.RDFA_XHTML, RDFSyntax.byFileExtension(".xhtml").get());
+ assertEquals(RDFSyntax.RDFXML, RDFSyntax.byFileExtension(".rdf").get());
+ assertEquals(RDFSyntax.TRIG, RDFSyntax.byFileExtension(".trig").get());
+ assertEquals(RDFSyntax.TURTLE, RDFSyntax.byFileExtension(".ttl").get());
+ }
+
+ @Test
+ public void byFileExtensionFailsWithoutDot() throws Exception {
+ assertEquals(Optional.empty(), RDFSyntax.byFileExtension("rdf"));
+ }
+
+ @Test
+ public void byFileExtensionLowerCase() throws Exception {
+ assertEquals(RDFSyntax.TURTLE, RDFSyntax.byFileExtension(".TtL").get());
+ }
+
+ @Test
+ public void byFileExtensionUnknown() throws Exception {
+ assertEquals(Optional.empty(), RDFSyntax.byFileExtension(".tar"));
+ }
+
+ @Test
+ public void byMediaType() throws Exception {
+ assertEquals(RDFSyntax.JSONLD, RDFSyntax.byMediaType("application/ld+json").get());
+ assertEquals(RDFSyntax.NQUADS, RDFSyntax.byMediaType("application/n-quads").get());
+ assertEquals(RDFSyntax.NTRIPLES, RDFSyntax.byMediaType("application/n-triples").get());
+ assertEquals(RDFSyntax.RDFA_HTML, RDFSyntax.byMediaType("text/html").get());
+ assertEquals(RDFSyntax.RDFA_XHTML, RDFSyntax.byMediaType("application/xhtml+xml").get());
+ assertEquals(RDFSyntax.RDFXML, RDFSyntax.byMediaType("application/rdf+xml").get());
+ assertEquals(RDFSyntax.TRIG, RDFSyntax.byMediaType("application/trig").get());
+ assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle").get());
+ }
+
+ @Test
+ public void byMediaTypeContentType() throws Exception {
+ assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle; charset=\"UTF-8\"").get());
+ assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle ; charset=\"UTF-8\"").get());
+ assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle, text/plain").get());
+ assertEquals(Optional.empty(), RDFSyntax.byMediaType(" text/turtle"));
+ }
+
+ @Test
+ public void byMediaTypeLowerCase() throws Exception {
+ assertEquals(RDFSyntax.JSONLD, RDFSyntax.byMediaType("APPLICATION/ld+JSON").get());
+ }
+
+ @Test
+ public void byMediaTypeUnknown() throws Exception {
+ assertEquals(Optional.empty(), RDFSyntax.byMediaType("application/octet-stream"));
+ }
+
+ @Test
+ public void fileExtension() throws Exception {
+ assertEquals(".jsonld", RDFSyntax.JSONLD.fileExtension);
+ assertEquals(".nq", RDFSyntax.NQUADS.fileExtension);
+ assertEquals(".nt", RDFSyntax.NTRIPLES.fileExtension);
+ assertEquals(".html", RDFSyntax.RDFA_HTML.fileExtension);
+ assertEquals(".xhtml", RDFSyntax.RDFA_XHTML.fileExtension);
+ assertEquals(".rdf", RDFSyntax.RDFXML.fileExtension);
+ assertEquals(".trig", RDFSyntax.TRIG.fileExtension);
+ assertEquals(".ttl", RDFSyntax.TURTLE.fileExtension);
+ }
+
+ @Test
+ public void mediaType() throws Exception {
+ assertEquals("application/ld+json", RDFSyntax.JSONLD.mediaType);
+ assertEquals("application/n-quads", RDFSyntax.NQUADS.mediaType);
+ assertEquals("application/n-triples", RDFSyntax.NTRIPLES.mediaType);
+ assertEquals("text/html", RDFSyntax.RDFA_HTML.mediaType);
+ assertEquals("application/xhtml+xml", RDFSyntax.RDFA_XHTML.mediaType);
+ assertEquals("application/rdf+xml", RDFSyntax.RDFXML.mediaType);
+ assertEquals("application/trig", RDFSyntax.TRIG.mediaType);
+ assertEquals("text/turtle", RDFSyntax.TURTLE.mediaType);
+ }
+
+ @Test
+ public void name() throws Exception {
+ assertEquals("JSON-LD 1.0", RDFSyntax.JSONLD.toString());
+ assertEquals("RDF 1.1 Turtle", RDFSyntax.TURTLE.toString());
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/examples/src/example/UserGuideTest.java
----------------------------------------------------------------------
diff --git a/examples/src/example/UserGuideTest.java b/examples/src/example/UserGuideTest.java
index fe884dd..f0ec618 100644
--- a/examples/src/example/UserGuideTest.java
+++ b/examples/src/example/UserGuideTest.java
@@ -42,225 +42,218 @@ import org.junit.Test;
public class UserGuideTest {
- private RDF factory;
+ private RDF factory;
- @Before
- public void factory() {
- factory = new SimpleRDF();
- }
+ @Before
+ public void factory() {
+ factory = new SimpleRDF();
+ }
+
+ @Test
+ public void creating() throws Exception {
+ BlankNode aliceBlankNode = factory.createBlankNode();
+ IRI nameIri = factory.createIRI("http://example.com/name");
+ Literal aliceLiteral = factory.createLiteral("Alice");
+ Triple triple = factory.createTriple(aliceBlankNode, nameIri, aliceLiteral);
+
+ System.out.println(aliceBlankNode.ntriplesString());
+ System.out.println(nameIri.ntriplesString());
+ System.out.println(aliceLiteral.ntriplesString());
+
+ }
+
+ @Test
+ public void ntriples() throws Exception {
+ IRI iri = factory.createIRI("http://example.com/alice");
+ System.out.println(iri.getIRIString());
+
+ IRI iri2 = factory.createIRI("http://example.com/alice");
+ System.out.println(iri.equals(iri2));
+
+ IRI iri3 = factory.createIRI("http://example.com/alice/./");
+ System.out.println(iri.equals(iri3));
+
+ System.out.println(iri.equals("http://example.com/alice"));
+ System.out.println(iri.equals(factory.createLiteral("http://example.com/alice")));
+
+ }
+
+ @Test
+ public void blanknode() throws Exception {
+ BlankNode bnode = factory.createBlankNode();
+ System.out.println(bnode.equals(bnode));
+ System.out.println(bnode.equals(factory.createBlankNode()));
+
+ BlankNode b1 = factory.createBlankNode("b1");
+
+ System.out.println(b1.ntriplesString());
+
+ System.out.println(b1.equals(factory.createBlankNode("b1")));
+ System.out.println(b1.equals(new SimpleRDF().createBlankNode("b1")));
- @Test
- public void creating() throws Exception {
- BlankNode aliceBlankNode = factory.createBlankNode();
- IRI nameIri = factory.createIRI("http://example.com/name");
- Literal aliceLiteral = factory.createLiteral("Alice");
- Triple triple = factory.createTriple(aliceBlankNode, nameIri, aliceLiteral);
+ System.out.println(bnode.uniqueReference());
+ }
+
+ @Test
+ public void literal() throws Exception {
+ Literal literal = factory.createLiteral("Hello world!");
+ System.out.println(literal.ntriplesString());
- System.out.println(aliceBlankNode.ntriplesString());
- System.out.println(nameIri.ntriplesString());
- System.out.println(aliceLiteral.ntriplesString());
+ String lexical = literal.getLexicalForm();
+ System.out.println(lexical);
- }
+ IRI datatype = literal.getDatatype();
+ System.out.println(datatype.ntriplesString());
- @Test
- public void ntriples() throws Exception {
- IRI iri = factory.createIRI("http://example.com/alice");
- System.out.println(iri.getIRIString());
+ IRI xsdDouble = factory.createIRI("http://www.w3.org/2001/XMLSchema#double");
+ Literal literalDouble = factory.createLiteral("13.37", xsdDouble);
+ System.out.println(literalDouble.ntriplesString());
- IRI iri2 = factory.createIRI("http://example.com/alice");
- System.out.println(iri.equals(iri2));
-
- IRI iri3 = factory.createIRI("http://example.com/alice/./");
- System.out.println(iri.equals(iri3));
-
- System.out.println(iri.equals("http://example.com/alice"));
- System.out.println(iri.equals(factory.createLiteral("http://example.com/alice")));
-
- }
-
- @Test
- public void blanknode() throws Exception {
- BlankNode bnode = factory.createBlankNode();
- System.out.println(bnode.equals(bnode));
- System.out.println(bnode.equals(factory.createBlankNode()));
-
- BlankNode b1 = factory.createBlankNode("b1");
-
- System.out.println(b1.ntriplesString());
-
- System.out.println(b1.equals(factory.createBlankNode("b1")));
- System.out.println(b1.equals(new SimpleRDF().createBlankNode("b1")));
-
- System.out.println(bnode.uniqueReference());
- }
-
- @Test
- public void literal() throws Exception {
- Literal literal = factory.createLiteral("Hello world!");
- System.out.println(literal.ntriplesString());
-
- String lexical = literal.getLexicalForm();
- System.out.println(lexical);
-
- IRI datatype = literal.getDatatype();
- System.out.println(datatype.ntriplesString());
-
- IRI xsdDouble = factory.createIRI("http://www.w3.org/2001/XMLSchema#double");
- Literal literalDouble = factory.createLiteral("13.37", xsdDouble);
- System.out.println(literalDouble.ntriplesString());
-
- Literal literalDouble2 = factory.createLiteral("13.37", Types.XSD_DOUBLE);
-
- System.out.println(Types.XSD_STRING.equals(literal.getDatatype()));
-
- Literal inSpanish = factory.createLiteral("�Hola, Mundo!", "es");
- System.out.println(inSpanish.ntriplesString());
- System.out.println(inSpanish.getLexicalForm());
- System.out.println(inSpanish.getDatatype().ntriplesString());
-
- Optional<String> tag = inSpanish.getLanguageTag();
- if (tag.isPresent()) {
- System.out.println(tag.get());
- }
-
- System.out.println(literal.getLanguageTag().isPresent());
- System.out.println(literalDouble.getLanguageTag().isPresent());
- }
-
- @Test
- public void triple() throws Exception {
- BlankNodeOrIRI subject = factory.createBlankNode();
- IRI predicate = factory.createIRI("http://example.com/says");
- RDFTerm object = factory.createLiteral("Hello");
- Triple triple = factory.createTriple(subject, predicate, object);
-
- BlankNodeOrIRI subj = triple.getSubject();
- System.out.println(subj.ntriplesString());
-
- IRI pred = triple.getPredicate();
- System.out.println(pred.getIRIString());
-
- RDFTerm obj = triple.getObject();
- System.out.println(obj.ntriplesString());
-
- if (subj instanceof IRI) {
- String s = ((IRI) subj).getIRIString();
- System.out.println(s);
- }
- // ..
- if (obj instanceof Literal) {
- IRI type = ((Literal) obj).getDatatype();
- System.out.println(type);
- }
+ Literal literalDouble2 = factory.createLiteral("13.37", Types.XSD_DOUBLE);
- // Equal triples must have same s,p,o
- System.out.println(triple.equals(factory.createTriple(subj, pred, obj)));
- }
+ System.out.println(Types.XSD_STRING.equals(literal.getDatatype()));
- @Test
- public void quad() throws Exception {
- BlankNodeOrIRI graph = factory.createIRI("http://example.com/graph");
- BlankNodeOrIRI subject = factory.createBlankNode();
- IRI predicate = factory.createIRI("http://example.com/says");
- RDFTerm object = factory.createLiteral("Hello");
- Quad quad = factory.createQuad(graph, subject, predicate, object);
+ Literal inSpanish = factory.createLiteral("�Hola, Mundo!", "es");
+ System.out.println(inSpanish.ntriplesString());
+ System.out.println(inSpanish.getLexicalForm());
+ System.out.println(inSpanish.getDatatype().ntriplesString());
- Optional<BlankNodeOrIRI> g = quad.getGraphName();
- if (g.isPresent()) {
- System.out.println(g.get().ntriplesString());
- }
-
- BlankNodeOrIRI subj = quad.getSubject();
- System.out.println(subj.ntriplesString());
-
- // null means default graph
- Quad otherQuad = factory.createQuad(null, subject, predicate, object);
- // Equal quads must have same g,s,p,o
- System.out.println(quad.equals(otherQuad));
-
- // all quads can be viewed as triples - "stripping" the graph
- Triple asTriple = quad.asTriple();
- Triple otherAsTriple = quad.asTriple();
- System.out.println(asTriple.equals(otherAsTriple));
-
- // NOTE: Quad does NOT extend Triple, however both Triple and Quad
- // extend TripleLike
-
- TripleLike a = quad;
- TripleLike b = quad.asTriple();
- // Unlike Triple and Quad, TripleLike does not mandate any .equals(),
- // it just provides common access to getSubject(), getPredicate(), getObject()
-
-
- // TripleLike supports generalized RDF - therefore all s/p/o are of type RDFTerm
- RDFTerm s = a.getSubject();
- }
-
-
- @Test
- public void graph() throws Exception {
- IRI nameIri = factory.createIRI("http://example.com/name");
- BlankNode aliceBlankNode = factory.createBlankNode();
- Literal aliceLiteral = factory.createLiteral("Alice");
- Triple triple = factory.createTriple(aliceBlankNode, nameIri, aliceLiteral);
-
- Graph graph = factory.createGraph();
-
- graph.add(triple);
-
- IRI bob = factory.createIRI("http://example.com/bob");
- Literal bobName = factory.createLiteral("Bob");
- graph.add(bob, nameIri, bobName);
-
-
- System.out.println(graph.contains(triple));
-
-
- System.out.println(graph.contains(null, nameIri, bobName));
-
- System.out.println(graph.size());
-
- for (Triple t : graph.iterate()) {
- System.out.println(t.getObject());
- }
-
-
- for (Triple t : graph.iterate(null, null, bobName)) {
- System.out.println(t.getPredicate());
- }
-
- try (Stream<? extends Triple> triples = graph.stream()) {
- Stream<RDFTerm> subjects = triples.map(t -> t.getObject());
- String s = subjects.map(RDFTerm::ntriplesString).collect(Collectors.joining(" "));
- System.out.println(s);
- }
-
- try (Stream<? extends Triple> named = graph.stream(null, nameIri,null)) {
- Stream<? extends Triple> namedB = named.filter(
- t -> t.getObject().ntriplesString().contains("B"));
- System.out.println(namedB.map(t -> t.getSubject()).findAny().get());
- }
-
- graph.remove(triple);
- System.out.println(graph.contains(triple));
-
- graph.remove(null, nameIri, null);
-
- graph.clear();
- System.out.println(graph.contains(null, null, null));
-
-
- }
+ Optional<String> tag = inSpanish.getLanguageTag();
+ if (tag.isPresent()) {
+ System.out.println(tag.get());
+ }
+ System.out.println(literal.getLanguageTag().isPresent());
+ System.out.println(literalDouble.getLanguageTag().isPresent());
+ }
+
+ @Test
+ public void triple() throws Exception {
+ BlankNodeOrIRI subject = factory.createBlankNode();
+ IRI predicate = factory.createIRI("http://example.com/says");
+ RDFTerm object = factory.createLiteral("Hello");
+ Triple triple = factory.createTriple(subject, predicate, object);
+
+ BlankNodeOrIRI subj = triple.getSubject();
+ System.out.println(subj.ntriplesString());
+
+ IRI pred = triple.getPredicate();
+ System.out.println(pred.getIRIString());
+
+ RDFTerm obj = triple.getObject();
+ System.out.println(obj.ntriplesString());
+
+ if (subj instanceof IRI) {
+ String s = ((IRI) subj).getIRIString();
+ System.out.println(s);
+ }
+ // ..
+ if (obj instanceof Literal) {
+ IRI type = ((Literal) obj).getDatatype();
+ System.out.println(type);
+ }
+
+ // Equal triples must have same s,p,o
+ System.out.println(triple.equals(factory.createTriple(subj, pred, obj)));
+ }
+
+ @Test
+ public void quad() throws Exception {
+ BlankNodeOrIRI graph = factory.createIRI("http://example.com/graph");
+ BlankNodeOrIRI subject = factory.createBlankNode();
+ IRI predicate = factory.createIRI("http://example.com/says");
+ RDFTerm object = factory.createLiteral("Hello");
+ Quad quad = factory.createQuad(graph, subject, predicate, object);
+
+ Optional<BlankNodeOrIRI> g = quad.getGraphName();
+ if (g.isPresent()) {
+ System.out.println(g.get().ntriplesString());
+ }
+
+ BlankNodeOrIRI subj = quad.getSubject();
+ System.out.println(subj.ntriplesString());
+
+ // null means default graph
+ Quad otherQuad = factory.createQuad(null, subject, predicate, object);
+ // Equal quads must have same g,s,p,o
+ System.out.println(quad.equals(otherQuad));
+
+ // all quads can be viewed as triples - "stripping" the graph
+ Triple asTriple = quad.asTriple();
+ Triple otherAsTriple = quad.asTriple();
+ System.out.println(asTriple.equals(otherAsTriple));
+
+ // NOTE: Quad does NOT extend Triple, however both Triple and Quad
+ // extend TripleLike
+
+ TripleLike a = quad;
+ TripleLike b = quad.asTriple();
+ // Unlike Triple and Quad, TripleLike does not mandate any .equals(),
+ // it just provides common access to getSubject(), getPredicate(),
+ // getObject()
+
+ // TripleLike supports generalized RDF - therefore all s/p/o are of type
+ // RDFTerm
+ RDFTerm s = a.getSubject();
+ }
+
+ @Test
+ public void graph() throws Exception {
+ IRI nameIri = factory.createIRI("http://example.com/name");
+ BlankNode aliceBlankNode = factory.createBlankNode();
+ Literal aliceLiteral = factory.createLiteral("Alice");
+ Triple triple = factory.createTriple(aliceBlankNode, nameIri, aliceLiteral);
+
+ Graph graph = factory.createGraph();
+
+ graph.add(triple);
+
+ IRI bob = factory.createIRI("http://example.com/bob");
+ Literal bobName = factory.createLiteral("Bob");
+ graph.add(bob, nameIri, bobName);
+
+ System.out.println(graph.contains(triple));
+
+ System.out.println(graph.contains(null, nameIri, bobName));
+
+ System.out.println(graph.size());
+
+ for (Triple t : graph.iterate()) {
+ System.out.println(t.getObject());
+ }
+
+ for (Triple t : graph.iterate(null, null, bobName)) {
+ System.out.println(t.getPredicate());
+ }
+
+ try (Stream<? extends Triple> triples = graph.stream()) {
+ Stream<RDFTerm> subjects = triples.map(t -> t.getObject());
+ String s = subjects.map(RDFTerm::ntriplesString).collect(Collectors.joining(" "));
+ System.out.println(s);
+ }
+
+ try (Stream<? extends Triple> named = graph.stream(null, nameIri, null)) {
+ Stream<? extends Triple> namedB = named.filter(t -> t.getObject().ntriplesString().contains("B"));
+ System.out.println(namedB.map(t -> t.getSubject()).findAny().get());
+ }
+
+ graph.remove(triple);
+ System.out.println(graph.contains(triple));
+
+ graph.remove(null, nameIri, null);
+
+ graph.clear();
+ System.out.println(graph.contains(null, null, null));
+
+ }
public static String tripleAsString(Triple t) {
- return t.getSubject().ntriplesString() + " "
- + t.getPredicate().ntriplesString() + " " +
- t.getObject().ntriplesString() + " .";
+ return t.getSubject().ntriplesString() + " " + t.getPredicate().ntriplesString() + " "
+ + t.getObject().ntriplesString() + " .";
}
- public static void writeGraph(Graph graph, Path graphFile) throws Exception {
+ public static void writeGraph(Graph graph, Path graphFile) throws Exception {
Stream<CharSequence> stream = graph.stream().map(UserGuideTest::tripleAsString);
Files.write(graphFile, stream::iterator, StandardCharsets.UTF_8);
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
----------------------------------------------------------------------
diff --git a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
index 5a4cdcf..b6dce6f 100644
--- a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
+++ b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/AllToAllTest.java
@@ -44,133 +44,128 @@ import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class AllToAllTest {
- private RDF nodeFactory;
- private RDF graphFactory;
-
-
- public AllToAllTest(
- Class<? extends RDF> from,
- Class<? extends RDF> to) throws InstantiationException, IllegalAccessException {
- this.nodeFactory = from.newInstance();
- this.graphFactory = to.newInstance();
- }
-
- @SuppressWarnings("rawtypes")
- @Parameters(name = "{index}: {0}->{1}")
- public static Collection<Object[]> data() {
- List<Class> factories = Arrays.asList(
- SimpleRDF.class,
- JenaRDF.class,
- RDF4J.class,
- JsonLdRDF.class);
- Collection<Object[]> allToAll = new ArrayList<>();
- for (Class from : factories) {
- for (Class to : factories) {
- // NOTE: we deliberately include self-to-self here
- // to test two instances of the same implementation
- allToAll.add(new Object[]{from, to});
- }
- }
- return allToAll;
- }
-
- /**
- * This test creates a {@link Graph} with the first
- * {@link RDFTermFactory}, then inserts/queries with
- * triples using {@link RDFTerm}s created with the second factory.
- *
- * @throws Exception Just in case..
- */
- @Test
- public void addTermsFromOtherFactory() throws Exception {
- Graph g = graphFactory.createGraph();
- BlankNode s = nodeFactory.createBlankNode();
- IRI p = nodeFactory.createIRI("http://example.com/p");
- Literal o = nodeFactory.createLiteral("Hello");
-
- g.add(s, p, o);
-
- // blankNode should still work with g.contains()
- assertTrue(g.contains(s, p, o));
- Triple t1 = g.stream().findAny().get();
-
- // Can't make assumptions about BlankNode equality - it might
- // have been mapped to a different BlankNode.uniqueReference()
- // assertEquals(s, t.getSubject());
-
- assertEquals(p, t1.getPredicate());
- assertEquals(o, t1.getObject());
-
- IRI s2 = nodeFactory.createIRI("http://example.com/s2");
- g.add(s2, p, s);
- assertTrue(g.contains(s2, p, s));
-
- // This should be mapped to the same BlankNode
- // (even if it has a different identifier), e.g.
- // we should be able to do:
-
- Triple t2 = g.stream(s2, p, null).findAny().get();
-
- BlankNode bnode = (BlankNode) t2.getObject();
- // And that (possibly adapted) BlankNode object should
- // match the subject of t1 statement
- assertEquals(bnode, t1.getSubject());
- // And can be used as a key:
- Triple t3 = g.stream(bnode, p, null).findAny().get();
- assertEquals(t1, t3);
- }
-
-
- /**
- * This is a variation of {@link #addTermsFromOtherFactory()}, but here
- * {@link Triple} is created in the "foreign" nodeFactory before adding to
- * the graph.
- *
- * @throws Exception
- * Just in case..
- */
- @Test
- public void addTriplesFromOtherFactory() throws Exception {
- Graph g = graphFactory.createGraph();
- BlankNode s = nodeFactory.createBlankNode();
- IRI p = nodeFactory.createIRI("http://example.com/p");
- Literal o = nodeFactory.createLiteral("Hello");
-
- Triple srcT1 = nodeFactory.createTriple(s, p, o);
- // This should work even with BlankNode as they are from the same factory
- assertEquals(s, srcT1.getSubject());
- assertEquals(p, srcT1.getPredicate());
- assertEquals(o, srcT1.getObject());
- g.add(srcT1);
-
- // what about the blankNode within?
- assertTrue(g.contains(srcT1));
- Triple t1 = g.stream().findAny().get();
-
- // Can't make assumptions about BlankNode equality - it might
- // have been mapped to a different BlankNode.uniqueReference()
- //assertEquals(srcT1, t1);
- //assertEquals(s, t1.getSubject());
- assertEquals(p, t1.getPredicate());
- assertEquals(o, t1.getObject());
-
- IRI s2 = nodeFactory.createIRI("http://example.com/s2");
- Triple srcT2 = nodeFactory.createTriple(s2, p, s);
- g.add(srcT2);
- assertTrue(g.contains(srcT2));
-
- // This should be mapped to the same BlankNode
- // (even if it has a different identifier), e.g.
- // we should be able to do:
-
- Triple t2 = g.stream(s2, p, null).findAny().get();
-
- BlankNode bnode = (BlankNode) t2.getObject();
- // And that (possibly adapted) BlankNode object should
- // match the subject of t1 statement
- assertEquals(bnode, t1.getSubject());
- // And can be used as a key:
- Triple t3 = g.stream(bnode, p, null).findAny().get();
- assertEquals(t1, t3);
- }
+ private RDF nodeFactory;
+ private RDF graphFactory;
+
+ public AllToAllTest(Class<? extends RDF> from, Class<? extends RDF> to)
+ throws InstantiationException, IllegalAccessException {
+ this.nodeFactory = from.newInstance();
+ this.graphFactory = to.newInstance();
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Parameters(name = "{index}: {0}->{1}")
+ public static Collection<Object[]> data() {
+ List<Class> factories = Arrays.asList(SimpleRDF.class, JenaRDF.class, RDF4J.class, JsonLdRDF.class);
+ Collection<Object[]> allToAll = new ArrayList<>();
+ for (Class from : factories) {
+ for (Class to : factories) {
+ // NOTE: we deliberately include self-to-self here
+ // to test two instances of the same implementation
+ allToAll.add(new Object[] { from, to });
+ }
+ }
+ return allToAll;
+ }
+
+ /**
+ * This test creates a {@link Graph} with the first {@link RDFTermFactory},
+ * then inserts/queries with triples using {@link RDFTerm}s created with the
+ * second factory.
+ *
+ * @throws Exception
+ * Just in case..
+ */
+ @Test
+ public void addTermsFromOtherFactory() throws Exception {
+ Graph g = graphFactory.createGraph();
+ BlankNode s = nodeFactory.createBlankNode();
+ IRI p = nodeFactory.createIRI("http://example.com/p");
+ Literal o = nodeFactory.createLiteral("Hello");
+
+ g.add(s, p, o);
+
+ // blankNode should still work with g.contains()
+ assertTrue(g.contains(s, p, o));
+ Triple t1 = g.stream().findAny().get();
+
+ // Can't make assumptions about BlankNode equality - it might
+ // have been mapped to a different BlankNode.uniqueReference()
+ // assertEquals(s, t.getSubject());
+
+ assertEquals(p, t1.getPredicate());
+ assertEquals(o, t1.getObject());
+
+ IRI s2 = nodeFactory.createIRI("http://example.com/s2");
+ g.add(s2, p, s);
+ assertTrue(g.contains(s2, p, s));
+
+ // This should be mapped to the same BlankNode
+ // (even if it has a different identifier), e.g.
+ // we should be able to do:
+
+ Triple t2 = g.stream(s2, p, null).findAny().get();
+
+ BlankNode bnode = (BlankNode) t2.getObject();
+ // And that (possibly adapted) BlankNode object should
+ // match the subject of t1 statement
+ assertEquals(bnode, t1.getSubject());
+ // And can be used as a key:
+ Triple t3 = g.stream(bnode, p, null).findAny().get();
+ assertEquals(t1, t3);
+ }
+
+ /**
+ * This is a variation of {@link #addTermsFromOtherFactory()}, but here
+ * {@link Triple} is created in the "foreign" nodeFactory before adding to
+ * the graph.
+ *
+ * @throws Exception
+ * Just in case..
+ */
+ @Test
+ public void addTriplesFromOtherFactory() throws Exception {
+ Graph g = graphFactory.createGraph();
+ BlankNode s = nodeFactory.createBlankNode();
+ IRI p = nodeFactory.createIRI("http://example.com/p");
+ Literal o = nodeFactory.createLiteral("Hello");
+
+ Triple srcT1 = nodeFactory.createTriple(s, p, o);
+ // This should work even with BlankNode as they are from the same
+ // factory
+ assertEquals(s, srcT1.getSubject());
+ assertEquals(p, srcT1.getPredicate());
+ assertEquals(o, srcT1.getObject());
+ g.add(srcT1);
+
+ // what about the blankNode within?
+ assertTrue(g.contains(srcT1));
+ Triple t1 = g.stream().findAny().get();
+
+ // Can't make assumptions about BlankNode equality - it might
+ // have been mapped to a different BlankNode.uniqueReference()
+ // assertEquals(srcT1, t1);
+ // assertEquals(s, t1.getSubject());
+ assertEquals(p, t1.getPredicate());
+ assertEquals(o, t1.getObject());
+
+ IRI s2 = nodeFactory.createIRI("http://example.com/s2");
+ Triple srcT2 = nodeFactory.createTriple(s2, p, s);
+ g.add(srcT2);
+ assertTrue(g.contains(srcT2));
+
+ // This should be mapped to the same BlankNode
+ // (even if it has a different identifier), e.g.
+ // we should be able to do:
+
+ Triple t2 = g.stream(s2, p, null).findAny().get();
+
+ BlankNode bnode = (BlankNode) t2.getObject();
+ // And that (possibly adapted) BlankNode object should
+ // match the subject of t1 statement
+ assertEquals(bnode, t1.getSubject());
+ // And can be used as a key:
+ Triple t3 = g.stream(bnode, p, null).findAny().get();
+ assertEquals(t1, t3);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/ConversionException.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/ConversionException.java b/jena/src/main/java/org/apache/commons/rdf/jena/ConversionException.java
index 29b9060..20bc44c 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/ConversionException.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/ConversionException.java
@@ -28,21 +28,21 @@ package org.apache.commons.rdf.jena;
*/
public class ConversionException extends RuntimeException {
- private static final long serialVersionUID = -898179977312382568L;
+ private static final long serialVersionUID = -898179977312382568L;
- public ConversionException() {
- super();
- }
+ public ConversionException() {
+ super();
+ }
- public ConversionException(String message) {
- super(message);
- }
+ public ConversionException(String message) {
+ super(message);
+ }
- public ConversionException(Throwable cause) {
- super(cause);
- }
+ public ConversionException(Throwable cause) {
+ super(cause);
+ }
- public ConversionException(String message, Throwable cause) {
- super(message, cause);
- }
+ public ConversionException(String message, Throwable cause) {
+ super(message, cause);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/JenaDataset.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaDataset.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaDataset.java
index 4a85d34..bb8e39c 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaDataset.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaDataset.java
@@ -29,29 +29,28 @@ import org.apache.jena.sparql.core.DatasetGraph;
* {@link #asJenaDatasetGraph()}.
*/
public interface JenaDataset extends org.apache.commons.rdf.api.Dataset {
-
- /**
- * Return the underlying Jena {@link DatasetGraph}.
- * <p>
- * Changes to the Jena <em>dataset graph</em> are reflected in the Commons
- * RDF dataset and vice versa.
- *
- * @return A Jena {@link DatasetGraph}
- */
- public DatasetGraph asJenaDatasetGraph();
-
- /**
- * Return a union graph view of this dataset.
- * <p>
- * The <em>union graph</em> contains triples in any graph (including the
- * default graph).
- * <p>
- * Changes in the union graph are reflected in the Commons RDF dataset and
- * vice versa. Triples added to the graph are added to the default graph.
- *
- * @return A union {@link Graph}
- */
- public JenaGraph getUnionGraph();
+ /**
+ * Return the underlying Jena {@link DatasetGraph}.
+ * <p>
+ * Changes to the Jena <em>dataset graph</em> are reflected in the Commons
+ * RDF dataset and vice versa.
+ *
+ * @return A Jena {@link DatasetGraph}
+ */
+ public DatasetGraph asJenaDatasetGraph();
+
+ /**
+ * Return a union graph view of this dataset.
+ * <p>
+ * The <em>union graph</em> contains triples in any graph (including the
+ * default graph).
+ * <p>
+ * Changes in the union graph are reflected in the Commons RDF dataset and
+ * vice versa. Triples added to the graph are added to the default graph.
+ *
+ * @return A union {@link Graph}
+ */
+ public JenaGraph getUnionGraph();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/JenaGeneralizedTripleLike.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaGeneralizedTripleLike.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaGeneralizedTripleLike.java
index 634d05c..f65ed35 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaGeneralizedTripleLike.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaGeneralizedTripleLike.java
@@ -34,6 +34,5 @@ import org.apache.commons.rdf.api.Triple;
*
* @see JenaGeneralizedQuadLike
*/
-public interface JenaGeneralizedTripleLike
- extends JenaTripleLike {
+public interface JenaGeneralizedTripleLike extends JenaTripleLike {
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/JenaGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaGraph.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaGraph.java
index 86b9f29..b605b4b 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaGraph.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaGraph.java
@@ -29,27 +29,28 @@ import org.apache.jena.rdf.model.Model;
* {@link #asJenaGraph()}.
*/
public interface JenaGraph extends org.apache.commons.rdf.api.Graph {
-
- /**
- * Return the underlying Jena {@link org.apache.jena.graph.Graph}.
- * <p>
- * Changes to the Jena graph are reflected in the Commons RDF graph and vice versa.
- *
- * @return A Jena {@link org.apache.jena.graph.Graph}
- */
- public org.apache.jena.graph.Graph asJenaGraph();
- /**
- * Return the graph as a Jena {@link Model}.
- * <p>
- * Changes to the Jena model are reflected in the Commons RDF graph and vice
- * versa.
- * <p>
- * Note that in some cases there is no underlying Jena {@link Model}, in
- * which case this method will create one. Subsequent calls should return
- * the same model.
- *
- * @return A Jena {@link Model}
- */
- public Model asJenaModel();
+ /**
+ * Return the underlying Jena {@link org.apache.jena.graph.Graph}.
+ * <p>
+ * Changes to the Jena graph are reflected in the Commons RDF graph and vice
+ * versa.
+ *
+ * @return A Jena {@link org.apache.jena.graph.Graph}
+ */
+ public org.apache.jena.graph.Graph asJenaGraph();
+
+ /**
+ * Return the graph as a Jena {@link Model}.
+ * <p>
+ * Changes to the Jena model are reflected in the Commons RDF graph and vice
+ * versa.
+ * <p>
+ * Note that in some cases there is no underlying Jena {@link Model}, in
+ * which case this method will create one. Subsequent calls should return
+ * the same model.
+ *
+ * @return A Jena {@link Model}
+ */
+ public Model asJenaModel();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/JenaIRI.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaIRI.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaIRI.java
index bcc46c8..0edd1b5 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaIRI.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaIRI.java
@@ -23,7 +23,7 @@ import org.apache.jena.graph.Node;
/**
* A Jena-backed {@link IRI}.
* <p>
- * The underlying Jena {@link Node} can be accessed from {@link #asJenaNode()}.
+ * The underlying Jena {@link Node} can be accessed from {@link #asJenaNode()}.
*
* @see Node#isURI()
*/
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/JenaQuad.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaQuad.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaQuad.java
index fffbef7..0004017 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaQuad.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaQuad.java
@@ -19,12 +19,11 @@ package org.apache.commons.rdf.jena;
import org.apache.commons.rdf.api.BlankNodeOrIRI;
-/**
+/**
* A Jena-backed {@link org.apache.commons.rdf.api.Quad}.
* <p>
- * The underlying Jena {@link org.apache.jena.sparql.core.Quad}
- * can be accessed with {@link #asJenaQuad()}.
+ * The underlying Jena {@link org.apache.jena.sparql.core.Quad} can be accessed
+ * with {@link #asJenaQuad()}.
*/
-public interface JenaQuad extends org.apache.commons.rdf.api.Quad,
- JenaQuadLike<BlankNodeOrIRI> {
+public interface JenaQuad extends org.apache.commons.rdf.api.Quad, JenaQuadLike<BlankNodeOrIRI> {
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/JenaQuadLike.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/JenaQuadLike.java b/jena/src/main/java/org/apache/commons/rdf/jena/JenaQuadLike.java
index 2e869c3..480bdb9 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/JenaQuadLike.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaQuadLike.java
@@ -32,13 +32,12 @@ import org.apache.jena.sparql.core.Quad;
* @see JenaGeneralizedQuadLike
*
*/
-public interface JenaQuadLike<G extends RDFTerm>
- extends JenaTripleLike, QuadLike<G> {
+public interface JenaQuadLike<G extends RDFTerm> extends JenaTripleLike, QuadLike<G> {
- /**
- * Return the adapted Jena quad
- *
- * @return Adapted Jena {@link Quad}.
- */
- public Quad asJenaQuad();
+ /**
+ * Return the adapted Jena quad
+ *
+ * @return Adapted Jena {@link Quad}.
+ */
+ public Quad asJenaQuad();
}
[35/50] [abbrv] incubator-commonsrdf git commit: typo
Posted by st...@apache.org.
typo
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/fb806177
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/fb806177
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/fb806177
Branch: refs/heads/COMMONSRDF-7
Commit: fb8061770f5faf11f7c7b736ef5e61beefc780fa
Parents: fb0dd9c
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 28 11:33:37 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 28 11:33:37 2016 +0100
----------------------------------------------------------------------
src/site/markdown/userguide.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/fb806177/src/site/markdown/userguide.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md
index 6191889..ce9af61 100644
--- a/src/site/markdown/userguide.md
+++ b/src/site/markdown/userguide.md
@@ -222,7 +222,7 @@ subtypes for interoperability with their underlying RDF framework's API.
the super-interface for instances that can be used as subject, predicate and
object of a [Triple](apidocs/org/apache/commons/rdf/api/Triple.html).
-The RDF term interfaces are arranged in this ty[e hierarchy:
+The RDF term interfaces are arranged in this type hierarchy:
* [RDFTerm](apidocs/org/apache/commons/rdf/api/RDFTerm.html)
* [BlankNodeOrIRI](apidocs/org/apache/commons/rdf/api/BlankNodeOrIRI.html)
[40/50] [abbrv] incubator-commonsrdf git commit: Reformat tab ->
spaces
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java
index 37487b4..2398194 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java
@@ -28,49 +28,48 @@ import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
-abstract class AbstractRepositoryGraphLike<T extends TripleLike>
- implements RDF4JGraphLike<T> {
+abstract class AbstractRepositoryGraphLike<T extends TripleLike> implements RDF4JGraphLike<T> {
- protected final Repository repository;
- protected final boolean includeInferred;
- protected final boolean handleInitAndShutdown;
- protected final RDF4J rdf4jTermFactory;
- protected final UUID salt;
+ protected final Repository repository;
+ protected final boolean includeInferred;
+ protected final boolean handleInitAndShutdown;
+ protected final RDF4J rdf4jTermFactory;
+ protected final UUID salt;
- AbstractRepositoryGraphLike(Repository repository, UUID salt, boolean handleInitAndShutdown, boolean includeInferred) {
- this.repository = repository;
- this.salt = salt;
- this.includeInferred = includeInferred;
- this.handleInitAndShutdown = handleInitAndShutdown;
- if (handleInitAndShutdown && !repository.isInitialized()) {
- repository.initialize();
- }
- rdf4jTermFactory = new RDF4J(repository.getValueFactory(), salt);
- }
-
- @Override
- public void close() throws Exception {
- if (handleInitAndShutdown) {
- repository.shutDown();
- }
- // else: repository was initialized outside, so we should not shut it
- // down
- }
+ AbstractRepositoryGraphLike(Repository repository, UUID salt, boolean handleInitAndShutdown,
+ boolean includeInferred) {
+ this.repository = repository;
+ this.salt = salt;
+ this.includeInferred = includeInferred;
+ this.handleInitAndShutdown = handleInitAndShutdown;
+ if (handleInitAndShutdown && !repository.isInitialized()) {
+ repository.initialize();
+ }
+ rdf4jTermFactory = new RDF4J(repository.getValueFactory(), salt);
+ }
-
- protected abstract T asTripleLike(Statement s);
+ @Override
+ public void close() throws Exception {
+ if (handleInitAndShutdown) {
+ repository.shutDown();
+ }
+ // else: repository was initialized outside, so we should not shut it
+ // down
+ }
- protected RepositoryConnection getRepositoryConnection() {
- return repository.getConnection();
- }
+ protected abstract T asTripleLike(Statement s);
- public Optional<Repository> asRepository() {
- return Optional.of(repository);
- }
+ protected RepositoryConnection getRepositoryConnection() {
+ return repository.getConnection();
+ }
- @Override
- public Optional<Model> asModel() {
- return Optional.empty();
- }
+ public Optional<Repository> asRepository() {
+ return Optional.of(repository);
+ }
+
+ @Override
+ public Optional<Model> asModel() {
+ return Optional.empty();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/BlankNodeImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/BlankNodeImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/BlankNodeImpl.java
index bdb82d1..8c5fc30 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/BlankNodeImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/BlankNodeImpl.java
@@ -25,69 +25,68 @@ import org.apache.commons.rdf.rdf4j.RDF4JBlankNode;
import org.eclipse.rdf4j.model.BNode;
import org.eclipse.rdf4j.rio.turtle.TurtleUtil;
-final class BlankNodeImpl extends AbstractRDFTerm<BNode>
- implements RDF4JBlankNode {
-
- private transient int hashCode = 0;
- private long saltUUIDleast;
- private long saltUUIDmost;
-
- BlankNodeImpl(BNode bNode, UUID salt) {
- super(bNode);
- // Space-efficient storage of salt UUID
- saltUUIDmost = salt.getMostSignificantBits();
- saltUUIDleast = salt.getLeastSignificantBits();
- }
-
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- // NOTE: Do NOT use Bnode.equals() as it has a more generous
- // equality based only on the value.getID();
- if (obj instanceof BlankNode) {
- BlankNode blankNode = (BlankNode) obj;
- return uniqueReference().equals(blankNode.uniqueReference());
- }
- return false;
- }
+final class BlankNodeImpl extends AbstractRDFTerm<BNode> implements RDF4JBlankNode {
- @Override
- public int hashCode() {
- if (hashCode != 0) {
- return hashCode;
- }
- return hashCode = uniqueReference().hashCode();
- }
+ private transient int hashCode = 0;
+ private long saltUUIDleast;
+ private long saltUUIDmost;
- private boolean isValidBlankNodeLabel(String id) {
- // FIXME: Replace with a regular expression?
- if (id.isEmpty()) {
- return false;
- }
- if (! TurtleUtil.isBLANK_NODE_LABEL_StartChar(id.codePointAt(0))) {
- return false;
- }
- for (int i=1; i<id.length(); i++) {
- if (! TurtleUtil.isBLANK_NODE_LABEL_Char(id.codePointAt(i))) {
- return false;
- }
- }
- return true;
- }
+ BlankNodeImpl(BNode bNode, UUID salt) {
+ super(bNode);
+ // Space-efficient storage of salt UUID
+ saltUUIDmost = salt.getMostSignificantBits();
+ saltUUIDleast = salt.getLeastSignificantBits();
+ }
- @Override
- public String ntriplesString() {
- if (isValidBlankNodeLabel(value.getID())) {
- return "_:" + value.getID();
- } else {
- return "_:" + UUID.nameUUIDFromBytes(value.getID().getBytes(StandardCharsets.UTF_8));
- }
- }
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ // NOTE: Do NOT use Bnode.equals() as it has a more generous
+ // equality based only on the value.getID();
+ if (obj instanceof BlankNode) {
+ BlankNode blankNode = (BlankNode) obj;
+ return uniqueReference().equals(blankNode.uniqueReference());
+ }
+ return false;
+ }
- @Override
- public String uniqueReference() {
- UUID uuid = new UUID(saltUUIDmost, saltUUIDleast);
- return "urn:uuid:" + uuid + "#" + value.getID();
- }
+ @Override
+ public int hashCode() {
+ if (hashCode != 0) {
+ return hashCode;
+ }
+ return hashCode = uniqueReference().hashCode();
+ }
+
+ private boolean isValidBlankNodeLabel(String id) {
+ // FIXME: Replace with a regular expression?
+ if (id.isEmpty()) {
+ return false;
+ }
+ if (!TurtleUtil.isBLANK_NODE_LABEL_StartChar(id.codePointAt(0))) {
+ return false;
+ }
+ for (int i = 1; i < id.length(); i++) {
+ if (!TurtleUtil.isBLANK_NODE_LABEL_Char(id.codePointAt(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public String ntriplesString() {
+ if (isValidBlankNodeLabel(value.getID())) {
+ return "_:" + value.getID();
+ } else {
+ return "_:" + UUID.nameUUIDFromBytes(value.getID().getBytes(StandardCharsets.UTF_8));
+ }
+ }
+
+ @Override
+ public String uniqueReference() {
+ UUID uuid = new UUID(saltUUIDmost, saltUUIDleast);
+ return "urn:uuid:" + uuid + "#" + value.getID();
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ConvertedStatements.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ConvertedStatements.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ConvertedStatements.java
index 4c8478a..f199b8f 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ConvertedStatements.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ConvertedStatements.java
@@ -29,43 +29,43 @@ import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryResult;
final class ConvertedStatements<T> implements ClosableIterable<T> {
-
- private RepositoryConnection conn;
- private RepositoryResult<Statement> results;
- private Function<Statement, T> statementAdapter;
- ConvertedStatements(Supplier<RepositoryConnection> repositoryConnector, Function<Statement, T> statementAdapter,
- Resource subj, org.eclipse.rdf4j.model.IRI pred, Value obj, Resource... contexts) {
- this.statementAdapter = statementAdapter;
- this.conn = repositoryConnector.get();
- this.results = conn.getStatements(subj, pred, obj, contexts);
- }
+ private RepositoryConnection conn;
+ private RepositoryResult<Statement> results;
+ private Function<Statement, T> statementAdapter;
- @Override
- public Iterator<T> iterator() {
- return new ConvertedIterator();
- }
+ ConvertedStatements(Supplier<RepositoryConnection> repositoryConnector, Function<Statement, T> statementAdapter,
+ Resource subj, org.eclipse.rdf4j.model.IRI pred, Value obj, Resource... contexts) {
+ this.statementAdapter = statementAdapter;
+ this.conn = repositoryConnector.get();
+ this.results = conn.getStatements(subj, pred, obj, contexts);
+ }
- @Override
- public void close() {
- results.close();
- conn.close();
- }
+ @Override
+ public Iterator<T> iterator() {
+ return new ConvertedIterator();
+ }
- private final class ConvertedIterator implements Iterator<T> {
- @Override
- public boolean hasNext() {
- boolean hasNext = results.hasNext();
- if (!hasNext) {
- close();
- }
- return hasNext;
- }
+ @Override
+ public void close() {
+ results.close();
+ conn.close();
+ }
- @Override
- public T next() {
- return statementAdapter.apply(results.next());
- }
- }
+ private final class ConvertedIterator implements Iterator<T> {
+ @Override
+ public boolean hasNext() {
+ boolean hasNext = results.hasNext();
+ if (!hasNext) {
+ close();
+ }
+ return hasNext;
+ }
+
+ @Override
+ public T next() {
+ return statementAdapter.apply(results.next());
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/IRIImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/IRIImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/IRIImpl.java
index e88ac27..f566c21 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/IRIImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/IRIImpl.java
@@ -19,43 +19,46 @@ package org.apache.commons.rdf.rdf4j.impl;
import org.apache.commons.rdf.rdf4j.RDF4JIRI;
-final class IRIImpl extends AbstractRDFTerm<org.eclipse.rdf4j.model.IRI>
- implements RDF4JIRI {
-
- IRIImpl(org.eclipse.rdf4j.model.IRI iri) {
- super(iri);
- }
- @Override
- public boolean equals(Object obj) {
- if (obj == this) { return true; }
- if (obj instanceof IRIImpl) {
- IRIImpl impl = (IRIImpl) obj;
- return asValue().equals(impl.asValue());
- }
- if (obj instanceof org.apache.commons.rdf.api.IRI) {
- org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) obj;
- return value.toString().equals(iri.getIRIString());
- }
- return false;
- }
-
- @Override
- public String getIRIString() {
- return value.toString();
- }
-
- public int hashCode() {
- // Same definition
- return value.hashCode();
- }
-
- @Override
- public String ntriplesString() {
- return "<" + value.toString() + ">";
- }
- @Override
- public String toString() {
- return value.toString();
- }
-
+final class IRIImpl extends AbstractRDFTerm<org.eclipse.rdf4j.model.IRI> implements RDF4JIRI {
+
+ IRIImpl(org.eclipse.rdf4j.model.IRI iri) {
+ super(iri);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj instanceof IRIImpl) {
+ IRIImpl impl = (IRIImpl) obj;
+ return asValue().equals(impl.asValue());
+ }
+ if (obj instanceof org.apache.commons.rdf.api.IRI) {
+ org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) obj;
+ return value.toString().equals(iri.getIRIString());
+ }
+ return false;
+ }
+
+ @Override
+ public String getIRIString() {
+ return value.toString();
+ }
+
+ public int hashCode() {
+ // Same definition
+ return value.hashCode();
+ }
+
+ @Override
+ public String ntriplesString() {
+ return "<" + value.toString() + ">";
+ }
+
+ @Override
+ public String toString() {
+ return value.toString();
+ }
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
index b6d6b29..25a7620 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
@@ -43,8 +43,7 @@ import org.eclipse.rdf4j.repository.Repository;
* <p>
* <strong>Internal class:</strong> This "abstract" class is intended for
* internal use by Commons RDF and may change in any minor update. Use instead
- * {@link RDF4J} methods like
- * {@link RDF4J#createBlankNode()},
+ * {@link RDF4J} methods like {@link RDF4J#createBlankNode()},
* {@link RDF4J#asRDFTerm(org.eclipse.rdf4j.model.Value)} and
* {@link RDF4J#asGraph(Repository, Option...)}
* <p>
@@ -57,128 +56,129 @@ import org.eclipse.rdf4j.repository.Repository;
*/
public abstract class InternalRDF4JFactory {
- /**
- * Construct a {@link RDF4JBlankNode} from a RDF4J {@link BNode}.
- *
- * @param bNode
- * RDF4J {@link BNode} to adapt
- * @param salt
- * {@link UUID} to use for {@link BlankNode#uniqueReference()} in
- * combination with {@link BNode#getID()}
- * @return Adapted {@link RDF4JBlankNode}
- */
- public RDF4JBlankNode createBlankNodeImpl(BNode bNode, UUID salt) {
- return new BlankNodeImpl(bNode, salt);
- }
+ /**
+ * Construct a {@link RDF4JBlankNode} from a RDF4J {@link BNode}.
+ *
+ * @param bNode
+ * RDF4J {@link BNode} to adapt
+ * @param salt
+ * {@link UUID} to use for {@link BlankNode#uniqueReference()} in
+ * combination with {@link BNode#getID()}
+ * @return Adapted {@link RDF4JBlankNode}
+ */
+ public RDF4JBlankNode createBlankNodeImpl(BNode bNode, UUID salt) {
+ return new BlankNodeImpl(bNode, salt);
+ }
- /**
- * Construct a {@link RDF4JIRI} from a RDF4J {@link IRI}.
- *
- * @param iri
- * RDF4J {@link IRI} to adapt
- * @return Adapted {@link RDF4JIRI}
- */
- public RDF4JIRI createIRIImpl(IRI iri) {
- return new IRIImpl(iri);
- }
+ /**
+ * Construct a {@link RDF4JIRI} from a RDF4J {@link IRI}.
+ *
+ * @param iri
+ * RDF4J {@link IRI} to adapt
+ * @return Adapted {@link RDF4JIRI}
+ */
+ public RDF4JIRI createIRIImpl(IRI iri) {
+ return new IRIImpl(iri);
+ }
- /**
- * Construct a {@link RDF4JLiteral} from a RDF4J {@link Literal}.
- *
- * @param literal
- * RDF4J {@link Literal}
- * @return Adapted {@link RDF4JLiteral}
- */
- public RDF4JLiteral createLiteralImpl(Literal literal) {
- return new LiteralImpl(literal);
- }
+ /**
+ * Construct a {@link RDF4JLiteral} from a RDF4J {@link Literal}.
+ *
+ * @param literal
+ * RDF4J {@link Literal}
+ * @return Adapted {@link RDF4JLiteral}
+ */
+ public RDF4JLiteral createLiteralImpl(Literal literal) {
+ return new LiteralImpl(literal);
+ }
- /**
- * Construct a {@link RDF4JGraph} from a RDF4J {@link Model}.
- * <p>
- * Changes in the graph will be reflected in the model, and vice versa.
- *
- * @param model
- * RDF4J {@link Model} to adapt
- * @param rdf4jTermFactory
- * factory to use for adapting graph triples
- * @return Adapted {@link RDF4JGraph}
- */
- public RDF4JGraph createModelGraphImpl(Model model, RDF4J rdf4jTermFactory) {
- return new ModelGraphImpl(model, rdf4jTermFactory);
- }
+ /**
+ * Construct a {@link RDF4JGraph} from a RDF4J {@link Model}.
+ * <p>
+ * Changes in the graph will be reflected in the model, and vice versa.
+ *
+ * @param model
+ * RDF4J {@link Model} to adapt
+ * @param rdf4jTermFactory
+ * factory to use for adapting graph triples
+ * @return Adapted {@link RDF4JGraph}
+ */
+ public RDF4JGraph createModelGraphImpl(Model model, RDF4J rdf4jTermFactory) {
+ return new ModelGraphImpl(model, rdf4jTermFactory);
+ }
- /**
- * Construct a {@link RDF4JQuad} from a RDF4J {@link Statement}.
- *
- * @param statement
- * RDF4J {@link Statement} to adapt
- * @param salt
- * {@link UUID} for adapting any {@link BNode}s
- * @return Adapted {@link RDF4JQuad}
- */
- public RDF4JQuad createQuadImpl(Statement statement, UUID salt) {
- return new QuadImpl(statement, salt);
- }
+ /**
+ * Construct a {@link RDF4JQuad} from a RDF4J {@link Statement}.
+ *
+ * @param statement
+ * RDF4J {@link Statement} to adapt
+ * @param salt
+ * {@link UUID} for adapting any {@link BNode}s
+ * @return Adapted {@link RDF4JQuad}
+ */
+ public RDF4JQuad createQuadImpl(Statement statement, UUID salt) {
+ return new QuadImpl(statement, salt);
+ }
- /**
- * Construct a {@link RDF4JDataset} from a RDF4J {@link Repository}.
- * <p>
- * Changes in the dataset will be reflected in the repsitory, and vice
- * versa.
- *
- * @param repository
- * RDF4J {@link Repository} to adapt
- * @param handleInitAndShutdown
- * If <code>true</code>, the {@link RDF4JDataset} will initialize
- * the repository (if needed), and shut it down on
- * {@link RDF4JDataset#close()}.
- * @param includeInferred
- * If true, any inferred quads are included in the dataset
- *
- * @return Adapted {@link RDF4JDataset}
- */
- public RDF4JDataset createRepositoryDatasetImpl(Repository repository, boolean handleInitAndShutdown,
- boolean includeInferred) {
- return new RepositoryDatasetImpl(repository, UUID.randomUUID(), handleInitAndShutdown, includeInferred);
- }
+ /**
+ * Construct a {@link RDF4JDataset} from a RDF4J {@link Repository}.
+ * <p>
+ * Changes in the dataset will be reflected in the repsitory, and vice
+ * versa.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to adapt
+ * @param handleInitAndShutdown
+ * If <code>true</code>, the {@link RDF4JDataset} will initialize
+ * the repository (if needed), and shut it down on
+ * {@link RDF4JDataset#close()}.
+ * @param includeInferred
+ * If true, any inferred quads are included in the dataset
+ *
+ * @return Adapted {@link RDF4JDataset}
+ */
+ public RDF4JDataset createRepositoryDatasetImpl(Repository repository, boolean handleInitAndShutdown,
+ boolean includeInferred) {
+ return new RepositoryDatasetImpl(repository, UUID.randomUUID(), handleInitAndShutdown, includeInferred);
+ }
- /**
- * Construct a {@link RDF4JGraph} from a RDF4J {@link Model}.
- * <p>
- * Changes in the graph will be reflected in the model, and vice versa.
- *
- * @param repository
- * RDF4J {@link Repository} to adapt
- * @param handleInitAndShutdown
- * If <code>true</code>, the {@link RDF4JGraph} will initialize
- * the repository (if needed), and shut it down on
- * {@link RDF4JGraph#close()}.
- * @param includeInferred
- * If true, any inferred quads are included in the dataset
- * @param contextMask
- * Zero or more {@link Resource}s contexts. The array may contain
- * the value <code>null</code> for the default graph - however
- * care must be taken to not provide a null-array
- * <code>(Resource[]) null</code>.
- * @return Adapted {@link RDF4JGraph}
- */
- public RDF4JGraph createRepositoryGraphImpl(Repository repository, boolean handleInitAndShutdown,
- boolean includeInferred, Resource... contextMask) {
- return new RepositoryGraphImpl(repository, UUID.randomUUID(), handleInitAndShutdown, includeInferred, contextMask);
- }
+ /**
+ * Construct a {@link RDF4JGraph} from a RDF4J {@link Model}.
+ * <p>
+ * Changes in the graph will be reflected in the model, and vice versa.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to adapt
+ * @param handleInitAndShutdown
+ * If <code>true</code>, the {@link RDF4JGraph} will initialize
+ * the repository (if needed), and shut it down on
+ * {@link RDF4JGraph#close()}.
+ * @param includeInferred
+ * If true, any inferred quads are included in the dataset
+ * @param contextMask
+ * Zero or more {@link Resource}s contexts. The array may contain
+ * the value <code>null</code> for the default graph - however
+ * care must be taken to not provide a null-array
+ * <code>(Resource[]) null</code>.
+ * @return Adapted {@link RDF4JGraph}
+ */
+ public RDF4JGraph createRepositoryGraphImpl(Repository repository, boolean handleInitAndShutdown,
+ boolean includeInferred, Resource... contextMask) {
+ return new RepositoryGraphImpl(repository, UUID.randomUUID(), handleInitAndShutdown, includeInferred,
+ contextMask);
+ }
- /**
- * Construct a {@link RDF4JTriple} from a RDF4J {@link Statement}.
- *
- * @param statement
- * RDF4J {@link Statement} to adapt
- * @param salt
- * {@link UUID} for adapting any {@link BNode}s
- * @return Adapted {@link RDF4JTriple}
- */
- public RDF4JTriple createTripleImpl(Statement statement, UUID salt) {
- return new TripleImpl(statement, salt);
- }
+ /**
+ * Construct a {@link RDF4JTriple} from a RDF4J {@link Statement}.
+ *
+ * @param statement
+ * RDF4J {@link Statement} to adapt
+ * @param salt
+ * {@link UUID} for adapting any {@link BNode}s
+ * @return Adapted {@link RDF4JTriple}
+ */
+ public RDF4JTriple createTripleImpl(Statement statement, UUID salt) {
+ return new TripleImpl(statement, salt);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/LiteralImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/LiteralImpl.java
index aef298d..9fa93b1 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/LiteralImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/LiteralImpl.java
@@ -24,62 +24,62 @@ import org.apache.commons.rdf.rdf4j.RDF4JLiteral;
import org.eclipse.rdf4j.model.vocabulary.XMLSchema;
import org.eclipse.rdf4j.rio.turtle.TurtleUtil;
-final class LiteralImpl
- extends AbstractRDFTerm<org.eclipse.rdf4j.model.Literal>
- implements RDF4JLiteral {
+final class LiteralImpl extends AbstractRDFTerm<org.eclipse.rdf4j.model.Literal> implements RDF4JLiteral {
- private static final String QUOTE = "\"";
-
- LiteralImpl(org.eclipse.rdf4j.model.Literal literal) {
- super(literal);
- }
- @Override
- public boolean equals(Object obj) {
- if (obj == this) { return true; }
- if (obj instanceof org.apache.commons.rdf.api.Literal) {
- org.apache.commons.rdf.api.Literal other = (org.apache.commons.rdf.api.Literal) obj;
- return getLexicalForm().equals(other.getLexicalForm()) &&
- getDatatype().equals(other.getDatatype()) &&
- getLanguageTag().equals(other.getLanguageTag());
-
- }
- return false;
- }
+ private static final String QUOTE = "\"";
- @Override
- public org.apache.commons.rdf.api.IRI getDatatype() {
- return new IRIImpl(value.getDatatype());
- }
+ LiteralImpl(org.eclipse.rdf4j.model.Literal literal) {
+ super(literal);
+ }
- @Override
- public Optional<String> getLanguageTag() {
- return value.getLanguage();
- }
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj instanceof org.apache.commons.rdf.api.Literal) {
+ org.apache.commons.rdf.api.Literal other = (org.apache.commons.rdf.api.Literal) obj;
+ return getLexicalForm().equals(other.getLexicalForm()) && getDatatype().equals(other.getDatatype())
+ && getLanguageTag().equals(other.getLanguageTag());
- @Override
- public String getLexicalForm() {
- return value.getLabel();
- }
+ }
+ return false;
+ }
- public int hashCode() {
- return Objects.hash(value.getLabel(), value.getDatatype(), value.getLanguage());
- }
+ @Override
+ public org.apache.commons.rdf.api.IRI getDatatype() {
+ return new IRIImpl(value.getDatatype());
+ }
- @Override
- public String ntriplesString() {
- // TODO: Use a more efficient StringBuffer
- String escaped = QUOTE + TurtleUtil.encodeString(value.getLabel()) + QUOTE;
- if (value.getLanguage().isPresent()) {
- return escaped + "@" + value.getLanguage().get();
- }
- if (value.getDatatype().equals(XMLSchema.STRING)) {
- return escaped;
- }
- return escaped + "^^<" + TurtleUtil.encodeURIString(value.getDatatype().toString()) + ">";
- }
+ @Override
+ public Optional<String> getLanguageTag() {
+ return value.getLanguage();
+ }
- @Override
- public String toString() {
- return ntriplesString();
- }
+ @Override
+ public String getLexicalForm() {
+ return value.getLabel();
+ }
+
+ public int hashCode() {
+ return Objects.hash(value.getLabel(), value.getDatatype(), value.getLanguage());
+ }
+
+ @Override
+ public String ntriplesString() {
+ // TODO: Use a more efficient StringBuffer
+ String escaped = QUOTE + TurtleUtil.encodeString(value.getLabel()) + QUOTE;
+ if (value.getLanguage().isPresent()) {
+ return escaped + "@" + value.getLanguage().get();
+ }
+ if (value.getDatatype().equals(XMLSchema.STRING)) {
+ return escaped;
+ }
+ return escaped + "^^<" + TurtleUtil.encodeURIString(value.getDatatype().toString()) + ">";
+ }
+
+ @Override
+ public String toString() {
+ return ntriplesString();
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java
index ced9c99..7debacc 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java
@@ -38,121 +38,115 @@ import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.repository.Repository;
final class ModelGraphImpl implements RDF4JGraph {
-
- private Model model;
- private RDF4J rdf4jTermFactory;
-
- ModelGraphImpl(Model model, RDF4J rdf4jTermFactory) {
- this.model = model;
- this.rdf4jTermFactory = rdf4jTermFactory;
- }
-
- @Override
- public void add(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object) {
- model.add(
- (Resource)rdf4jTermFactory.asValue(subject),
- (org.eclipse.rdf4j.model.IRI)rdf4jTermFactory.asValue(predicate),
- rdf4jTermFactory.asValue(object));
- }
-
- @Override
- public void add(Triple triple) {
- model.add(rdf4jTermFactory.asStatement(triple));
- }
-
- public Optional<Model> asModel() {
- return Optional.of(model);
- }
-
- @Override
- public Optional<Repository> asRepository() {
- return Optional.empty();
- }
-
- @Override
- public void clear() {
- model.clear();
- }
-
- @Override
- public boolean contains(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object) {
- return model.contains(
- (Resource)rdf4jTermFactory.asValue(subject),
- (org.eclipse.rdf4j.model.IRI)rdf4jTermFactory.asValue(predicate),
- rdf4jTermFactory.asValue(object));
- }
-
- @Override
- public boolean contains(Triple triple) {
- return model.contains(rdf4jTermFactory.asStatement(triple));
- }
-
- @Override
- public void remove(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object) {
- model.remove(
- (Resource)rdf4jTermFactory.asValue(subject),
- (org.eclipse.rdf4j.model.IRI)rdf4jTermFactory.asValue(predicate),
- rdf4jTermFactory.asValue(object));
- }
-
- @Override
- public void remove(Triple triple) {
- model.remove(rdf4jTermFactory.asStatement(triple));
- }
-
- @Override
- public long size() {
- int size = model.size();
- if (size < Integer.MAX_VALUE) {
- return size;
- } else {
- // TODO: Check if this can really happen with RDF4J models
- // Collection.size() can't help us, we'll have to count
- return model.parallelStream().count();
- }
- }
-
- @Override
- public Stream<RDF4JTriple> stream() {
- return model.parallelStream().map(rdf4jTermFactory::asTriple);
- }
-
- @Override
- public Stream<RDF4JTriple> stream(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object) {
- return model.filter(
- (Resource)rdf4jTermFactory.asValue(subject),
- (org.eclipse.rdf4j.model.IRI)rdf4jTermFactory.asValue(predicate),
- rdf4jTermFactory.asValue(object)).parallelStream()
- .map(rdf4jTermFactory::asTriple);
- }
-
- @Override
- public Set<RDF4JBlankNodeOrIRI> getContextMask() {
- // ModelGraph always do the unionGraph
- return Collections.emptySet();
- // TODO: Should we support contextMask like in RepositoryGraphImpl?
- }
-
- @Override
- public ClosableIterable<Triple> iterate(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return new ClosableIterable<Triple>() {
- @SuppressWarnings("unchecked")
- @Override
- public Iterator<Triple> iterator() {
- // double-cast to fight Java generics..
- Stream<? extends Triple> s = stream(subject, predicate, object);
- return (Iterator<Triple>) s.iterator();
- }
- @Override
- public void close() throws Exception {
- // no-op as Model don't have transaction
- }
- };
- }
-
- @Override
- public ClosableIterable<Triple> iterate() throws ConcurrentModificationException, IllegalStateException {
- return iterate(null, null, null);
- }
-
+
+ private Model model;
+ private RDF4J rdf4jTermFactory;
+
+ ModelGraphImpl(Model model, RDF4J rdf4jTermFactory) {
+ this.model = model;
+ this.rdf4jTermFactory = rdf4jTermFactory;
+ }
+
+ @Override
+ public void add(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object) {
+ model.add((Resource) rdf4jTermFactory.asValue(subject),
+ (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate), rdf4jTermFactory.asValue(object));
+ }
+
+ @Override
+ public void add(Triple triple) {
+ model.add(rdf4jTermFactory.asStatement(triple));
+ }
+
+ public Optional<Model> asModel() {
+ return Optional.of(model);
+ }
+
+ @Override
+ public Optional<Repository> asRepository() {
+ return Optional.empty();
+ }
+
+ @Override
+ public void clear() {
+ model.clear();
+ }
+
+ @Override
+ public boolean contains(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object) {
+ return model.contains((Resource) rdf4jTermFactory.asValue(subject),
+ (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate), rdf4jTermFactory.asValue(object));
+ }
+
+ @Override
+ public boolean contains(Triple triple) {
+ return model.contains(rdf4jTermFactory.asStatement(triple));
+ }
+
+ @Override
+ public void remove(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object) {
+ model.remove((Resource) rdf4jTermFactory.asValue(subject),
+ (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate), rdf4jTermFactory.asValue(object));
+ }
+
+ @Override
+ public void remove(Triple triple) {
+ model.remove(rdf4jTermFactory.asStatement(triple));
+ }
+
+ @Override
+ public long size() {
+ int size = model.size();
+ if (size < Integer.MAX_VALUE) {
+ return size;
+ } else {
+ // TODO: Check if this can really happen with RDF4J models
+ // Collection.size() can't help us, we'll have to count
+ return model.parallelStream().count();
+ }
+ }
+
+ @Override
+ public Stream<RDF4JTriple> stream() {
+ return model.parallelStream().map(rdf4jTermFactory::asTriple);
+ }
+
+ @Override
+ public Stream<RDF4JTriple> stream(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate,
+ RDFTerm object) {
+ return model.filter((Resource) rdf4jTermFactory.asValue(subject),
+ (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate), rdf4jTermFactory.asValue(object))
+ .parallelStream().map(rdf4jTermFactory::asTriple);
+ }
+
+ @Override
+ public Set<RDF4JBlankNodeOrIRI> getContextMask() {
+ // ModelGraph always do the unionGraph
+ return Collections.emptySet();
+ // TODO: Should we support contextMask like in RepositoryGraphImpl?
+ }
+
+ @Override
+ public ClosableIterable<Triple> iterate(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return new ClosableIterable<Triple>() {
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterator<Triple> iterator() {
+ // double-cast to fight Java generics..
+ Stream<? extends Triple> s = stream(subject, predicate, object);
+ return (Iterator<Triple>) s.iterator();
+ }
+
+ @Override
+ public void close() throws Exception {
+ // no-op as Model don't have transaction
+ }
+ };
+ }
+
+ @Override
+ public ClosableIterable<Triple> iterate() throws ConcurrentModificationException, IllegalStateException {
+ return iterate(null, null, null);
+ }
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java
index 8da29b6..6962803 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java
@@ -30,70 +30,69 @@ import org.apache.commons.rdf.rdf4j.RDF4J;
import org.eclipse.rdf4j.model.Statement;
final class QuadImpl implements Quad, RDF4JQuad {
- private transient int hashCode = 0;
- private UUID salt;
- private final Statement statement;
-
- QuadImpl(Statement statement, UUID salt) {
- this.statement = statement;
- this.salt = salt;
- }
-
- @Override
- public Statement asStatement() {
- return statement;
- }
-
- @Override
- public Triple asTriple() {
- return new TripleImpl(statement, salt);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof Triple) {
- Triple triple = (Triple) obj;
- return getSubject().equals(triple.getSubject()) &&
- getPredicate().equals(triple.getPredicate()) &&
- getObject().equals(triple.getObject());
- }
- return false;
- }
-
- @Override
- public Optional<BlankNodeOrIRI> getGraphName() {
- if (statement.getContext() == null) {
- return Optional.empty();
- }
- BlankNodeOrIRI g = (BlankNodeOrIRI) RDF4J.asRDFTerm(statement.getContext(), salt);
- return Optional.of(g);
- }
-
- @Override
- public RDFTerm getObject() {
- return RDF4J.asRDFTerm(statement.getObject(), salt);
- }
-
- @Override
- public org.apache.commons.rdf.api.IRI getPredicate() {
- return (org.apache.commons.rdf.api.IRI) RDF4J.asRDFTerm(statement.getPredicate(), null);
- }
-
- @Override
- public BlankNodeOrIRI getSubject() {
- return (BlankNodeOrIRI) RDF4J.asRDFTerm(statement.getSubject(), salt);
- }
+ private transient int hashCode = 0;
+ private UUID salt;
+ private final Statement statement;
- @Override
- public int hashCode() {
- if (hashCode != 0) {
- return hashCode;
- }
- return hashCode = Objects.hash(getSubject(), getPredicate(), getObject(), getGraphName());
- }
-
- @Override
- public String toString() {
- return statement.toString();
- }
+ QuadImpl(Statement statement, UUID salt) {
+ this.statement = statement;
+ this.salt = salt;
+ }
+
+ @Override
+ public Statement asStatement() {
+ return statement;
+ }
+
+ @Override
+ public Triple asTriple() {
+ return new TripleImpl(statement, salt);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Triple) {
+ Triple triple = (Triple) obj;
+ return getSubject().equals(triple.getSubject()) && getPredicate().equals(triple.getPredicate())
+ && getObject().equals(triple.getObject());
+ }
+ return false;
+ }
+
+ @Override
+ public Optional<BlankNodeOrIRI> getGraphName() {
+ if (statement.getContext() == null) {
+ return Optional.empty();
+ }
+ BlankNodeOrIRI g = (BlankNodeOrIRI) RDF4J.asRDFTerm(statement.getContext(), salt);
+ return Optional.of(g);
+ }
+
+ @Override
+ public RDFTerm getObject() {
+ return RDF4J.asRDFTerm(statement.getObject(), salt);
+ }
+
+ @Override
+ public org.apache.commons.rdf.api.IRI getPredicate() {
+ return (org.apache.commons.rdf.api.IRI) RDF4J.asRDFTerm(statement.getPredicate(), null);
+ }
+
+ @Override
+ public BlankNodeOrIRI getSubject() {
+ return (BlankNodeOrIRI) RDF4J.asRDFTerm(statement.getSubject(), salt);
+ }
+
+ @Override
+ public int hashCode() {
+ if (hashCode != 0) {
+ return hashCode;
+ }
+ return hashCode = Objects.hash(getSubject(), getPredicate(), getObject(), getGraphName());
+ }
+
+ @Override
+ public String toString() {
+ return statement.toString();
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java
index 64f3bbd..8c266a9 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java
@@ -41,183 +41,188 @@ import org.eclipse.rdf4j.repository.RepositoryResult;
class RepositoryDatasetImpl extends AbstractRepositoryGraphLike<Quad> implements RDF4JDataset, Dataset {
- RepositoryDatasetImpl(Repository repository, UUID salt, boolean handleInitAndShutdown, boolean includeInferred) {
- super(repository, salt, handleInitAndShutdown, includeInferred);
- }
-
- @Override
- public void add(Quad tripleLike) {
- Statement statement = rdf4jTermFactory.asStatement(tripleLike);
- try (RepositoryConnection conn = getRepositoryConnection()) {
- conn.add(statement);
- conn.commit();
- }
- }
-
-
- @Override
- public boolean contains(Quad tripleLike) {
- Statement statement = rdf4jTermFactory.asStatement(tripleLike);
- try (RepositoryConnection conn = getRepositoryConnection()) {
- return conn.hasStatement(statement, includeInferred);
- }
- }
-
- @Override
- public void remove(Quad tripleLike) {
- Statement statement = rdf4jTermFactory.asStatement(tripleLike);
- try (RepositoryConnection conn = getRepositoryConnection()) {
- conn.remove(statement);
- conn.commit();
- }
- }
-
- @Override
- public void clear() {
- try (RepositoryConnection conn = getRepositoryConnection()) {
- conn.clear();
- conn.commit();
- }
- }
-
- @Override
- public long size() {
- if (includeInferred) {
- // We'll need to count them all
- return stream().count();
- }
- // else: Ask directly
- try (RepositoryConnection conn = getRepositoryConnection()) {
- return conn.size();
- }
- }
-
- @Override
- public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- Resource context = (Resource) rdf4jTermFactory.asValue(graphName);
- Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
- org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
- Value obj = rdf4jTermFactory.asValue(object);
- try (RepositoryConnection conn = getRepositoryConnection()) {
- conn.add(subj, pred, obj, context);
- conn.commit();
- }
- }
-
- @Override
- public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
- org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
- Value obj = rdf4jTermFactory.asValue(object);
- Resource[] contexts = asContexts(graphName);
- try (RepositoryConnection conn = getRepositoryConnection()) {
- return conn.hasStatement(subj, pred, obj, includeInferred, contexts);
- }
- }
-
- private Resource[] asContexts(Optional<BlankNodeOrIRI> graphName) {
- Resource[] contexts;
- if (graphName == null) {
- // no contexts == any contexts
- contexts = new Resource[0];
- } else {
- BlankNodeOrIRI g = graphName.orElse(null);
- Resource context = (Resource) rdf4jTermFactory.asValue(g);
- contexts = new Resource[] { context };
- }
- return contexts;
- }
-
- @Override
- public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
- org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
- Value obj = rdf4jTermFactory.asValue(object);
- Resource[] contexts = asContexts(graphName);
-
- try (RepositoryConnection conn = getRepositoryConnection()) {
- conn.remove(subj, pred, obj, contexts);
- conn.commit();
- }
- }
-
- @Override
- public Stream<RDF4JQuad> stream() {
- return stream(null, null, null, null);
- }
-
- @Override
- public Stream<RDF4JQuad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
- org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
- Value obj = rdf4jTermFactory.asValue(object);
- Resource[] contexts = asContexts(graphName);
-
- // NOTE: We can't do the usual try..with closing of the
- // RepositoryConnection here as it will have to be closed outside
- // by the user of the returned stream
- RepositoryConnection conn = getRepositoryConnection();
- Stream<RDF4JQuad> stream = null;
- try {
- RepositoryResult<Statement> statements = conn.getStatements(subj, pred, obj, includeInferred, contexts);
- // NOTE: Iterations.stream should close RepositoryResult as long as our caller closes the stream
- stream = Iterations.stream(statements).map(rdf4jTermFactory::asQuad);
- } finally {
- if (stream == null) {
- // Some exception before we made the stream, close connection here
- conn.close();
- }
- }
- // Make sure the RepositoryConnection is closed
- return stream.onClose(conn::close);
-
- }
-
-
- @Override
- public ClosableIterable<Quad> iterate() throws ConcurrentModificationException, IllegalStateException {
- return iterate(null, null, null, null);
- }
-
- @Override
- public ClosableIterable<Quad> iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
- throws ConcurrentModificationException, IllegalStateException {
- Resource[] contexts = asContexts(graphName);
- Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
- org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
- Value obj = rdf4jTermFactory.asValue(object);
- return new ConvertedStatements<Quad>(this::getRepositoryConnection,
- rdf4jTermFactory::asQuad, subj, pred, obj, contexts);
- }
-
- @Override
- protected RDF4JQuad asTripleLike(Statement s) {
- return rdf4jTermFactory.asQuad(s);
- }
-
- @Override
- public Graph getGraph() {
- // default context only
- // NOTE: We carry over the 'salt' as the graph's BlankNode should be equal to our BlankNodes
- return new RepositoryGraphImpl(repository, salt, false, includeInferred, (Resource)null);
- }
-
- @Override
- public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
- // NOTE: May be null to indicate default context
- Resource context = (Resource) rdf4jTermFactory.asValue(graphName);
- // NOTE: We carry over the 'salt' as the graph's BlankNode should be equal to our BlankNodes
- return Optional.of(new RepositoryGraphImpl(repository, salt, false, includeInferred, context));
- }
-
- @Override
- public Stream<BlankNodeOrIRI> getGraphNames() {
- // FIXME: Will the below close the connection before the stream has been consumed outside?
- try (RepositoryConnection conn = getRepositoryConnection()) {
- RepositoryResult<Resource> contexts = conn.getContextIDs();
- // NOTE: connection will be closed outside by the Iterations.stream()
- return Iterations.stream(contexts).map(g -> (BlankNodeOrIRI) rdf4jTermFactory.asRDFTerm(g));
- }
- }
+ RepositoryDatasetImpl(Repository repository, UUID salt, boolean handleInitAndShutdown, boolean includeInferred) {
+ super(repository, salt, handleInitAndShutdown, includeInferred);
+ }
+
+ @Override
+ public void add(Quad tripleLike) {
+ Statement statement = rdf4jTermFactory.asStatement(tripleLike);
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ conn.add(statement);
+ conn.commit();
+ }
+ }
+
+ @Override
+ public boolean contains(Quad tripleLike) {
+ Statement statement = rdf4jTermFactory.asStatement(tripleLike);
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ return conn.hasStatement(statement, includeInferred);
+ }
+ }
+
+ @Override
+ public void remove(Quad tripleLike) {
+ Statement statement = rdf4jTermFactory.asStatement(tripleLike);
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ conn.remove(statement);
+ conn.commit();
+ }
+ }
+
+ @Override
+ public void clear() {
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ conn.clear();
+ conn.commit();
+ }
+ }
+
+ @Override
+ public long size() {
+ if (includeInferred) {
+ // We'll need to count them all
+ return stream().count();
+ }
+ // else: Ask directly
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ return conn.size();
+ }
+ }
+
+ @Override
+ public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ Resource context = (Resource) rdf4jTermFactory.asValue(graphName);
+ Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
+ org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
+ Value obj = rdf4jTermFactory.asValue(object);
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ conn.add(subj, pred, obj, context);
+ conn.commit();
+ }
+ }
+
+ @Override
+ public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
+ org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
+ Value obj = rdf4jTermFactory.asValue(object);
+ Resource[] contexts = asContexts(graphName);
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ return conn.hasStatement(subj, pred, obj, includeInferred, contexts);
+ }
+ }
+
+ private Resource[] asContexts(Optional<BlankNodeOrIRI> graphName) {
+ Resource[] contexts;
+ if (graphName == null) {
+ // no contexts == any contexts
+ contexts = new Resource[0];
+ } else {
+ BlankNodeOrIRI g = graphName.orElse(null);
+ Resource context = (Resource) rdf4jTermFactory.asValue(g);
+ contexts = new Resource[] { context };
+ }
+ return contexts;
+ }
+
+ @Override
+ public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
+ org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
+ Value obj = rdf4jTermFactory.asValue(object);
+ Resource[] contexts = asContexts(graphName);
+
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ conn.remove(subj, pred, obj, contexts);
+ conn.commit();
+ }
+ }
+
+ @Override
+ public Stream<RDF4JQuad> stream() {
+ return stream(null, null, null, null);
+ }
+
+ @Override
+ public Stream<RDF4JQuad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) {
+ Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
+ org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
+ Value obj = rdf4jTermFactory.asValue(object);
+ Resource[] contexts = asContexts(graphName);
+
+ // NOTE: We can't do the usual try..with closing of the
+ // RepositoryConnection here as it will have to be closed outside
+ // by the user of the returned stream
+ RepositoryConnection conn = getRepositoryConnection();
+ Stream<RDF4JQuad> stream = null;
+ try {
+ RepositoryResult<Statement> statements = conn.getStatements(subj, pred, obj, includeInferred, contexts);
+ // NOTE: Iterations.stream should close RepositoryResult as long as
+ // our caller closes the stream
+ stream = Iterations.stream(statements).map(rdf4jTermFactory::asQuad);
+ } finally {
+ if (stream == null) {
+ // Some exception before we made the stream, close connection
+ // here
+ conn.close();
+ }
+ }
+ // Make sure the RepositoryConnection is closed
+ return stream.onClose(conn::close);
+
+ }
+
+ @Override
+ public ClosableIterable<Quad> iterate() throws ConcurrentModificationException, IllegalStateException {
+ return iterate(null, null, null, null);
+ }
+
+ @Override
+ public ClosableIterable<Quad> iterate(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) throws ConcurrentModificationException, IllegalStateException {
+ Resource[] contexts = asContexts(graphName);
+ Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
+ org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
+ Value obj = rdf4jTermFactory.asValue(object);
+ return new ConvertedStatements<Quad>(this::getRepositoryConnection, rdf4jTermFactory::asQuad, subj, pred, obj,
+ contexts);
+ }
+
+ @Override
+ protected RDF4JQuad asTripleLike(Statement s) {
+ return rdf4jTermFactory.asQuad(s);
+ }
+
+ @Override
+ public Graph getGraph() {
+ // default context only
+ // NOTE: We carry over the 'salt' as the graph's BlankNode should be
+ // equal to our BlankNodes
+ return new RepositoryGraphImpl(repository, salt, false, includeInferred, (Resource) null);
+ }
+
+ @Override
+ public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
+ // NOTE: May be null to indicate default context
+ Resource context = (Resource) rdf4jTermFactory.asValue(graphName);
+ // NOTE: We carry over the 'salt' as the graph's BlankNode should be
+ // equal to our BlankNodes
+ return Optional.of(new RepositoryGraphImpl(repository, salt, false, includeInferred, context));
+ }
+
+ @Override
+ public Stream<BlankNodeOrIRI> getGraphNames() {
+ // FIXME: Will the below close the connection before the stream has been
+ // consumed outside?
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ RepositoryResult<Resource> contexts = conn.getContextIDs();
+ // NOTE: connection will be closed outside by the
+ // Iterations.stream()
+ return Iterations.stream(contexts).map(g -> (BlankNodeOrIRI) rdf4jTermFactory.asRDFTerm(g));
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java
index 55b909e..ca07f9e 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java
@@ -43,152 +43,153 @@ import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryResult;
class RepositoryGraphImpl extends AbstractRepositoryGraphLike<Triple> implements Graph, RDF4JGraph {
-
- private final Resource[] contextMask;
-
- RepositoryGraphImpl(Repository repository, UUID salt, boolean handleInitAndShutdown, boolean includeInferred, Resource... contextMask) {
- super(repository, salt, handleInitAndShutdown, includeInferred);
- this.contextMask = Objects.requireNonNull(contextMask);
- }
-
-
- @Override
- public void add(Triple tripleLike) {
- Statement statement = rdf4jTermFactory.asStatement(tripleLike);
- try (RepositoryConnection conn = getRepositoryConnection()) {
- conn.add(statement, contextMask);
- conn.commit();
- }
- }
-
-
- @Override
- public boolean contains(Triple tripleLike) {
- Statement statement = rdf4jTermFactory.asStatement(tripleLike);
- try (RepositoryConnection conn = getRepositoryConnection()) {
- return conn.hasStatement(statement, includeInferred, contextMask);
- }
- }
-
- @Override
- public void remove(Triple tripleLike) {
- Statement statement = rdf4jTermFactory.asStatement(tripleLike);
- try (RepositoryConnection conn = getRepositoryConnection()) {
- conn.remove(statement, contextMask);
- conn.commit();
- }
- }
-
- @Override
- public void clear() {
- try (RepositoryConnection conn = getRepositoryConnection()) {
- conn.clear(contextMask);
- conn.commit();
- }
- }
-
- @Override
- public long size() {
- if (!includeInferred && contextMask.length == 0) {
- try (RepositoryConnection conn = getRepositoryConnection()) {
- return conn.size();
- }
- } else {
- try (Stream<RDF4JTriple> stream = stream()) {
- return stream.count();
- }
- }
- }
-
- @Override
- public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
- org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
- Value obj = rdf4jTermFactory.asValue(object);
- try (RepositoryConnection conn = getRepositoryConnection()) {
- conn.add(subj, pred, obj, contextMask);
- conn.commit();
- }
- }
-
- @Override
- public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
- org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
- Value obj = rdf4jTermFactory.asValue(object);
- try (RepositoryConnection conn = getRepositoryConnection()) {
- return conn.hasStatement(subj, pred, obj, includeInferred, contextMask);
- }
- }
-
- @Override
- public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
- org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
- Value obj = rdf4jTermFactory.asValue(object);
- try (RepositoryConnection conn = getRepositoryConnection()) {
- conn.remove(subj, pred, obj, contextMask);
- conn.commit();
- }
- }
-
- @Override
- public ClosableIterable<Triple> iterate() throws ConcurrentModificationException, IllegalStateException {
- return iterate(null, null, null);
- }
-
- @Override
- public ClosableIterable<Triple> iterate(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
- throws ConcurrentModificationException, IllegalStateException {
- Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
- org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
- Value obj = rdf4jTermFactory.asValue(object);
- return new ConvertedStatements<Triple>(this::getRepositoryConnection, rdf4jTermFactory::asTriple,
- subj, pred, obj, contextMask);
- }
-
- @Override
- public Stream<RDF4JTriple> stream() {
- return stream(null, null, null);
- }
-
- @Override
- public Stream<RDF4JTriple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
- org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
- Value obj = rdf4jTermFactory.asValue(object);
-
- // NOTE: We can't do the usual try..with closing of the
- // RepositoryConnection here as it will have to be closed outside
- // by the user of the returned stream
- RepositoryConnection conn = getRepositoryConnection();
- Stream<RDF4JTriple> stream = null;
- try {
- RepositoryResult<Statement> statements = conn.getStatements(subj, pred, obj, includeInferred, contextMask);
- // NOTE: Iterations.stream should close RepositoryResult as long as our caller closes the stream
- stream = Iterations.stream(statements).map(this::asTripleLike);
- } finally {
- if (stream == null) {
- // Some exception before we made the stream, close connection here
- conn.close();
- }
- }
- // Make sure the RepositoryConnection is closed
- return stream.onClose(conn::close);
- }
-
- @Override
- protected RDF4JTriple asTripleLike(Statement statement) {
- return rdf4jTermFactory.asTriple(statement);
- }
-
- @Override
- public Set<RDF4JBlankNodeOrIRI> getContextMask() {
- Set<RDF4JBlankNodeOrIRI> mask = new HashSet<>();
- for (Resource s : contextMask) {
- mask.add((RDF4JBlankNodeOrIRI) rdf4jTermFactory.asRDFTerm(s));
- }
- return Collections.unmodifiableSet(mask);
- }
-
+
+ private final Resource[] contextMask;
+
+ RepositoryGraphImpl(Repository repository, UUID salt, boolean handleInitAndShutdown, boolean includeInferred,
+ Resource... contextMask) {
+ super(repository, salt, handleInitAndShutdown, includeInferred);
+ this.contextMask = Objects.requireNonNull(contextMask);
+ }
+
+ @Override
+ public void add(Triple tripleLike) {
+ Statement statement = rdf4jTermFactory.asStatement(tripleLike);
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ conn.add(statement, contextMask);
+ conn.commit();
+ }
+ }
+
+ @Override
+ public boolean contains(Triple tripleLike) {
+ Statement statement = rdf4jTermFactory.asStatement(tripleLike);
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ return conn.hasStatement(statement, includeInferred, contextMask);
+ }
+ }
+
+ @Override
+ public void remove(Triple tripleLike) {
+ Statement statement = rdf4jTermFactory.asStatement(tripleLike);
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ conn.remove(statement, contextMask);
+ conn.commit();
+ }
+ }
+
+ @Override
+ public void clear() {
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ conn.clear(contextMask);
+ conn.commit();
+ }
+ }
+
+ @Override
+ public long size() {
+ if (!includeInferred && contextMask.length == 0) {
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ return conn.size();
+ }
+ } else {
+ try (Stream<RDF4JTriple> stream = stream()) {
+ return stream.count();
+ }
+ }
+ }
+
+ @Override
+ public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
+ org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
+ Value obj = rdf4jTermFactory.asValue(object);
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ conn.add(subj, pred, obj, contextMask);
+ conn.commit();
+ }
+ }
+
+ @Override
+ public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
+ org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
+ Value obj = rdf4jTermFactory.asValue(object);
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ return conn.hasStatement(subj, pred, obj, includeInferred, contextMask);
+ }
+ }
+
+ @Override
+ public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
+ org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
+ Value obj = rdf4jTermFactory.asValue(object);
+ try (RepositoryConnection conn = getRepositoryConnection()) {
+ conn.remove(subj, pred, obj, contextMask);
+ conn.commit();
+ }
+ }
+
+ @Override
+ public ClosableIterable<Triple> iterate() throws ConcurrentModificationException, IllegalStateException {
+ return iterate(null, null, null);
+ }
+
+ @Override
+ public ClosableIterable<Triple> iterate(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
+ throws ConcurrentModificationException, IllegalStateException {
+ Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
+ org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
+ Value obj = rdf4jTermFactory.asValue(object);
+ return new ConvertedStatements<Triple>(this::getRepositoryConnection, rdf4jTermFactory::asTriple, subj, pred,
+ obj, contextMask);
+ }
+
+ @Override
+ public Stream<RDF4JTriple> stream() {
+ return stream(null, null, null);
+ }
+
+ @Override
+ public Stream<RDF4JTriple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
+ org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
+ Value obj = rdf4jTermFactory.asValue(object);
+
+ // NOTE: We can't do the usual try..with closing of the
+ // RepositoryConnection here as it will have to be closed outside
+ // by the user of the returned stream
+ RepositoryConnection conn = getRepositoryConnection();
+ Stream<RDF4JTriple> stream = null;
+ try {
+ RepositoryResult<Statement> statements = conn.getStatements(subj, pred, obj, includeInferred, contextMask);
+ // NOTE: Iterations.stream should close RepositoryResult as long as
+ // our caller closes the stream
+ stream = Iterations.stream(statements).map(this::asTripleLike);
+ } finally {
+ if (stream == null) {
+ // Some exception before we made the stream, close connection
+ // here
+ conn.close();
+ }
+ }
+ // Make sure the RepositoryConnection is closed
+ return stream.onClose(conn::close);
+ }
+
+ @Override
+ protected RDF4JTriple asTripleLike(Statement statement) {
+ return rdf4jTermFactory.asTriple(statement);
+ }
+
+ @Override
+ public Set<RDF4JBlankNodeOrIRI> getContextMask() {
+ Set<RDF4JBlankNodeOrIRI> mask = new HashSet<>();
+ for (Resource s : contextMask) {
+ mask.add((RDF4JBlankNodeOrIRI) rdf4jTermFactory.asRDFTerm(s));
+ }
+ return Collections.unmodifiableSet(mask);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java
index 0526c77..4ed3946 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java
@@ -28,52 +28,51 @@ import org.apache.commons.rdf.rdf4j.RDF4JTriple;
import org.eclipse.rdf4j.model.Statement;
final class TripleImpl implements Triple, RDF4JTriple {
- private UUID salt;
- private final Statement statement;
-
- TripleImpl(Statement statement, UUID salt) {
- this.statement = statement;
- this.salt = salt;
- }
-
- @Override
- public Statement asStatement() {
- return statement;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof Triple) {
- Triple triple = (Triple) obj;
- return getSubject().equals(triple.getSubject()) &&
- getPredicate().equals(triple.getPredicate()) &&
- getObject().equals(triple.getObject());
- }
- return false;
- }
-
- @Override
- public RDFTerm getObject() {
- return RDF4J.asRDFTerm(statement.getObject(), salt);
- }
-
- @Override
- public org.apache.commons.rdf.api.IRI getPredicate() {
- return (org.apache.commons.rdf.api.IRI) RDF4J.asRDFTerm(statement.getPredicate(), null);
- }
-
- @Override
- public BlankNodeOrIRI getSubject() {
- return (BlankNodeOrIRI) RDF4J.asRDFTerm(statement.getSubject(), salt);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(getSubject(), getPredicate(), getObject());
- }
-
- @Override
- public String toString() {
- return statement.toString();
- }
+ private UUID salt;
+ private final Statement statement;
+
+ TripleImpl(Statement statement, UUID salt) {
+ this.statement = statement;
+ this.salt = salt;
+ }
+
+ @Override
+ public Statement asStatement() {
+ return statement;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Triple) {
+ Triple triple = (Triple) obj;
+ return getSubject().equals(triple.getSubject()) && getPredicate().equals(triple.getPredicate())
+ && getObject().equals(triple.getObject());
+ }
+ return false;
+ }
+
+ @Override
+ public RDFTerm getObject() {
+ return RDF4J.asRDFTerm(statement.getObject(), salt);
+ }
+
+ @Override
+ public org.apache.commons.rdf.api.IRI getPredicate() {
+ return (org.apache.commons.rdf.api.IRI) RDF4J.asRDFTerm(statement.getPredicate(), null);
+ }
+
+ @Override
+ public BlankNodeOrIRI getSubject() {
+ return (BlankNodeOrIRI) RDF4J.asRDFTerm(statement.getSubject(), salt);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getSubject(), getPredicate(), getObject());
+ }
+
+ @Override
+ public String toString() {
+ return statement.toString();
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
index f4bfb7a..e40e985 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
@@ -18,39 +18,33 @@
/**
* Commons RDF integration with <a href="http://rdf4j.org/">RDF4J</a>.
* <p>
- * Use the {@link RDF4J} to convert
- * between Commons RDF and RDF4J types, for instance
- * {@link RDF4J#asQuad(org.eclipse.rdf4j.model.Statement)}
- * converts a RDF4J {@link org.eclipse.rdf4j.model.Statement} to a
+ * Use the {@link RDF4J} to convert between Commons RDF and RDF4J types, for
+ * instance {@link RDF4J#asQuad(org.eclipse.rdf4j.model.Statement)} converts a
+ * RDF4J {@link org.eclipse.rdf4j.model.Statement} to a
* {@link org.apache.commons.rdf.api.Quad}. Converted RDF terms implement the
- * {@link RDF4JTerm} interface, and converted
- * statements the {@link RDF4JTripleLike}
- * interface, which provide convenience access to the underlying RDF4J
- * implementations.
+ * {@link RDF4JTerm} interface, and converted statements the
+ * {@link RDF4JTripleLike} interface, which provide convenience access to the
+ * underlying RDF4J implementations.
* <p>
* RDF4J {@link org.eclipse.rdf4j.model.Model}s and
* {@link org.eclipse.rdf4j.repository.Repository} instances can be adapted to
- * Commons RDF {@link Graph} and
- * {@link Dataset}, e.g. using
- * {@link RDF4J#asGraph(org.eclipse.rdf4j.model.Model)}
- * or
+ * Commons RDF {@link Graph} and {@link Dataset}, e.g. using
+ * {@link RDF4J#asGraph(org.eclipse.rdf4j.model.Model)} or
* {@link RDF4J#asDataset(org.eclipse.rdf4j.repository.Repository, RDF4J.Option...)}
* The returned adapted graph/dataset is directly mapped, so changes are
* propagated both ways. For convenience, the marker interface
- * {@link RDF4JGraph} and
- * {@link RDF4JDataset} provide access to the
- * underlying RDF4J implementations.
+ * {@link RDF4JGraph} and {@link RDF4JDataset} provide access to the underlying
+ * RDF4J implementations.
* <p>
- * The {@link RDF4JParser} can be used to
- * parse RDF files using RDF4j. It should be most efficient if used with
- * {@link RDF4JParser#target(Dataset)}
- * and an adapted {@link RDF4JDataset}, or
- * {@link RDF4JParser#target(Graph)}
- * and a an adapted {@link RDF4JGraph}
+ * The {@link RDF4JParser} can be used to parse RDF files using RDF4j. It should
+ * be most efficient if used with {@link RDF4JParser#target(Dataset)} and an
+ * adapted {@link RDF4JDataset}, or {@link RDF4JParser#target(Graph)} and a an
+ * adapted {@link RDF4JGraph}
*
*
*/
package org.apache.commons.rdf.rdf4j;
+
// Imports for Javadoc, do not remove
import org.apache.commons.rdf.api.Dataset;
import org.apache.commons.rdf.api.Graph;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java
index d31c24d..f068040 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java
@@ -22,16 +22,16 @@ import org.apache.commons.rdf.api.BlankNode;
public class BlankNodeTest extends AbstractBlankNodeTest {
- RDF4J factory = new RDF4J();
-
- @Override
- protected BlankNode getBlankNode() {
- return factory.createBlankNode();
- }
+ RDF4J factory = new RDF4J();
- @Override
- protected BlankNode getBlankNode(String identifier) {
- return factory.createBlankNode(identifier);
- }
+ @Override
+ protected BlankNode getBlankNode() {
+ return factory.createBlankNode();
+ }
+
+ @Override
+ protected BlankNode getBlankNode(String identifier) {
+ return factory.createBlankNode(identifier);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java
index 4ad8969..81c77da 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java
@@ -20,11 +20,11 @@ package org.apache.commons.rdf.rdf4j;
import org.apache.commons.rdf.api.AbstractGraphTest;
import org.apache.commons.rdf.api.RDF;
-public class GraphTest extends AbstractGraphTest{
+public class GraphTest extends AbstractGraphTest {
- @Override
- public RDF createFactory() {
- return new RDF4J();
- }
+ @Override
+ public RDF createFactory() {
+ return new RDF4J();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java
index ab7a459..9d9c802 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java
@@ -33,57 +33,57 @@ import org.eclipse.rdf4j.sail.memory.model.MemValueFactory;
public class MemoryGraphTest extends AbstractGraphTest {
- public static final class MemoryStoreRDF implements RDF {
-
- RDF4J rdf4jFactory = new RDF4J(new MemValueFactory());
-
- public RDF4JBlankNode createBlankNode() {
- return rdf4jFactory.createBlankNode();
- }
-
- public RDF4JBlankNode createBlankNode(String name) {
- return rdf4jFactory.createBlankNode(name);
- }
-
- public Dataset createDataset() {
- return rdf4jFactory.createDataset();
- }
-
- public RDF4JIRI createIRI(String iri) throws IllegalArgumentException, UnsupportedOperationException {
- return rdf4jFactory.createIRI(iri);
- }
-
- public RDF4JLiteral createLiteral(String lexicalForm) {
- return rdf4jFactory.createLiteral(lexicalForm);
- }
-
- public Literal createLiteral(String lexicalForm, IRI dataType) {
- return rdf4jFactory.createLiteral(lexicalForm, dataType);
- }
-
- public Literal createLiteral(String lexicalForm, String languageTag) {
- return rdf4jFactory.createLiteral(lexicalForm, languageTag);
- }
-
- public RDF4JTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return rdf4jFactory.createTriple(subject, predicate, object);
- }
-
- public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return rdf4jFactory.createQuad(graphName, subject, predicate, object);
- }
-
- public RDF4JGraph createGraph() {
- Sail sail = new MemoryStore();
- Repository repository = new SailRepository(sail);
- repository.initialize();
- return rdf4jFactory.asGraph(repository);
- }
- }
-
- @Override
- public RDF createFactory() {
- return new MemoryStoreRDF();
- }
+ public static final class MemoryStoreRDF implements RDF {
+
+ RDF4J rdf4jFactory = new RDF4J(new MemValueFactory());
+
+ public RDF4JBlankNode createBlankNode() {
+ return rdf4jFactory.createBlankNode();
+ }
+
+ public RDF4JBlankNode createBlankNode(String name) {
+ return rdf4jFactory.createBlankNode(name);
+ }
+
+ public Dataset createDataset() {
+ return rdf4jFactory.createDataset();
+ }
+
+ public RDF4JIRI createIRI(String iri) throws IllegalArgumentException, UnsupportedOperationException {
+ return rdf4jFactory.createIRI(iri);
+ }
+
+ public RDF4JLiteral createLiteral(String lexicalForm) {
+ return rdf4jFactory.createLiteral(lexicalForm);
+ }
+
+ public Literal createLiteral(String lexicalForm, IRI dataType) {
+ return rdf4jFactory.createLiteral(lexicalForm, dataType);
+ }
+
+ public Literal createLiteral(String lexicalForm, String languageTag) {
+ return rdf4jFactory.createLiteral(lexicalForm, languageTag);
+ }
+
+ public RDF4JTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return rdf4jFactory.createTriple(subject, predicate, object);
+ }
+
+ public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return rdf4jFactory.createQuad(graphName, subject, predicate, object);
+ }
+
+ public RDF4JGraph createGraph() {
+ Sail sail = new MemoryStore();
+ Repository repository = new SailRepository(sail);
+ repository.initialize();
+ return rdf4jFactory.asGraph(repository);
+ }
+ }
+
+ @Override
+ public RDF createFactory() {
+ return new MemoryStoreRDF();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryStoreRDFTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryStoreRDFTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryStoreRDFTest.java
index fd4efcb..5954d13 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryStoreRDFTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryStoreRDFTest.java
@@ -23,15 +23,15 @@ import org.junit.Assume;
public class MemoryStoreRDFTest extends AbstractRDFTest {
- @Override
- public RDF createFactory() {
- return new MemoryGraphTest.MemoryStoreRDF();
- }
-
- @Override
- public void testInvalidLiteralLang() throws Exception {
- Assume.assumeTrue("RDF4J doesn't check Lang strings",false);
- super.testInvalidLiteralLang();
- }
-
+ @Override
+ public RDF createFactory() {
+ return new MemoryGraphTest.MemoryStoreRDF();
+ }
+
+ @Override
+ public void testInvalidLiteralLang() throws Exception {
+ Assume.assumeTrue("RDF4J doesn't check Lang strings", false);
+ super.testInvalidLiteralLang();
+ }
+
}
[32/50] [abbrv] incubator-commonsrdf git commit: *RDFTermFactoryTest
-> *RDFTest
Posted by st...@apache.org.
*RDFTermFactoryTest -> *RDFTest
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/de6842f9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/de6842f9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/de6842f9
Branch: refs/heads/COMMONSRDF-7
Commit: de6842f9828fc7c9678c014d3650cd569e131294
Parents: b7016f0
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 28 11:15:09 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 28 11:15:09 2016 +0100
----------------------------------------------------------------------
.../rdf/api/AbstractRDFTermFactoryTest.java | 334 -------------------
.../apache/commons/rdf/api/AbstractRDFTest.java | 334 +++++++++++++++++++
.../apache/commons/rdf/jena/JenaRDFTest.java | 32 ++
.../rdf/jena/TestRDFTermFactoryJena.java | 32 --
.../rdf/jsonldjava/JsonLdFactoryTest.java | 56 ----
.../commons/rdf/jsonldjava/JsonLdRDFTest.java | 56 ++++
.../rdf/rdf4j/MemoryRDFTermFactoryTest.java | 37 --
.../commons/rdf/rdf4j/MemoryStoreRDFTest.java | 37 ++
.../org/apache/commons/rdf/rdf4j/RDF4JTest.java | 37 ++
.../rdf/rdf4j/Rdf4JRDFTermFactoryTest.java | 37 --
.../SimpleNoRelativeIRIRDFTermFactoryTest.java | 46 ---
.../rdf/simple/SimpleNoRelativeIRIRDTest.java | 46 +++
.../rdf/simple/SimpleRDFTermFactoryTest.java | 33 --
.../commons/rdf/simple/SimpleRDFTest.java | 33 ++
14 files changed, 575 insertions(+), 575 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
deleted file mode 100644
index 97ee5fa..0000000
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
+++ /dev/null
@@ -1,334 +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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotSame;
-
-import java.util.Objects;
-
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Test RDF implementation (and thus its RDFTerm implementations)
- * <p>
- * To add to your implementation's tests, create a subclass with a name ending
- * in <code>Test</code> and provide {@link #createFactory()} which minimally
- * supports one of the operations, but ideally supports all operations.
- *
- * @see RDF
- */
-public abstract class AbstractRDFTermFactoryTest {
-
- private RDF factory;
-
- /**
- *
- * This method must be overridden by the implementing test to provide a
- * factory for the test to create {@link Literal}, {@link IRI} etc.
- *
- * @return {@link RDF} instance to be tested.
- */
- protected abstract RDF createFactory();
-
- @Before
- public void setUp() {
- factory = createFactory();
- }
-
- @Test
- public void testCreateBlankNode() throws Exception {
- BlankNode bnode = factory.createBlankNode();
-
- BlankNode bnode2 = factory.createBlankNode();
- assertNotEquals(
- "Second blank node has not got a unique internal identifier",
- bnode.uniqueReference(), bnode2.uniqueReference());
- }
-
- @Test
- public void testCreateBlankNodeIdentifierEmpty() throws Exception {
- try {
- factory.createBlankNode("");
- } catch (IllegalArgumentException e) {
- // Expected exception
- }
- }
-
- @Test
- public void testCreateBlankNodeIdentifier() throws Exception {
- factory.createBlankNode("example1");
- }
-
- @Test
- public void testCreateBlankNodeIdentifierTwice() throws Exception {
- BlankNode bnode1, bnode2, bnode3;
- bnode1 = factory.createBlankNode("example1");
- bnode2 = factory.createBlankNode("example1");
- bnode3 = factory.createBlankNode("differ");
- // We don't know what the identifier is, but it MUST be the same
- assertEquals(bnode1.uniqueReference(), bnode2.uniqueReference());
- // We don't know what the ntriplesString is, but it MUST be the same
- assertEquals(bnode1.ntriplesString(), bnode2.ntriplesString());
- // and here it MUST differ
- assertNotEquals(bnode1.uniqueReference(),
- bnode3.uniqueReference());
- assertNotEquals(bnode1.ntriplesString(), bnode3.ntriplesString());
- }
-
- @Test
- public void testCreateBlankNodeIdentifierTwiceDifferentFactories() throws Exception {
- BlankNode bnode1, differentFactory;
- bnode1 = factory.createBlankNode();
- // it MUST differ from a second factory
- differentFactory = createFactory().createBlankNode();
-
- // NOTE: We can't make similar assumption if we provide a
- // name to createBlankNode(String) as its documentation
- // only says:
- //
- // * BlankNodes created using this method with the same parameter, for
- // * different instances of RDFFactory, SHOULD NOT be equivalent.
- //
- // https://github.com/apache/incubator-commonsrdf/pull/7#issuecomment-92312779
- assertNotEquals(bnode1, differentFactory);
- assertNotEquals(bnode1.uniqueReference(),
- differentFactory.uniqueReference());
- // but we can't require:
- //assertNotEquals(bnode1.ntriplesString(), differentFactory.ntriplesString());
- }
-
-
- @Test
- public void testCreateGraph() {
- Graph graph = factory.createGraph();
-
- assertEquals("Graph was not empty", 0, graph.size());
- graph.add(factory.createBlankNode(),
- factory.createIRI("http://example.com/"),
- factory.createBlankNode());
-
- Graph graph2 = factory.createGraph();
- assertNotSame(graph, graph2);
- assertEquals("Graph was empty after adding", 1, graph.size());
- assertEquals("New graph was not empty", 0, graph2.size());
- }
-
- @Test
- public void testCreateIRI() throws Exception {
- IRI example = factory.createIRI("http://example.com/");
-
- assertEquals("http://example.com/", example.getIRIString());
- assertEquals("<http://example.com/>", example.ntriplesString());
-
- IRI term = factory.createIRI("http://example.com/vocab#term");
- assertEquals("http://example.com/vocab#term", term.getIRIString());
- assertEquals("<http://example.com/vocab#term>", term.ntriplesString());
-
- // and now for the international fun!
-
- IRI latin1 = factory.createIRI("http://acc�nt.example.com/premi�re");
- assertEquals("http://acc�nt.example.com/premi�re",
- latin1.getIRIString());
- assertEquals("<http://acc�nt.example.com/premi�re>",
- latin1.ntriplesString());
-
- IRI cyrillic = factory.createIRI("http://example.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435/\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430");
- assertEquals("http://example.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435/\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430",
- cyrillic.getIRIString());
- assertEquals("<http://example.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435/\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430>",
- cyrillic.ntriplesString());
-
- IRI deseret = factory.createIRI("http://\U00010400.example.com/\U00010400");
- assertEquals("http://\U00010400.example.com/\U00010400", deseret.getIRIString());
- assertEquals("<http://\U00010400.example.com/\U00010400>", deseret.ntriplesString());
- }
-
- @Test
- public void testCreateLiteral() throws Exception {
- Literal example = factory.createLiteral("Example");
- assertEquals("Example", example.getLexicalForm());
- assertFalse(example.getLanguageTag().isPresent());
- assertEquals("http://www.w3.org/2001/XMLSchema#string", example
- .getDatatype().getIRIString());
- // http://lists.w3.org/Archives/Public/public-rdf-comments/2014Dec/0004.html
- assertEquals("\"Example\"", example.ntriplesString());
- }
-
- @Test
- public void testCreateLiteralDateTime() throws Exception {
- Literal dateTime = factory
- .createLiteral(
- "2014-12-27T00:50:00T-0600",
- factory.createIRI("http://www.w3.org/2001/XMLSchema#dateTime"));
- assertEquals("2014-12-27T00:50:00T-0600", dateTime.getLexicalForm());
- assertFalse(dateTime.getLanguageTag().isPresent());
- assertEquals("http://www.w3.org/2001/XMLSchema#dateTime", dateTime
- .getDatatype().getIRIString());
- assertEquals(
- "\"2014-12-27T00:50:00T-0600\"^^<http://www.w3.org/2001/XMLSchema#dateTime>",
- dateTime.ntriplesString());
- }
-
- @Test
- public void testCreateLiteralLang() throws Exception {
- Literal example = factory.createLiteral("Example", "en");
-
- assertEquals("Example", example.getLexicalForm());
- assertEquals("en", example.getLanguageTag().get());
- assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",
- example.getDatatype().getIRIString());
- assertEquals("\"Example\"@en", example.ntriplesString());
- }
-
- @Test
- public void testCreateLiteralLangISO693_3() throws Exception {
- // see https://issues.apache.org/jira/browse/JENA-827
- Literal vls = factory.createLiteral("Herbert Van de Sompel", "vls"); // JENA-827
-
- assertEquals("vls", vls.getLanguageTag().get());
- assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",
- vls.getDatatype().getIRIString());
- assertEquals("\"Herbert Van de Sompel\"@vls", vls.ntriplesString());
- }
-
- @Test
- public void testCreateLiteralString() throws Exception {
- Literal example = factory.createLiteral("Example", factory
- .createIRI("http://www.w3.org/2001/XMLSchema#string"));
- assertEquals("Example", example.getLexicalForm());
- assertFalse(example.getLanguageTag().isPresent());
- assertEquals("http://www.w3.org/2001/XMLSchema#string", example
- .getDatatype().getIRIString());
- // http://lists.w3.org/Archives/Public/public-rdf-comments/2014Dec/0004.html
- assertEquals("\"Example\"", example.ntriplesString());
- }
-
- @Test
- public void testCreateTripleBnodeBnode() {
- BlankNode subject = factory.createBlankNode("b1");
- IRI predicate = factory.createIRI("http://example.com/pred");
- BlankNode object = factory.createBlankNode("b2");
- Triple triple = factory.createTriple(subject, predicate, object);
-
- // bnode equivalence should be OK as we used the same
- // factory and have not yet inserted Triple into a Graph
- assertEquals(subject, triple.getSubject());
- assertEquals(predicate, triple.getPredicate());
- assertEquals(object, triple.getObject());
- }
-
- @Test
- public void testCreateTripleBnodeIRI() {
- BlankNode subject = factory.createBlankNode("b1");
- IRI predicate = factory.createIRI("http://example.com/pred");
- IRI object = factory.createIRI("http://example.com/obj");
- Triple triple = factory.createTriple(subject, predicate, object);
-
- // bnode equivalence should be OK as we used the same
- // factory and have not yet inserted Triple into a Graph
- assertEquals(subject, triple.getSubject());
- assertEquals(predicate, triple.getPredicate());
- assertEquals(object, triple.getObject());
- }
-
- @Test
- public void testCreateTripleBnodeTriple() {
- BlankNode subject = factory.createBlankNode();
- IRI predicate = factory.createIRI("http://example.com/pred");
- Literal object = factory.createLiteral("Example", "en");
- Triple triple = factory.createTriple(subject, predicate, object);
-
- // bnode equivalence should be OK as we used the same
- // factory and have not yet inserted Triple into a Graph
- assertEquals(subject, triple.getSubject());
- assertEquals(predicate, triple.getPredicate());
- assertEquals(object, triple.getObject());
- }
-
- @Test
- public void testPossiblyInvalidBlankNode() throws Exception {
- BlankNode withColon;
- try {
- withColon = factory.createBlankNode("with:colon");
- } catch (IllegalArgumentException ex) {
- // Good!
- return;
- }
- // Factory allows :colon, which is OK as long as it's not causing an
- // invalid ntriplesString
- assertFalse(withColon.ntriplesString().contains("with:colon"));
-
- // and creating it twice gets the same ntriplesString
- assertEquals(withColon.ntriplesString(),
- factory.createBlankNode("with:colon").ntriplesString());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testInvalidIRI() throws Exception {
- factory.createIRI("<no_brackets>");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testInvalidLiteralLang() throws Exception {
- factory.createLiteral("Example", "with space");
- }
-
- @Test(expected = Exception.class)
- public void testInvalidTriplePredicate() {
- BlankNode subject = factory.createBlankNode("b1");
- BlankNode predicate = factory.createBlankNode("b2");
- BlankNode object = factory.createBlankNode("b3");
- factory.createTriple(subject, (IRI) predicate, object);
- }
-
- @Test
- public void hashCodeBlankNode() throws Exception {
- BlankNode bnode1 = factory.createBlankNode();
- assertEquals(bnode1.uniqueReference().hashCode(), bnode1.hashCode());
- }
-
- @Test
- public void hashCodeIRI() throws Exception {
- IRI iri = factory.createIRI("http://example.com/");
- assertEquals(iri.getIRIString().hashCode(), iri.hashCode());
- }
-
- @Test
- public void hashCodeLiteral() throws Exception {
- Literal literal = factory.createLiteral("Hello");
- assertEquals(Objects.hash(
- literal.getLexicalForm(),
- literal.getDatatype(),
- literal.getLanguageTag()
- ),
- literal.hashCode());
- }
-
- @Test
- public void hashCodeTriple() throws Exception {
- IRI iri = factory.createIRI("http://example.com/");
- Triple triple = factory.createTriple(iri, iri, iri);
- assertEquals(Objects.hash(iri, iri, iri),
- triple.hashCode());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java
new file mode 100644
index 0000000..c664da8
--- /dev/null
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTest.java
@@ -0,0 +1,334 @@
+/**
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotSame;
+
+import java.util.Objects;
+
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test RDF implementation (and thus its RDFTerm implementations)
+ * <p>
+ * To add to your implementation's tests, create a subclass with a name ending
+ * in <code>Test</code> and provide {@link #createFactory()} which minimally
+ * supports one of the operations, but ideally supports all operations.
+ *
+ * @see RDF
+ */
+public abstract class AbstractRDFTest {
+
+ private RDF factory;
+
+ /**
+ *
+ * This method must be overridden by the implementing test to provide a
+ * factory for the test to create {@link Literal}, {@link IRI} etc.
+ *
+ * @return {@link RDF} instance to be tested.
+ */
+ protected abstract RDF createFactory();
+
+ @Before
+ public void setUp() {
+ factory = createFactory();
+ }
+
+ @Test
+ public void testCreateBlankNode() throws Exception {
+ BlankNode bnode = factory.createBlankNode();
+
+ BlankNode bnode2 = factory.createBlankNode();
+ assertNotEquals(
+ "Second blank node has not got a unique internal identifier",
+ bnode.uniqueReference(), bnode2.uniqueReference());
+ }
+
+ @Test
+ public void testCreateBlankNodeIdentifierEmpty() throws Exception {
+ try {
+ factory.createBlankNode("");
+ } catch (IllegalArgumentException e) {
+ // Expected exception
+ }
+ }
+
+ @Test
+ public void testCreateBlankNodeIdentifier() throws Exception {
+ factory.createBlankNode("example1");
+ }
+
+ @Test
+ public void testCreateBlankNodeIdentifierTwice() throws Exception {
+ BlankNode bnode1, bnode2, bnode3;
+ bnode1 = factory.createBlankNode("example1");
+ bnode2 = factory.createBlankNode("example1");
+ bnode3 = factory.createBlankNode("differ");
+ // We don't know what the identifier is, but it MUST be the same
+ assertEquals(bnode1.uniqueReference(), bnode2.uniqueReference());
+ // We don't know what the ntriplesString is, but it MUST be the same
+ assertEquals(bnode1.ntriplesString(), bnode2.ntriplesString());
+ // and here it MUST differ
+ assertNotEquals(bnode1.uniqueReference(),
+ bnode3.uniqueReference());
+ assertNotEquals(bnode1.ntriplesString(), bnode3.ntriplesString());
+ }
+
+ @Test
+ public void testCreateBlankNodeIdentifierTwiceDifferentFactories() throws Exception {
+ BlankNode bnode1, differentFactory;
+ bnode1 = factory.createBlankNode();
+ // it MUST differ from a second factory
+ differentFactory = createFactory().createBlankNode();
+
+ // NOTE: We can't make similar assumption if we provide a
+ // name to createBlankNode(String) as its documentation
+ // only says:
+ //
+ // * BlankNodes created using this method with the same parameter, for
+ // * different instances of RDFFactory, SHOULD NOT be equivalent.
+ //
+ // https://github.com/apache/incubator-commonsrdf/pull/7#issuecomment-92312779
+ assertNotEquals(bnode1, differentFactory);
+ assertNotEquals(bnode1.uniqueReference(),
+ differentFactory.uniqueReference());
+ // but we can't require:
+ //assertNotEquals(bnode1.ntriplesString(), differentFactory.ntriplesString());
+ }
+
+
+ @Test
+ public void testCreateGraph() {
+ Graph graph = factory.createGraph();
+
+ assertEquals("Graph was not empty", 0, graph.size());
+ graph.add(factory.createBlankNode(),
+ factory.createIRI("http://example.com/"),
+ factory.createBlankNode());
+
+ Graph graph2 = factory.createGraph();
+ assertNotSame(graph, graph2);
+ assertEquals("Graph was empty after adding", 1, graph.size());
+ assertEquals("New graph was not empty", 0, graph2.size());
+ }
+
+ @Test
+ public void testCreateIRI() throws Exception {
+ IRI example = factory.createIRI("http://example.com/");
+
+ assertEquals("http://example.com/", example.getIRIString());
+ assertEquals("<http://example.com/>", example.ntriplesString());
+
+ IRI term = factory.createIRI("http://example.com/vocab#term");
+ assertEquals("http://example.com/vocab#term", term.getIRIString());
+ assertEquals("<http://example.com/vocab#term>", term.ntriplesString());
+
+ // and now for the international fun!
+
+ IRI latin1 = factory.createIRI("http://acc�nt.example.com/premi�re");
+ assertEquals("http://acc�nt.example.com/premi�re",
+ latin1.getIRIString());
+ assertEquals("<http://acc�nt.example.com/premi�re>",
+ latin1.ntriplesString());
+
+ IRI cyrillic = factory.createIRI("http://example.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435/\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430");
+ assertEquals("http://example.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435/\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430",
+ cyrillic.getIRIString());
+ assertEquals("<http://example.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435/\u041a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430>",
+ cyrillic.ntriplesString());
+
+ IRI deseret = factory.createIRI("http://\U00010400.example.com/\U00010400");
+ assertEquals("http://\U00010400.example.com/\U00010400", deseret.getIRIString());
+ assertEquals("<http://\U00010400.example.com/\U00010400>", deseret.ntriplesString());
+ }
+
+ @Test
+ public void testCreateLiteral() throws Exception {
+ Literal example = factory.createLiteral("Example");
+ assertEquals("Example", example.getLexicalForm());
+ assertFalse(example.getLanguageTag().isPresent());
+ assertEquals("http://www.w3.org/2001/XMLSchema#string", example
+ .getDatatype().getIRIString());
+ // http://lists.w3.org/Archives/Public/public-rdf-comments/2014Dec/0004.html
+ assertEquals("\"Example\"", example.ntriplesString());
+ }
+
+ @Test
+ public void testCreateLiteralDateTime() throws Exception {
+ Literal dateTime = factory
+ .createLiteral(
+ "2014-12-27T00:50:00T-0600",
+ factory.createIRI("http://www.w3.org/2001/XMLSchema#dateTime"));
+ assertEquals("2014-12-27T00:50:00T-0600", dateTime.getLexicalForm());
+ assertFalse(dateTime.getLanguageTag().isPresent());
+ assertEquals("http://www.w3.org/2001/XMLSchema#dateTime", dateTime
+ .getDatatype().getIRIString());
+ assertEquals(
+ "\"2014-12-27T00:50:00T-0600\"^^<http://www.w3.org/2001/XMLSchema#dateTime>",
+ dateTime.ntriplesString());
+ }
+
+ @Test
+ public void testCreateLiteralLang() throws Exception {
+ Literal example = factory.createLiteral("Example", "en");
+
+ assertEquals("Example", example.getLexicalForm());
+ assertEquals("en", example.getLanguageTag().get());
+ assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",
+ example.getDatatype().getIRIString());
+ assertEquals("\"Example\"@en", example.ntriplesString());
+ }
+
+ @Test
+ public void testCreateLiteralLangISO693_3() throws Exception {
+ // see https://issues.apache.org/jira/browse/JENA-827
+ Literal vls = factory.createLiteral("Herbert Van de Sompel", "vls"); // JENA-827
+
+ assertEquals("vls", vls.getLanguageTag().get());
+ assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",
+ vls.getDatatype().getIRIString());
+ assertEquals("\"Herbert Van de Sompel\"@vls", vls.ntriplesString());
+ }
+
+ @Test
+ public void testCreateLiteralString() throws Exception {
+ Literal example = factory.createLiteral("Example", factory
+ .createIRI("http://www.w3.org/2001/XMLSchema#string"));
+ assertEquals("Example", example.getLexicalForm());
+ assertFalse(example.getLanguageTag().isPresent());
+ assertEquals("http://www.w3.org/2001/XMLSchema#string", example
+ .getDatatype().getIRIString());
+ // http://lists.w3.org/Archives/Public/public-rdf-comments/2014Dec/0004.html
+ assertEquals("\"Example\"", example.ntriplesString());
+ }
+
+ @Test
+ public void testCreateTripleBnodeBnode() {
+ BlankNode subject = factory.createBlankNode("b1");
+ IRI predicate = factory.createIRI("http://example.com/pred");
+ BlankNode object = factory.createBlankNode("b2");
+ Triple triple = factory.createTriple(subject, predicate, object);
+
+ // bnode equivalence should be OK as we used the same
+ // factory and have not yet inserted Triple into a Graph
+ assertEquals(subject, triple.getSubject());
+ assertEquals(predicate, triple.getPredicate());
+ assertEquals(object, triple.getObject());
+ }
+
+ @Test
+ public void testCreateTripleBnodeIRI() {
+ BlankNode subject = factory.createBlankNode("b1");
+ IRI predicate = factory.createIRI("http://example.com/pred");
+ IRI object = factory.createIRI("http://example.com/obj");
+ Triple triple = factory.createTriple(subject, predicate, object);
+
+ // bnode equivalence should be OK as we used the same
+ // factory and have not yet inserted Triple into a Graph
+ assertEquals(subject, triple.getSubject());
+ assertEquals(predicate, triple.getPredicate());
+ assertEquals(object, triple.getObject());
+ }
+
+ @Test
+ public void testCreateTripleBnodeTriple() {
+ BlankNode subject = factory.createBlankNode();
+ IRI predicate = factory.createIRI("http://example.com/pred");
+ Literal object = factory.createLiteral("Example", "en");
+ Triple triple = factory.createTriple(subject, predicate, object);
+
+ // bnode equivalence should be OK as we used the same
+ // factory and have not yet inserted Triple into a Graph
+ assertEquals(subject, triple.getSubject());
+ assertEquals(predicate, triple.getPredicate());
+ assertEquals(object, triple.getObject());
+ }
+
+ @Test
+ public void testPossiblyInvalidBlankNode() throws Exception {
+ BlankNode withColon;
+ try {
+ withColon = factory.createBlankNode("with:colon");
+ } catch (IllegalArgumentException ex) {
+ // Good!
+ return;
+ }
+ // Factory allows :colon, which is OK as long as it's not causing an
+ // invalid ntriplesString
+ assertFalse(withColon.ntriplesString().contains("with:colon"));
+
+ // and creating it twice gets the same ntriplesString
+ assertEquals(withColon.ntriplesString(),
+ factory.createBlankNode("with:colon").ntriplesString());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidIRI() throws Exception {
+ factory.createIRI("<no_brackets>");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidLiteralLang() throws Exception {
+ factory.createLiteral("Example", "with space");
+ }
+
+ @Test(expected = Exception.class)
+ public void testInvalidTriplePredicate() {
+ BlankNode subject = factory.createBlankNode("b1");
+ BlankNode predicate = factory.createBlankNode("b2");
+ BlankNode object = factory.createBlankNode("b3");
+ factory.createTriple(subject, (IRI) predicate, object);
+ }
+
+ @Test
+ public void hashCodeBlankNode() throws Exception {
+ BlankNode bnode1 = factory.createBlankNode();
+ assertEquals(bnode1.uniqueReference().hashCode(), bnode1.hashCode());
+ }
+
+ @Test
+ public void hashCodeIRI() throws Exception {
+ IRI iri = factory.createIRI("http://example.com/");
+ assertEquals(iri.getIRIString().hashCode(), iri.hashCode());
+ }
+
+ @Test
+ public void hashCodeLiteral() throws Exception {
+ Literal literal = factory.createLiteral("Hello");
+ assertEquals(Objects.hash(
+ literal.getLexicalForm(),
+ literal.getDatatype(),
+ literal.getLanguageTag()
+ ),
+ literal.hashCode());
+ }
+
+ @Test
+ public void hashCodeTriple() throws Exception {
+ IRI iri = factory.createIRI("http://example.com/");
+ Triple triple = factory.createTriple(iri, iri, iri);
+ assertEquals(Objects.hash(iri, iri, iri),
+ triple.hashCode());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/jena/src/test/java/org/apache/commons/rdf/jena/JenaRDFTest.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/JenaRDFTest.java b/jena/src/test/java/org/apache/commons/rdf/jena/JenaRDFTest.java
new file mode 100644
index 0000000..87a4618
--- /dev/null
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/JenaRDFTest.java
@@ -0,0 +1,32 @@
+/**
+ * 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.jena;
+
+import org.apache.commons.rdf.api.AbstractRDFTest;
+import org.apache.commons.rdf.api.RDF;
+
+public class JenaRDFTest extends AbstractRDFTest {
+
+ @Override
+ public RDF createFactory() {
+ return new JenaRDF();
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
deleted file mode 100644
index 870546a..0000000
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFTermFactoryJena.java
+++ /dev/null
@@ -1,32 +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.jena;
-
-import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
-import org.apache.commons.rdf.api.RDF;
-
-public class TestRDFTermFactoryJena extends AbstractRDFTermFactoryTest {
-
- @Override
- public RDF createFactory() {
- return new JenaRDF();
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
deleted file mode 100644
index 22010f7..0000000
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
+++ /dev/null
@@ -1,56 +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.jsonldjava;
-
-import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
-import org.apache.commons.rdf.api.RDF;
-import org.junit.Assume;
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class JsonLdFactoryTest extends AbstractRDFTermFactoryTest {
-
- @Override
- public RDF createFactory() {
- return new JsonLdRDF();
- }
-
- // TODO: Add support for checking for invalid lang/iri/blanknode IDs
-
- @Test
- @Override
- public void testInvalidLiteralLang() throws Exception {
- Assume.assumeFalse("JSONLD-Java does not validate lang strings", false);
- super.testInvalidLiteralLang();
- }
-
- @Test
- @Override
- public void testInvalidIRI() throws Exception {
- Assume.assumeFalse("JSONLD-Java does not validate IRIs", false);
- super.testInvalidIRI();
- }
-
- @Ignore
- @Test
- @Override
- public void testPossiblyInvalidBlankNode() throws Exception {
- // TODO: Fix blank node in ntriplesString()
- super.testPossiblyInvalidBlankNode();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java
new file mode 100644
index 0000000..14099e8
--- /dev/null
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTest.java
@@ -0,0 +1,56 @@
+/**
+ * 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.jsonldjava;
+
+import org.apache.commons.rdf.api.AbstractRDFTest;
+import org.apache.commons.rdf.api.RDF;
+import org.junit.Assume;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class JsonLdRDFTest extends AbstractRDFTest {
+
+ @Override
+ public RDF createFactory() {
+ return new JsonLdRDF();
+ }
+
+ // TODO: Add support for checking for invalid lang/iri/blanknode IDs
+
+ @Test
+ @Override
+ public void testInvalidLiteralLang() throws Exception {
+ Assume.assumeFalse("JSONLD-Java does not validate lang strings", false);
+ super.testInvalidLiteralLang();
+ }
+
+ @Test
+ @Override
+ public void testInvalidIRI() throws Exception {
+ Assume.assumeFalse("JSONLD-Java does not validate IRIs", false);
+ super.testInvalidIRI();
+ }
+
+ @Ignore
+ @Test
+ @Override
+ public void testPossiblyInvalidBlankNode() throws Exception {
+ // TODO: Fix blank node in ntriplesString()
+ super.testPossiblyInvalidBlankNode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java
deleted file mode 100644
index 0a44a5e..0000000
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java
+++ /dev/null
@@ -1,37 +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.rdf4j;
-
-import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
-import org.apache.commons.rdf.api.RDF;
-import org.junit.Assume;
-
-public class MemoryRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
-
- @Override
- public RDF createFactory() {
- return new MemoryGraphTest.MemoryStoreRDF();
- }
-
- @Override
- public void testInvalidLiteralLang() throws Exception {
- Assume.assumeTrue("RDF4J doesn't check Lang strings",false);
- super.testInvalidLiteralLang();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryStoreRDFTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryStoreRDFTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryStoreRDFTest.java
new file mode 100644
index 0000000..fd4efcb
--- /dev/null
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryStoreRDFTest.java
@@ -0,0 +1,37 @@
+/**
+ * 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.rdf4j;
+
+import org.apache.commons.rdf.api.AbstractRDFTest;
+import org.apache.commons.rdf.api.RDF;
+import org.junit.Assume;
+
+public class MemoryStoreRDFTest extends AbstractRDFTest {
+
+ @Override
+ public RDF createFactory() {
+ return new MemoryGraphTest.MemoryStoreRDF();
+ }
+
+ @Override
+ public void testInvalidLiteralLang() throws Exception {
+ Assume.assumeTrue("RDF4J doesn't check Lang strings",false);
+ super.testInvalidLiteralLang();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JTest.java
new file mode 100644
index 0000000..c10ea9a
--- /dev/null
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JTest.java
@@ -0,0 +1,37 @@
+/**
+ * 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.rdf4j;
+
+import org.apache.commons.rdf.api.AbstractRDFTest;
+import org.apache.commons.rdf.api.RDF;
+import org.junit.Assume;
+
+public class RDF4JTest extends AbstractRDFTest {
+
+ @Override
+ public RDF createFactory() {
+ return new RDF4J();
+ }
+
+ @Override
+ public void testInvalidLiteralLang() throws Exception {
+ Assume.assumeTrue("RDF4J doesn't check Lang strings",false);
+ super.testInvalidLiteralLang();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
deleted file mode 100644
index 29c8ab0..0000000
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
+++ /dev/null
@@ -1,37 +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.rdf4j;
-
-import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
-import org.apache.commons.rdf.api.RDF;
-import org.junit.Assume;
-
-public class Rdf4JRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
-
- @Override
- public RDF createFactory() {
- return new RDF4J();
- }
-
- @Override
- public void testInvalidLiteralLang() throws Exception {
- Assume.assumeTrue("RDD4J doesn't check Lang strings",false);
- super.testInvalidLiteralLang();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
deleted file mode 100644
index 3167243..0000000
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDFTermFactoryTest.java
+++ /dev/null
@@ -1,46 +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.simple;
-
-import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.RDF;
-
-import java.net.URI;
-
-/**
- * Test simple IRI without relative IRI support.
- * <p>
- * Ensures that {@link AbstractRDFTermFactoryTest#testCreateIRIRelative()} is
- * correctly skipped (without causing an error).
- */
-public class SimpleNoRelativeIRIRDFTermFactoryTest extends
- AbstractRDFTermFactoryTest {
- @Override
- public RDF createFactory() {
- return new SimpleRDF() {
- @Override
- public IRI createIRI(String iri) {
- if (!URI.create(iri).isAbsolute()) {
- throw new IllegalArgumentException("IRIs must be absolute");
- }
- return super.createIRI(iri);
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDTest.java
new file mode 100644
index 0000000..abec6c0
--- /dev/null
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.simple;
+
+import org.apache.commons.rdf.api.AbstractRDFTest;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.RDF;
+
+import java.net.URI;
+
+/**
+ * Test simple IRI without relative IRI support.
+ * <p>
+ * Ensures that {@link AbstractRDFTest#testCreateIRIRelative()} is
+ * correctly skipped (without causing an error).
+ */
+public class SimpleNoRelativeIRIRDTest extends
+ AbstractRDFTest {
+ @Override
+ public RDF createFactory() {
+ return new SimpleRDF() {
+ @Override
+ public IRI createIRI(String iri) {
+ if (!URI.create(iri).isAbsolute()) {
+ throw new IllegalArgumentException("IRIs must be absolute");
+ }
+ return super.createIRI(iri);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
deleted file mode 100644
index 816eef9..0000000
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryTest.java
+++ /dev/null
@@ -1,33 +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.simple;
-
-import org.apache.commons.rdf.api.AbstractRDFTermFactoryTest;
-import org.apache.commons.rdf.api.RDF;
-
-/**
- * Simple RDF Test
- */
-public class SimpleRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
-
- @Override
- public RDF createFactory() {
- return new SimpleRDF();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de6842f9/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTest.java
new file mode 100644
index 0000000..31915de
--- /dev/null
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTest.java
@@ -0,0 +1,33 @@
+/**
+ * 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.simple;
+
+import org.apache.commons.rdf.api.AbstractRDFTest;
+import org.apache.commons.rdf.api.RDF;
+
+/**
+ * Simple RDF Test
+ */
+public class SimpleRDFTest extends AbstractRDFTest {
+
+ @Override
+ public RDF createFactory() {
+ return new SimpleRDF();
+ }
+
+}
[04/50] [abbrv] incubator-commonsrdf git commit: tests for
ServiceLoader
Posted by st...@apache.org.
tests for ServiceLoader
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/102a9fce
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/102a9fce
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/102a9fce
Branch: refs/heads/COMMONSRDF-7
Commit: 102a9fcebe32a384139ec2267fa332a3da8129a3
Parents: 2c62ada
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Oct 19 18:02:16 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Oct 19 18:02:53 2016 +0100
----------------------------------------------------------------------
.../commons/rdf/jena/JenaServiceLoaderTest.java | 40 +++++++++++++++++++
.../rdf/jsonldjava/JsonLdServiceLoaderTest.java | 40 +++++++++++++++++++
.../rdf/rdf4j/RDF4JServiceLoaderTest.java | 40 +++++++++++++++++++
.../simple/SimpleRDFTermFactoryLookupTest.java | 42 --------------------
.../rdf/simple/SimpleServiceLoaderTest.java | 40 +++++++++++++++++++
5 files changed, 160 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/102a9fce/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java b/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
new file mode 100644
index 0000000..1793c3e
--- /dev/null
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.jena;
+
+import static org.junit.Assert.fail;
+
+import java.util.ServiceLoader;
+
+import org.apache.commons.rdf.api.RDFFactory;
+import org.junit.Test;
+
+public class JenaServiceLoaderTest {
+
+ @Test
+ public void testServiceLoaderLookup() {
+ ServiceLoader<RDFFactory> loader = ServiceLoader.load(RDFFactory.class);
+ for (RDFFactory impl : loader) {
+ if (impl instanceof JenaFactory) {
+ return; // yay
+ }
+ }
+ fail("JenaFactory not found in ServiceLoader");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/102a9fce/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
new file mode 100644
index 0000000..ce07a37
--- /dev/null
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.jsonldjava;
+
+import static org.junit.Assert.fail;
+
+import java.util.ServiceLoader;
+
+import org.apache.commons.rdf.api.RDFFactory;
+import org.junit.Test;
+
+public class JsonLdServiceLoaderTest {
+
+ @Test
+ public void testServiceLoaderLookup() {
+ ServiceLoader<RDFFactory> loader = ServiceLoader.load(RDFFactory.class);
+ for (RDFFactory impl : loader) {
+ if (impl instanceof JsonLdFactory) {
+ return; // yay
+ }
+ }
+ fail("JsonLdFactory not found in ServiceLoader");
+ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/102a9fce/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
new file mode 100644
index 0000000..77c396c
--- /dev/null
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.rdf4j;
+
+import static org.junit.Assert.fail;
+
+import java.util.ServiceLoader;
+
+import org.apache.commons.rdf.api.RDFFactory;
+import org.junit.Test;
+
+public class RDF4JServiceLoaderTest {
+
+ @Test
+ public void testServiceLoaderLookup() {
+ ServiceLoader<RDFFactory> loader = ServiceLoader.load(RDFFactory.class);
+ for (RDFFactory impl : loader) {
+ if (impl instanceof RDF4JFactory) {
+ return; // yay
+ }
+ }
+ fail("RDF4JFactory not found in ServiceLoader");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/102a9fce/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryLookupTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryLookupTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryLookupTest.java
deleted file mode 100644
index 179b7ef..0000000
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleRDFTermFactoryLookupTest.java
+++ /dev/null
@@ -1,42 +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.simple;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Iterator;
-import java.util.ServiceLoader;
-
-import org.apache.commons.rdf.api.RDFFactory;
-import org.junit.Test;
-
-public class SimpleRDFTermFactoryLookupTest {
-
- @Test
- public void testServiceLoaderLookup() {
- ServiceLoader<RDFFactory> loader = ServiceLoader.load(RDFFactory.class);
-
- Iterator<RDFFactory> iterator = loader.iterator();
- RDFFactory factory = iterator.next();
-
- assertTrue(factory instanceof SimpleRDFFactory);
- assertFalse(iterator.hasNext());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/102a9fce/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
new file mode 100644
index 0000000..00e33d3
--- /dev/null
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.simple;
+
+import static org.junit.Assert.fail;
+
+import java.util.ServiceLoader;
+
+import org.apache.commons.rdf.api.RDFFactory;
+import org.junit.Test;
+
+public class SimpleServiceLoaderTest {
+
+ @Test
+ public void testServiceLoaderLookup() {
+ ServiceLoader<RDFFactory> loader = ServiceLoader.load(RDFFactory.class);
+ for (RDFFactory impl : loader) {
+ if (impl instanceof SimpleRDFFactory) {
+ return; // yay
+ }
+ }
+ fail("SimpleRDFFactory not found in ServiceLoader");
+ }
+}
[48/50] [abbrv] incubator-commonsrdf git commit: COMMONSRDF-7
RDFTerm/Triple/Quad are immutable
Posted by st...@apache.org.
COMMONSRDF-7 RDFTerm/Triple/Quad are immutable
also clarify RDFTerm.equals() and RDFTerm.hashCode()
by delegation to its specializations IRI/BlankNode/Literal
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/2efe1ab3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/2efe1ab3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/2efe1ab3
Branch: refs/heads/COMMONSRDF-7
Commit: 2efe1ab37c4995037b8c3a6ee431e9ba58e21cd5
Parents: 413dd09
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Thu Oct 27 10:56:38 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 28 11:45:44 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/commons/rdf/api/Quad.java | 16 ++++-
.../org/apache/commons/rdf/api/RDFTerm.java | 62 ++++++++++++++++++--
.../java/org/apache/commons/rdf/api/Triple.java | 14 +++++
3 files changed, 87 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2efe1ab3/api/src/main/java/org/apache/commons/rdf/api/Quad.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Quad.java b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
index 3b286cb..b2e8ed5 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Quad.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Quad.java
@@ -17,16 +17,30 @@
*/
package org.apache.commons.rdf.api;
+import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.Optional;
+import java.util.Set;
/**
* A Quad is a statement in a
* <a href= "http://www.w3.org/TR/rdf11-concepts/#section-dataset" >RDF-1.1
* Dataset</a>, as defined by
- * <a href= "https://www.w3.org/TR/2014/NOTE-rdf11-datasets-20140225/" >RDF-1.1
+ * <a href= "https://www.w3.org/TR/2014/NOTE-rdf11-datasets-20140225/#quad-semantics" >RDF-1.1
* Concepts and Abstract Syntax</a>, a W3C Working Group Note published on 25
* February 2014.
+ * <p>
+ * A {@link Quad} object in Commons RDF is considered <em>immutable</em>, that
+ * is, over it's life time it will have consistent behaviour for its
+ * {@link #equals(Object)} and {@link #hashCode()}, and the instances returned
+ * from {@link #getGraphName()}, {@link #getSubject()}, {@link #getPredicate()}
+ * and {@link #getObject()} will have consistent {@link Object#equals(Object)}
+ * behaviour.
+ * <p>
+ * Thus, a {@link Quad} is thread-safe and can be safely used in collections
+ * like {@link List}, {@link Map} or {@link Set}, and a {@link Quad} can be
+ * used interchangeably across Commons RDF implementations.
*
* @since 0.3.0-incubating
* @see Dataset
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2efe1ab3/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
index 2b69b24..a277140 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFTerm.java
@@ -17,15 +17,27 @@
*/
package org.apache.commons.rdf.api;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* An <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-term" >RDF-1.1
* Term</a>, as defined by
* <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.<br>
+ * Abstract Syntax</a>, a W3C Recommendation published on 25 February 2014.
+ * <p>
+ * A {@link RDFTerm} object in Commons RDF is considered <em>immutable</em>,
+ * that is, over it's life time it will have consistent behaviour for its
+ * {@link #equals(Object)} and {@link #hashCode()}, and objects returned from
+ * its getter methods (e.g. {@link IRI#getIRIString()} and
+ * {@link Literal#getLanguageTag()}) will have consistent
+ * {@link #equals(Object)} behaviour.
* <p>
- * Instances of RDFTerm SHOULD be an {@link IRI}, {@link BlankNode} or
- * {@link Literal}.
- *
+ * Thus, an {@link RDFTerm} is thread-safe and can be safely used in collections
+ * like {@link List}, {@link Map} or {@link Set}, and a {@link RDFTerm} can be
+ * used interchangeably across Commons RDF implementations.
+ *
* @see <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-term" >RDF-1.1
* Term</a>
*/
@@ -41,4 +53,46 @@ public interface RDFTerm {
*/
String ntriplesString();
+ /**
+ * Check it this RDFTerm is equal to another RDFTerm.
+ * <p>
+ * If this object is an {@link IRI}, equality is checked using
+ * {@link IRI#equals(Object)}, or if this object is a {@link BlankNode},
+ * equality is checked using {@link BlankNode#equals(Object)}, or if this
+ * object is a {@link Literal}, equality is checked using
+ * {@link Literal#equals(Object)}.
+ * <p>
+ * Implementations MUST also override {@link #hashCode()} so that two equal
+ * Literals produce the same hash code.
+ *
+ * @see IRI#equals(Object)
+ * @see BlankNode#equals(Object)
+ * @see Literal#equals(Object)
+ *
+ * @param other
+ * Another object
+ * @return true if other is a RDFTerm and is equal to this
+ */
+ @Override
+ public boolean equals(Object other);
+
+ /**
+ * Calculate a hash code for this RDFTerm.
+ * <p>
+ * As an {@link RDFTerm} is <em>immutable</em>, this method will always
+ * return the same hashCode over the lifetime of this object.
+ * <p>
+ * This method MUST be implemented in conjunction with
+ * {@link #equals(Object)} so that two equal RDFTerm produce the same hash
+ * code.
+ *
+ * @see IRI#hashCode()
+ * @see Literal#hashCode()
+ * @see BlankNode#hashCode()
+ *
+ * @return a hash code value for this RDFTerm.
+ */
+ @Override
+ public int hashCode();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2efe1ab3/api/src/main/java/org/apache/commons/rdf/api/Triple.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Triple.java b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
index ef9bdaa..57934fa 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Triple.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Triple.java
@@ -17,13 +17,27 @@
*/
package org.apache.commons.rdf.api;
+import java.util.List;
+import java.util.Map;
import java.util.Objects;
+import java.util.Set;
/**
* An <a href= "http://www.w3.org/TR/rdf11-concepts/#dfn-rdf-triple" >RDF-1.1
* Triple</a>, as defined by
* <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.<br>
+ * <p>
+ * A {@link Triple} object in Commons RDF is considered <em>immutable</em>, that
+ * is, over it's life time it will have consistent behaviour for its
+ * {@link #equals(Object)} and {@link #hashCode()}, and the {@link RDFTerm}
+ * instances returned from {@link #getSubject()}, {@link #getPredicate()} and
+ * {@link #getObject()} will have consistent {@link RDFTerm#equals(Object)}
+ * behaviour.
+ * <p>
+ * Thus, a {@link Triple} is thread-safe and can be safely used in collections
+ * like {@link List}, {@link Map} or {@link Set}, and a {@link Triple} can be
+ * used interchangeably across Commons RDF implementations.
*
* @see Quad
* @see RDF#createTriple(BlankNodeOrIRI,IRI,RDFTerm)
[18/50] [abbrv] incubator-commonsrdf git commit: RDFFactory -> RDF in
user guide
Posted by st...@apache.org.
RDFFactory -> RDF in user guide
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/9c191fc2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/9c191fc2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/9c191fc2
Branch: refs/heads/COMMONSRDF-7
Commit: 9c191fc2f4ae00b6537e213d2681821b14104293
Parents: fa27a17
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Oct 23 02:58:01 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Oct 23 02:58:01 2016 +0100
----------------------------------------------------------------------
src/site/markdown/userguide.md | 257 +++++++++++++++++++-----------------
1 file changed, 134 insertions(+), 123 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/9c191fc2/src/site/markdown/userguide.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md
index 8451ab9..6191889 100644
--- a/src/site/markdown/userguide.md
+++ b/src/site/markdown/userguide.md
@@ -28,8 +28,8 @@ Commons RDF [API](apidocs/).
* [RDF concepts](#RDF_concepts)
* [Using Commons RDF from Maven](#Using_Commons_RDF_from_Maven)
* [Creating Commons RDF instances](#Creating_Commons_RDF_instances)
- * [Creating a RDFFactory](#Creating_a_RDFFactory)
- * [Using a RDFFactory](#Using_a_RDFFactory)
+ * [Finding an RDF implementation](#Finding_an_RDF_implementation)
+ * [Using an RDF implementation](#Using_an_RDF_implementation)
* [RDF terms](#RDF_terms)
* [N-Triples string](#N-Triples_string)
* [IRI](#IRI)
@@ -146,25 +146,26 @@ see the [download page](download.html) for the latest version._
To create instances of Commons RDF interfaces like
[`Graph`](apidocs/org/apache/commons/rdf/api/Graph.html) and
[`IRI`](apidocs/org/apache/commons/rdf/api/IRI.html) you will need a
-[RDFFactory](apidocs/org/apache/commons/rdf/api/RDFFactory.html).
+[RDF](apidocs/org/apache/commons/rdf/api/RDF.html) implementation.
-### Creating a RDFFactory
+### Finding an RDF implementation
-How to get an instance of this factory is implementation-specific, for the
-_simple_ implementation, you can construct the
-[SimpleRDFFactory](apidocs/org/apache/commons/rdf/simple/SimpleRDFFactory.html):
+The [implementations](implementations.md) of `RDF` can usually be
+created using a normal Java constructor, for instance the
+_simple_ implementation from
+[SimpleRDF](apidocs/org/apache/commons/rdf/simple/SimpleRDF.html):
```java
import org.apache.commons.rdf.api.*;
-import org.apache.commons.rdf.simple.SimpleRDFFactory;
+import org.apache.commons.rdf.simple.SimpleRDF;
// ...
-RDFFactory factory = new SimpleRDFFactory();
+RDF rdf = new SimpleRDF();
```
-If you don't want to depend on instantiating a concrete implementation,
-you can alternatively use the
+If you don't want to depend on instantiating a concrete `RDF`
+implementation, you can alternatively use the
[ServiceLoader](http://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html)
-to lookup any `RDFFactory` implementations found on the classpath:
+to lookup any `RDF` implementations found on the classpath:
```java
import java.util.Iterator;
@@ -172,43 +173,47 @@ import java.util.ServiceLoader;
import org.apache.commons.rdf.api.*;
// ...
-ServiceLoader<RDFFactory> loader = ServiceLoader.load(RDFFactory.class);
-Iterator<RDFFactory> iterator = loader.iterator();
-RDFFactory factory = iterator.next();
+ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class);
+Iterator<RDF> iterator = loader.iterator();
+RDF rdf = iterator.next();
```
Note that the `ServiceLoader` approach above might not work well within
split classloader systems like OSGi.
+When using the factory method
+[createBlankNode(String)](apidocs/org/apache/commons/rdf/api/RDF.html#createBlankNode-java.lang.String-)
+from different sources,
+care should be taken to create correspondingly different `RDF` instances.
-### Using a RDFFactory
-Using the factory you can construct
+### Using an RDF implementation
+
+Using the `RDF` implementation you can construct
any [RDFTerm](apidocs/org/apache/commons/rdf/api/RDFTerm.html), e.g. to create a
[BlankNode](apidocs/org/apache/commons/rdf/api/BlankNode.html),
[IRI](apidocs/org/apache/commons/rdf/api/IRI.html) and
[Literal](apidocs/org/apache/commons/rdf/api/Literal.html):
```java
-BlankNode aliceBlankNode = factory.createBlankNode();
-IRI nameIri = factory.createIRI("http://example.com/name");
-Literal aliceLiteral = factory.createLiteral("Alice");
+BlankNode aliceBlankNode = rdf.createBlankNode();
+IRI nameIri = rdf.createIRI("http://example.com/name");
+Literal aliceLiteral = rdf.createLiteral("Alice");
```
You can also create a stand-alone [Triple](apidocs/org/apache/commons/rdf/api/Triple.html):
```java
-Triple triple = factory.createTriple(aliceBlankNode, nameIri, aliceLiteral);
+Triple triple = rdf.createTriple(aliceBlankNode, nameIri, aliceLiteral);
```
-The [RDFFactory](apidocs/org/apache/commons/rdf/api/RDFFactory.html) also
+The [RDF](apidocs/org/apache/commons/rdf/api/RDF.html) interface also
contains more specific variants of some of the methods above, e.g. to create a
typed literal.
-Note that for any given implementation, `RDFTerm` instances need not be created
-using a `RDFFactory`. More likely, implementation-specific methods might create these
-objects as part of data parsing, storage lookup and queries.
-
+In addition, the [implementations](implementations.md) of `RDF` may add
+specific converter methods and implementation-specific
+subtypes for interoperability with their underlying RDF framework's API.
## RDF terms
@@ -217,7 +222,7 @@ objects as part of data parsing, storage lookup and queries.
the super-interface for instances that can be used as subject, predicate and
object of a [Triple](apidocs/org/apache/commons/rdf/api/Triple.html).
-The RDF term interfaces are arranged in this class hierarchy:
+The RDF term interfaces are arranged in this ty[e hierarchy:
* [RDFTerm](apidocs/org/apache/commons/rdf/api/RDFTerm.html)
* [BlankNodeOrIRI](apidocs/org/apache/commons/rdf/api/BlankNodeOrIRI.html)
@@ -243,7 +248,7 @@ System.out.println(aliceLiteral.ntriplesString());
> ``"Alice"``
This returns the [N-Triples](http://www.w3.org/TR/n-triples) canonical form
-of the term, which can be useful both for debugging and simple serialization.
+of the term, which can be useful for debugging or simple serialization.
_Note: The `.toString()` of the `simple` implementation used in
some of these examples use `ntriplesString()` internally, but Commons RDF
@@ -292,10 +297,10 @@ _predicate_ or _object_ of a [Triple](apidocs/org/apache/commons/rdf/api/Triple.
[Quad](apidocs/org/apache/commons/rdf/api/Quad.html),
where it can also be used a _graph name_.
-To create an `IRI` instance from a `RDFFactory`, use [createIRI](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createIRI-java.lang.String-):
+To create an `IRI` instance from an `RDF` implementation, use [createIRI](apidocs/org/apache/commons/rdf/api/RDF.html#createIRI-java.lang.String-):
```java
-IRI iri = factory.createIRI("http://example.com/alice");
+IRI iri = rdf.createIRI("http://example.com/alice");
```
You can retrieve the IRI string using [getIRIString](apidocs/org/apache/commons/rdf/api/IRI.html#getIRIString--):
@@ -316,14 +321,14 @@ Two IRI instances can be compared using the
method, which uses [simple string comparison](http://tools.ietf.org/html/rfc3987#section-5.3.1):
```java
-IRI iri2 = factory.createIRI("http://example.com/alice");
+IRI iri2 = rdf.createIRI("http://example.com/alice");
System.out.println(iri.equals(iri2));
```
> `true`
```java
-IRI iri3 = factory.createIRI("http://example.com/alice/./");
+IRI iri3 = rdf.createIRI("http://example.com/alice/./");
System.out.println(iri.equals(iri3));
```
@@ -335,7 +340,7 @@ instances of [IRI](apidocs/org/apache/commons/rdf/api/IRI.html):
```java
System.out.println(iri.equals("http://example.com/alice"));
-System.out.println(iri.equals(factory.createLiteral("http://example.com/alice")));
+System.out.println(iri.equals(rdf.createLiteral("http://example.com/alice")));
```
> `false`
>
@@ -353,11 +358,11 @@ where it can also be used a _graph name_.
To create a new
[BlankNode](apidocs/org/apache/commons/rdf/api/BlankNode.html) instance from a
-`RDFFactory`, use
-[createBlankNode](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createBlankNode--):
+`RDF` implementation, use
+[createBlankNode](apidocs/org/apache/commons/rdf/api/RDF.html#createBlankNode--):
```java
-BlankNode bnode = factory.createBlankNode();
+BlankNode bnode = rdf.createBlankNode();
```
Every call to `createBlankNode()` returns a brand new blank node
@@ -368,7 +373,7 @@ to itself:
```java
System.out.println(bnode.equals(bnode));
-System.out.println(bnode.equals(factory.createBlankNode()));
+System.out.println(bnode.equals(rdf.createBlankNode()));
```
> `true`
@@ -377,13 +382,13 @@ System.out.println(bnode.equals(factory.createBlankNode()));
Sometimes it can be beneficial to create a blank node based on a
localized _name_, without needing to keep object references
-to earlier `BlankNode` instances. For that purpose, `RDFFactory`
-may support the
-[expanded createBlankNode](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createBlankNode-java.lang.String-)
+to earlier `BlankNode` instances. For that purpose, the
+`RDF` interface provides the
+[expanded createBlankNode](apidocs/org/apache/commons/rdf/api/RDF.html#createBlankNode-java.lang.String-)
method:
```java
-BlankNode b1 = factory.createBlankNode("b1");
+BlankNode b1 = rdf.createBlankNode("b1");
```
Note that there is no requirement for the
@@ -398,22 +403,22 @@ System.out.println(b1.ntriplesString());
-Any later `createBlankNode("b1")` **on the same factory instance**
+Any later `createBlankNode("b1")` **on the same `RDF` instance**
returns a `BlankNode` which are
[equal](apidocs/org/apache/commons/rdf/api/BlankNode.html#equals-java.lang.Object-)
to the previous b1:
```java
-System.out.println(b1.equals(factory.createBlankNode("b1")));
+System.out.println(b1.equals(rdf.createBlankNode("b1")));
```
> `true`
-That means that care should be taken to create a new `RDFFactory` if making
-"different" blank nodes (e.g. parsed from a different RDF file)
+That means that care should be taken to create a new `RDF` instance
+if making "different" blank nodes (e.g. parsed from a different RDF file)
which accidfentally might have the same name:
```java
-System.out.println(b1.equals(new SimpleRDFFactory().createBlankNode("b1")));
+System.out.println(b1.equals(new SimpleRDF().createBlankNode("b1")));
```
> `false`
@@ -455,11 +460,11 @@ an _object_ of a [Triple](apidocs/org/apache/commons/rdf/api/Triple.html#getObje
or [Quad](apidocs/org/apache/commons/rdf/api/Quad.html#getObject--)
To create a [Literal](apidocs/org/apache/commons/rdf/api/Literal.html) instance
-from an `RDFFactory`, use
-[createLiteral](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createLiteral-java.lang.String-):
+from an `RDF` implementation, use
+[createLiteral](apidocs/org/apache/commons/rdf/api/RDF.html#createLiteral-java.lang.String-):
```java
-Literal literal = factory.createLiteral("Hello world!");
+Literal literal = rdf.createLiteral("Hello world!");
System.out.println(literal.ntriplesString());
```
@@ -515,11 +520,11 @@ literal</a> data type.
To create a literal with any other
[datatype](http://www.w3.org/TR/rdf11-concepts/#dfn-datatype-iri) (e.g. `xsd:double`),
then create the datatype `IRI` and pass it to the expanded
-[createLiteral](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createLiteral-java.lang.String-org.apache.commons.rdf.api.IRI-):
+[createLiteral](apidocs/org/apache/commons/rdf/api/RDF.html#createLiteral-java.lang.String-org.apache.commons.rdf.api.IRI-):
```java
-IRI xsdDouble = factory.createIRI("http://www.w3.org/2001/XMLSchema#double");
-Literal literalDouble = factory.createLiteral("13.37", xsdDouble);
+IRI xsdDouble = rdf.createIRI("http://www.w3.org/2001/XMLSchema#double");
+Literal literalDouble = rdf.createLiteral("13.37", xsdDouble);
System.out.println(literalDouble.ntriplesString());
```
@@ -536,7 +541,7 @@ XML Schema datatypes like `xsd:dateTime` and `xsd:float`. Using `Types`,
the above example can be simplified to:
```java
-Literal literalDouble2 = factory.createLiteral("13.37", Types.XSD_DOUBLE);
+Literal literalDouble2 = rdf.createLiteral("13.37", Types.XSD_DOUBLE);
```
As the constants in `Types` are all instances of `IRI`, so they can
@@ -552,10 +557,10 @@ System.out.println(Types.XSD_STRING.equals(literal.getDatatype()));
Literals may be created with an associated
[language tag](http://www.w3.org/TR/rdf11-concepts/#dfn-language-tagged-string)
-using the expanded [createLiteral](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createLiteral-java.lang.String-java.lang.String-):
+using the expanded [createLiteral](apidocs/org/apache/commons/rdf/api/RDF.html#createLiteral-java.lang.String-java.lang.String-):
```java
-Literal inSpanish = factory.createLiteral("�Hola, Mundo!", "es");
+Literal inSpanish = rdf.createLiteral("�Hola, Mundo!", "es");
System.out.println(inSpanish.ntriplesString());
System.out.println(inSpanish.getLexicalForm());
```
@@ -609,15 +614,15 @@ RDF 1.1 consists of:
* The [object](apidocs/org/apache/commons/rdf/api/Triple.html#getObject--), which is an [IRI](apidocs/org/apache/commons/rdf/api/IRI.html), a [BlankNode](apidocs/org/apache/commons/rdf/api/BlankNode.html) or a [Literal](apidocs/org/apache/commons/rdf/api/Literal.html)
-To construct a [Triple](apidocs/org/apache/commons/rdf/api/Triple.html) from a
-`RDFFactory`, use
-[createTriple](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createTriple-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-):
+To construct a [Triple](apidocs/org/apache/commons/rdf/api/Triple.html) from an
+`RDF` implementation, use
+[createTriple](apidocs/org/apache/commons/rdf/api/RDF.html#createTriple-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-):
```java
-BlankNodeOrIRI subject = factory.createBlankNode();
-IRI predicate = factory.createIRI("http://example.com/says");
-RDFTerm object = factory.createLiteral("Hello");
-Triple triple = factory.createTriple(subject, predicate, object);
+BlankNodeOrIRI subject = rdf.createBlankNode();
+IRI predicate = rdf.createIRI("http://example.com/says");
+RDFTerm object = rdf.createLiteral("Hello");
+Triple triple = rdf.createTriple(subject, predicate, object);
```
The subject of the triple can be retrieved
@@ -675,7 +680,7 @@ to another `Triple` if each of their subject, predicate and object are
equal:
```java
-System.out.println(triple.equals(factory.createTriple(subj, pred, obj)));
+System.out.println(triple.equals(rdf.createTriple(subj, pred, obj)));
```
> `true`
@@ -700,14 +705,14 @@ Commons RDF represents such statements using the class [Quad](apidocs/org/apache
* The [graph name](apidocs/org/apache/commons/rdf/api/Quad.html#getGraphName--), which is an [IRI](apidocs/org/apache/commons/rdf/api/IRI.html) or a [BlankNode](apidocs/org/apache/commons/rdf/api/BlankNode.html); wrapped as an `java.util.Optional`
-To create a `Quad`, use [createQuad](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createQuad-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-):
+To create a `Quad`, use [createQuad](apidocs/org/apache/commons/rdf/api/RDF.html#createQuad-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-):
```
-BlankNodeOrIRI graph = factory.createIRI("http://example.com/graph");
-BlankNodeOrIRI subject = factory.createBlankNode();
-IRI predicate = factory.createIRI("http://example.com/says");
-RDFTerm object = factory.createLiteral("Hello");
-Quad quad = factory.createQuad(graph, subject, predicate, object);
+BlankNodeOrIRI graph = rdf.createIRI("http://example.com/graph");
+BlankNodeOrIRI subject = rdf.createBlankNode();
+IRI predicate = rdf.createIRI("http://example.com/says");
+RDFTerm object = rdf.createLiteral("Hello");
+Quad quad = rdf.createQuad(graph, subject, predicate, object);
```
The subject, predicate and object are accessible just like in a `Triple`:
@@ -747,7 +752,7 @@ To create a quad in the _default graph_, supply `null` as the graph name
to the factory method:
```
-Quad otherQuad = factory.createQuad(null, subject, predicate, object);
+Quad otherQuad = rdf.createQuad(null, subject, predicate, object);
System.out.println(otherQuad.getGraphName().isPresent());
```
@@ -769,7 +774,7 @@ BlankNodeOrIRI g = quad.getGraphName().orElse(null);
if (g == null) {
System.out.println("In default graph");
}
-factory.createQuad(g,s,p,o);
+rdf.createQuad(g,s,p,o);
```
@@ -810,13 +815,13 @@ System.out.println(quadAsTriple.equals(otherQuad.asTriple());
> `true`
To create a triple from a quad, you will need to use
-[RDFFactory.createQuad](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createQuad-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-)
+[RDF.createQuad](apidocs/org/apache/commons/rdf/api/RDF.html#createQuad-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-)
providing the desired graph name:
```
Triple t; // ..
BlankNodeOrIRI g; // ..
-Quad q = factory.createQuad(g, t.getSubject(), t.getPredicate(), t.getObject());
+Quad q = rdf.createQuad(g, t.getSubject(), t.getPredicate(), t.getObject());
```
@@ -867,11 +872,11 @@ A [graph](http://www.w3.org/TR/rdf11-concepts/#section-rdf-graph)
is a collection of triples.
To create a [Graph](apidocs/org/apache/commons/rdf/api/Graph.html) instance
-from a `RDFFactory`, use
-[createGraph()](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createGraph--):
+from a `RDF` implementation, use
+[createGraph()](apidocs/org/apache/commons/rdf/api/RDF.html#createGraph--):
```java
-Graph graph = factory.createGraph();
+Graph graph = rdf.createGraph();
```
Implementations will typically also have other ways of retrieving a `Graph`,
@@ -892,9 +897,9 @@ _subject/predicate/object_ form of
[Graph.add](apidocs/org/apache/commons/rdf/api/Graph.html#add-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-):
```java
-IRI bob = factory.createIRI("http://example.com/bob");
-IRI nameIri = factory.createIRI("http://example.com/name");
-Literal bobName = factory.createLiteral("Bob");
+IRI bob = rdf.createIRI("http://example.com/bob");
+IRI nameIri = rdf.createIRI("http://example.com/name");
+Literal bobName = rdf.createLiteral("Bob");
graph.add(bob, nameIRI, bobName);
```
@@ -1037,11 +1042,11 @@ A [dataset](https://www.w3.org/TR/rdf11-concepts/#section-dataset)
is a collection of quads, or if you like, a collection of `Graph`s.
To create a [Dataset](apidocs/org/apache/commons/rdf/api/Dataset.html) instance
-from a `RDFFactory`, use
-[createDataset()](apidocs/org/apache/commons/rdf/api/RDFFactory.html#createDataset--):
+from a `RDF` implementation, use
+[createDataset()](apidocs/org/apache/commons/rdf/api/RDF.html#createDataset--):
```java
-Dataset dataset = factory.createDataset();
+Dataset dataset = rdf.createDataset();
```
Implementations will typically also have other ways of retrieving a `Dataset`,
@@ -1065,7 +1070,7 @@ dataset.remove(quad);
The convenience method [add(g,s,p,o)](apidocs/org/apache/commons/rdf/api/Dataset.html#add-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-) take an additional `BlankNodeOrIRI` parameter for the
-graph name - matching `RDFFactory.createQuad(g,s,p,o)`.
+graph name - matching `RDF.createQuad(g,s,p,o)`.
Note that the expanded pattern methods like [contains(g,s,p,o)](apidocs/org/apache/commons/rdf/api/Dataset.html#contains-java.util.Optional-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-) and
[stream(g,s,p,o)](apidocs/org/apache/commons/rdf/api/Dataset.html#stream-java.util.Optional-org.apache.commons.rdf.api.BlankNodeOrIRI-org.apache.commons.rdf.api.IRI-org.apache.commons.rdf.api.RDFTerm-) uses `null` as a wildcard pattern, and
@@ -1073,7 +1078,7 @@ therefore an explicit _graph name_ parameter must be supplied as [Optional.empty
or wrapped using [Optional.of(g)](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#of-T-):
```
-Literal foo = factory.createLiteral("Foo");
+Literal foo = rdf.createLiteral("Foo");
// Match Foo in any graph, any subject, any predicate
if (dataset.contains(null, null, null, foo)) {
System.out.println("Foo literal found");
@@ -1085,7 +1090,7 @@ if (dataset.contains(Optional.empty(), null, null, foo)) {
}
-BlankNodeOrIRI g1 = factory.createIRI("http://example.com/graph1");
+BlankNodeOrIRI g1 = rdf.createIRI("http://example.com/graph1");
// Match Foo in named graph, any subject, any predicate
if (dataset.contains(Optional.of(g1), null, null, foo)) {
System.out.println("Foo literal found in default graph");
@@ -1110,7 +1115,7 @@ It is possible to retrieve these graphs from a `Dataset` using:
```
Graph defaultGraph = dataset.getGraph();
-BlankNodeOrIRI graphName = factory.createIRI("http://example.com/graph");
+BlankNodeOrIRI graphName = rdf.createIRI("http://example.com/graph");
Optional<Graph> otherGraph = dataset.getGraph(graphName);
```
@@ -1198,43 +1203,44 @@ is a set of Java interfaces, which can be implemented by several Java RDF
frameworks. See the [implementations](implementations.html) page for an
updated list of providers.
-Implementations are free to choose their level of integration with Commons RDF.
-Several methods defined in Commons RDF therefore explicitly note the
-possibility of throwing a `UnsupportedOperationException` - however the
-implementations provided by Commons RDF
-
-Different RDF frameworks might have different mechanisms to retrieve a Commons
-RDF objects like `Graph` or `Triple` (e.g. returned from a query).
+Commons RDF defines a `RDF` interface as a factory for
+using a particular implementations' `RDFTerm`, `Triple`, `Quad`,
+`Graph` and `Dataset`. The `RDF` implementations
+also add adapter/converter methods to facilitate interoperability with their
+underlying framework's API.
-Commons RDF provides a `RDFFactory` interface as an interoperable
-way to create new instances, but does not mandate how the factory
-itself should be instantiated (e.g. a factory might be returned for an
-open network connection).
+Note that some RDF frameworks have several possibilities for creating a backend
+for a `Graph` or `Dataset`, which configuration is implementation-specific.
### Cross-compatibility
-While different frameworks will have their own classes implementing the Commons
-RDF interfaces, Commons RDF objects are intended to be cross-compatible. Thus a
-client would be able to mix and match objects from multiple implementations:
+While different frameworks have their own classes implementing the Commons
+RDF interfaces, Commons RDF objects are cross-compatible. Thus a
+client is able to mix and match objects from multiple implementations:
```java
-import com.example.foo.FooRDFFactory;
-import net.example.bar.BarGraph;
+import org.apache.commons.rdf.rdf4j.RDF4J;
+import org.apache.commons.rdf.jena.JenaRDF;
+
+RDF rdf4j = new RDF4J();
+JenaRDF jena = new JenaRDF();
+
+JenaGraph jenaGraph = jena.createGraph();
+// Jena-specific load method
+jenaGraph.asJenaModel().read("dataset.ttl");
-RDFFactory fooFactory = new FooRDFFactory();
-FooGraph g1 = (FooGraph) fooFactory.createGraph();
-// Foo-specific load method
-g1.load("dataset.ttl");
// Another Graph, from a different implementation
-Graph g2 = new BarGraph("localhost", 1337);
+Graph rdf4jGraph = rdf4j.createGraph();
-// Any factory can be used
-IRI iri1 = fooFactory.createIRI("http://example.com/property1");
+// Any RDF implementation can make RDFTerms
+IRI rdfIRI = rdf4j.createIRI("http://example.com/property1");
+// and used added to a different implementation's
+jenaGraph.add(rdfIRI,rdfIRI,rdfIRI);
// Both Triple and RDFTerm instances can be used
-//
+// with interoperability
for (Triple t1: g1.stream(null, iri1, null)) {
if (g2.contains(t1.getSubject(), null, t1.getObject())) {
g2.remove(t1);
@@ -1242,24 +1248,29 @@ for (Triple t1: g1.stream(null, iri1, null)) {
}
```
-_Note: Special care might need to be taken for cross-interoperability of
-`BlankNode` instances. While multiple triples with the same
-"foreign" `BlankNode` can be added without breaking their
-connections, the `Graph` is not required to
-return blank node instances that `.equals()` those
-inserted - specifically it is **not** required to persist the
-blank node [uniqueReference](apidocs/org/apache/commons/rdf/api/BlankNode.html#uniqueReference--).
- See
-[COMMONSRDF-15](https://issues.apache.org/jira/browse/COMMONSRDF-15)._
-
-The `.equals()` methods of `RDFTerm` interfaces are explicitly defined, so
-their instances can be compared across implementations.
+It is however generally recommended to use the matching `RDF` implementation
+for operations on a `Graph` or `Dataset` as it avoids unnecessary
+conversion round-trips.
_Note: The `Graph` implementation is not required to keep the JVM object
reference, e.g. after `g2.add(subj1, pred, obj)` it is not required to later
return the same `subj1` implementation in `g2.stream()`. Special care
should be taken if returned values needs to be casted to implementation
-specific types._
+specific types, e.g. using the appropriate adapter method from the
+desired `RDF` implementation._
+
+The `.equals()` methods of `RDFTerm`, `Triple` and `Quad`
+are explicitly defined, so their instances can be compared
+across implementations, and thus can safely
+be used for instance as keys in a `java.util.Map` or `java.util.Set`.
+
+_Note: Special care might need to be taken for cross-interoperability of
+`BlankNode` instances. While multiple triples/quads with the same
+"foreign" `BlankNode` can be added without breaking their
+connections, the `Graph`/`Quad` is not required to
+**return** blank node instances that `.equals()` those previously
+inserted - specifically implementations are **not** expected to persist the
+blank node [uniqueReference](apidocs/org/apache/commons/rdf/api/BlankNode.html#uniqueReference--)._
## Complete example
[12/50] [abbrv] incubator-commonsrdf git commit: JsonLDFactory ->
JsonLDRDF
Posted by st...@apache.org.
JsonLDFactory -> JsonLDRDF
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/430bc4d7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/430bc4d7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/430bc4d7
Branch: refs/heads/COMMONSRDF-7
Commit: 430bc4d7c253ab9a023c39ff0afe9e750ff422e0
Parents: defb7d8
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Oct 23 00:47:13 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Oct 23 00:47:13 2016 +0100
----------------------------------------------------------------------
.../apache/commons/rdf/jsonldjava/JsonLdGraphLike.java | 8 ++++----
.../apache/commons/rdf/jsonldjava/JsonLdQuadLike.java | 2 +-
.../org/apache/commons/rdf/jsonldjava/JsonLdRDF.java | 6 +++---
.../rdf/jsonldjava/experimental/JsonLdParser.java | 12 ++++++------
.../org/apache/commons/rdf/jsonldjava/package-info.java | 2 +-
.../services/org.apache.commons.rdf.api.RDFFactory | 2 +-
.../commons/rdf/jsonldjava/JsonLdFactoryTest.java | 2 +-
.../apache/commons/rdf/jsonldjava/JsonLdGraphTest.java | 2 +-
.../commons/rdf/jsonldjava/JsonLdParserBuilderTest.java | 2 +-
.../commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java | 4 ++--
10 files changed, 21 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/430bc4d7/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
index 401de1f..d4417ec 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
@@ -72,7 +72,7 @@ abstract class AbstractJsonLdGraphLike<T extends TripleLike>
*/
final String bnodePrefix;
- final JsonLdFactory factory;
+ final JsonLdRDF factory;
/**
* The underlying JSON-LD {@link RDFDataset}.
@@ -89,7 +89,7 @@ abstract class AbstractJsonLdGraphLike<T extends TripleLike>
AbstractJsonLdGraphLike(RDFDataset rdfDataSet, String bnodePrefix) {
this.rdfDataSet = Objects.requireNonNull(rdfDataSet);
this.bnodePrefix = Objects.requireNonNull(bnodePrefix);
- this.factory = new JsonLdFactory(bnodePrefix);
+ this.factory = new JsonLdRDF(bnodePrefix);
}
AbstractJsonLdGraphLike(String bnodePrefix) {
@@ -161,8 +161,8 @@ abstract class AbstractJsonLdGraphLike<T extends TripleLike>
* Convert JsonLd Quad to a Commons RDF {@link Triple} or {@link org.apache.commons.rdf.api.Quad}
*
*
- * @see JsonLdFactory#asTriple(Quad)
- * @see JsonLdFactory#asQuad(Quad)
+ * @see JsonLdRDF#asTriple(Quad)
+ * @see JsonLdRDF#asQuad(Quad)
* @param jsonldQuad jsonld quad to convert
* @return converted {@link TripleLike}
*/
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/430bc4d7/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
index acb429a..1584f9e 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
@@ -32,7 +32,7 @@ public interface JsonLdQuadLike<G extends RDFTerm> extends QuadLike<G>, JsonLdTr
// Note: We always pass the blankNodePrefix and don't rely on the internal
// blankNodePrefix in this static factory
- private static JsonLdFactory rdfTermFactory = new JsonLdFactory();
+ private static JsonLdRDF rdfTermFactory = new JsonLdRDF();
private final Quad quad;
private String blankNodePrefix;
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/430bc4d7/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
index d5c49f8..bb57b1a 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDF.java
@@ -35,16 +35,16 @@ import org.apache.commons.rdf.simple.Types;
import com.github.jsonldjava.core.RDFDataset;
import com.github.jsonldjava.core.RDFDataset.Node;
-public final class JsonLdFactory implements RDF {
+public final class JsonLdRDF implements RDF {
final String bnodePrefix;
- public JsonLdFactory() {
+ public JsonLdRDF() {
// An "outside Graph" bnodePrefix
this("urn:uuid:" + UUID.randomUUID() + "#b");
}
- JsonLdFactory(String bnodePrefix) {
+ JsonLdRDF(String bnodePrefix) {
this.bnodePrefix = Objects.requireNonNull(bnodePrefix);
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/430bc4d7/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java
index 464015f..ff3ffe8 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/experimental/JsonLdParser.java
@@ -32,7 +32,7 @@ import org.apache.commons.rdf.api.IRI;
import org.apache.commons.rdf.api.RDFSyntax;
import org.apache.commons.rdf.jsonldjava.JsonLdDataset;
import org.apache.commons.rdf.jsonldjava.JsonLdGraph;
-import org.apache.commons.rdf.jsonldjava.JsonLdFactory;
+import org.apache.commons.rdf.jsonldjava.JsonLdRDF;
import org.apache.commons.rdf.simple.experimental.AbstractRDFParser;
import com.github.jsonldjava.core.JsonLdError;
@@ -44,8 +44,8 @@ import com.github.jsonldjava.utils.JsonUtils;
public class JsonLdParser extends AbstractRDFParser<JsonLdParser> {
@Override
- protected JsonLdFactory createRDFTermFactory() {
- return new JsonLdFactory();
+ protected JsonLdRDF createRDFTermFactory() {
+ return new JsonLdRDF();
}
@Override
@@ -129,9 +129,9 @@ public class JsonLdParser extends AbstractRDFParser<JsonLdParser> {
}
}
- private JsonLdFactory getJsonLdFactory() {
- if (getRdfTermFactory().isPresent() && getRdfTermFactory().get() instanceof JsonLdFactory) {
- return (JsonLdFactory) getRdfTermFactory().get();
+ private JsonLdRDF getJsonLdFactory() {
+ if (getRdfTermFactory().isPresent() && getRdfTermFactory().get() instanceof JsonLdRDF) {
+ return (JsonLdRDF) getRdfTermFactory().get();
}
return createRDFTermFactory();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/430bc4d7/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/package-info.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/package-info.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/package-info.java
index 1cb5c77..7eb323b 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/package-info.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/package-info.java
@@ -18,7 +18,7 @@
/**
* Integration with jsonld-java
*
- * @see org.apache.commons.rdf.jsonldjava.JsonLdFactory
+ * @see org.apache.commons.rdf.jsonldjava.JsonLdRDF
* @see org.apache.commons.rdf.jsonldjava.JsonLdGraph
* @see org.apache.commons.rdf.jsonldjava.JsonLdUnionGraph
* @see org.apache.commons.rdf.jsonldjava.JsonLdDataset
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/430bc4d7/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory b/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
index ecb7535..2c97ca5 100644
--- a/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
+++ b/jsonld-java/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
@@ -1 +1 @@
-org.apache.commons.rdf.jsonldjava.JsonLdFactory
+org.apache.commons.rdf.jsonldjava.JsonLdRDF
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/430bc4d7/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
index ea87fa8..81fb532 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdFactoryTest.java
@@ -26,7 +26,7 @@ public class JsonLdFactoryTest extends AbstractRDFTermFactoryTest {
@Override
public RDF createFactory() {
- return new JsonLdFactory();
+ return new JsonLdRDF();
}
// TODO: Add support for checking for invalid lang/iri/blanknode IDs
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/430bc4d7/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java
index 51c768f..64e94e5 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphTest.java
@@ -24,7 +24,7 @@ public class JsonLdGraphTest extends AbstractGraphTest {
@Override
public RDF createFactory() {
- return new JsonLdFactory();
+ return new JsonLdRDF();
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/430bc4d7/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java
index bd3c6bb..6cdb841 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdParserBuilderTest.java
@@ -39,7 +39,7 @@ import org.junit.Test;
public class JsonLdParserBuilderTest {
private static final String TEST_JSONLD = "/test.jsonld";
- static JsonLdFactory factory = new JsonLdFactory();
+ static JsonLdRDF factory = new JsonLdRDF();
IRI test = factory.createIRI("http://example.com/test");
IRI Type = factory.createIRI("http://example.com/Type");
IRI type = factory.createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/430bc4d7/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
index f35a41b..dd44586 100644
--- a/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
+++ b/jsonld-java/src/test/java/org/apache/commons/rdf/jsonldjava/JsonLdServiceLoaderTest.java
@@ -31,10 +31,10 @@ public class JsonLdServiceLoaderTest {
public void testServiceLoaderLookup() {
ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class);
for (RDF impl : loader) {
- if (impl instanceof JsonLdFactory) {
+ if (impl instanceof JsonLdRDF) {
return; // yay
}
}
- fail("JsonLdFactory not found in ServiceLoader");
+ fail("JsonLdRDF not found in ServiceLoader");
}
}
[11/50] [abbrv] incubator-commonsrdf git commit: RDF4JFactory -> RDF4J
Posted by st...@apache.org.
RDF4JFactory -> RDF4J
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/defb7d81
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/defb7d81
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/defb7d81
Branch: refs/heads/COMMONSRDF-7
Commit: defb7d81ca349f1403ff261cff0acf08275e61b7
Parents: 790b605
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Oct 23 00:46:53 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Oct 23 00:46:53 2016 +0100
----------------------------------------------------------------------
.../org/apache/commons/rdf/rdf4j/RDF4J.java | 601 +++++++++++++++++++
.../commons/rdf/rdf4j/RDF4JBlankNode.java | 2 +-
.../apache/commons/rdf/rdf4j/RDF4JDataset.java | 4 +-
.../apache/commons/rdf/rdf4j/RDF4JFactory.java | 601 -------------------
.../apache/commons/rdf/rdf4j/RDF4JGraph.java | 10 +-
.../org/apache/commons/rdf/rdf4j/RDF4JIRI.java | 2 +-
.../apache/commons/rdf/rdf4j/RDF4JLiteral.java | 2 +-
.../org/apache/commons/rdf/rdf4j/RDF4JQuad.java | 2 +-
.../apache/commons/rdf/rdf4j/RDF4JTriple.java | 2 +-
.../rdf/rdf4j/experimental/RDF4JParser.java | 12 +-
.../rdf4j/impl/AbstractRepositoryGraphLike.java | 6 +-
.../rdf/rdf4j/impl/InternalRDF4JFactory.java | 14 +-
.../commons/rdf/rdf4j/impl/ModelGraphImpl.java | 6 +-
.../apache/commons/rdf/rdf4j/impl/QuadImpl.java | 10 +-
.../commons/rdf/rdf4j/impl/TripleImpl.java | 8 +-
.../apache/commons/rdf/rdf4j/package-info.java | 8 +-
.../org.apache.commons.rdf.api.RDFFactory | 2 +-
.../apache/commons/rdf/rdf4j/BlankNodeTest.java | 2 +-
.../org/apache/commons/rdf/rdf4j/GraphTest.java | 2 +-
.../commons/rdf/rdf4j/MemoryGraphTest.java | 6 +-
.../rdf/rdf4j/MemoryRDFTermFactoryTest.java | 2 +-
.../commons/rdf/rdf4j/NativeStoreGraphTest.java | 6 +-
.../rdf/rdf4j/RDF4JServiceLoaderTest.java | 4 +-
.../rdf/rdf4j/Rdf4JRDFTermFactoryTest.java | 2 +-
24 files changed, 658 insertions(+), 658 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
new file mode 100644
index 0000000..37dd7a2
--- /dev/null
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
@@ -0,0 +1,601 @@
+/**
+ * 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.rdf4j;
+
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+
+// To avoid confusion, avoid importing
+// classes that are in both
+// commons.rdf and openrdf.model (e.g. IRI, Literal)
+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.Quad;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.RDF;
+import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.api.TripleLike;
+import org.apache.commons.rdf.rdf4j.impl.InternalRDF4JFactory;
+import org.eclipse.rdf4j.model.BNode;
+import org.eclipse.rdf4j.model.Model;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.Statement;
+import org.eclipse.rdf4j.model.Value;
+import org.eclipse.rdf4j.model.ValueFactory;
+import org.eclipse.rdf4j.model.impl.LinkedHashModel;
+import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
+import org.eclipse.rdf4j.repository.Repository;
+import org.eclipse.rdf4j.repository.RepositoryConnection;
+import org.eclipse.rdf4j.repository.sail.SailRepository;
+import org.eclipse.rdf4j.sail.Sail;
+import org.eclipse.rdf4j.sail.memory.MemoryStore;
+
+/**
+ * RDF4J implementation of RDF.
+ * <p>
+ * The {@link #RDF4J()} constructor uses a {@link SimpleValueFactory}
+ * to create corresponding RDF4J {@link Value} instances. Alternatively, this
+ * factory can be constructed with a different {@link ValueFactory} using
+ * {@link #RDF4J(ValueFactory)}.
+ * <p>
+ * {@link #asRDFTerm(Value)} can be used to convert any RDF4J {@link Value} to
+ * an RDFTerm. Note that adapted {@link BNode}s are considered equal if they are
+ * converted with the same {@link RDF4J} instance and have the same
+ * {@link BNode#getID()}.
+ * <p>
+ * {@link #createGraph()} creates a new Graph backed by {@link LinkedHashModel}.
+ * To use other models, see {@link #asRDFTermGraph(Model)}.
+ * <p>
+ * To adapt a RDF4J {@link Repository} as a {@link Dataset} or {@link Graph},
+ * use {@link #asRDFTermDataset(Repository, Option...)}
+ * or
+ * {@link #asRDFTermGraph(Repository, Option...)}.
+ * <p>
+ * {@link #asTriple(Statement)} can be used to convert a RDF4J {@link Statement}
+ * to a Commons RDF {@link Triple}, and equivalent {@link #asQuad(Statement)} to
+ * convert a {@link Quad}.
+ * <p>
+ * To convert any {@link Triple} or {@link Quad} to to RDF4J {@link Statement},
+ * use {@link #asStatement(TripleLike)}. This recognises previously converted
+ * {@link RDF4JTriple}s and {@link RDF4JQuad}s without re-converting their
+ * {@link RDF4JTripleLike#asStatement()}.
+ * <p>
+ * Likewise, {@link #asValue(RDFTerm)} can be used to convert any Commons RDF
+ * {@link RDFTerm} to a corresponding RDF4J {@link Value}. This recognises
+ * previously converted {@link RDF4JTerm}s without re-converting their
+ * {@link RDF4JTerm#asValue()}.
+ * <p>
+ * For the purpose of {@link BlankNode} equivalence, this factory contains an
+ * internal {@link UUID} salt that is used by adapter methods like
+ * {@link #asQuad(Statement)}, {@link #asTriple(Statement)},
+ * {@link #asRDFTerm(Value)} as well as {@link #createBlankNode(String)}. As
+ * RDF4J {@link BNode} instances from multiple repositories or models may have
+ * the same {@link BNode#getID()}, converting them with the above methods might
+ * cause accidental {@link BlankNode} equivalence. Note that the {@link Graph}
+ * and {@link Dataset} adapter methods like
+ * {@link #asRDFTermDataset(Repository, Option...)}
+ * and
+ * {@link #asRDFTermGraph(Repository, Option...)}
+ * therefore uses a unique {@link RDF4J} internally.
+ *
+ */
+public final class RDF4J implements RDF {
+
+ /**
+ * InternalRDF4JFactory is deliberately abstract
+ */
+ private static InternalRDF4JFactory rdf4j = new InternalRDF4JFactory() {
+ };
+
+ public enum Option {
+ /**
+ * The Graph/Dataset should include any inferred statements
+ */
+ includeInferred,
+ /**
+ * The graph/dataset should handle {@link Repository#initialize()} (if
+ * needed) and {@link Repository#shutDown()} on {@link Graph#close()} /
+ * {@link Dataset#close()}.
+ */
+ handleInitAndShutdown
+ }
+
+ private final UUID salt;
+
+ private final ValueFactory valueFactory;
+
+ /**
+ * Construct an {@link RDF4J}.
+ *
+ */
+ public RDF4J() {
+ this(SimpleValueFactory.getInstance(), UUID.randomUUID());
+ }
+
+ /**
+ * Construct an {@link RDF4J}.
+ * <p>
+ * This constructor is intended for use with the value factory from
+ * {@link Repository#getValueFactory()} when using
+ * Repository-based graphs and datasets.
+ *
+ * @param valueFactory
+ * The RDF4J {@link ValueFactory} to use
+ */
+ public RDF4J(ValueFactory valueFactory) {
+ this(valueFactory, UUID.randomUUID());
+ }
+
+ /**
+ * Construct an {@link RDF4J}.
+ * <p>
+ * This constructor may be used if reproducible
+ * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable.
+ *
+ * @param salt
+ * An {@link UUID} salt to be used by any created
+ * {@link BlankNode}s for the purpose of
+ * {@link BlankNode#uniqueReference()}
+ */
+ public RDF4J(UUID salt) {
+ this(SimpleValueFactory.getInstance(), salt);
+ }
+ /**
+ * Construct an {@link RDF4J}.
+ * <p>
+ * This constructor may be used if reproducible
+ * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable.
+ *
+ * @param valueFactory
+ * The RDF4J {@link ValueFactory} to use
+ * @param salt
+ * An {@link UUID} salt to be used by any created
+ * {@link BlankNode}s for the purpose of
+ * {@link BlankNode#uniqueReference()}
+ */
+ public RDF4J(ValueFactory valueFactory, UUID salt) {
+ this.valueFactory = valueFactory;
+ this.salt = salt;
+ }
+
+ /**
+ * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Quad}.
+ * <p>
+ * For the purpose of {@link BlankNode} equivalence, this method will use an
+ * internal salt UUID that is unique per instance of
+ * {@link RDF4J}.
+ * <p>
+ * <strong>NOTE:</strong> If combining RDF4J {@link Statement}s multiple
+ * repositories or models, then their {@link BNode}s may have the same
+ * {@link BNode#getID()}, which with this method would become equivalent
+ * according to {@link BlankNode#equals(Object)} and
+ * {@link BlankNode#uniqueReference()}, unless a separate
+ * {@link RDF4J} instance is used per RDF4J repository/model.
+ *
+ * @param statement
+ * The statement to convert
+ * @return A {@link RDF4JQuad} that is equivalent to the statement
+ */
+ public RDF4JQuad asQuad(final Statement statement) {
+ return rdf4j.createQuadImpl(statement, salt);
+ }
+
+ /**
+ *
+ * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
+ * <p>
+ * The value will be of the same kind as the term, e.g. a
+ * {@link org.eclipse.rdf4j.model.BNode} is converted to a
+ * {@link org.apache.commons.rdf.api.BlankNode}, a
+ * {@link org.eclipse.rdf4j.model.IRI} is converted to a
+ * {@link org.apache.commons.rdf.api.IRI} and a
+ * {@link org.eclipse.rdf4j.model.Literal}. is converted to a
+ * {@link org.apache.commons.rdf.api.Literal}
+ * <p>
+ * For the purpose of {@link BlankNode} equivalence, this method will use an
+ * internal salt UUID that is unique per instance of
+ * {@link RDF4J}.
+ * <p>
+ * <strong>NOTE:</strong> If combining RDF4J values from multiple
+ * repositories or models, then their {@link BNode}s may have the same
+ * {@link BNode#getID()}, which with this method would become equivalent
+ * according to {@link BlankNode#equals(Object)} and
+ * {@link BlankNode#uniqueReference()}, unless a separate
+ * {@link RDF4J} instance is used per RDF4J repository/model.
+ *
+ * @param value
+ * The RDF4J {@link Value} to convert.
+ * @return A {@link RDFTerm} that corresponds to the RDF4J value
+ * @throws IllegalArgumentException
+ * if the value is not a BNode, Literal or IRI
+ */
+ public RDF4JTerm asRDFTerm(Value value) {
+ return asRDFTerm(value, salt);
+ }
+
+ /**
+ * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
+ * <p>
+ * The value will be of the same kind as the term, e.g. a
+ * {@link org.eclipse.rdf4j.model.BNode} is converted to a
+ * {@link org.apache.commons.rdf.api.BlankNode}, a
+ * {@link org.eclipse.rdf4j.model.IRI} is converted to a
+ * {@link org.apache.commons.rdf.api.IRI} and a
+ * {@link org.eclipse.rdf4j.model.Literal}. is converted to a
+ * {@link org.apache.commons.rdf.api.Literal}
+ *
+ * @param value
+ * The RDF4J {@link Value} to convert.
+ * @param salt
+ * A {@link UUID} salt to use for uniquely mapping any
+ * {@link BNode}s. The salt should typically be the same for
+ * multiple statements in the same {@link Repository} or
+ * {@link Model} to ensure {@link BlankNode#equals(Object)} and
+ * {@link BlankNode#uniqueReference()} works as intended.
+ * @return A {@link RDFTerm} that corresponds to the RDF4J value
+ * @throws IllegalArgumentException
+ * if the value is not a BNode, Literal or IRI
+ */
+ public static RDF4JTerm asRDFTerm(final Value value, UUID salt) {
+ if (value instanceof BNode) {
+ return rdf4j.createBlankNodeImpl((BNode) value, salt);
+ }
+ if (value instanceof org.eclipse.rdf4j.model.Literal) {
+ return rdf4j.createLiteralImpl((org.eclipse.rdf4j.model.Literal) value);
+ }
+ if (value instanceof org.eclipse.rdf4j.model.IRI) {
+ return rdf4j.createIRIImpl((org.eclipse.rdf4j.model.IRI) value);
+ }
+ throw new IllegalArgumentException("Value is not a BNode, Literal or IRI: " + value.getClass());
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Dataset}.
+ * <p>
+ * Changes to the dataset are reflected in the repository, and vice versa.
+ * <p>
+ * <strong>Note:</strong> Some operations on the {@link RDF4JDataset}
+ * requires the use of try-with-resources to close underlying
+ * {@link RepositoryConnection}s, including
+ * {@link RDF4JDataset#iterate()},
+ * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param options
+ * Zero or more {@link Option}
+ * @return A {@link Dataset} backed by the RDF4J repository.
+ */
+ public RDF4JDataset asRDFTermDataset(Repository repository, Option... options) {
+ EnumSet<Option> opts = optionSet(options);
+ return rdf4j.createRepositoryDatasetImpl(repository,
+ opts.contains(Option.handleInitAndShutdown),
+ opts.contains(Option.includeInferred));
+ }
+
+ /**
+ * Adapt an RDF4J {@link Model} as a Commons RDF {@link Graph}.
+ * <p>
+ * Changes to the graph are reflected in the model, and vice versa.
+ *
+ * @param model
+ * RDF4J {@link Model} to adapt.
+ * @return Adapted {@link Graph}.
+ */
+ public RDF4JGraph asRDFTermGraph(Model model) {
+ return rdf4j.createModelGraphImpl(model, this);
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
+ * <p>
+ * The graph will only include triples in the default graph (equivalent to
+ * context <code>new Resource[0]{null})</code> in RDF4J).
+ * <p>
+ * Changes to the graph are reflected in the repository, and vice versa.
+ * <p>
+ * <strong>Note:</strong> Some operations on the {@link RDF4JGraph}
+ * requires the use of try-with-resources to close underlying
+ * {@link RepositoryConnection}s, including
+ * {@link RDF4JGraph#iterate()} and
+ * {@link RDF4JGraph#stream()}.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param options
+ * Zero or more {@link Option}
+ * @return A {@link Graph} backed by the RDF4J repository.
+ */
+ public RDF4JGraph asRDFTermGraph(Repository repository, Option... options) {
+ EnumSet<Option> opts = optionSet(options);
+ return rdf4j.createRepositoryGraphImpl(repository,
+ opts.contains(Option.handleInitAndShutdown),
+ opts.contains(Option.includeInferred),
+ new Resource[]{null}); // default graph
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
+ * <p>
+ * The graph will include triples in any contexts (e.g. the union graph).
+ * <p>
+ * Changes to the graph are reflected in the repository, and vice versa.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param options
+ * Zero or more {@link Option}
+ * @return A union {@link Graph} backed by the RDF4J repository.
+ */
+ public RDF4JGraph asRDFTermGraphUnion(Repository repository, Option... options) {
+ EnumSet<Option> opts = optionSet(options);
+ return rdf4j.createRepositoryGraphImpl(repository,
+ opts.contains(Option.handleInitAndShutdown),
+ opts.contains(Option.includeInferred),
+ new Resource[]{}); // union graph
+
+ }
+
+ /**
+ * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
+ * <p>
+ * The graph will include triples in the specified contexts.
+ * <p>
+ * Changes to the graph are reflected in the repository, and vice versa.
+ * Triples added/removed to the graph are reflected in all the specified
+ * contexts.
+ * <p>
+ * <strong>Note:</strong> Some operations on the {@link RDF4JGraph}
+ * requires the use of try-with-resources to close underlying
+ * {@link RepositoryConnection}s, including
+ * {@link RDF4JGraph#iterate()} and
+ * {@link RDF4JGraph#stream()}.
+ *
+ * @param repository
+ * RDF4J {@link Repository} to connect to.
+ * @param contexts
+ * A {@link Set} of {@link BlankNodeOrIRI} specifying the graph
+ * names to use as a context. The set may include the value
+ * <code>null</code> to indicate the default graph. The empty set
+ * indicates any context, e.g. the <em>union graph</em>.
+ * @param option
+ * Zero or more {@link Option}s
+ * @return A {@link Graph} backed by the RDF4J repository.
+ */
+ public RDF4JGraph asRDFTermGraph(Repository repository, Set<? extends BlankNodeOrIRI> contexts,
+ Option... option) {
+ EnumSet<Option> opts = optionSet(option);
+ /** NOTE: asValue() deliberately CAN handle <code>null</code> */
+ Resource[] resources = contexts.stream().map(g -> (Resource) asValue(g)).toArray(Resource[]::new);
+ return rdf4j.createRepositoryGraphImpl(Objects.requireNonNull(repository),
+ opts.contains(Option.handleInitAndShutdown),
+ opts.contains(Option.includeInferred),
+ resources);
+ }
+
+ /**
+ * Adapt a Commons RDF {@link Triple} or {@link Quad} as a RDF4J
+ * {@link Statement}.
+ * <p>
+ * If the <code>tripleLike</code> argument is an {@link RDF4JTriple} or a
+ * {@link RDF4JQuad}, then its {@link RDF4JTripleLike#asStatement()} is
+ * returned as-is. Note that this means that a {@link RDF4JTriple} would
+ * preserve its {@link Statement#getContext()}, and that any
+ * {@link BlankNode}s would be deemed equivalent in RDF4J if they have the
+ * same {@link BNode#getID()}.
+ *
+ * @param tripleLike
+ * A {@link Triple} or {@link Quad} to adapt
+ * @return A corresponding {@link Statement}
+ */
+ public Statement asStatement(TripleLike tripleLike) {
+ if (tripleLike instanceof RDF4JTripleLike) {
+ // Return original statement - this covers both RDF4JQuad and
+ // RDF4JTriple
+ return ((RDF4JTripleLike) tripleLike).asStatement();
+ }
+
+ org.eclipse.rdf4j.model.Resource subject = (org.eclipse.rdf4j.model.Resource) asValue(tripleLike.getSubject());
+ org.eclipse.rdf4j.model.IRI predicate = (org.eclipse.rdf4j.model.IRI) asValue(tripleLike.getPredicate());
+ Value object = asValue(tripleLike.getObject());
+
+ org.eclipse.rdf4j.model.Resource context = null;
+ if (tripleLike instanceof Quad) {
+ Quad quad = (Quad) tripleLike;
+ context = (org.eclipse.rdf4j.model.Resource) asValue(quad.getGraphName().orElse(null));
+ }
+
+ return getValueFactory().createStatement(subject, predicate, object, context);
+ }
+
+ /**
+ * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Triple}.
+ * <p>
+ * For the purpose of {@link BlankNode} equivalence, this method will use an
+ * internal salt UUID that is unique per instance of
+ * {@link RDF4J}.
+ * <p>
+ * <strong>NOTE:</strong> If combining RDF4J statements from multiple
+ * repositories or models, then their {@link BNode}s may have the same
+ * {@link BNode#getID()}, which with this method would become equivalent
+ * according to {@link BlankNode#equals(Object)} and
+ * {@link BlankNode#uniqueReference()}, unless a separate
+ * {@link RDF4J} instance is used per RDF4J repository/model.
+ *
+ * @param statement
+ * The RDF4J {@link Statement} to adapt.
+ * @return A {@link RDF4JTriple} that is equivalent to the statement
+ */
+ public RDF4JTriple asTriple(final Statement statement) {
+ return rdf4j.createTripleImpl(statement, salt);
+ }
+
+ /**
+ * Adapt a Commons RDF {@link RDFTerm} as a RDF4J {@link Value}.
+ * <p>
+ * The value will be of the same kind as the term, e.g. a
+ * {@link org.apache.commons.rdf.api.BlankNode} is converted to a
+ * {@link org.eclipse.rdf4j.model.BNode}, a
+ * {@link org.apache.commons.rdf.api.IRI} is converted to a
+ * {@link org.eclipse.rdf4j.model.IRI} and a
+ * {@link org.apache.commons.rdf.api.Literal} is converted to a
+ * {@link org.eclipse.rdf4j.model.Literal}.
+ * <p>
+ * If the provided {@link RDFTerm} is <code>null</code>, then the returned
+ * value is <code>null</code>.
+ * <p>
+ * If the provided term is an instance of {@link RDF4JTerm}, then the
+ * {@link RDF4JTerm#asValue()} is returned without any conversion. Note that
+ * this could mean that a {@link Value} from a different kind of
+ * {@link ValueFactory} could be returned.
+ *
+ * @param term
+ * RDFTerm to adapt to RDF4J Value
+ * @return Adapted RDF4J {@link Value}
+ */
+ public Value asValue(RDFTerm term) {
+ if (term == null) {
+ return null;
+ }
+ if (term instanceof RDF4JTerm) {
+ // One of our own - avoid converting again.
+ // (This is crucial to avoid double-escaping in BlankNode)
+ return ((RDF4JTerm) term).asValue();
+ }
+ if (term instanceof org.apache.commons.rdf.api.IRI) {
+ org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) term;
+ return getValueFactory().createIRI(iri.getIRIString());
+ }
+ if (term instanceof org.apache.commons.rdf.api.Literal) {
+ org.apache.commons.rdf.api.Literal literal = (org.apache.commons.rdf.api.Literal) term;
+ String label = literal.getLexicalForm();
+ if (literal.getLanguageTag().isPresent()) {
+ String lang = literal.getLanguageTag().get();
+ return getValueFactory().createLiteral(label, lang);
+ }
+ org.eclipse.rdf4j.model.IRI dataType = (org.eclipse.rdf4j.model.IRI) asValue(literal.getDatatype());
+ return getValueFactory().createLiteral(label, dataType);
+ }
+ if (term instanceof BlankNode) {
+ // This is where it gets tricky to support round trips!
+ BlankNode blankNode = (BlankNode) term;
+ // FIXME: The uniqueReference might not be a valid BlankNode
+ // identifier..
+ // does it have to be in RDF4J?
+ return getValueFactory().createBNode(blankNode.uniqueReference());
+ }
+ throw new IllegalArgumentException("RDFTerm was not an IRI, Literal or BlankNode: " + term.getClass());
+ }
+
+ @Override
+ public RDF4JBlankNode createBlankNode() {
+ BNode bnode = getValueFactory().createBNode();
+ return (RDF4JBlankNode) asRDFTerm(bnode);
+ }
+
+ @Override
+ public RDF4JBlankNode createBlankNode(String name) {
+ BNode bnode = getValueFactory().createBNode(name);
+ return (RDF4JBlankNode) asRDFTerm(bnode);
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * <strong>Note:</strong> Some operations on the {@link RDF4JDataset}
+ * requires the use of try-with-resources to close underlying
+ * {@link RepositoryConnection}s, including
+ * {@link RDF4JDataset#iterate()},
+ * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}.
+ *
+ */
+ @Override
+ public RDF4JDataset createDataset() {
+ Sail sail = new MemoryStore();
+ Repository repository = new SailRepository(sail);
+ return rdf4j.createRepositoryDatasetImpl(repository, true, false);
+ }
+
+ @Override
+ public RDF4JGraph createGraph() {
+ return asRDFTermGraph(new LinkedHashModel());
+ }
+
+ @Override
+ public RDF4JIRI createIRI(String iri) throws IllegalArgumentException {
+ return (RDF4JIRI) asRDFTerm(getValueFactory().createIRI(iri));
+ }
+
+ @Override
+ public RDF4JLiteral createLiteral(String lexicalForm)
+ throws IllegalArgumentException {
+ org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm);
+ return (RDF4JLiteral) asRDFTerm(lit);
+ }
+
+ @Override
+ public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, org.apache.commons.rdf.api.IRI dataType)
+ throws IllegalArgumentException {
+ org.eclipse.rdf4j.model.IRI iri = getValueFactory().createIRI(dataType.getIRIString());
+ org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, iri);
+ return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit);
+ }
+
+ @Override
+ public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, String languageTag)
+ throws IllegalArgumentException {
+ org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, languageTag);
+ return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit);
+ }
+
+ @Override
+ public RDF4JTriple createTriple(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object)
+ throws IllegalArgumentException {
+ final Statement statement = getValueFactory().createStatement(
+ (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate),
+ asValue(object));
+ return asTriple(statement);
+ }
+
+ @Override
+ public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate,
+ RDFTerm object) throws IllegalArgumentException {
+ final Statement statement = getValueFactory().createStatement(
+ (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate),
+ asValue(object), (org.eclipse.rdf4j.model.Resource) asValue(graphName));
+ return asQuad(statement);
+ }
+
+ public ValueFactory getValueFactory() {
+ return valueFactory;
+ }
+
+ private EnumSet<Option> optionSet(Option... options) {
+ EnumSet<Option> opts = EnumSet.noneOf(Option.class);
+ opts.addAll(Arrays.asList(options));
+ return opts;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java
index 2ed616f..15ca381 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java
@@ -27,7 +27,7 @@ import org.eclipse.rdf4j.model.BNode;
* The underlying RDF4J {@link BNode} instance can
* be retrieved with {@link #asValue()}.
*
- * @see RDF4JFactory#createBlankNode()
+ * @see RDF4J#createBlankNode()
*/
public interface RDF4JBlankNode extends RDF4JBlankNodeOrIRI, BlankNode {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
index 2066c34..28c2659 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java
@@ -30,8 +30,8 @@ import org.apache.commons.rdf.api.RDFTerm;
/**
* Marker interface for RDF4J implementations of Dataset.
*
- * @see RDF4JFactory#createDataset()
- * @see RDF4JFactory#asRDFTermDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)
+ * @see RDF4J#createDataset()
+ * @see RDF4J#asRDFTermDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...)
*/
public interface RDF4JDataset extends Dataset, RDF4JGraphLike<Quad> {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JFactory.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JFactory.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JFactory.java
deleted file mode 100644
index 8dd9745..0000000
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JFactory.java
+++ /dev/null
@@ -1,601 +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.rdf4j;
-
-import java.util.Arrays;
-import java.util.EnumSet;
-import java.util.Objects;
-import java.util.Set;
-import java.util.UUID;
-
-// To avoid confusion, avoid importing
-// classes that are in both
-// commons.rdf and openrdf.model (e.g. IRI, Literal)
-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.Quad;
-import org.apache.commons.rdf.api.RDFTerm;
-import org.apache.commons.rdf.api.RDF;
-import org.apache.commons.rdf.api.Triple;
-import org.apache.commons.rdf.api.TripleLike;
-import org.apache.commons.rdf.rdf4j.impl.InternalRDF4JFactory;
-import org.eclipse.rdf4j.model.BNode;
-import org.eclipse.rdf4j.model.Model;
-import org.eclipse.rdf4j.model.Resource;
-import org.eclipse.rdf4j.model.Statement;
-import org.eclipse.rdf4j.model.Value;
-import org.eclipse.rdf4j.model.ValueFactory;
-import org.eclipse.rdf4j.model.impl.LinkedHashModel;
-import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
-import org.eclipse.rdf4j.repository.Repository;
-import org.eclipse.rdf4j.repository.RepositoryConnection;
-import org.eclipse.rdf4j.repository.sail.SailRepository;
-import org.eclipse.rdf4j.sail.Sail;
-import org.eclipse.rdf4j.sail.memory.MemoryStore;
-
-/**
- * RDF4J implementation of RDF.
- * <p>
- * The {@link #RDF4JFactory()} constructor uses a {@link SimpleValueFactory}
- * to create corresponding RDF4J {@link Value} instances. Alternatively, this
- * factory can be constructed with a different {@link ValueFactory} using
- * {@link #RDF4JFactory(ValueFactory)}.
- * <p>
- * {@link #asRDFTerm(Value)} can be used to convert any RDF4J {@link Value} to
- * an RDFTerm. Note that adapted {@link BNode}s are considered equal if they are
- * converted with the same {@link RDF4JFactory} instance and have the same
- * {@link BNode#getID()}.
- * <p>
- * {@link #createGraph()} creates a new Graph backed by {@link LinkedHashModel}.
- * To use other models, see {@link #asRDFTermGraph(Model)}.
- * <p>
- * To adapt a RDF4J {@link Repository} as a {@link Dataset} or {@link Graph},
- * use {@link #asRDFTermDataset(Repository, Option...)}
- * or
- * {@link #asRDFTermGraph(Repository, Option...)}.
- * <p>
- * {@link #asTriple(Statement)} can be used to convert a RDF4J {@link Statement}
- * to a Commons RDF {@link Triple}, and equivalent {@link #asQuad(Statement)} to
- * convert a {@link Quad}.
- * <p>
- * To convert any {@link Triple} or {@link Quad} to to RDF4J {@link Statement},
- * use {@link #asStatement(TripleLike)}. This recognises previously converted
- * {@link RDF4JTriple}s and {@link RDF4JQuad}s without re-converting their
- * {@link RDF4JTripleLike#asStatement()}.
- * <p>
- * Likewise, {@link #asValue(RDFTerm)} can be used to convert any Commons RDF
- * {@link RDFTerm} to a corresponding RDF4J {@link Value}. This recognises
- * previously converted {@link RDF4JTerm}s without re-converting their
- * {@link RDF4JTerm#asValue()}.
- * <p>
- * For the purpose of {@link BlankNode} equivalence, this factory contains an
- * internal {@link UUID} salt that is used by adapter methods like
- * {@link #asQuad(Statement)}, {@link #asTriple(Statement)},
- * {@link #asRDFTerm(Value)} as well as {@link #createBlankNode(String)}. As
- * RDF4J {@link BNode} instances from multiple repositories or models may have
- * the same {@link BNode#getID()}, converting them with the above methods might
- * cause accidental {@link BlankNode} equivalence. Note that the {@link Graph}
- * and {@link Dataset} adapter methods like
- * {@link #asRDFTermDataset(Repository, Option...)}
- * and
- * {@link #asRDFTermGraph(Repository, Option...)}
- * therefore uses a unique {@link RDF4JFactory} internally.
- *
- */
-public final class RDF4JFactory implements RDF {
-
- /**
- * InternalRDF4JFactory is deliberately abstract
- */
- private static InternalRDF4JFactory rdf4j = new InternalRDF4JFactory() {
- };
-
- public enum Option {
- /**
- * The Graph/Dataset should include any inferred statements
- */
- includeInferred,
- /**
- * The graph/dataset should handle {@link Repository#initialize()} (if
- * needed) and {@link Repository#shutDown()} on {@link Graph#close()} /
- * {@link Dataset#close()}.
- */
- handleInitAndShutdown
- }
-
- private final UUID salt;
-
- private final ValueFactory valueFactory;
-
- /**
- * Construct an {@link RDF4JFactory}.
- *
- */
- public RDF4JFactory() {
- this(SimpleValueFactory.getInstance(), UUID.randomUUID());
- }
-
- /**
- * Construct an {@link RDF4JFactory}.
- * <p>
- * This constructor is intended for use with the value factory from
- * {@link Repository#getValueFactory()} when using
- * Repository-based graphs and datasets.
- *
- * @param valueFactory
- * The RDF4J {@link ValueFactory} to use
- */
- public RDF4JFactory(ValueFactory valueFactory) {
- this(valueFactory, UUID.randomUUID());
- }
-
- /**
- * Construct an {@link RDF4JFactory}.
- * <p>
- * This constructor may be used if reproducible
- * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable.
- *
- * @param salt
- * An {@link UUID} salt to be used by any created
- * {@link BlankNode}s for the purpose of
- * {@link BlankNode#uniqueReference()}
- */
- public RDF4JFactory(UUID salt) {
- this(SimpleValueFactory.getInstance(), salt);
- }
- /**
- * Construct an {@link RDF4JFactory}.
- * <p>
- * This constructor may be used if reproducible
- * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable.
- *
- * @param valueFactory
- * The RDF4J {@link ValueFactory} to use
- * @param salt
- * An {@link UUID} salt to be used by any created
- * {@link BlankNode}s for the purpose of
- * {@link BlankNode#uniqueReference()}
- */
- public RDF4JFactory(ValueFactory valueFactory, UUID salt) {
- this.valueFactory = valueFactory;
- this.salt = salt;
- }
-
- /**
- * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Quad}.
- * <p>
- * For the purpose of {@link BlankNode} equivalence, this method will use an
- * internal salt UUID that is unique per instance of
- * {@link RDF4JFactory}.
- * <p>
- * <strong>NOTE:</strong> If combining RDF4J {@link Statement}s multiple
- * repositories or models, then their {@link BNode}s may have the same
- * {@link BNode#getID()}, which with this method would become equivalent
- * according to {@link BlankNode#equals(Object)} and
- * {@link BlankNode#uniqueReference()}, unless a separate
- * {@link RDF4JFactory} instance is used per RDF4J repository/model.
- *
- * @param statement
- * The statement to convert
- * @return A {@link RDF4JQuad} that is equivalent to the statement
- */
- public RDF4JQuad asQuad(final Statement statement) {
- return rdf4j.createQuadImpl(statement, salt);
- }
-
- /**
- *
- * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
- * <p>
- * The value will be of the same kind as the term, e.g. a
- * {@link org.eclipse.rdf4j.model.BNode} is converted to a
- * {@link org.apache.commons.rdf.api.BlankNode}, a
- * {@link org.eclipse.rdf4j.model.IRI} is converted to a
- * {@link org.apache.commons.rdf.api.IRI} and a
- * {@link org.eclipse.rdf4j.model.Literal}. is converted to a
- * {@link org.apache.commons.rdf.api.Literal}
- * <p>
- * For the purpose of {@link BlankNode} equivalence, this method will use an
- * internal salt UUID that is unique per instance of
- * {@link RDF4JFactory}.
- * <p>
- * <strong>NOTE:</strong> If combining RDF4J values from multiple
- * repositories or models, then their {@link BNode}s may have the same
- * {@link BNode#getID()}, which with this method would become equivalent
- * according to {@link BlankNode#equals(Object)} and
- * {@link BlankNode#uniqueReference()}, unless a separate
- * {@link RDF4JFactory} instance is used per RDF4J repository/model.
- *
- * @param value
- * The RDF4J {@link Value} to convert.
- * @return A {@link RDFTerm} that corresponds to the RDF4J value
- * @throws IllegalArgumentException
- * if the value is not a BNode, Literal or IRI
- */
- public RDF4JTerm asRDFTerm(Value value) {
- return asRDFTerm(value, salt);
- }
-
- /**
- * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
- * <p>
- * The value will be of the same kind as the term, e.g. a
- * {@link org.eclipse.rdf4j.model.BNode} is converted to a
- * {@link org.apache.commons.rdf.api.BlankNode}, a
- * {@link org.eclipse.rdf4j.model.IRI} is converted to a
- * {@link org.apache.commons.rdf.api.IRI} and a
- * {@link org.eclipse.rdf4j.model.Literal}. is converted to a
- * {@link org.apache.commons.rdf.api.Literal}
- *
- * @param value
- * The RDF4J {@link Value} to convert.
- * @param salt
- * A {@link UUID} salt to use for uniquely mapping any
- * {@link BNode}s. The salt should typically be the same for
- * multiple statements in the same {@link Repository} or
- * {@link Model} to ensure {@link BlankNode#equals(Object)} and
- * {@link BlankNode#uniqueReference()} works as intended.
- * @return A {@link RDFTerm} that corresponds to the RDF4J value
- * @throws IllegalArgumentException
- * if the value is not a BNode, Literal or IRI
- */
- public static RDF4JTerm asRDFTerm(final Value value, UUID salt) {
- if (value instanceof BNode) {
- return rdf4j.createBlankNodeImpl((BNode) value, salt);
- }
- if (value instanceof org.eclipse.rdf4j.model.Literal) {
- return rdf4j.createLiteralImpl((org.eclipse.rdf4j.model.Literal) value);
- }
- if (value instanceof org.eclipse.rdf4j.model.IRI) {
- return rdf4j.createIRIImpl((org.eclipse.rdf4j.model.IRI) value);
- }
- throw new IllegalArgumentException("Value is not a BNode, Literal or IRI: " + value.getClass());
- }
-
- /**
- * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Dataset}.
- * <p>
- * Changes to the dataset are reflected in the repository, and vice versa.
- * <p>
- * <strong>Note:</strong> Some operations on the {@link RDF4JDataset}
- * requires the use of try-with-resources to close underlying
- * {@link RepositoryConnection}s, including
- * {@link RDF4JDataset#iterate()},
- * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}.
- *
- * @param repository
- * RDF4J {@link Repository} to connect to.
- * @param options
- * Zero or more {@link Option}
- * @return A {@link Dataset} backed by the RDF4J repository.
- */
- public RDF4JDataset asRDFTermDataset(Repository repository, Option... options) {
- EnumSet<Option> opts = optionSet(options);
- return rdf4j.createRepositoryDatasetImpl(repository,
- opts.contains(Option.handleInitAndShutdown),
- opts.contains(Option.includeInferred));
- }
-
- /**
- * Adapt an RDF4J {@link Model} as a Commons RDF {@link Graph}.
- * <p>
- * Changes to the graph are reflected in the model, and vice versa.
- *
- * @param model
- * RDF4J {@link Model} to adapt.
- * @return Adapted {@link Graph}.
- */
- public RDF4JGraph asRDFTermGraph(Model model) {
- return rdf4j.createModelGraphImpl(model, this);
- }
-
- /**
- * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
- * <p>
- * The graph will only include triples in the default graph (equivalent to
- * context <code>new Resource[0]{null})</code> in RDF4J).
- * <p>
- * Changes to the graph are reflected in the repository, and vice versa.
- * <p>
- * <strong>Note:</strong> Some operations on the {@link RDF4JGraph}
- * requires the use of try-with-resources to close underlying
- * {@link RepositoryConnection}s, including
- * {@link RDF4JGraph#iterate()} and
- * {@link RDF4JGraph#stream()}.
- *
- * @param repository
- * RDF4J {@link Repository} to connect to.
- * @param options
- * Zero or more {@link Option}
- * @return A {@link Graph} backed by the RDF4J repository.
- */
- public RDF4JGraph asRDFTermGraph(Repository repository, Option... options) {
- EnumSet<Option> opts = optionSet(options);
- return rdf4j.createRepositoryGraphImpl(repository,
- opts.contains(Option.handleInitAndShutdown),
- opts.contains(Option.includeInferred),
- new Resource[]{null}); // default graph
- }
-
- /**
- * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
- * <p>
- * The graph will include triples in any contexts (e.g. the union graph).
- * <p>
- * Changes to the graph are reflected in the repository, and vice versa.
- *
- * @param repository
- * RDF4J {@link Repository} to connect to.
- * @param options
- * Zero or more {@link Option}
- * @return A union {@link Graph} backed by the RDF4J repository.
- */
- public RDF4JGraph asRDFTermGraphUnion(Repository repository, Option... options) {
- EnumSet<Option> opts = optionSet(options);
- return rdf4j.createRepositoryGraphImpl(repository,
- opts.contains(Option.handleInitAndShutdown),
- opts.contains(Option.includeInferred),
- new Resource[]{}); // union graph
-
- }
-
- /**
- * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}.
- * <p>
- * The graph will include triples in the specified contexts.
- * <p>
- * Changes to the graph are reflected in the repository, and vice versa.
- * Triples added/removed to the graph are reflected in all the specified
- * contexts.
- * <p>
- * <strong>Note:</strong> Some operations on the {@link RDF4JGraph}
- * requires the use of try-with-resources to close underlying
- * {@link RepositoryConnection}s, including
- * {@link RDF4JGraph#iterate()} and
- * {@link RDF4JGraph#stream()}.
- *
- * @param repository
- * RDF4J {@link Repository} to connect to.
- * @param contexts
- * A {@link Set} of {@link BlankNodeOrIRI} specifying the graph
- * names to use as a context. The set may include the value
- * <code>null</code> to indicate the default graph. The empty set
- * indicates any context, e.g. the <em>union graph</em>.
- * @param option
- * Zero or more {@link Option}s
- * @return A {@link Graph} backed by the RDF4J repository.
- */
- public RDF4JGraph asRDFTermGraph(Repository repository, Set<? extends BlankNodeOrIRI> contexts,
- Option... option) {
- EnumSet<Option> opts = optionSet(option);
- /** NOTE: asValue() deliberately CAN handle <code>null</code> */
- Resource[] resources = contexts.stream().map(g -> (Resource) asValue(g)).toArray(Resource[]::new);
- return rdf4j.createRepositoryGraphImpl(Objects.requireNonNull(repository),
- opts.contains(Option.handleInitAndShutdown),
- opts.contains(Option.includeInferred),
- resources);
- }
-
- /**
- * Adapt a Commons RDF {@link Triple} or {@link Quad} as a RDF4J
- * {@link Statement}.
- * <p>
- * If the <code>tripleLike</code> argument is an {@link RDF4JTriple} or a
- * {@link RDF4JQuad}, then its {@link RDF4JTripleLike#asStatement()} is
- * returned as-is. Note that this means that a {@link RDF4JTriple} would
- * preserve its {@link Statement#getContext()}, and that any
- * {@link BlankNode}s would be deemed equivalent in RDF4J if they have the
- * same {@link BNode#getID()}.
- *
- * @param tripleLike
- * A {@link Triple} or {@link Quad} to adapt
- * @return A corresponding {@link Statement}
- */
- public Statement asStatement(TripleLike tripleLike) {
- if (tripleLike instanceof RDF4JTripleLike) {
- // Return original statement - this covers both RDF4JQuad and
- // RDF4JTriple
- return ((RDF4JTripleLike) tripleLike).asStatement();
- }
-
- org.eclipse.rdf4j.model.Resource subject = (org.eclipse.rdf4j.model.Resource) asValue(tripleLike.getSubject());
- org.eclipse.rdf4j.model.IRI predicate = (org.eclipse.rdf4j.model.IRI) asValue(tripleLike.getPredicate());
- Value object = asValue(tripleLike.getObject());
-
- org.eclipse.rdf4j.model.Resource context = null;
- if (tripleLike instanceof Quad) {
- Quad quad = (Quad) tripleLike;
- context = (org.eclipse.rdf4j.model.Resource) asValue(quad.getGraphName().orElse(null));
- }
-
- return getValueFactory().createStatement(subject, predicate, object, context);
- }
-
- /**
- * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Triple}.
- * <p>
- * For the purpose of {@link BlankNode} equivalence, this method will use an
- * internal salt UUID that is unique per instance of
- * {@link RDF4JFactory}.
- * <p>
- * <strong>NOTE:</strong> If combining RDF4J statements from multiple
- * repositories or models, then their {@link BNode}s may have the same
- * {@link BNode#getID()}, which with this method would become equivalent
- * according to {@link BlankNode#equals(Object)} and
- * {@link BlankNode#uniqueReference()}, unless a separate
- * {@link RDF4JFactory} instance is used per RDF4J repository/model.
- *
- * @param statement
- * The RDF4J {@link Statement} to adapt.
- * @return A {@link RDF4JTriple} that is equivalent to the statement
- */
- public RDF4JTriple asTriple(final Statement statement) {
- return rdf4j.createTripleImpl(statement, salt);
- }
-
- /**
- * Adapt a Commons RDF {@link RDFTerm} as a RDF4J {@link Value}.
- * <p>
- * The value will be of the same kind as the term, e.g. a
- * {@link org.apache.commons.rdf.api.BlankNode} is converted to a
- * {@link org.eclipse.rdf4j.model.BNode}, a
- * {@link org.apache.commons.rdf.api.IRI} is converted to a
- * {@link org.eclipse.rdf4j.model.IRI} and a
- * {@link org.apache.commons.rdf.api.Literal} is converted to a
- * {@link org.eclipse.rdf4j.model.Literal}.
- * <p>
- * If the provided {@link RDFTerm} is <code>null</code>, then the returned
- * value is <code>null</code>.
- * <p>
- * If the provided term is an instance of {@link RDF4JTerm}, then the
- * {@link RDF4JTerm#asValue()} is returned without any conversion. Note that
- * this could mean that a {@link Value} from a different kind of
- * {@link ValueFactory} could be returned.
- *
- * @param term
- * RDFTerm to adapt to RDF4J Value
- * @return Adapted RDF4J {@link Value}
- */
- public Value asValue(RDFTerm term) {
- if (term == null) {
- return null;
- }
- if (term instanceof RDF4JTerm) {
- // One of our own - avoid converting again.
- // (This is crucial to avoid double-escaping in BlankNode)
- return ((RDF4JTerm) term).asValue();
- }
- if (term instanceof org.apache.commons.rdf.api.IRI) {
- org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) term;
- return getValueFactory().createIRI(iri.getIRIString());
- }
- if (term instanceof org.apache.commons.rdf.api.Literal) {
- org.apache.commons.rdf.api.Literal literal = (org.apache.commons.rdf.api.Literal) term;
- String label = literal.getLexicalForm();
- if (literal.getLanguageTag().isPresent()) {
- String lang = literal.getLanguageTag().get();
- return getValueFactory().createLiteral(label, lang);
- }
- org.eclipse.rdf4j.model.IRI dataType = (org.eclipse.rdf4j.model.IRI) asValue(literal.getDatatype());
- return getValueFactory().createLiteral(label, dataType);
- }
- if (term instanceof BlankNode) {
- // This is where it gets tricky to support round trips!
- BlankNode blankNode = (BlankNode) term;
- // FIXME: The uniqueReference might not be a valid BlankNode
- // identifier..
- // does it have to be in RDF4J?
- return getValueFactory().createBNode(blankNode.uniqueReference());
- }
- throw new IllegalArgumentException("RDFTerm was not an IRI, Literal or BlankNode: " + term.getClass());
- }
-
- @Override
- public RDF4JBlankNode createBlankNode() {
- BNode bnode = getValueFactory().createBNode();
- return (RDF4JBlankNode) asRDFTerm(bnode);
- }
-
- @Override
- public RDF4JBlankNode createBlankNode(String name) {
- BNode bnode = getValueFactory().createBNode(name);
- return (RDF4JBlankNode) asRDFTerm(bnode);
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * <strong>Note:</strong> Some operations on the {@link RDF4JDataset}
- * requires the use of try-with-resources to close underlying
- * {@link RepositoryConnection}s, including
- * {@link RDF4JDataset#iterate()},
- * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}.
- *
- */
- @Override
- public RDF4JDataset createDataset() {
- Sail sail = new MemoryStore();
- Repository repository = new SailRepository(sail);
- return rdf4j.createRepositoryDatasetImpl(repository, true, false);
- }
-
- @Override
- public RDF4JGraph createGraph() {
- return asRDFTermGraph(new LinkedHashModel());
- }
-
- @Override
- public RDF4JIRI createIRI(String iri) throws IllegalArgumentException {
- return (RDF4JIRI) asRDFTerm(getValueFactory().createIRI(iri));
- }
-
- @Override
- public RDF4JLiteral createLiteral(String lexicalForm)
- throws IllegalArgumentException {
- org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm);
- return (RDF4JLiteral) asRDFTerm(lit);
- }
-
- @Override
- public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, org.apache.commons.rdf.api.IRI dataType)
- throws IllegalArgumentException {
- org.eclipse.rdf4j.model.IRI iri = getValueFactory().createIRI(dataType.getIRIString());
- org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, iri);
- return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit);
- }
-
- @Override
- public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, String languageTag)
- throws IllegalArgumentException {
- org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, languageTag);
- return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit);
- }
-
- @Override
- public RDF4JTriple createTriple(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object)
- throws IllegalArgumentException {
- final Statement statement = getValueFactory().createStatement(
- (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate),
- asValue(object));
- return asTriple(statement);
- }
-
- @Override
- public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate,
- RDFTerm object) throws IllegalArgumentException {
- final Statement statement = getValueFactory().createStatement(
- (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate),
- asValue(object), (org.eclipse.rdf4j.model.Resource) asValue(graphName));
- return asQuad(statement);
- }
-
- public ValueFactory getValueFactory() {
- return valueFactory;
- }
-
- private EnumSet<Option> optionSet(Option... options) {
- EnumSet<Option> opts = EnumSet.noneOf(Option.class);
- opts.addAll(Arrays.asList(options));
- return opts;
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
index b7ef9a2..68978ce 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java
@@ -33,10 +33,10 @@ import org.eclipse.rdf4j.repository.Repository;
/**
* Marker interface for RDF4J implementations of Graph.
*
- * @see RDF4JFactory#createGraph()
- * @see RDF4JFactory#asRDFTermGraph(Model)
- * @see RDF4JFactory#asRDFTermGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)
- * @see RDF4JFactory#asRDFTermGraphUnion(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)
+ * @see RDF4J#createGraph()
+ * @see RDF4J#asRDFTermGraph(Model)
+ * @see RDF4J#asRDFTermGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...)
+ * @see RDF4J#asRDFTermGraphUnion(Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...)
* @see RDF4JDataset#getGraph()
* @see RDF4JDataset#getGraph(BlankNodeOrIRI)
*/
@@ -64,7 +64,7 @@ public interface RDF4JGraph extends Graph, RDF4JGraphLike<Triple> {
* Note that the context mask itself cannot be <code>null</code>.
* <p>
* The returned set is an immutable copy; to specify a different mask, use
- * {@link RDF4JFactory#asRDFTermGraph(Repository, Set, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)}
+ * {@link RDF4J#asRDFTermGraph(Repository, Set, org.apache.commons.rdf.rdf4j.RDF4J.Option...)}
*
* @return The context mask as a set of {@link BlankNodeOrIRI} graph names, which
* may contain the value <code>null</code>.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java
index 270567b..72c83fa 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java
@@ -24,7 +24,7 @@ package org.apache.commons.rdf.rdf4j;
* The underlying RDF4J {@link org.eclipse.rdf4j.model.IRI}
* instance can be retrieved with {@link #asValue()}.
*
- * @see RDF4JFactory#createIRI(String)
+ * @see RDF4J#createIRI(String)
*/
public interface RDF4JIRI
extends RDF4JBlankNodeOrIRI, org.apache.commons.rdf.api.IRI {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JLiteral.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JLiteral.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JLiteral.java
index f6b0349..6022da7 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JLiteral.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JLiteral.java
@@ -24,7 +24,7 @@ package org.apache.commons.rdf.rdf4j;
* The underlying RDF4J {@link org.eclipse.rdf4j.model.Literal} instance can be
* retrieved with {@link #asValue()}.
*
- * @see RDF4JFactory#createLiteral(String)
+ * @see RDF4J#createLiteral(String)
*/
public interface RDF4JLiteral extends RDF4JTerm, org.apache.commons.rdf.api.Literal {
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java
index d3fbcf0..23b6cdf 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java
@@ -22,7 +22,7 @@ import org.apache.commons.rdf.api.Quad;
/**
* Marker interface for RDF4J implementations of Quad.
*
- * @see RDF4JFactory#createQuad(org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.IRI, org.apache.commons.rdf.api.RDFTerm)
+ * @see RDF4J#createQuad(org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.IRI, org.apache.commons.rdf.api.RDFTerm)
*/
public interface RDF4JQuad extends Quad, RDF4JTripleLike {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java
index e475a08..ca32d94 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java
@@ -22,7 +22,7 @@ import org.apache.commons.rdf.api.Triple;
/**
* Marker interface for RDF4J implementations of Triple.
*
- * @see RDF4JFactory#createTriple(org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.IRI, org.apache.commons.rdf.api.RDFTerm)
+ * @see RDF4J#createTriple(org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.IRI, org.apache.commons.rdf.api.RDFTerm)
*/
public interface RDF4JTriple extends Triple, RDF4JTripleLike {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
index f9a1e74..558108b 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
@@ -34,7 +34,7 @@ import org.apache.commons.rdf.experimental.RDFParser;
import org.apache.commons.rdf.rdf4j.RDF4JBlankNodeOrIRI;
import org.apache.commons.rdf.rdf4j.RDF4JDataset;
import org.apache.commons.rdf.rdf4j.RDF4JGraph;
-import org.apache.commons.rdf.rdf4j.RDF4JFactory;
+import org.apache.commons.rdf.rdf4j.RDF4J;
import org.apache.commons.rdf.simple.experimental.AbstractRDFParser;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
@@ -101,20 +101,20 @@ public class RDF4JParser extends AbstractRDFParser<RDF4JParser> implements RDFPa
}
}
- private RDF4JFactory rdf4jTermFactory;
+ private RDF4J rdf4jTermFactory;
private ParserConfig parserConfig = new ParserConfig();
@Override
- protected RDF4JFactory createRDFTermFactory() {
- return new RDF4JFactory();
+ protected RDF4J createRDFTermFactory() {
+ return new RDF4J();
}
@Override
protected RDF4JParser prepareForParsing() throws IOException, IllegalStateException {
RDF4JParser c = prepareForParsing();
- // Ensure we have an RDF4JFactory for conversion.
+ // Ensure we have an RDF4J for conversion.
// We'll make a new one if user has provided a non-RDF4J factory
- c.rdf4jTermFactory = (RDF4JFactory) getRdfTermFactory().filter(RDF4JFactory.class::isInstance)
+ c.rdf4jTermFactory = (RDF4J) getRdfTermFactory().filter(RDF4J.class::isInstance)
.orElseGet(c::createRDFTermFactory);
return c;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java
index 1948a32..37487b4 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java
@@ -22,7 +22,7 @@ import java.util.UUID;
import org.apache.commons.rdf.api.TripleLike;
import org.apache.commons.rdf.rdf4j.RDF4JGraphLike;
-import org.apache.commons.rdf.rdf4j.RDF4JFactory;
+import org.apache.commons.rdf.rdf4j.RDF4J;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.repository.Repository;
@@ -34,7 +34,7 @@ abstract class AbstractRepositoryGraphLike<T extends TripleLike>
protected final Repository repository;
protected final boolean includeInferred;
protected final boolean handleInitAndShutdown;
- protected final RDF4JFactory rdf4jTermFactory;
+ protected final RDF4J rdf4jTermFactory;
protected final UUID salt;
AbstractRepositoryGraphLike(Repository repository, UUID salt, boolean handleInitAndShutdown, boolean includeInferred) {
@@ -45,7 +45,7 @@ abstract class AbstractRepositoryGraphLike<T extends TripleLike>
if (handleInitAndShutdown && !repository.isInitialized()) {
repository.initialize();
}
- rdf4jTermFactory = new RDF4JFactory(repository.getValueFactory(), salt);
+ rdf4jTermFactory = new RDF4J(repository.getValueFactory(), salt);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
index 7744e01..b1cd419 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java
@@ -27,7 +27,7 @@ import org.apache.commons.rdf.rdf4j.RDF4JIRI;
import org.apache.commons.rdf.rdf4j.RDF4JLiteral;
import org.apache.commons.rdf.rdf4j.RDF4JQuad;
import org.apache.commons.rdf.rdf4j.RDF4JTerm;
-import org.apache.commons.rdf.rdf4j.RDF4JFactory;
+import org.apache.commons.rdf.rdf4j.RDF4J;
import org.apache.commons.rdf.rdf4j.RDF4JTriple;
import org.eclipse.rdf4j.model.BNode;
import org.eclipse.rdf4j.model.IRI;
@@ -42,17 +42,17 @@ import org.eclipse.rdf4j.repository.Repository;
* <p>
* <strong>Internal class:</strong> This "abstract" class is intended for
* internal use by Commons RDF and may change in any minor update. Use instead
- * {@link RDF4JFactory} methods like
- * {@link RDF4JFactory#createBlankNode()},
- * {@link RDF4JFactory#asRDFTerm(org.eclipse.rdf4j.model.Value)} and
- * {@link RDF4JFactory#asRDFTermGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)}
+ * {@link RDF4J} methods like
+ * {@link RDF4J#createBlankNode()},
+ * {@link RDF4J#asRDFTerm(org.eclipse.rdf4j.model.Value)} and
+ * {@link RDF4J#asRDFTermGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...)}
* <p>
* This class exists as a <code>public</code> bridge between the packages
* {@link org.apache.commons.rdf.rdf4j} and
* {@link org.apache.commons.rdf.rdf4j.impl} by exposing the package-public
* constructors.
*
- * @see RDF4JFactory
+ * @see RDF4J
*/
public abstract class InternalRDF4JFactory {
@@ -103,7 +103,7 @@ public abstract class InternalRDF4JFactory {
* factory to use for adapting graph triples
* @return Adapted {@link RDF4JGraph}
*/
- public RDF4JGraph createModelGraphImpl(Model model, RDF4JFactory rdf4jTermFactory) {
+ public RDF4JGraph createModelGraphImpl(Model model, RDF4J rdf4jTermFactory) {
return new ModelGraphImpl(model, rdf4jTermFactory);
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java
index 0d2695e..ced9c99 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java
@@ -31,7 +31,7 @@ import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.rdf4j.ClosableIterable;
import org.apache.commons.rdf.rdf4j.RDF4JBlankNodeOrIRI;
import org.apache.commons.rdf.rdf4j.RDF4JGraph;
-import org.apache.commons.rdf.rdf4j.RDF4JFactory;
+import org.apache.commons.rdf.rdf4j.RDF4J;
import org.apache.commons.rdf.rdf4j.RDF4JTriple;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Resource;
@@ -40,9 +40,9 @@ import org.eclipse.rdf4j.repository.Repository;
final class ModelGraphImpl implements RDF4JGraph {
private Model model;
- private RDF4JFactory rdf4jTermFactory;
+ private RDF4J rdf4jTermFactory;
- ModelGraphImpl(Model model, RDF4JFactory rdf4jTermFactory) {
+ ModelGraphImpl(Model model, RDF4J rdf4jTermFactory) {
this.model = model;
this.rdf4jTermFactory = rdf4jTermFactory;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java
index cf60883..8da29b6 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java
@@ -26,7 +26,7 @@ import org.apache.commons.rdf.api.Quad;
import org.apache.commons.rdf.api.RDFTerm;
import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.rdf4j.RDF4JQuad;
-import org.apache.commons.rdf.rdf4j.RDF4JFactory;
+import org.apache.commons.rdf.rdf4j.RDF4J;
import org.eclipse.rdf4j.model.Statement;
final class QuadImpl implements Quad, RDF4JQuad {
@@ -65,23 +65,23 @@ final class QuadImpl implements Quad, RDF4JQuad {
if (statement.getContext() == null) {
return Optional.empty();
}
- BlankNodeOrIRI g = (BlankNodeOrIRI) RDF4JFactory.asRDFTerm(statement.getContext(), salt);
+ BlankNodeOrIRI g = (BlankNodeOrIRI) RDF4J.asRDFTerm(statement.getContext(), salt);
return Optional.of(g);
}
@Override
public RDFTerm getObject() {
- return RDF4JFactory.asRDFTerm(statement.getObject(), salt);
+ return RDF4J.asRDFTerm(statement.getObject(), salt);
}
@Override
public org.apache.commons.rdf.api.IRI getPredicate() {
- return (org.apache.commons.rdf.api.IRI) RDF4JFactory.asRDFTerm(statement.getPredicate(), null);
+ return (org.apache.commons.rdf.api.IRI) RDF4J.asRDFTerm(statement.getPredicate(), null);
}
@Override
public BlankNodeOrIRI getSubject() {
- return (BlankNodeOrIRI) RDF4JFactory.asRDFTerm(statement.getSubject(), salt);
+ return (BlankNodeOrIRI) RDF4J.asRDFTerm(statement.getSubject(), salt);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java
index 23041c4..0526c77 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java
@@ -23,7 +23,7 @@ import java.util.UUID;
import org.apache.commons.rdf.api.BlankNodeOrIRI;
import org.apache.commons.rdf.api.RDFTerm;
import org.apache.commons.rdf.api.Triple;
-import org.apache.commons.rdf.rdf4j.RDF4JFactory;
+import org.apache.commons.rdf.rdf4j.RDF4J;
import org.apache.commons.rdf.rdf4j.RDF4JTriple;
import org.eclipse.rdf4j.model.Statement;
@@ -54,17 +54,17 @@ final class TripleImpl implements Triple, RDF4JTriple {
@Override
public RDFTerm getObject() {
- return RDF4JFactory.asRDFTerm(statement.getObject(), salt);
+ return RDF4J.asRDFTerm(statement.getObject(), salt);
}
@Override
public org.apache.commons.rdf.api.IRI getPredicate() {
- return (org.apache.commons.rdf.api.IRI) RDF4JFactory.asRDFTerm(statement.getPredicate(), null);
+ return (org.apache.commons.rdf.api.IRI) RDF4J.asRDFTerm(statement.getPredicate(), null);
}
@Override
public BlankNodeOrIRI getSubject() {
- return (BlankNodeOrIRI) RDF4JFactory.asRDFTerm(statement.getSubject(), salt);
+ return (BlankNodeOrIRI) RDF4J.asRDFTerm(statement.getSubject(), salt);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
index f17a499..51556bc 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java
@@ -18,9 +18,9 @@
/**
* Commons RDF integration with <a href="http://rdf4j.org/">RDF4J</a>.
* <p>
- * Use the {@link org.apache.commons.rdf.rdf4j.RDF4JFactory} to convert
+ * Use the {@link org.apache.commons.rdf.rdf4j.RDF4J} to convert
* between Commons RDF and RDF4J types, for instance
- * {@link org.apache.commons.rdf.rdf4j.RDF4JFactory#asQuad(org.eclipse.rdf4j.model.Statement)}
+ * {@link org.apache.commons.rdf.rdf4j.RDF4J#asQuad(org.eclipse.rdf4j.model.Statement)}
* converts a RDF4J {@link org.eclipse.rdf4j.model.Statement} to a
* {@link org.apache.commons.rdf.api.Quad}. Converted RDF terms implement the
* {@link org.apache.commons.rdf.rdf4j.RDF4JTerm} interface, and converted
@@ -32,9 +32,9 @@
* {@link org.eclipse.rdf4j.repository.Repository} instances can be adapted to
* Commons RDF {@link org.apache.commons.rdf.api.Graph} and
* {@link org.apache.commons.rdf.api.Dataset}, e.g. using
- * {@link org.apache.commons.rdf.rdf4j.RDF4JFactory#asRDFTermGraph(org.eclipse.rdf4j.model.Model)}
+ * {@link org.apache.commons.rdf.rdf4j.RDF4J#asRDFTermGraph(org.eclipse.rdf4j.model.Model)}
* or
- * {@link org.apache.commons.rdf.rdf4j.RDF4JFactory#asRDFTermDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)}
+ * {@link org.apache.commons.rdf.rdf4j.RDF4J#asRDFTermDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...)}
* The returned adapted graph/dataset is directly mapped, so changes are
* propagated both ways. For convenience, the marker interface
* {@link org.apache.commons.rdf.rdf4j.RDF4JGraph} and
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory b/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
index bfcdc12..f8a94bb 100644
--- a/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
+++ b/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory
@@ -1 +1 @@
-org.apache.commons.rdf.rdf4j.RDF4JFactory
+org.apache.commons.rdf.rdf4j.RDF4J
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java
index 1da3c11..d31c24d 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java
@@ -22,7 +22,7 @@ import org.apache.commons.rdf.api.BlankNode;
public class BlankNodeTest extends AbstractBlankNodeTest {
- RDF4JFactory factory = new RDF4JFactory();
+ RDF4J factory = new RDF4J();
@Override
protected BlankNode getBlankNode() {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java
index 7d6104d..4ad8969 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java
@@ -24,7 +24,7 @@ public class GraphTest extends AbstractGraphTest{
@Override
public RDF createFactory() {
- return new RDF4JFactory();
+ return new RDF4J();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java
index 5377983..37ba0ff 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java
@@ -33,9 +33,9 @@ import org.eclipse.rdf4j.sail.memory.model.MemValueFactory;
public class MemoryGraphTest extends AbstractGraphTest {
- public static final class MemoryStoreFactory implements RDF {
+ public static final class MemoryStoreRDF implements RDF {
- RDF4JFactory rdf4jFactory = new RDF4JFactory(new MemValueFactory());
+ RDF4J rdf4jFactory = new RDF4J(new MemValueFactory());
public RDF4JBlankNode createBlankNode() {
return rdf4jFactory.createBlankNode();
@@ -83,7 +83,7 @@ public class MemoryGraphTest extends AbstractGraphTest {
@Override
public RDF createFactory() {
- return new MemoryStoreFactory();
+ return new MemoryStoreRDF();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java
index 73ea05e..83968ee 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java
@@ -25,7 +25,7 @@ public class MemoryRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
@Override
public RDF createFactory() {
- return new MemoryGraphTest.MemoryStoreFactory();
+ return new MemoryGraphTest.MemoryStoreRDF();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
index 7b31738..bedea22 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java
@@ -49,9 +49,9 @@ import org.junit.rules.Timeout;
*/
public class NativeStoreGraphTest extends AbstractGraphTest {
- public final class NativeStoreFactory implements RDF {
+ public final class NativeStoreRDF implements RDF {
- RDF4JFactory rdf4jFactory = new RDF4JFactory(getRepository().getValueFactory());
+ RDF4J rdf4jFactory = new RDF4J(getRepository().getValueFactory());
@Override
public RDF4JGraph createGraph() {
@@ -146,7 +146,7 @@ public class NativeStoreGraphTest extends AbstractGraphTest {
@Override
public RDF createFactory() {
- return new NativeStoreFactory();
+ return new NativeStoreRDF();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
index 46da04a..cbd85f1 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java
@@ -31,10 +31,10 @@ public class RDF4JServiceLoaderTest {
public void testServiceLoaderLookup() {
ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class);
for (RDF impl : loader) {
- if (impl instanceof RDF4JFactory) {
+ if (impl instanceof RDF4J) {
return; // yay
}
}
- fail("RDF4JFactory not found in ServiceLoader");
+ fail("RDF4J not found in ServiceLoader");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
index 24283c3..502d9ac 100644
--- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java
@@ -25,7 +25,7 @@ public class Rdf4JRDFTermFactoryTest extends AbstractRDFTermFactoryTest {
@Override
public RDF createFactory() {
- return new RDF4JFactory();
+ return new RDF4J();
}
@Override
[43/50] [abbrv] incubator-commonsrdf git commit: Reformat tab ->
spaces
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
index 17cb641..2cb0876 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaDatasetImpl.java
@@ -42,150 +42,135 @@ import org.apache.jena.sparql.core.GraphView;
class JenaDatasetImpl implements JenaDataset {
- private DatasetGraph graph;
- private UUID salt;
- private JenaRDF factory;
-
- JenaDatasetImpl(DatasetGraph graph, UUID salt) {
- this.graph = graph;
- this.salt = salt;
- this.factory = new JenaRDF(salt);
- }
-
- @Override
- public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- graph.add(
- org.apache.jena.sparql.core.Quad.create(
- factory.asJenaNode(graphName),
- factory.asJenaNode(subject),
- factory.asJenaNode(predicate),
- factory.asJenaNode(object)));
- }
-
- @Override
- public void add(Quad quad) {
- graph.add(factory.asJenaQuad(quad));
- }
-
- @Override
- public DatasetGraph asJenaDatasetGraph() {
- return graph;
- }
-
- @Override
- public void clear() {
- graph.clear();
- }
-
- @Override
- public void close() {
- graph.close();
- }
-
-
- @Override
- public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return graph.contains(
- toJenaPattern(graphName),
- toJenaPattern(subject),
- toJenaPattern(predicate),
- toJenaPattern(object));
- }
-
- private Node toJenaPattern(Optional<? extends RDFTerm> graphName) {
- // In theory we could have done:
- // factory.toJena(graphName.orElse(internalJenaFactory::createAnyVariable))
- // but because of generics casting rules that doesn't work :(
-
- if (graphName == null) {
- return ANY;
- }
- // null: default graph
- return factory.asJenaNode(graphName.orElse(null));
- }
-
- private Node toJenaPattern(RDFTerm term) {
- if (term == null)
- return ANY;
- return factory.asJenaNode(term);
- }
-
- @Override
- public boolean contains(Quad quad) {
- return graph.contains(factory.asJenaQuad(quad));
- }
-
- @Override
- public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- graph.delete(org.apache.jena.sparql.core.Quad.create(
- toJenaPattern(graphName),
- toJenaPattern(subject),
- toJenaPattern(predicate),
- toJenaPattern(object)));
- }
-
- @Override
- public void remove(Quad quad) {
- graph.delete(factory.asJenaQuad(quad));
- }
-
- @Override
- public long size() {
- return graph.size();
- }
-
- @Override
- public Stream<? extends Quad> stream() {
- JenaRDF factory = new JenaRDF(salt);
- return Iter.asStream(graph.find(ANY, ANY, ANY, ANY), true)
- .map(factory::asQuad);
- }
-
- @Override
- public Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> g, BlankNodeOrIRI s, IRI p, RDFTerm o) {
- JenaRDF factory = new JenaRDF(salt);
- return Iter.asStream(graph.find(toJenaPattern(g), toJenaPattern(s), toJenaPattern(p), toJenaPattern(o)), true)
- .map(factory::asQuad);
- }
-
- @Override
- public String toString() {
- StringWriter sw = new StringWriter();
- RDFDataMgr.write(sw, graph, Lang.NT);
- return sw.toString();
- }
-
- @Override
- public Graph getGraph() {
- GraphView gv = GraphView.createDefaultGraph(graph);
- return new JenaGraphImpl(gv, salt);
- }
-
- @Override
- public JenaGraph getUnionGraph() {
- GraphView gv = GraphView.createUnionGraph(graph);
- return new JenaGraphImpl(gv, salt);
- }
-
- @Override
- public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
- GraphView gv = GraphView.createNamedGraph(graph, factory.asJenaNode(graphName));
- return Optional.of(new JenaGraphImpl(gv, salt));
- }
-
- @Override
- public Stream<BlankNodeOrIRI> getGraphNames() {
- JenaRDF factory = new JenaRDF(salt);
- return Iter.asStream(graph.listGraphNodes()).map(node ->
- (BlankNodeOrIRI) factory.asRDFTerm(node));
- }
-
- @Override
- public Iterable<Quad> iterate() {
- final JenaRDF factory = new JenaRDF(salt);
- return Iter.asStream(graph.find(), false)
- .map(q -> (Quad) factory.asQuad(q))
- ::iterator;
- }
+ private DatasetGraph graph;
+ private UUID salt;
+ private JenaRDF factory;
+
+ JenaDatasetImpl(DatasetGraph graph, UUID salt) {
+ this.graph = graph;
+ this.salt = salt;
+ this.factory = new JenaRDF(salt);
+ }
+
+ @Override
+ public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ graph.add(org.apache.jena.sparql.core.Quad.create(factory.asJenaNode(graphName), factory.asJenaNode(subject),
+ factory.asJenaNode(predicate), factory.asJenaNode(object)));
+ }
+
+ @Override
+ public void add(Quad quad) {
+ graph.add(factory.asJenaQuad(quad));
+ }
+
+ @Override
+ public DatasetGraph asJenaDatasetGraph() {
+ return graph;
+ }
+
+ @Override
+ public void clear() {
+ graph.clear();
+ }
+
+ @Override
+ public void close() {
+ graph.close();
+ }
+
+ @Override
+ public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return graph.contains(toJenaPattern(graphName), toJenaPattern(subject), toJenaPattern(predicate),
+ toJenaPattern(object));
+ }
+
+ private Node toJenaPattern(Optional<? extends RDFTerm> graphName) {
+ // In theory we could have done:
+ // factory.toJena(graphName.orElse(internalJenaFactory::createAnyVariable))
+ // but because of generics casting rules that doesn't work :(
+
+ if (graphName == null) {
+ return ANY;
+ }
+ // null: default graph
+ return factory.asJenaNode(graphName.orElse(null));
+ }
+
+ private Node toJenaPattern(RDFTerm term) {
+ if (term == null)
+ return ANY;
+ return factory.asJenaNode(term);
+ }
+
+ @Override
+ public boolean contains(Quad quad) {
+ return graph.contains(factory.asJenaQuad(quad));
+ }
+
+ @Override
+ public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ graph.delete(org.apache.jena.sparql.core.Quad.create(toJenaPattern(graphName), toJenaPattern(subject),
+ toJenaPattern(predicate), toJenaPattern(object)));
+ }
+
+ @Override
+ public void remove(Quad quad) {
+ graph.delete(factory.asJenaQuad(quad));
+ }
+
+ @Override
+ public long size() {
+ return graph.size();
+ }
+
+ @Override
+ public Stream<? extends Quad> stream() {
+ JenaRDF factory = new JenaRDF(salt);
+ return Iter.asStream(graph.find(ANY, ANY, ANY, ANY), true).map(factory::asQuad);
+ }
+
+ @Override
+ public Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> g, BlankNodeOrIRI s, IRI p, RDFTerm o) {
+ JenaRDF factory = new JenaRDF(salt);
+ return Iter.asStream(graph.find(toJenaPattern(g), toJenaPattern(s), toJenaPattern(p), toJenaPattern(o)), true)
+ .map(factory::asQuad);
+ }
+
+ @Override
+ public String toString() {
+ StringWriter sw = new StringWriter();
+ RDFDataMgr.write(sw, graph, Lang.NT);
+ return sw.toString();
+ }
+
+ @Override
+ public Graph getGraph() {
+ GraphView gv = GraphView.createDefaultGraph(graph);
+ return new JenaGraphImpl(gv, salt);
+ }
+
+ @Override
+ public JenaGraph getUnionGraph() {
+ GraphView gv = GraphView.createUnionGraph(graph);
+ return new JenaGraphImpl(gv, salt);
+ }
+
+ @Override
+ public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
+ GraphView gv = GraphView.createNamedGraph(graph, factory.asJenaNode(graphName));
+ return Optional.of(new JenaGraphImpl(gv, salt));
+ }
+
+ @Override
+ public Stream<BlankNodeOrIRI> getGraphNames() {
+ JenaRDF factory = new JenaRDF(salt);
+ return Iter.asStream(graph.listGraphNodes()).map(node -> (BlankNodeOrIRI) factory.asRDFTerm(node));
+ }
+
+ @Override
+ public Iterable<Quad> iterate() {
+ final JenaRDF factory = new JenaRDF(salt);
+ return Iter.asStream(graph.find(), false).map(q -> (Quad) factory.asQuad(q))::iterator;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedQuadLikeImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedQuadLikeImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedQuadLikeImpl.java
index df74900..65eaae5 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedQuadLikeImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedQuadLikeImpl.java
@@ -25,15 +25,14 @@ import org.apache.commons.rdf.jena.JenaGeneralizedQuadLike;
import org.apache.jena.sparql.core.Quad;
class JenaGeneralizedQuadLikeImpl extends AbstractQuadLike<RDFTerm, RDFTerm, RDFTerm, RDFTerm>
- implements JenaGeneralizedQuadLike {
+ implements JenaGeneralizedQuadLike {
- JenaGeneralizedQuadLikeImpl(RDFTerm subject, RDFTerm predicate, RDFTerm object,
- Optional<RDFTerm> ofNullable) {
- super(subject, predicate, object, ofNullable);
- }
+ JenaGeneralizedQuadLikeImpl(RDFTerm subject, RDFTerm predicate, RDFTerm object, Optional<RDFTerm> ofNullable) {
+ super(subject, predicate, object, ofNullable);
+ }
- JenaGeneralizedQuadLikeImpl(Quad quad, UUID salt) {
- super(quad, salt);
- }
+ JenaGeneralizedQuadLikeImpl(Quad quad, UUID salt) {
+ super(quad, salt);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedTripleLikeImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedTripleLikeImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedTripleLikeImpl.java
index ecaa46a..a54075a 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedTripleLikeImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGeneralizedTripleLikeImpl.java
@@ -24,14 +24,14 @@ import org.apache.commons.rdf.jena.JenaGeneralizedTripleLike;
import org.apache.jena.graph.Triple;
class JenaGeneralizedTripleLikeImpl extends AbstractQuadLike<RDFTerm, RDFTerm, RDFTerm, RDFTerm>
- implements JenaGeneralizedTripleLike {
+ implements JenaGeneralizedTripleLike {
- JenaGeneralizedTripleLikeImpl(RDFTerm subject, RDFTerm predicate, RDFTerm object) {
- super(subject, predicate, object);
- }
+ JenaGeneralizedTripleLikeImpl(RDFTerm subject, RDFTerm predicate, RDFTerm object) {
+ super(subject, predicate, object);
+ }
- JenaGeneralizedTripleLikeImpl(Triple triple, UUID salt) {
- super(triple, salt);
- }
+ JenaGeneralizedTripleLikeImpl(Triple triple, UUID salt) {
+ super(triple, salt);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
index fd2f6c4..c482a0f 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaGraphImpl.java
@@ -37,121 +37,114 @@ import org.apache.jena.riot.RDFDataMgr;
class JenaGraphImpl implements JenaGraph {
- private final org.apache.jena.graph.Graph graph;
- private final UUID salt;
- private final transient JenaRDF factory;
- private Model model;
-
- JenaGraphImpl(org.apache.jena.graph.Graph graph, UUID salt) {
- this.graph = graph;
- this.salt = salt;
- this.factory = new JenaRDF(salt);
- }
-
- JenaGraphImpl(Model model, UUID salt) {
- this.model = model;
- this.graph = model.getGraph();
- this.salt = salt;
- this.factory = new JenaRDF(salt);
- }
-
- @Override
- public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- graph.add(org.apache.jena.graph.Triple.create(
- factory.asJenaNode(subject),
- factory.asJenaNode(predicate),
- factory.asJenaNode(object)));
- }
-
- @Override
- public void add(Triple triple) {
- graph.add(factory.asJenaTriple(triple));
- }
-
- @Override
- public org.apache.jena.graph.Graph asJenaGraph() {
- return graph;
- }
-
- @Override
- public void clear() {
- graph.clear();
- }
-
- @Override
- public void close() {
- graph.close();
- }
-
- @Override
- public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return graph.contains(
- factory.asJenaNode(subject),
- factory.asJenaNode(predicate),
- factory.asJenaNode(object));
- }
-
- @Override
- public boolean contains(Triple triple) {
- return graph.contains(factory.asJenaTriple(triple));
- }
-
- @Override
- public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- graph.delete(org.apache.jena.graph.Triple.create(
- factory.asJenaNode(subject),
- factory.asJenaNode(predicate),
- factory.asJenaNode(object)));
- }
-
- @Override
- public void remove(Triple triple) {
- graph.delete(factory.asJenaTriple(triple));
- }
-
- @Override
- public long size() {
- return graph.size();
- }
-
- @Override
- public Stream<? extends Triple> stream() {
- JenaRDF factory = new JenaRDF(salt);
- return Iter.asStream(graph.find(null, null, null), true).map(factory::asTriple);
- }
-
- @Override
- public Stream<? extends Triple> stream(BlankNodeOrIRI s, IRI p, RDFTerm o) {
- JenaRDF factory = new JenaRDF(salt);
- return Iter.asStream(graph.find(toJenaAny(s), toJenaAny(p), toJenaAny(o)), true)
- .map(factory::asTriple);
- }
-
- private Node toJenaAny(RDFTerm term) {
- if (term == null)
- return Node.ANY;
- return factory.asJenaNode(term);
- }
-
- @Override
- public String toString() {
- StringWriter sw = new StringWriter();
- RDFDataMgr.write(sw, graph, Lang.NT);
- return sw.toString();
- }
-
- @Override
- public Model asJenaModel() {
- if (model == null) {
- synchronized(this) {
- // As Model can be used for locks, we should make sure we don't make
- // more than one model
- if (model == null) {
- model = ModelFactory.createModelForGraph(graph);
- }
- }
- }
- return model;
- }
+ private final org.apache.jena.graph.Graph graph;
+ private final UUID salt;
+ private final transient JenaRDF factory;
+ private Model model;
+
+ JenaGraphImpl(org.apache.jena.graph.Graph graph, UUID salt) {
+ this.graph = graph;
+ this.salt = salt;
+ this.factory = new JenaRDF(salt);
+ }
+
+ JenaGraphImpl(Model model, UUID salt) {
+ this.model = model;
+ this.graph = model.getGraph();
+ this.salt = salt;
+ this.factory = new JenaRDF(salt);
+ }
+
+ @Override
+ public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ graph.add(org.apache.jena.graph.Triple.create(factory.asJenaNode(subject), factory.asJenaNode(predicate),
+ factory.asJenaNode(object)));
+ }
+
+ @Override
+ public void add(Triple triple) {
+ graph.add(factory.asJenaTriple(triple));
+ }
+
+ @Override
+ public org.apache.jena.graph.Graph asJenaGraph() {
+ return graph;
+ }
+
+ @Override
+ public void clear() {
+ graph.clear();
+ }
+
+ @Override
+ public void close() {
+ graph.close();
+ }
+
+ @Override
+ public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return graph.contains(factory.asJenaNode(subject), factory.asJenaNode(predicate), factory.asJenaNode(object));
+ }
+
+ @Override
+ public boolean contains(Triple triple) {
+ return graph.contains(factory.asJenaTriple(triple));
+ }
+
+ @Override
+ public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ graph.delete(org.apache.jena.graph.Triple.create(factory.asJenaNode(subject), factory.asJenaNode(predicate),
+ factory.asJenaNode(object)));
+ }
+
+ @Override
+ public void remove(Triple triple) {
+ graph.delete(factory.asJenaTriple(triple));
+ }
+
+ @Override
+ public long size() {
+ return graph.size();
+ }
+
+ @Override
+ public Stream<? extends Triple> stream() {
+ JenaRDF factory = new JenaRDF(salt);
+ return Iter.asStream(graph.find(null, null, null), true).map(factory::asTriple);
+ }
+
+ @Override
+ public Stream<? extends Triple> stream(BlankNodeOrIRI s, IRI p, RDFTerm o) {
+ JenaRDF factory = new JenaRDF(salt);
+ return Iter.asStream(graph.find(toJenaAny(s), toJenaAny(p), toJenaAny(o)), true).map(factory::asTriple);
+ }
+
+ private Node toJenaAny(RDFTerm term) {
+ if (term == null)
+ return Node.ANY;
+ return factory.asJenaNode(term);
+ }
+
+ @Override
+ public String toString() {
+ StringWriter sw = new StringWriter();
+ RDFDataMgr.write(sw, graph, Lang.NT);
+ return sw.toString();
+ }
+
+ @Override
+ public Model asJenaModel() {
+ if (model == null) {
+ synchronized (this) {
+ // As Model can be used for locks, we should make sure we don't
+ // make
+ // more than one model
+ if (model == null) {
+ model = ModelFactory.createModelForGraph(graph);
+ }
+ }
+ }
+ return model;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaIRIImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaIRIImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaIRIImpl.java
index 7fbf284..e09dbaf 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaIRIImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaIRIImpl.java
@@ -25,37 +25,37 @@ import org.apache.jena.graph.NodeFactory;
class JenaIRIImpl extends AbstractJenaRDFTerm implements JenaIRI {
- JenaIRIImpl(Node node) {
- super(node);
- if (! node.isURI()) {
- throw new IllegalArgumentException("Node is not a blank node: " + node);
- }
-
- }
-
- JenaIRIImpl(String iriStr) {
- super(NodeFactory.createURI(iriStr));
- }
-
- @Override
- public boolean equals(Object other) {
- if (other == this)
- return true;
- if (other == null)
- return false;
- if (!(other instanceof IRI))
- return false;
- IRI iri = (IRI) other;
- return getIRIString().equals(iri.getIRIString());
- }
-
- @Override
- public String getIRIString() {
- return asJenaNode().getURI();
- }
-
- @Override
- public int hashCode() {
- return getIRIString().hashCode();
- }
+ JenaIRIImpl(Node node) {
+ super(node);
+ if (!node.isURI()) {
+ throw new IllegalArgumentException("Node is not a blank node: " + node);
+ }
+
+ }
+
+ JenaIRIImpl(String iriStr) {
+ super(NodeFactory.createURI(iriStr));
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this)
+ return true;
+ if (other == null)
+ return false;
+ if (!(other instanceof IRI))
+ return false;
+ IRI iri = (IRI) other;
+ return getIRIString().equals(iri.getIRIString());
+ }
+
+ @Override
+ public String getIRIString() {
+ return asJenaNode().getURI();
+ }
+
+ @Override
+ public int hashCode() {
+ return getIRIString().hashCode();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaLiteralImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaLiteralImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaLiteralImpl.java
index 74c6d9c..d2afbe3 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaLiteralImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaLiteralImpl.java
@@ -28,48 +28,49 @@ import org.apache.jena.graph.Node;
class JenaLiteralImpl extends AbstractJenaRDFTerm implements JenaLiteral {
- private static InternalJenaFactory internalJenaFactory = new InternalJenaFactory(){};
-
- JenaLiteralImpl(Node node) {
- super(node);
- if (! node.isLiteral()) {
- throw new IllegalArgumentException("Node is not a literal: " + node);
- }
- }
+ private static InternalJenaFactory internalJenaFactory = new InternalJenaFactory() {
+ };
- @Override
- public boolean equals(Object other) {
- if (other == this)
- return true;
- if (other == null)
- return false;
- if (!(other instanceof Literal))
- return false;
- Literal literal = (Literal) other;
- return getLexicalForm().equals(literal.getLexicalForm()) && getLanguageTag().equals(literal.getLanguageTag())
- && getDatatype().equals(literal.getDatatype());
- }
+ JenaLiteralImpl(Node node) {
+ super(node);
+ if (!node.isLiteral()) {
+ throw new IllegalArgumentException("Node is not a literal: " + node);
+ }
+ }
- @Override
- public IRI getDatatype() {
- return internalJenaFactory.createIRI(asJenaNode().getLiteralDatatype().getURI());
- }
+ @Override
+ public boolean equals(Object other) {
+ if (other == this)
+ return true;
+ if (other == null)
+ return false;
+ if (!(other instanceof Literal))
+ return false;
+ Literal literal = (Literal) other;
+ return getLexicalForm().equals(literal.getLexicalForm()) && getLanguageTag().equals(literal.getLanguageTag())
+ && getDatatype().equals(literal.getDatatype());
+ }
- @Override
- public Optional<String> getLanguageTag() {
- String x = asJenaNode().getLiteralLanguage();
- if (x == null || x.isEmpty())
- return Optional.empty();
- return Optional.of(x);
- }
+ @Override
+ public IRI getDatatype() {
+ return internalJenaFactory.createIRI(asJenaNode().getLiteralDatatype().getURI());
+ }
- @Override
- public String getLexicalForm() {
- return asJenaNode().getLiteralLexicalForm();
- }
+ @Override
+ public Optional<String> getLanguageTag() {
+ String x = asJenaNode().getLiteralLanguage();
+ if (x == null || x.isEmpty())
+ return Optional.empty();
+ return Optional.of(x);
+ }
- @Override
- public int hashCode() {
- return Objects.hash(getLexicalForm(), getDatatype(), getLanguageTag());
- }
+ @Override
+ public String getLexicalForm() {
+ return asJenaNode().getLiteralLexicalForm();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getLexicalForm(), getDatatype(), getLanguageTag());
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaQuadImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaQuadImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaQuadImpl.java
index 61ddf9b..e69200f 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaQuadImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaQuadImpl.java
@@ -29,38 +29,36 @@ import org.apache.commons.rdf.api.RDFTerm;
import org.apache.commons.rdf.jena.ConversionException;
import org.apache.commons.rdf.jena.JenaQuad;
-class JenaQuadImpl extends AbstractQuadLike<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI>
- implements JenaQuad {
+class JenaQuadImpl extends AbstractQuadLike<BlankNodeOrIRI, IRI, RDFTerm, BlankNodeOrIRI> implements JenaQuad {
- JenaQuadImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object, Optional<BlankNodeOrIRI> graphName) {
- super(subject, predicate, object, graphName);
- }
+ JenaQuadImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object, Optional<BlankNodeOrIRI> graphName) {
+ super(subject, predicate, object, graphName);
+ }
- JenaQuadImpl(org.apache.jena.sparql.core.Quad quad, UUID salt) {
- super(quad, salt);
- // Check the conversion
- if ((graphName.isPresent() && ! (graphName.get() instanceof BlankNodeOrIRI)) ||
- ! (subject instanceof BlankNodeOrIRI) ||
- ! (predicate instanceof IRI) ||
- ! (object instanceof RDFTerm)) {
- throw new ConversionException("Can't adapt generalized quad: " + quad);
- }
- }
+ JenaQuadImpl(org.apache.jena.sparql.core.Quad quad, UUID salt) {
+ super(quad, salt);
+ // Check the conversion
+ if ((graphName.isPresent() && !(graphName.get() instanceof BlankNodeOrIRI))
+ || !(subject instanceof BlankNodeOrIRI) || !(predicate instanceof IRI)
+ || !(object instanceof RDFTerm)) {
+ throw new ConversionException("Can't adapt generalized quad: " + quad);
+ }
+ }
- @Override
- public boolean equals(Object other) {
- if (other == this)
- return true;
- if (!(other instanceof Quad))
- return false;
- Quad quad = (Quad) other;
- return getGraphName().equals(quad.getGraphName()) && getSubject().equals(quad.getSubject())
- && getPredicate().equals(quad.getPredicate()) && getObject().equals(quad.getObject());
- }
+ @Override
+ public boolean equals(Object other) {
+ if (other == this)
+ return true;
+ if (!(other instanceof Quad))
+ return false;
+ Quad quad = (Quad) other;
+ return getGraphName().equals(quad.getGraphName()) && getSubject().equals(quad.getSubject())
+ && getPredicate().equals(quad.getPredicate()) && getObject().equals(quad.getObject());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getSubject(), getPredicate(), getObject(), getGraphName());
+ }
- @Override
- public int hashCode() {
- return Objects.hash(getSubject(), getPredicate(), getObject(), getGraphName());
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTripleImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTripleImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTripleImpl.java
index 453300c..b9de91f 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTripleImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaTripleImpl.java
@@ -28,40 +28,36 @@ import org.apache.commons.rdf.api.Triple;
import org.apache.commons.rdf.jena.ConversionException;
import org.apache.commons.rdf.jena.JenaTriple;
-class JenaTripleImpl extends AbstractQuadLike<BlankNodeOrIRI, IRI, RDFTerm, RDFTerm>
- implements JenaTriple {
+class JenaTripleImpl extends AbstractQuadLike<BlankNodeOrIRI, IRI, RDFTerm, RDFTerm> implements JenaTriple {
+
+ JenaTripleImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ super(subject, predicate, object);
+ }
+
+ JenaTripleImpl(org.apache.jena.graph.Triple triple, UUID salt) throws ConversionException {
+ super(triple, salt);
+ // Check the conversion
+ if (!(subject instanceof BlankNodeOrIRI) || !(predicate instanceof IRI) || !(object instanceof RDFTerm)) {
+ throw new ConversionException("Can't adapt generalized triple: " + quad);
+ }
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this)
+ return true;
+ if (other == null)
+ return false;
+ if (!(other instanceof Triple))
+ return false;
+ Triple triple = (Triple) other;
+ return getSubject().equals(triple.getSubject()) && getPredicate().equals(triple.getPredicate())
+ && getObject().equals(triple.getObject());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getSubject(), getPredicate(), getObject());
+ }
- JenaTripleImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- super(subject, predicate, object);
- }
-
- JenaTripleImpl(org.apache.jena.graph.Triple triple, UUID salt) throws ConversionException {
- super(triple, salt);
- // Check the conversion
- if (! (subject instanceof BlankNodeOrIRI) ||
- ! (predicate instanceof IRI) ||
- ! (object instanceof RDFTerm)) {
- throw new ConversionException("Can't adapt generalized triple: " + quad);
- }
- }
-
- @Override
- public boolean equals(Object other) {
- if (other == this)
- return true;
- if (other == null)
- return false;
- if (!(other instanceof Triple))
- return false;
- Triple triple = (Triple) other;
- return getSubject().equals(triple.getSubject()) && getPredicate().equals(triple.getPredicate())
- && getObject().equals(triple.getObject());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(getSubject(), getPredicate(), getObject());
- }
-
-
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/test/java/org/apache/commons/rdf/jena/JenaRDFTest.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/JenaRDFTest.java b/jena/src/test/java/org/apache/commons/rdf/jena/JenaRDFTest.java
index 87a4618..72986d0 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/JenaRDFTest.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/JenaRDFTest.java
@@ -22,11 +22,10 @@ import org.apache.commons.rdf.api.AbstractRDFTest;
import org.apache.commons.rdf.api.RDF;
public class JenaRDFTest extends AbstractRDFTest {
-
+
@Override
public RDF createFactory() {
return new JenaRDF();
}
}
-
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java b/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
index 836e2ec..dc0c8bd 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/JenaServiceLoaderTest.java
@@ -31,10 +31,10 @@ public class JenaServiceLoaderTest {
public void testServiceLoaderLookup() {
ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class);
for (RDF impl : loader) {
- if (impl instanceof JenaRDF) {
- return; // yay
- }
+ if (impl instanceof JenaRDF) {
+ return; // yay
+ }
}
- fail("JenaRDF not found in ServiceLoader");
+ fail("JenaRDF not found in ServiceLoader");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java
index abe8080..49470c0 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestBlankNodeJena.java
@@ -26,21 +26,21 @@ import org.apache.commons.rdf.jena.impl.InternalJenaFactory;
public class TestBlankNodeJena extends AbstractBlankNodeTest {
- InternalJenaFactory internalJenaFactory = new InternalJenaFactory(){};
-
- /**
- * Fixed salt for the purpose of this test.
- */
+ InternalJenaFactory internalJenaFactory = new InternalJenaFactory() {
+ };
+
+ /**
+ * Fixed salt for the purpose of this test.
+ */
private static final UUID SALT = UUID.fromString("ccfde817-55b8-4a5f-bc2d-6bfd8eaa41ce");
- @Override
+ @Override
protected BlankNode getBlankNode() {
return internalJenaFactory.createBlankNode(SALT);
}
-
+
@Override
protected BlankNode getBlankNode(String identifier) {
return internalJenaFactory.createBlankNode(identifier, SALT);
}
}
-
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
index 296c42d..1ab01f9 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestGraphJena.java
@@ -29,4 +29,3 @@ public class TestGraphJena extends AbstractGraphTest {
}
}
-
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
index 50bb1ff..632cce9 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestJenaGraphToCommonsRDFGraph.java
@@ -42,93 +42,82 @@ import org.junit.Test;
/** Adapt a Jena Graph after parsing data into it */
public class TestJenaGraphToCommonsRDFGraph {
private static final boolean DEBUG = false;
- private Path turtleFile;
+ private Path turtleFile;
-
@Before
- public void preparePath() throws IOException {
- turtleFile = Files.createTempFile("commonsrdf", "test.ttl");
- Files.copy(getClass().getResourceAsStream("/D.ttl"), turtleFile, StandardCopyOption.REPLACE_EXISTING);
+ public void preparePath() throws IOException {
+ turtleFile = Files.createTempFile("commonsrdf", "test.ttl");
+ Files.copy(getClass().getResourceAsStream("/D.ttl"), turtleFile, StandardCopyOption.REPLACE_EXISTING);
}
-
+
@After
public void deletePath() throws IOException {
- if (turtleFile != null) {
- Files.deleteIfExists(turtleFile);
- }
+ if (turtleFile != null) {
+ Files.deleteIfExists(turtleFile);
+ }
}
-
+
@Test
- public void jenaToCommonsRDF() throws Exception {
+ public void jenaToCommonsRDF() throws Exception {
org.apache.jena.graph.Graph jGraph = GraphFactory.createGraphMem();
RDFDataMgr.read(jGraph, turtleFile.toUri().toString());
-
+
JenaRDF factory = new JenaRDF();
-
- // "graph" is a CommonsRDF graph
+
+ // "graph" is a CommonsRDF graph
Graph graph = factory.asGraph(jGraph);
-
-
-
+
// The below check expected statements from D.ttl
-
+
JenaIRI p = factory.createIRI("http://example.com/p");
- JenaIRI s = factory.createIRI("http://example.com/s");
- JenaLiteral literal123 = factory.createLiteral("123", Types.XSD_INTEGER);
- assertTrue(graph.contains(s, p, literal123));
-
+ JenaIRI s = factory.createIRI("http://example.com/s");
+ JenaLiteral literal123 = factory.createLiteral("123", Types.XSD_INTEGER);
+ assertTrue(graph.contains(s, p, literal123));
+
JenaIRI p1 = factory.createIRI("http://example.com/p1");
// Let's look up the BlankNode
- BlankNodeOrIRI bnode1 = graph.stream(null, p1, null)
- .findFirst().map(Triple::getSubject).get();
+ BlankNodeOrIRI bnode1 = graph.stream(null, p1, null).findFirst().map(Triple::getSubject).get();
assertTrue(bnode1 instanceof BlankNode);
-
+
// Verify we can use BlankNode in query again
RDFTerm obj = graph.stream(bnode1, p1, null).findFirst().map(Triple::getObject).get();
-
+
// Let's look up also that nested blank node
assertTrue(obj instanceof BlankNode);
- BlankNode bnode2 = (BlankNode)obj;
-
-
-
+ BlankNode bnode2 = (BlankNode) obj;
+
JenaIRI q = factory.createIRI("http://example.com/q");
JenaLiteral literalR = factory.createLiteral("r", "en");
- assertTrue(graph.contains(bnode2, q, literalR));
-
+ assertTrue(graph.contains(bnode2, q, literalR));
+
+ // Can we add the same triple again as s/p/o
+ // without affecting graph size?
+ // Just to be evil we add a blanknode-iri-blanknode statement
+ assertEquals(3, graph.size());
+ graph.add(bnode1, p1, bnode2);
+ assertEquals(3, graph.size());
- // Can we add the same triple again as s/p/o
- // without affecting graph size?
- // Just to be evil we add a blanknode-iri-blanknode statement
+ // Add the same Triple again
+ graph.stream(bnode2, null, null).findFirst().ifPresent(graph::add);
assertEquals(3, graph.size());
- graph.add(bnode1, p1, bnode2);
- assertEquals(3, graph.size());
-
- // Add the same Triple again
- graph.stream(bnode2,null,null).findFirst().ifPresent(graph::add);
- assertEquals(3, graph.size());
-
-
+
// Add to CommonsRDF Graph
JenaIRI s2 = factory.createIRI("http://example/s2");
- JenaIRI p2 = factory.createIRI("http://example/p2");
- JenaLiteral foo = factory.createLiteral("foo");
- graph.add(s2,
- p2,
- foo);
- assertEquals(4, graph.size());
- assertTrue(graph.contains(s2,p2,foo));
-
+ JenaIRI p2 = factory.createIRI("http://example/p2");
+ JenaLiteral foo = factory.createLiteral("foo");
+ graph.add(s2, p2, foo);
+ assertEquals(4, graph.size());
+ assertTrue(graph.contains(s2, p2, foo));
+
// Verify the corresponding Jena Nodes are in Jena graph
assertTrue(jGraph.contains(s2.asJenaNode(), p2.asJenaNode(), foo.asJenaNode()));
-
+
if (DEBUG) {
- System.out.println("==== Write CommonsRDF graph\n");
- graph.stream().forEach(System.out::println);
- // And its in the Jena graph
- System.out.println("\n==== Write Jena graph directly\n");
- RDFDataMgr.write(System.out, jGraph, Lang.TTL);
+ System.out.println("==== Write CommonsRDF graph\n");
+ graph.stream().forEach(System.out::println);
+ // And its in the Jena graph
+ System.out.println("\n==== Write Jena graph directly\n");
+ RDFDataMgr.write(System.out, jGraph, Lang.TTL);
}
}
}
-
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
index 7760e1f..da60602 100644
--- a/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/TestRDFParserBuilder.java
@@ -36,28 +36,28 @@ import org.junit.Before;
import org.junit.Test;
public class TestRDFParserBuilder {
-
- private Path turtleFile;
-
- @Before
- public void preparePath() throws IOException {
- turtleFile = Files.createTempFile("commonsrdf", "test.ttl");
- Files.copy(getClass().getResourceAsStream("/D.ttl"), turtleFile, StandardCopyOption.REPLACE_EXISTING);
- }
-
- @After
- public void deletePath() throws IOException {
- if (turtleFile != null) {
- Files.deleteIfExists(turtleFile);
- }
- }
-
- @Test
- public void parseTurtle() throws Exception {
- Graph g = new JenaRDF().createGraph();
- Future<ParseResult> gFuture = new JenaRDFParser().contentType(RDFSyntax.TURTLE).source(turtleFile)
- .target(g).parse();
- gFuture.get(5, TimeUnit.SECONDS);
- assertEquals(3, g.size());
- }
+
+ private Path turtleFile;
+
+ @Before
+ public void preparePath() throws IOException {
+ turtleFile = Files.createTempFile("commonsrdf", "test.ttl");
+ Files.copy(getClass().getResourceAsStream("/D.ttl"), turtleFile, StandardCopyOption.REPLACE_EXISTING);
+ }
+
+ @After
+ public void deletePath() throws IOException {
+ if (turtleFile != null) {
+ Files.deleteIfExists(turtleFile);
+ }
+ }
+
+ @Test
+ public void parseTurtle() throws Exception {
+ Graph g = new JenaRDF().createGraph();
+ Future<ParseResult> gFuture = new JenaRDFParser().contentType(RDFSyntax.TURTLE).source(turtleFile).target(g)
+ .parse();
+ gFuture.get(5, TimeUnit.SECONDS);
+ assertEquals(3, g.size());
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNode.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNode.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNode.java
index 0a7d59c..d3ac1f0 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNode.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdBlankNode.java
@@ -22,42 +22,41 @@ import org.apache.commons.rdf.api.BlankNode;
import com.github.jsonldjava.core.RDFDataset.Node;
public interface JsonLdBlankNode extends JsonLdTerm, BlankNode {
-}
-
- final class JsonLdBlankNodeImpl extends JsonLdTermImpl implements JsonLdBlankNode {
- private String blankNodePrefix;
-
- JsonLdBlankNodeImpl(Node node, String blankNodePrefix) {
- super(node);
- this.blankNodePrefix = blankNodePrefix;
- if (! node.isBlankNode()) {
- throw new IllegalArgumentException("Node is not a BlankNode:" + node);
- }
- }
-
- @Override
- public String ntriplesString() {
- // TODO: Escape if this is not valid ntriples string (e.g. contains :)
- return node.getValue();
- }
-
- @Override
- public String uniqueReference() {
- return blankNodePrefix + node.getValue();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (! ( obj instanceof BlankNode)) {
- return false;
- }
- BlankNode other = (BlankNode) obj;
- return uniqueReference().equals(other.uniqueReference());
- }
-
- @Override
- public int hashCode() {
- return uniqueReference().hashCode();
- }
- }
+}
+final class JsonLdBlankNodeImpl extends JsonLdTermImpl implements JsonLdBlankNode {
+ private String blankNodePrefix;
+
+ JsonLdBlankNodeImpl(Node node, String blankNodePrefix) {
+ super(node);
+ this.blankNodePrefix = blankNodePrefix;
+ if (!node.isBlankNode()) {
+ throw new IllegalArgumentException("Node is not a BlankNode:" + node);
+ }
+ }
+
+ @Override
+ public String ntriplesString() {
+ // TODO: Escape if this is not valid ntriples string (e.g. contains :)
+ return node.getValue();
+ }
+
+ @Override
+ public String uniqueReference() {
+ return blankNodePrefix + node.getValue();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof BlankNode)) {
+ return false;
+ }
+ BlankNode other = (BlankNode) obj;
+ return uniqueReference().equals(other.uniqueReference());
+ }
+
+ @Override
+ public int hashCode() {
+ return uniqueReference().hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
index 8774cdc..72aadc2 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdDataset.java
@@ -37,79 +37,74 @@ public interface JsonLdDataset extends JsonLdGraphLike<org.apache.commons.rdf.ap
class JsonLdDatasetImpl extends AbstractJsonLdGraphLike<org.apache.commons.rdf.api.Quad> implements JsonLdDataset {
- JsonLdDatasetImpl(RDFDataset rdfDataSet) {
- super(rdfDataSet);
- }
-
- JsonLdDatasetImpl(RDFDataset rdfDataset, String bnodePrefix) {
- super(rdfDataset, bnodePrefix);
- }
-
- JsonLdDatasetImpl(String bnodePrefix) {
- super(bnodePrefix);
- }
-
- @Override
- public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- super.add(graphName, subject, predicate, object);
- }
-
- @Override
- public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return super.contains(graphName, subject, predicate, object);
- }
-
- @Override
- public Graph getGraph() {
- return new JsonLdGraphImpl(rdfDataSet, Optional.empty(), bnodePrefix);
- }
-
- @Override
- public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
- if (graphName == null) {
- return Optional.of(getGraph());
- }
- return getGraphNames()
- .map(g -> (Graph)new JsonLdGraphImpl(rdfDataSet, Optional.of(g), bnodePrefix))
- .findAny();
- }
-
- @Override
- public Stream<BlankNodeOrIRI> getGraphNames() {
- return rdfDataSet.graphNames().parallelStream().filter(Predicate.isEqual("@default").negate())
- .map(s -> s.startsWith("_:") ? new RDFDataset.BlankNode(s) : new RDFDataset.IRI(s))
- .map(n -> (BlankNodeOrIRI) factory.asRDFTerm(n));
- }
-
- @Override
- public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- super.remove(graphName, subject, predicate, object);
- }
-
-
- @Override
- public void remove(Quad q) {
- remove(q.getGraphName(), q.getSubject(), q.getPredicate(), q.getObject());
- }
-
- @Override
- public Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) {
- return filteredGraphs(graphName)
- .flatMap(List::stream)
- .filter(quadFilter(subject, predicate, object))
- .map(factory::asQuad);
- }
-
- @Override
- public long size() {
- return rdfDataSet.graphNames().parallelStream().map(rdfDataSet::getQuads).collect(Collectors.summingLong(List::size));
- }
-
- @Override
- Quad asTripleOrQuad(com.github.jsonldjava.core.RDFDataset.Quad jsonldQuad) {
- return factory.asQuad(jsonldQuad);
- }
-
+ JsonLdDatasetImpl(RDFDataset rdfDataSet) {
+ super(rdfDataSet);
+ }
+
+ JsonLdDatasetImpl(RDFDataset rdfDataset, String bnodePrefix) {
+ super(rdfDataset, bnodePrefix);
+ }
+
+ JsonLdDatasetImpl(String bnodePrefix) {
+ super(bnodePrefix);
+ }
+
+ @Override
+ public void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ super.add(graphName, subject, predicate, object);
+ }
+
+ @Override
+ public boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return super.contains(graphName, subject, predicate, object);
+ }
+
+ @Override
+ public Graph getGraph() {
+ return new JsonLdGraphImpl(rdfDataSet, Optional.empty(), bnodePrefix);
+ }
+
+ @Override
+ public Optional<Graph> getGraph(BlankNodeOrIRI graphName) {
+ if (graphName == null) {
+ return Optional.of(getGraph());
+ }
+ return getGraphNames().map(g -> (Graph) new JsonLdGraphImpl(rdfDataSet, Optional.of(g), bnodePrefix)).findAny();
+ }
+
+ @Override
+ public Stream<BlankNodeOrIRI> getGraphNames() {
+ return rdfDataSet.graphNames().parallelStream().filter(Predicate.isEqual("@default").negate())
+ .map(s -> s.startsWith("_:") ? new RDFDataset.BlankNode(s) : new RDFDataset.IRI(s))
+ .map(n -> (BlankNodeOrIRI) factory.asRDFTerm(n));
+ }
+
+ @Override
+ public void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ super.remove(graphName, subject, predicate, object);
+ }
+
+ @Override
+ public void remove(Quad q) {
+ remove(q.getGraphName(), q.getSubject(), q.getPredicate(), q.getObject());
+ }
+
+ @Override
+ public Stream<? extends Quad> stream(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate,
+ RDFTerm object) {
+ return filteredGraphs(graphName).flatMap(List::stream).filter(quadFilter(subject, predicate, object))
+ .map(factory::asQuad);
+ }
+
+ @Override
+ public long size() {
+ return rdfDataSet.graphNames().parallelStream().map(rdfDataSet::getQuads)
+ .collect(Collectors.summingLong(List::size));
+ }
+
+ @Override
+ Quad asTripleOrQuad(com.github.jsonldjava.core.RDFDataset.Quad jsonldQuad) {
+ return factory.asQuad(jsonldQuad);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java
index 1acba7d..42061a1 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraph.java
@@ -37,82 +37,76 @@ import com.github.jsonldjava.core.RDFDataset;
public interface JsonLdGraph extends JsonLdGraphLike<Triple>, Graph {
}
-class JsonLdGraphImpl extends AbstractJsonLdGraphLike<Triple>
- implements JsonLdGraph {
-
- private final Optional<BlankNodeOrIRI> graphName;
-
- JsonLdGraphImpl(RDFDataset rdfDataSet) {
- super(rdfDataSet);
- this.graphName = Optional.empty();
- }
-
- JsonLdGraphImpl(RDFDataset rdfDataSet, Optional<BlankNodeOrIRI> graphName, String bnodePrefix) {
- super(rdfDataSet, bnodePrefix);
- this.graphName = Objects.requireNonNull(graphName);
- }
-
- JsonLdGraphImpl(String bnodePrefix) {
- super(bnodePrefix);
- this.graphName = Optional.empty();
- }
-
- @Override
- public void clear() {
- filteredGraphs(graphName).forEach(l -> l.clear());
- }
-
- @Override
- public void add(Triple t) {
- // Ensure it's added in the correct graph
- super.add(graphName.orElse(null), t.getSubject(), t.getPredicate(), t.getObject());
- }
-
- @Override
- public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- super.add(graphName.orElse(null), subject, predicate, object);
- }
-
- @Override
- public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- return super.contains(graphName, subject, predicate, object);
- }
-
- @Override
- public boolean contains(Triple t) {
- return contains(graphName, t.getSubject(), t.getPredicate(), t.getObject());
- }
-
- @Override
- public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- super.remove(graphName, subject, predicate, object);
- }
-
- @Override
- public void remove(Triple t) {
- // Only remove from the particular graph
- remove(graphName, t.getSubject(), t.getPredicate(), t.getObject());
- }
-
- @Override
- public long size() {
- String g = graphName.map(factory::asJsonLdString).orElse("@default");
- return Optional.ofNullable(rdfDataSet.getQuads(g))
- .map(List::size).orElse(0);
- }
-
- @Override
- public Stream<JsonLdTriple> stream(BlankNodeOrIRI subject, IRI predicate,
- RDFTerm object) {
- return filteredGraphs(graphName)
- .flatMap(List::stream)
- .filter(quadFilter(subject, predicate, object))
- .map(factory::asTriple);
- }
-
- @Override
- JsonLdTriple asTripleOrQuad(com.github.jsonldjava.core.RDFDataset.Quad jsonldQuad) {
- return factory.asTriple(jsonldQuad);
- }
-}
+class JsonLdGraphImpl extends AbstractJsonLdGraphLike<Triple> implements JsonLdGraph {
+
+ private final Optional<BlankNodeOrIRI> graphName;
+
+ JsonLdGraphImpl(RDFDataset rdfDataSet) {
+ super(rdfDataSet);
+ this.graphName = Optional.empty();
+ }
+
+ JsonLdGraphImpl(RDFDataset rdfDataSet, Optional<BlankNodeOrIRI> graphName, String bnodePrefix) {
+ super(rdfDataSet, bnodePrefix);
+ this.graphName = Objects.requireNonNull(graphName);
+ }
+
+ JsonLdGraphImpl(String bnodePrefix) {
+ super(bnodePrefix);
+ this.graphName = Optional.empty();
+ }
+
+ @Override
+ public void clear() {
+ filteredGraphs(graphName).forEach(l -> l.clear());
+ }
+
+ @Override
+ public void add(Triple t) {
+ // Ensure it's added in the correct graph
+ super.add(graphName.orElse(null), t.getSubject(), t.getPredicate(), t.getObject());
+ }
+
+ @Override
+ public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ super.add(graphName.orElse(null), subject, predicate, object);
+ }
+ @Override
+ public boolean contains(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return super.contains(graphName, subject, predicate, object);
+ }
+
+ @Override
+ public boolean contains(Triple t) {
+ return contains(graphName, t.getSubject(), t.getPredicate(), t.getObject());
+ }
+
+ @Override
+ public void remove(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ super.remove(graphName, subject, predicate, object);
+ }
+
+ @Override
+ public void remove(Triple t) {
+ // Only remove from the particular graph
+ remove(graphName, t.getSubject(), t.getPredicate(), t.getObject());
+ }
+
+ @Override
+ public long size() {
+ String g = graphName.map(factory::asJsonLdString).orElse("@default");
+ return Optional.ofNullable(rdfDataSet.getQuads(g)).map(List::size).orElse(0);
+ }
+
+ @Override
+ public Stream<JsonLdTriple> stream(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ return filteredGraphs(graphName).flatMap(List::stream).filter(quadFilter(subject, predicate, object))
+ .map(factory::asTriple);
+ }
+
+ @Override
+ JsonLdTriple asTripleOrQuad(com.github.jsonldjava.core.RDFDataset.Quad jsonldQuad) {
+ return factory.asTriple(jsonldQuad);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
index d4417ec..7b5b3f5 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdGraphLike.java
@@ -46,177 +46,176 @@ import com.github.jsonldjava.core.RDFDataset.Node;
* specialisation of {@link TripleLike}, e.g. {@link Triple} or
* {@link org.apache.commons.rdf.api.Quad}
*/
-public interface JsonLdGraphLike <T extends TripleLike>
- extends GraphLike<T> {
- /**
- * Return the underlying JSONLD-Java {@link RDFDataset}.
- * <p>
- * Changes in the JSONLD-Java dataset is reflected in this class and vice
- * versa.
- *
- * @return The underlying JSONLD-JAva RDFDataset
- */
- public RDFDataset getRdfDataSet();
+public interface JsonLdGraphLike<T extends TripleLike> extends GraphLike<T> {
+ /**
+ * Return the underlying JSONLD-Java {@link RDFDataset}.
+ * <p>
+ * Changes in the JSONLD-Java dataset is reflected in this class and vice
+ * versa.
+ *
+ * @return The underlying JSONLD-JAva RDFDataset
+ */
+ public RDFDataset getRdfDataSet();
}
-abstract class AbstractJsonLdGraphLike<T extends TripleLike>
- implements JsonLdGraphLike<T> {
-
- /**
- * Used by {@link #bnodePrefix()} to get a unique UUID per JVM run
- */
- private static UUID SALT = UUID.randomUUID();
-
- /**
- * Prefix to use in blank node identifiers
- */
- final String bnodePrefix;
-
- final JsonLdRDF factory;
-
- /**
- * The underlying JSON-LD {@link RDFDataset}.
- * <p>
- * Note: This is NOT final as it is reset to <code>null</code> by {@link #close()}
- * (to free memory).
- */
- RDFDataset rdfDataSet;
-
- AbstractJsonLdGraphLike(RDFDataset rdfDataSet) {
- this(rdfDataSet, "urn:uuid:" + SALT + "#" + "g"+ System.identityHashCode(rdfDataSet));
- }
-
- AbstractJsonLdGraphLike(RDFDataset rdfDataSet, String bnodePrefix) {
- this.rdfDataSet = Objects.requireNonNull(rdfDataSet);
- this.bnodePrefix = Objects.requireNonNull(bnodePrefix);
- this.factory = new JsonLdRDF(bnodePrefix);
- }
-
- AbstractJsonLdGraphLike(String bnodePrefix) {
- this(new RDFDataset(), bnodePrefix);
- }
-
- @Override
- public void add(T t) {
- // add triples to default graph by default
- BlankNodeOrIRI graphName = null;
- if (t instanceof org.apache.commons.rdf.api.Quad) {
- org.apache.commons.rdf.api.Quad q = (org.apache.commons.rdf.api.Quad)t;
- graphName = q.getGraphName().orElse(null);
- }
- // FIXME: JSON-LD's rdfDataSet.addQuad method does not support
- // generalized RDF, so we have to do a naive cast here
- add(graphName, (BlankNodeOrIRI)t.getSubject(), (IRI)t.getPredicate(), t.getObject());
- }
-
- void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- String g = factory.asJsonLdString(graphName);
- String s = factory.asJsonLdString(subject);
- String p = factory.asJsonLdString(predicate);
- if (object instanceof BlankNodeOrIRI) {
- String o = factory.asJsonLdString((BlankNodeOrIRI)object);
- rdfDataSet.addQuad(s,p,o,g);
- } else if(object instanceof Literal) {
- Literal literal = (Literal) object;
- String language = literal.getLanguageTag().orElse(null);
- String datatype = literal.getDatatype().getIRIString();
- rdfDataSet.addQuad(s,p,literal.getLexicalForm(), datatype, language, g);
- }
- }
-
- public void close() {
- // Drop the memory reference, but don't clear it
- rdfDataSet = null;
- }
-
- @Override
- public void clear() {
- filteredGraphs(null).forEach(s -> s.clear());
- // In theory we could use
- //rdfDataSet.clear();
- // but then we would need to also do
- //rdfDataSet.put("@default", new ArrayList());
- // .. both of which seems to be touching too much on JsonLd-Java's internal structure
- }
-
- @Override
- public boolean contains(T tripleOrQuad) {
- return stream().anyMatch(Predicate.isEqual(tripleOrQuad));
- }
-
- public RDFDataset getRdfDataSet() {
- return rdfDataSet;
- }
-
-
- @Override
- public Stream<? extends T> stream() {
- return rdfDataSet.graphNames().parallelStream()
- .map(rdfDataSet::getQuads)
- .flatMap(List<RDFDataset.Quad>::parallelStream)
- .map(this::asTripleOrQuad);
- }
-
- /**
- * Convert JsonLd Quad to a Commons RDF {@link Triple} or {@link org.apache.commons.rdf.api.Quad}
- *
- *
- * @see JsonLdRDF#asTriple(Quad)
- * @see JsonLdRDF#asQuad(Quad)
- * @param jsonldQuad jsonld quad to convert
- * @return converted {@link TripleLike}
- */
- abstract T asTripleOrQuad(RDFDataset.Quad jsonldQuad);
-
- // This will be made public in JsonLdDataset
- // and is used by the other methods.
- boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI s, IRI p, RDFTerm o) {
- return filteredGraphs(graphName).flatMap(List::stream).anyMatch(quadFilter(s,p,o));
- }
-
- Stream<List<RDFDataset.Quad>> filteredGraphs(Optional<BlankNodeOrIRI> graphName) {
- return rdfDataSet.graphNames().parallelStream()
- // if graphName == null (wildcard), select all graphs,
- // otherwise check its jsonld string
- // (including @default for default graph)
- .filter(g -> graphName == null ||
- g.equals(graphName.map(factory::asJsonLdString).orElse("@default")))
- // remove the quads which match our filter (which could have nulls as wildcards)
- .map(rdfDataSet::getQuads);
- }
-
- String graphNameAsJsonLdString(T tripleOrQuad) {
- if (tripleOrQuad instanceof org.apache.commons.rdf.api.Quad) {
- org.apache.commons.rdf.api.Quad quad = (org.apache.commons.rdf.api.Quad)tripleOrQuad;
- return quad.getGraphName().map(factory::asJsonLdString).orElse("@default");
- }
- return "@default";
- }
-
-
- Predicate<RDFDataset.Quad> quadFilter(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- Optional<Node> subjectNode = Optional.ofNullable(subject).map(factory::asJsonLdNode);
- Optional<Node> predicateNode = Optional.ofNullable(predicate).map(factory::asJsonLdNode);
- Optional<Node> objectNode = Optional.ofNullable(object).map(factory::asJsonLdNode);
-
- return q -> {
- if (subjectNode.isPresent() && subjectNode.get().compareTo(q.getSubject()) != 0) {
- return false;
- }
- if (predicateNode.isPresent() && predicateNode.get().compareTo(q.getPredicate()) != 0) {
- return false;
- }
- if (objectNode.isPresent() && objectNode.get().compareTo(q.getObject()) != 0) {
- return false;
- }
- return true;
- };
- }
-
- // NOTE: This is made public in JsonLdDataset and is used by the other remove methods.
- void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
- // remove the quads which match our filter (which could have nulls as wildcards)
- filteredGraphs(graphName).forEach(t -> t.removeIf(quadFilter(subject, predicate, object)));
- }
-
+abstract class AbstractJsonLdGraphLike<T extends TripleLike> implements JsonLdGraphLike<T> {
+
+ /**
+ * Used by {@link #bnodePrefix()} to get a unique UUID per JVM run
+ */
+ private static UUID SALT = UUID.randomUUID();
+
+ /**
+ * Prefix to use in blank node identifiers
+ */
+ final String bnodePrefix;
+
+ final JsonLdRDF factory;
+
+ /**
+ * The underlying JSON-LD {@link RDFDataset}.
+ * <p>
+ * Note: This is NOT final as it is reset to <code>null</code> by
+ * {@link #close()} (to free memory).
+ */
+ RDFDataset rdfDataSet;
+
+ AbstractJsonLdGraphLike(RDFDataset rdfDataSet) {
+ this(rdfDataSet, "urn:uuid:" + SALT + "#" + "g" + System.identityHashCode(rdfDataSet));
+ }
+
+ AbstractJsonLdGraphLike(RDFDataset rdfDataSet, String bnodePrefix) {
+ this.rdfDataSet = Objects.requireNonNull(rdfDataSet);
+ this.bnodePrefix = Objects.requireNonNull(bnodePrefix);
+ this.factory = new JsonLdRDF(bnodePrefix);
+ }
+
+ AbstractJsonLdGraphLike(String bnodePrefix) {
+ this(new RDFDataset(), bnodePrefix);
+ }
+
+ @Override
+ public void add(T t) {
+ // add triples to default graph by default
+ BlankNodeOrIRI graphName = null;
+ if (t instanceof org.apache.commons.rdf.api.Quad) {
+ org.apache.commons.rdf.api.Quad q = (org.apache.commons.rdf.api.Quad) t;
+ graphName = q.getGraphName().orElse(null);
+ }
+ // FIXME: JSON-LD's rdfDataSet.addQuad method does not support
+ // generalized RDF, so we have to do a naive cast here
+ add(graphName, (BlankNodeOrIRI) t.getSubject(), (IRI) t.getPredicate(), t.getObject());
+ }
+
+ void add(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ String g = factory.asJsonLdString(graphName);
+ String s = factory.asJsonLdString(subject);
+ String p = factory.asJsonLdString(predicate);
+ if (object instanceof BlankNodeOrIRI) {
+ String o = factory.asJsonLdString((BlankNodeOrIRI) object);
+ rdfDataSet.addQuad(s, p, o, g);
+ } else if (object instanceof Literal) {
+ Literal literal = (Literal) object;
+ String language = literal.getLanguageTag().orElse(null);
+ String datatype = literal.getDatatype().getIRIString();
+ rdfDataSet.addQuad(s, p, literal.getLexicalForm(), datatype, language, g);
+ }
+ }
+
+ public void close() {
+ // Drop the memory reference, but don't clear it
+ rdfDataSet = null;
+ }
+
+ @Override
+ public void clear() {
+ filteredGraphs(null).forEach(s -> s.clear());
+ // In theory we could use
+ // rdfDataSet.clear();
+ // but then we would need to also do
+ // rdfDataSet.put("@default", new ArrayList());
+ // .. both of which seems to be touching too much on JsonLd-Java's
+ // internal structure
+ }
+
+ @Override
+ public boolean contains(T tripleOrQuad) {
+ return stream().anyMatch(Predicate.isEqual(tripleOrQuad));
+ }
+
+ public RDFDataset getRdfDataSet() {
+ return rdfDataSet;
+ }
+
+ @Override
+ public Stream<? extends T> stream() {
+ return rdfDataSet.graphNames().parallelStream().map(rdfDataSet::getQuads)
+ .flatMap(List<RDFDataset.Quad>::parallelStream).map(this::asTripleOrQuad);
+ }
+
+ /**
+ * Convert JsonLd Quad to a Commons RDF {@link Triple} or
+ * {@link org.apache.commons.rdf.api.Quad}
+ *
+ *
+ * @see JsonLdRDF#asTriple(Quad)
+ * @see JsonLdRDF#asQuad(Quad)
+ * @param jsonldQuad
+ * jsonld quad to convert
+ * @return converted {@link TripleLike}
+ */
+ abstract T asTripleOrQuad(RDFDataset.Quad jsonldQuad);
+
+ // This will be made public in JsonLdDataset
+ // and is used by the other methods.
+ boolean contains(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI s, IRI p, RDFTerm o) {
+ return filteredGraphs(graphName).flatMap(List::stream).anyMatch(quadFilter(s, p, o));
+ }
+
+ Stream<List<RDFDataset.Quad>> filteredGraphs(Optional<BlankNodeOrIRI> graphName) {
+ return rdfDataSet.graphNames().parallelStream()
+ // if graphName == null (wildcard), select all graphs,
+ // otherwise check its jsonld string
+ // (including @default for default graph)
+ .filter(g -> graphName == null || g.equals(graphName.map(factory::asJsonLdString).orElse("@default")))
+ // remove the quads which match our filter (which could have
+ // nulls as wildcards)
+ .map(rdfDataSet::getQuads);
+ }
+
+ String graphNameAsJsonLdString(T tripleOrQuad) {
+ if (tripleOrQuad instanceof org.apache.commons.rdf.api.Quad) {
+ org.apache.commons.rdf.api.Quad quad = (org.apache.commons.rdf.api.Quad) tripleOrQuad;
+ return quad.getGraphName().map(factory::asJsonLdString).orElse("@default");
+ }
+ return "@default";
+ }
+
+ Predicate<RDFDataset.Quad> quadFilter(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ Optional<Node> subjectNode = Optional.ofNullable(subject).map(factory::asJsonLdNode);
+ Optional<Node> predicateNode = Optional.ofNullable(predicate).map(factory::asJsonLdNode);
+ Optional<Node> objectNode = Optional.ofNullable(object).map(factory::asJsonLdNode);
+
+ return q -> {
+ if (subjectNode.isPresent() && subjectNode.get().compareTo(q.getSubject()) != 0) {
+ return false;
+ }
+ if (predicateNode.isPresent() && predicateNode.get().compareTo(q.getPredicate()) != 0) {
+ return false;
+ }
+ if (objectNode.isPresent() && objectNode.get().compareTo(q.getObject()) != 0) {
+ return false;
+ }
+ return true;
+ };
+ }
+
+ // NOTE: This is made public in JsonLdDataset and is used by the other
+ // remove methods.
+ void remove(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ // remove the quads which match our filter (which could have nulls as
+ // wildcards)
+ filteredGraphs(graphName).forEach(t -> t.removeIf(quadFilter(subject, predicate, object)));
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdIRI.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdIRI.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdIRI.java
index dc94401..f7c1707 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdIRI.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdIRI.java
@@ -25,40 +25,40 @@ import com.github.jsonldjava.core.RDFDataset.Node;
public interface JsonLdIRI extends JsonLdTerm, IRI {
}
- final class JsonLdIRIImpl extends JsonLdTermImpl implements JsonLdIRI {
-
- JsonLdIRIImpl(Node node) {
- super(node);
- if (! node.isIRI()) {
- throw new IllegalArgumentException("Node is not an IRI:" + node);
- }
- }
-
- JsonLdIRIImpl(String iri) {
- super(new RDFDataset.IRI(iri));
- }
-
- @Override
- public String ntriplesString() {
- return "<" + node.getValue() + ">";
- }
-
- @Override
- public String getIRIString() {
- return node.getValue();
- }
-
- @Override
- public int hashCode() {
- return node.getValue().hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (! (obj instanceof IRI)) {
- return false;
- }
- IRI other = (IRI) obj;
- return node.getValue().equals(other.getIRIString());
- }
- }
+final class JsonLdIRIImpl extends JsonLdTermImpl implements JsonLdIRI {
+
+ JsonLdIRIImpl(Node node) {
+ super(node);
+ if (!node.isIRI()) {
+ throw new IllegalArgumentException("Node is not an IRI:" + node);
+ }
+ }
+
+ JsonLdIRIImpl(String iri) {
+ super(new RDFDataset.IRI(iri));
+ }
+
+ @Override
+ public String ntriplesString() {
+ return "<" + node.getValue() + ">";
+ }
+
+ @Override
+ public String getIRIString() {
+ return node.getValue();
+ }
+
+ @Override
+ public int hashCode() {
+ return node.getValue().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof IRI)) {
+ return false;
+ }
+ IRI other = (IRI) obj;
+ return node.getValue().equals(other.getIRIString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdLiteral.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdLiteral.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdLiteral.java
index 01dff6f..afb7da2 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdLiteral.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdLiteral.java
@@ -27,73 +27,72 @@ import org.apache.commons.rdf.simple.Types;
import com.github.jsonldjava.core.RDFDataset.Node;
public interface JsonLdLiteral extends JsonLdTerm, Literal {
-}
-
- class JsonLdLiteralImpl extends JsonLdTermImpl implements JsonLdLiteral {
-
- JsonLdLiteralImpl(Node node) {
- super(node);
- if (! node.isLiteral()) {
- throw new IllegalArgumentException("Node is not a Literal:" + node);
- }
- }
-
- @Override
- public String ntriplesString() {
- StringBuilder sb = new StringBuilder();
- sb.append('"');
- // Escape special characters
- sb.append(getLexicalForm().replace("\\", "\\\\"). // escaped to \\
- replace("\"", "\\\""). // escaped to \"
- replace("\r", "\\r"). // escaped to \r
- replace("\n", "\\n")); // escaped to \n
- sb.append('"');
-
- if (getLanguageTag().isPresent()) {
- sb.append("@");
- sb.append(getLanguageTag().get());
- } else if (!getDatatype().equals(Types.XSD_STRING)) {
- sb.append("^^");
- sb.append(getDatatype().ntriplesString());
- }
- return sb.toString();
- }
-
- @Override
- public String getLexicalForm() {
- return node.getValue();
- }
-
- @Override
- public IRI getDatatype() {
- return new JsonLdIRIImpl(node.getDatatype());
- }
-
- @Override
- public Optional<String> getLanguageTag() {
- return Optional.ofNullable(node.getLanguage());
- }
-
- @Override
- public int hashCode() {
- // Should be the same as
- // Objects.hash(getLexicalForm(), getDatatype(), getLanguageTag());
- return Objects.hash(node.getValue(), node.getDatatype(), node.getLanguage());
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof JsonLdLiteral) {
- JsonLdLiteral other = (JsonLdLiteral) obj;
- return asJsonLdNode().compareTo(other.asJsonLdNode()) == 0;
- }
- if (obj instanceof Literal) {
- Literal other = (Literal) obj;
- return getLexicalForm().equals(other.getLexicalForm()) &&
- getDatatype().equals(other.getDatatype()) &&
- getLanguageTag().equals(other.getLanguageTag());
- }
- return false;
-
- }
- }
+}
+
+class JsonLdLiteralImpl extends JsonLdTermImpl implements JsonLdLiteral {
+
+ JsonLdLiteralImpl(Node node) {
+ super(node);
+ if (!node.isLiteral()) {
+ throw new IllegalArgumentException("Node is not a Literal:" + node);
+ }
+ }
+
+ @Override
+ public String ntriplesString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append('"');
+ // Escape special characters
+ sb.append(getLexicalForm().replace("\\", "\\\\"). // escaped to \\
+ replace("\"", "\\\""). // escaped to \"
+ replace("\r", "\\r"). // escaped to \r
+ replace("\n", "\\n")); // escaped to \n
+ sb.append('"');
+
+ if (getLanguageTag().isPresent()) {
+ sb.append("@");
+ sb.append(getLanguageTag().get());
+ } else if (!getDatatype().equals(Types.XSD_STRING)) {
+ sb.append("^^");
+ sb.append(getDatatype().ntriplesString());
+ }
+ return sb.toString();
+ }
+
+ @Override
+ public String getLexicalForm() {
+ return node.getValue();
+ }
+
+ @Override
+ public IRI getDatatype() {
+ return new JsonLdIRIImpl(node.getDatatype());
+ }
+
+ @Override
+ public Optional<String> getLanguageTag() {
+ return Optional.ofNullable(node.getLanguage());
+ }
+
+ @Override
+ public int hashCode() {
+ // Should be the same as
+ // Objects.hash(getLexicalForm(), getDatatype(), getLanguageTag());
+ return Objects.hash(node.getValue(), node.getDatatype(), node.getLanguage());
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof JsonLdLiteral) {
+ JsonLdLiteral other = (JsonLdLiteral) obj;
+ return asJsonLdNode().compareTo(other.asJsonLdNode()) == 0;
+ }
+ if (obj instanceof Literal) {
+ Literal other = (Literal) obj;
+ return getLexicalForm().equals(other.getLexicalForm()) && getDatatype().equals(other.getDatatype())
+ && getLanguageTag().equals(other.getLanguageTag());
+ }
+ return false;
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuad.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuad.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuad.java
index fcf71f1..9b39514 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuad.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuad.java
@@ -28,31 +28,28 @@ public interface JsonLdQuad extends org.apache.commons.rdf.api.Quad, JsonLdTripl
}
- final class JsonLdQuadImpl extends JsonLdQuadLikeImpl<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI>
- implements JsonLdQuad {
-
- JsonLdQuadImpl(com.github.jsonldjava.core.RDFDataset.Quad quad, String blankNodePrefix) {
- super(quad, blankNodePrefix);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (! (obj instanceof org.apache.commons.rdf.api.Quad)) {
- return false;
- }
- org.apache.commons.rdf.api.Quad other = (org.apache.commons.rdf.api.Quad) obj;
- return getGraphName().equals(other.getGraphName()) &&
- getSubject().equals(other.getSubject()) &&
- getPredicate().equals(other.getPredicate()) &&
- getObject().equals(other.getObject());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(getGraphName(), getSubject(), getPredicate(), getObject());
- }
- }
-
+final class JsonLdQuadImpl extends JsonLdQuadLikeImpl<BlankNodeOrIRI, IRI, RDFTerm, BlankNodeOrIRI>
+ implements JsonLdQuad {
+
+ JsonLdQuadImpl(com.github.jsonldjava.core.RDFDataset.Quad quad, String blankNodePrefix) {
+ super(quad, blankNodePrefix);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof org.apache.commons.rdf.api.Quad)) {
+ return false;
+ }
+ org.apache.commons.rdf.api.Quad other = (org.apache.commons.rdf.api.Quad) obj;
+ return getGraphName().equals(other.getGraphName()) && getSubject().equals(other.getSubject())
+ && getPredicate().equals(other.getPredicate()) && getObject().equals(other.getObject());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getGraphName(), getSubject(), getPredicate(), getObject());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
index 1584f9e..9f92cda 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
@@ -25,50 +25,50 @@ import org.apache.commons.rdf.api.RDFTerm;
import com.github.jsonldjava.core.RDFDataset.Quad;
public interface JsonLdQuadLike<G extends RDFTerm> extends QuadLike<G>, JsonLdTripleLike {
-
+
}
-
- class JsonLdQuadLikeImpl<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm> implements JsonLdQuadLike<G> {
-
- // Note: We always pass the blankNodePrefix and don't rely on the internal
- // blankNodePrefix in this static factory
- private static JsonLdRDF rdfTermFactory = new JsonLdRDF();
-
- private final Quad quad;
- private String blankNodePrefix;
-
- JsonLdQuadLikeImpl(Quad jsonldQuad, String blankNodePrefix) {
- this.quad = jsonldQuad;
- this.blankNodePrefix = blankNodePrefix;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Optional<G> getGraphName() {
- G g = (G) rdfTermFactory.asRDFTerm(quad.getGraph(), blankNodePrefix);
- return Optional.ofNullable(g);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public S getSubject() {
- return (S) rdfTermFactory.asRDFTerm(quad.getSubject(), blankNodePrefix);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public P getPredicate() {
- return (P) rdfTermFactory.asRDFTerm(quad.getPredicate(), blankNodePrefix);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public O getObject() {
- return (O) rdfTermFactory.asRDFTerm(quad.getObject(), blankNodePrefix);
- }
-
- public Quad asJsonLdQuad() {
- return quad;
- }
- }
+class JsonLdQuadLikeImpl<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends RDFTerm>
+ implements JsonLdQuadLike<G> {
+
+ // Note: We always pass the blankNodePrefix and don't rely on the internal
+ // blankNodePrefix in this static factory
+ private static JsonLdRDF rdfTermFactory = new JsonLdRDF();
+
+ private final Quad quad;
+ private String blankNodePrefix;
+
+ JsonLdQuadLikeImpl(Quad jsonldQuad, String blankNodePrefix) {
+ this.quad = jsonldQuad;
+ this.blankNodePrefix = blankNodePrefix;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Optional<G> getGraphName() {
+ G g = (G) rdfTermFactory.asRDFTerm(quad.getGraph(), blankNodePrefix);
+ return Optional.ofNullable(g);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public S getSubject() {
+ return (S) rdfTermFactory.asRDFTerm(quad.getSubject(), blankNodePrefix);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public P getPredicate() {
+ return (P) rdfTermFactory.asRDFTerm(quad.getPredicate(), blankNodePrefix);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public O getObject() {
+ return (O) rdfTermFactory.asRDFTerm(quad.getObject(), blankNodePrefix);
+ }
+
+ public Quad asJsonLdQuad() {
+ return quad;
+ }
+}
[30/50] [abbrv] incubator-commonsrdf git commit: Don't test relative
IRIs
Posted by st...@apache.org.
Don't test relative IRIs
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/2e160b58
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/2e160b58
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/2e160b58
Branch: refs/heads/COMMONSRDF-7
Commit: 2e160b5839713fe3419775fb8dbdeaa82e089553
Parents: e340604
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 28 10:57:39 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 28 10:57:39 2016 +0100
----------------------------------------------------------------------
.../rdf/api/AbstractRDFTermFactoryTest.java | 26 --------------------
1 file changed, 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2e160b58/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
index 1ef5b6c..97ee5fa 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractRDFTermFactoryTest.java
@@ -164,32 +164,6 @@ public abstract class AbstractRDFTermFactoryTest {
}
@Test
- public void testCreateIRIRelative() throws Exception {
- // Although relative IRIs are defined in
- // http://www.w3.org/TR/rdf11-concepts/#section-IRIs
- // it is not a requirement for an implementation to support
- // it (all instances of an relative IRI should eventually
- // be possible to resolve to an absolute IRI)
- try {
- factory.createIRI("../relative");
- } catch (IllegalArgumentException ex) {
- Assume.assumeNoException("Relative IRIs not supported - ignore this test", ex);
- return;
- }
- IRI relative = factory.createIRI("../relative");
- assertEquals("../relative", relative.getIRIString());
- assertEquals("<../relative>", relative.ntriplesString());
-
- IRI relativeTerm = factory.createIRI("../relative#term");
- assertEquals("../relative#term", relativeTerm.getIRIString());
- assertEquals("<../relative#term>", relativeTerm.ntriplesString());
-
- IRI emptyRelative = factory.createIRI(""); // <> equals the base URI
- assertEquals("", emptyRelative.getIRIString());
- assertEquals("<>", emptyRelative.ntriplesString());
- }
-
- @Test
public void testCreateLiteral() throws Exception {
Literal example = factory.createLiteral("Example");
assertEquals("Example", example.getLexicalForm());
[36/50] [abbrv] incubator-commonsrdf git commit: Merge branch
'master' into COMMONSRDF-46
Posted by st...@apache.org.
Merge branch 'master' into COMMONSRDF-46
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/2d4b5d30
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/2d4b5d30
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/2d4b5d30
Branch: refs/heads/COMMONSRDF-7
Commit: 2d4b5d300c1f27f62b356e4ef2d6910b746549f2
Parents: fb80617 6aa5a5d
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Oct 28 11:34:20 2016 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Oct 28 11:34:20 2016 +0100
----------------------------------------------------------------------
RELEASE-NOTES.txt | 19 +++++++++++++++++++
pom.xml | 4 ++--
.../rdf/rdf4j/experimental/RDF4JParser.java | 2 +-
.../org/apache/commons/rdf/simple/GraphImpl.java | 2 +-
4 files changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2d4b5d30/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
----------------------------------------------------------------------
diff --cc rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
index 558108b,be37449..26b3647
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java
@@@ -111,10 -111,10 +111,10 @@@ public class RDF4JParser extends Abstra
@Override
protected RDF4JParser prepareForParsing() throws IOException, IllegalStateException {
- RDF4JParser c = prepareForParsing();
+ RDF4JParser c = super.prepareForParsing();
- // Ensure we have an RDF4JFactory for conversion.
+ // Ensure we have an RDF4J for conversion.
// We'll make a new one if user has provided a non-RDF4J factory
- c.rdf4jTermFactory = (RDF4JFactory) getRdfTermFactory().filter(RDF4JFactory.class::isInstance)
+ c.rdf4jTermFactory = (RDF4J) getRdfTermFactory().filter(RDF4J.class::isInstance)
.orElseGet(c::createRDFTermFactory);
return c;
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2d4b5d30/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
[38/50] [abbrv] incubator-commonsrdf git commit: Reformat tab ->
spaces
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
index e478c39..584bff3 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
@@ -56,503 +56,514 @@ import org.apache.commons.rdf.simple.SimpleRDF;
* {@link #parse()} (e.g. because it has its own threading model or use
* asynchronous remote execution).
*/
-public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>>
- implements RDFParser, Cloneable {
-
- public static final ThreadGroup threadGroup = new ThreadGroup("Commons RDF parsers");
- private static final ExecutorService threadpool = Executors.newCachedThreadPool(r -> new Thread(threadGroup, r));
-
- // Basically only used for creating IRIs
- private static RDF internalRdfTermFactory = new SimpleRDF();
-
- /**
- * Get the set {@link RDF}, if any.
- *
- * @return The {@link RDF} to use, or {@link Optional#empty()} if
- * it has not been set
- */
- public Optional<RDF> getRdfTermFactory() {
- return rdfTermFactory;
- }
-
- /**
- * Get the set content-type {@link RDFSyntax}, if any.
- * <p>
- * If this is {@link Optional#isPresent()}, then {@link #getContentType()}
- * contains the value of {@link RDFSyntax#mediaType}.
- *
- * @return The {@link RDFSyntax} of the content type, or
- * {@link Optional#empty()} if it has not been set
- */
- public Optional<RDFSyntax> getContentTypeSyntax() {
- return contentTypeSyntax;
- }
-
- /**
- * Get the set content-type String, if any.
- * <p>
- * If this is {@link Optional#isPresent()} and is recognized by
- * {@link RDFSyntax#byMediaType(String)}, then the corresponding
- * {@link RDFSyntax} is set on {@link #getContentType()}, otherwise that is
- * {@link Optional#empty()}.
- *
- * @return The Content-Type IANA media type, e.g. <code>text/turtle</code>,
- * or {@link Optional#empty()} if it has not been set
- */
- public final Optional<String> getContentType() {
- return contentType;
- }
-
- /**
- * Get the target to consume parsed Quads.
- * <p>
- * From the call to {@link #parseSynchronusly()}, this will be a
- * non-<code>null</code> value (as a target is a required setting).
- *
- * @return The target consumer of {@link Quad}s, or <code>null</code> if it
- * has not yet been set.
- *
- */
- public Consumer<Quad> getTarget() {
- return target;
- }
-
- /**
- * Get the target dataset as set by {@link #target(Dataset)}.
- * <p>
- * The return value is {@link Optional#isPresent()} if and only if
- * {@link #target(Dataset)} has been set, meaning that the implementation
- * may choose to append parsed quads to the {@link Dataset} directly instead
- * of relying on the generated {@link #getTarget()} consumer.
- * <p>
- * If this value is present, then {@link #getTargetGraph()} MUST
- * be {@link Optional#empty()}.
- *
- * @return The target Dataset, or {@link Optional#empty()} if another kind of target has been set.
- */
- public Optional<Dataset> getTargetDataset() {
- return targetDataset;
- }
-
- /**
- * Get the target graph as set by {@link #target(Graph)}.
- * <p>
- * The return value is {@link Optional#isPresent()} if and only if
- * {@link #target(Graph)} has been set, meaning that the implementation
- * may choose to append parsed triples to the {@link Graph} directly instead
- * of relying on the generated {@link #getTarget()} consumer.
- * <p>
- * If this value is present, then {@link #getTargetDataset()} MUST
- * be {@link Optional#empty()}.
- *
- * @return The target Graph, or {@link Optional#empty()} if another kind of target has been set.
- */
- public Optional<Graph> getTargetGraph() {
- return targetGraph;
- }
-
- /**
- * Get the set base {@link IRI}, if present.
- *
- * @return The base {@link IRI}, or {@link Optional#empty()} if it has not been set
- */
- public Optional<IRI> getBase() {
- return base;
- }
-
- /**
- * Get the set source {@link InputStream}.
- * <p>
- * If this is {@link Optional#isPresent()}, then
- * {@link #getSourceFile()} and {@link #getSourceIri()}
- * are {@link Optional#empty()}.
- *
- * @return The source {@link InputStream}, or {@link Optional#empty()} if it has not been set
- */
- public Optional<InputStream> getSourceInputStream() {
- return sourceInputStream;
- }
-
- /**
- * Get the set source {@link Path}.
- * <p>
- * If this is {@link Optional#isPresent()}, then
- * {@link #getSourceInputStream()} and {@link #getSourceIri()}
- * are {@link Optional#empty()}.
- *
- * @return The source {@link Path}, or {@link Optional#empty()} if it has not been set
- */
- public Optional<Path> getSourceFile() {
- return sourceFile;
- }
-
- /**
- * Get the set source {@link Path}.
- * <p>
- * If this is {@link Optional#isPresent()}, then
- * {@link #getSourceInputStream()} and {@link #getSourceInputStream()}
- * are {@link Optional#empty()}.
- *
- * @return The source {@link IRI}, or {@link Optional#empty()} if it has not been set
- */
- public Optional<IRI> getSourceIri() {
- return sourceIri;
- }
-
-
- private Optional<RDF> rdfTermFactory = Optional.empty();
- private Optional<RDFSyntax> contentTypeSyntax = Optional.empty();
- private Optional<String> contentType = Optional.empty();
- private Optional<IRI> base = Optional.empty();
- private Optional<InputStream> sourceInputStream = Optional.empty();
- private Optional<Path> sourceFile = Optional.empty();
- private Optional<IRI> sourceIri = Optional.empty();
- private Consumer<Quad> target;
- private Optional<Dataset> targetDataset;
- private Optional<Graph> targetGraph;
-
- @SuppressWarnings("unchecked")
- @Override
- public T clone() {
- try {
- return (T) super.clone();
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException(e);
- }
- }
-
- @SuppressWarnings("unchecked")
- protected T asT() {
- return (T) this;
- }
-
- @Override
- public T rdfTermFactory(RDF rdfTermFactory) {
- AbstractRDFParser<T> c = clone();
- c.rdfTermFactory = Optional.ofNullable(rdfTermFactory);
- return c.asT();
- }
-
- @Override
- public T contentType(RDFSyntax rdfSyntax) throws IllegalArgumentException {
- AbstractRDFParser<T> c = clone();
- c.contentTypeSyntax = Optional.ofNullable(rdfSyntax);
- c.contentType = c.contentTypeSyntax.map(syntax -> syntax.mediaType);
- return c.asT();
- }
-
- @Override
- public T contentType(String contentType) throws IllegalArgumentException {
- AbstractRDFParser<T> c = clone();
- c.contentType = Optional.ofNullable(contentType);
- c.contentTypeSyntax = c.contentType.flatMap(RDFSyntax::byMediaType);
- return c.asT();
- }
-
- @Override
- public T base(IRI base) {
- AbstractRDFParser<T> c = clone();
- c.base = Optional.ofNullable(base);
- c.base.ifPresent(i -> checkIsAbsolute(i));
- return c.asT();
- }
-
- @Override
- public T base(String base) throws IllegalArgumentException {
- return base(internalRdfTermFactory.createIRI(base));
- }
-
- @Override
- public T source(InputStream inputStream) {
- AbstractRDFParser<T> c = clone();
- c.resetSource();
- c.sourceInputStream = Optional.ofNullable(inputStream);
- return c.asT();
- }
-
- @Override
- public T source(Path file) {
- AbstractRDFParser<T> c = clone();
- c.resetSource();
- c.sourceFile = Optional.ofNullable(file);
- return c.asT();
- }
-
- @Override
- public T source(IRI iri) {
- AbstractRDFParser<T> c = clone();
- c.resetSource();
- c.sourceIri = Optional.ofNullable(iri);
- c.sourceIri.ifPresent(i -> checkIsAbsolute(i));
- return c.asT();
- }
-
- @Override
- public T source(String iri) throws IllegalArgumentException {
- AbstractRDFParser<T> c = clone();
- c.resetSource();
- c.sourceIri = Optional.ofNullable(iri).map(internalRdfTermFactory::createIRI);
- c.sourceIri.ifPresent(i -> checkIsAbsolute(i));
- return source(internalRdfTermFactory.createIRI(iri));
- }
-
- /**
- * Check if an iri is absolute.
- * <p>
- * Used by {@link #source(String)} and {@link #base(String)}.
- *
- * @param iri IRI to check
- * @throws IllegalArgumentException If the IRI is not absolute
- */
- protected void checkIsAbsolute(IRI iri) throws IllegalArgumentException {
- if (!URI.create(iri.getIRIString()).isAbsolute()) {
- throw new IllegalArgumentException("IRI is not absolute: " + iri);
- }
- }
-
- /**
- * Check that one and only one source is present and valid.
- * <p>
- * Used by {@link #parse()}.
- * <p>
- * Subclasses might override this method, e.g. to support other
- * source combinations, or to check if the sourceIri is
- * resolvable.
- *
- * @throws IOException If a source file can't be read
- */
- protected void checkSource() throws IOException {
- if (!sourceFile.isPresent() && !sourceInputStream.isPresent() && !sourceIri.isPresent()) {
- throw new IllegalStateException("No source has been set");
- }
- if (sourceIri.isPresent() && sourceInputStream.isPresent()) {
- throw new IllegalStateException("Both sourceIri and sourceInputStream have been set");
- }
- if (sourceIri.isPresent() && sourceFile.isPresent()) {
- throw new IllegalStateException("Both sourceIri and sourceFile have been set");
- }
- if (sourceInputStream.isPresent() && sourceFile.isPresent()) {
- throw new IllegalStateException("Both sourceInputStream and sourceFile have been set");
- }
- if (sourceFile.isPresent() && !sourceFile.filter(Files::isReadable).isPresent()) {
- throw new IOException("Can't read file: " + sourceFile);
- }
- }
-
- /**
- * Check if base is required.
- *
- * @throws IllegalStateException if base is required, but not set.
- */
- protected void checkBaseRequired() throws IllegalStateException {
- if (!base.isPresent() && sourceInputStream.isPresent()
- && !contentTypeSyntax.filter(t -> t == RDFSyntax.NQUADS || t == RDFSyntax.NTRIPLES).isPresent()) {
- throw new IllegalStateException("base iri required for inputstream source");
- }
- }
-
- /**
- * Reset all source* fields to Optional.empty()
- * <p>
- * Subclasses should override this and call <code>super.resetSource()</code>
- * if they need to reset any additional source* fields.
- *
- */
- protected void resetSource() {
- sourceInputStream = Optional.empty();
- sourceIri = Optional.empty();
- sourceFile = Optional.empty();
- }
-
- /**
- * Reset all optional target* fields to {@link Optional#empty()}.
- * <p>
- * Note that the consumer set for {@link #getTarget()} is
- * <strong>note</strong> reset.
- * <p>
- * Subclasses should override this and call <code>super.resetTarget()</code>
- * if they need to reset any additional target* fields.
- *
- */
- protected void resetTarget() {
- targetDataset = Optional.empty();
- targetGraph = Optional.empty();
- }
-
- /**
- * Parse {@link #sourceInputStream}, {@link #sourceFile} or
- * {@link #sourceIri}.
- * <p>
- * One of the source fields MUST be present, as checked by {@link #checkSource()}.
- * <p>
- * {@link #checkBaseRequired()} is called to verify if {@link #getBase()} is required.
- *
- * @throws IOException If the source could not be read
- * @throws RDFParseException If the source could not be parsed (e.g. a .ttl file was not valid Turtle)
- */
- protected abstract void parseSynchronusly() throws IOException, RDFParseException;
-
- /**
- * Prepare a clone of this RDFParser which have been checked and
- * completed.
- * <p>
- * The returned clone will always have
- * {@link #getTarget()} and {@link #getRdfTermFactory()} present.
- * <p>
- * If the {@link #getSourceFile()} is present, but the
- * {@link #getBase()} is not present, the base will be set to the
- * <code>file:///</code> IRI for the Path's real path (e.g. resolving any
- * symbolic links).
- *
- * @return A completed and checked clone of this RDFParser
- * @throws IOException If the source was not accessible (e.g. a file was not found)
- * @throws IllegalStateException If the parser was not in a compatible setting (e.g. contentType was an invalid string)
- */
- protected T prepareForParsing() throws IOException, IllegalStateException {
- checkSource();
- checkBaseRequired();
- checkContentType();
- checkTarget();
-
- // We'll make a clone of our current state which will be passed to
- // parseSynchronously()
- AbstractRDFParser<T> c = clone();
-
- // Use a fresh SimpleRDF for each parse
- if (!c.rdfTermFactory.isPresent()) {
- c.rdfTermFactory = Optional.of(createRDFTermFactory());
- }
- // sourceFile, but no base? Let's follow any symlinks and use
- // the file:/// URI
- if (c.sourceFile.isPresent() && !c.base.isPresent()) {
- URI baseUri = c.sourceFile.get().toRealPath().toUri();
- c.base = Optional.of(internalRdfTermFactory.createIRI(baseUri.toString()));
- }
-
- return c.asT();
- }
-
- /**
- * Subclasses can override this method to check the target is
- * valid.
- * <p>
- * The default implementation throws an IllegalStateException if the
- * target has not been set.
- */
- protected void checkTarget() {
- if (target == null) {
- throw new IllegalStateException("target has not been set");
- }
- if (targetGraph.isPresent() && targetDataset.isPresent()) {
- // This should not happen as each target(..) method resets the optionals
- throw new IllegalStateException("targetGraph and targetDataset can't both be set");
- }
- }
-
- /**
- * Subclasses can override this method to check compatibility with the
- * contentType setting.
- *
- * @throws IllegalStateException
- * if the {@link #getContentType()} or
- * {@link #getContentTypeSyntax()} is not compatible or invalid
- */
- protected void checkContentType() throws IllegalStateException {
- }
-
- /**
- * Guess RDFSyntax from a local file's extension.
- * <p>
- * This method can be used by subclasses if {@link #getContentType()} is not
- * present and {@link #getSourceFile()} is set.
- *
- * @param path Path which extension should be checked
- * @return The {@link RDFSyntax} which has a matching {@link RDFSyntax#fileExtension},
- * otherwise {@link Optional#empty()}.
- */
- protected static Optional<RDFSyntax> guessRDFSyntax(Path path) {
- return fileExtension(path).flatMap(RDFSyntax::byFileExtension);
- }
-
- /**
- * Return the file extension of a Path - if any.
- * <p>
- * The returned file extension includes the leading <code>.</code>
- * <p>
- * Note that this only returns the last extension, e.g. the
- * file extension for <code>archive.tar.gz</code> would be <code>.gz</code>
- *
- * @param path Path which filename might contain an extension
- * @return File extension (including the leading <code>.</code>,
- * or {@link Optional#empty()} if the path has no extension
- */
- private static Optional<String> fileExtension(Path path) {
- Path fileName = path.getFileName();
- if (fileName == null) {
- return Optional.empty();
- }
- String filenameStr = fileName.toString();
- int last = filenameStr.lastIndexOf(".");
- if (last > -1) {
- return Optional.of(filenameStr.substring(last));
- }
- return Optional.empty();
- }
-
-
- /**
- * Create a new {@link RDF} for a parse session.
- * <p>
- * This is called by {@link #parse()} to set
- * {@link #rdfTermFactory(RDF)} if it is
- * {@link Optional#empty()}.
- * <p>
- * As parsed blank nodes might be made with
- * {@link RDF#createBlankNode(String)},
- * each call to this method SHOULD return
- * a new RDF instance.
- *
- * @return A new {@link RDF}
- */
- protected RDF createRDFTermFactory() {
- return new SimpleRDF();
- }
-
- @Override
- public Future<ParseResult> parse() throws IOException, IllegalStateException {
- final AbstractRDFParser<T> c = prepareForParsing();
- return threadpool.submit(() -> {
- c.parseSynchronusly();
- return null;
- });
- }
-
- @Override
- public T target(Consumer<Quad> consumer) {
- AbstractRDFParser<T> c = clone();
- c.resetTarget();
- c.target = consumer;
- return c.asT();
- }
-
- @Override
- public T target(Dataset dataset) {
- @SuppressWarnings({ "rawtypes", "unchecked" })
- AbstractRDFParser<T> c = (AbstractRDFParser) RDFParser.super.target(dataset);
- c.resetTarget();
- c.targetDataset = Optional.of(dataset);
- return c.asT();
- }
-
- @Override
- public T target(Graph graph) {
- @SuppressWarnings({ "rawtypes", "unchecked" }) // super calls our .clone()
- AbstractRDFParser<T> c = (AbstractRDFParser) RDFParser.super.target(graph);
- c.resetTarget();
- c.targetGraph = Optional.of(graph);
- return c.asT();
- }
-
-
+public abstract class AbstractRDFParser<T extends AbstractRDFParser<T>> implements RDFParser, Cloneable {
+
+ public static final ThreadGroup threadGroup = new ThreadGroup("Commons RDF parsers");
+ private static final ExecutorService threadpool = Executors.newCachedThreadPool(r -> new Thread(threadGroup, r));
+
+ // Basically only used for creating IRIs
+ private static RDF internalRdfTermFactory = new SimpleRDF();
+
+ /**
+ * Get the set {@link RDF}, if any.
+ *
+ * @return The {@link RDF} to use, or {@link Optional#empty()} if it has not
+ * been set
+ */
+ public Optional<RDF> getRdfTermFactory() {
+ return rdfTermFactory;
+ }
+
+ /**
+ * Get the set content-type {@link RDFSyntax}, if any.
+ * <p>
+ * If this is {@link Optional#isPresent()}, then {@link #getContentType()}
+ * contains the value of {@link RDFSyntax#mediaType}.
+ *
+ * @return The {@link RDFSyntax} of the content type, or
+ * {@link Optional#empty()} if it has not been set
+ */
+ public Optional<RDFSyntax> getContentTypeSyntax() {
+ return contentTypeSyntax;
+ }
+
+ /**
+ * Get the set content-type String, if any.
+ * <p>
+ * If this is {@link Optional#isPresent()} and is recognized by
+ * {@link RDFSyntax#byMediaType(String)}, then the corresponding
+ * {@link RDFSyntax} is set on {@link #getContentType()}, otherwise that is
+ * {@link Optional#empty()}.
+ *
+ * @return The Content-Type IANA media type, e.g. <code>text/turtle</code>,
+ * or {@link Optional#empty()} if it has not been set
+ */
+ public final Optional<String> getContentType() {
+ return contentType;
+ }
+
+ /**
+ * Get the target to consume parsed Quads.
+ * <p>
+ * From the call to {@link #parseSynchronusly()}, this will be a
+ * non-<code>null</code> value (as a target is a required setting).
+ *
+ * @return The target consumer of {@link Quad}s, or <code>null</code> if it
+ * has not yet been set.
+ *
+ */
+ public Consumer<Quad> getTarget() {
+ return target;
+ }
+
+ /**
+ * Get the target dataset as set by {@link #target(Dataset)}.
+ * <p>
+ * The return value is {@link Optional#isPresent()} if and only if
+ * {@link #target(Dataset)} has been set, meaning that the implementation
+ * may choose to append parsed quads to the {@link Dataset} directly instead
+ * of relying on the generated {@link #getTarget()} consumer.
+ * <p>
+ * If this value is present, then {@link #getTargetGraph()} MUST be
+ * {@link Optional#empty()}.
+ *
+ * @return The target Dataset, or {@link Optional#empty()} if another kind
+ * of target has been set.
+ */
+ public Optional<Dataset> getTargetDataset() {
+ return targetDataset;
+ }
+
+ /**
+ * Get the target graph as set by {@link #target(Graph)}.
+ * <p>
+ * The return value is {@link Optional#isPresent()} if and only if
+ * {@link #target(Graph)} has been set, meaning that the implementation may
+ * choose to append parsed triples to the {@link Graph} directly instead of
+ * relying on the generated {@link #getTarget()} consumer.
+ * <p>
+ * If this value is present, then {@link #getTargetDataset()} MUST be
+ * {@link Optional#empty()}.
+ *
+ * @return The target Graph, or {@link Optional#empty()} if another kind of
+ * target has been set.
+ */
+ public Optional<Graph> getTargetGraph() {
+ return targetGraph;
+ }
+
+ /**
+ * Get the set base {@link IRI}, if present.
+ *
+ * @return The base {@link IRI}, or {@link Optional#empty()} if it has not
+ * been set
+ */
+ public Optional<IRI> getBase() {
+ return base;
+ }
+
+ /**
+ * Get the set source {@link InputStream}.
+ * <p>
+ * If this is {@link Optional#isPresent()}, then {@link #getSourceFile()}
+ * and {@link #getSourceIri()} are {@link Optional#empty()}.
+ *
+ * @return The source {@link InputStream}, or {@link Optional#empty()} if it
+ * has not been set
+ */
+ public Optional<InputStream> getSourceInputStream() {
+ return sourceInputStream;
+ }
+
+ /**
+ * Get the set source {@link Path}.
+ * <p>
+ * If this is {@link Optional#isPresent()}, then
+ * {@link #getSourceInputStream()} and {@link #getSourceIri()} are
+ * {@link Optional#empty()}.
+ *
+ * @return The source {@link Path}, or {@link Optional#empty()} if it has
+ * not been set
+ */
+ public Optional<Path> getSourceFile() {
+ return sourceFile;
+ }
+
+ /**
+ * Get the set source {@link Path}.
+ * <p>
+ * If this is {@link Optional#isPresent()}, then
+ * {@link #getSourceInputStream()} and {@link #getSourceInputStream()} are
+ * {@link Optional#empty()}.
+ *
+ * @return The source {@link IRI}, or {@link Optional#empty()} if it has not
+ * been set
+ */
+ public Optional<IRI> getSourceIri() {
+ return sourceIri;
+ }
+
+ private Optional<RDF> rdfTermFactory = Optional.empty();
+ private Optional<RDFSyntax> contentTypeSyntax = Optional.empty();
+ private Optional<String> contentType = Optional.empty();
+ private Optional<IRI> base = Optional.empty();
+ private Optional<InputStream> sourceInputStream = Optional.empty();
+ private Optional<Path> sourceFile = Optional.empty();
+ private Optional<IRI> sourceIri = Optional.empty();
+ private Consumer<Quad> target;
+ private Optional<Dataset> targetDataset;
+ private Optional<Graph> targetGraph;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T clone() {
+ try {
+ return (T) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected T asT() {
+ return (T) this;
+ }
+
+ @Override
+ public T rdfTermFactory(RDF rdfTermFactory) {
+ AbstractRDFParser<T> c = clone();
+ c.rdfTermFactory = Optional.ofNullable(rdfTermFactory);
+ return c.asT();
+ }
+
+ @Override
+ public T contentType(RDFSyntax rdfSyntax) throws IllegalArgumentException {
+ AbstractRDFParser<T> c = clone();
+ c.contentTypeSyntax = Optional.ofNullable(rdfSyntax);
+ c.contentType = c.contentTypeSyntax.map(syntax -> syntax.mediaType);
+ return c.asT();
+ }
+
+ @Override
+ public T contentType(String contentType) throws IllegalArgumentException {
+ AbstractRDFParser<T> c = clone();
+ c.contentType = Optional.ofNullable(contentType);
+ c.contentTypeSyntax = c.contentType.flatMap(RDFSyntax::byMediaType);
+ return c.asT();
+ }
+
+ @Override
+ public T base(IRI base) {
+ AbstractRDFParser<T> c = clone();
+ c.base = Optional.ofNullable(base);
+ c.base.ifPresent(i -> checkIsAbsolute(i));
+ return c.asT();
+ }
+
+ @Override
+ public T base(String base) throws IllegalArgumentException {
+ return base(internalRdfTermFactory.createIRI(base));
+ }
+
+ @Override
+ public T source(InputStream inputStream) {
+ AbstractRDFParser<T> c = clone();
+ c.resetSource();
+ c.sourceInputStream = Optional.ofNullable(inputStream);
+ return c.asT();
+ }
+
+ @Override
+ public T source(Path file) {
+ AbstractRDFParser<T> c = clone();
+ c.resetSource();
+ c.sourceFile = Optional.ofNullable(file);
+ return c.asT();
+ }
+
+ @Override
+ public T source(IRI iri) {
+ AbstractRDFParser<T> c = clone();
+ c.resetSource();
+ c.sourceIri = Optional.ofNullable(iri);
+ c.sourceIri.ifPresent(i -> checkIsAbsolute(i));
+ return c.asT();
+ }
+
+ @Override
+ public T source(String iri) throws IllegalArgumentException {
+ AbstractRDFParser<T> c = clone();
+ c.resetSource();
+ c.sourceIri = Optional.ofNullable(iri).map(internalRdfTermFactory::createIRI);
+ c.sourceIri.ifPresent(i -> checkIsAbsolute(i));
+ return source(internalRdfTermFactory.createIRI(iri));
+ }
+
+ /**
+ * Check if an iri is absolute.
+ * <p>
+ * Used by {@link #source(String)} and {@link #base(String)}.
+ *
+ * @param iri
+ * IRI to check
+ * @throws IllegalArgumentException
+ * If the IRI is not absolute
+ */
+ protected void checkIsAbsolute(IRI iri) throws IllegalArgumentException {
+ if (!URI.create(iri.getIRIString()).isAbsolute()) {
+ throw new IllegalArgumentException("IRI is not absolute: " + iri);
+ }
+ }
+
+ /**
+ * Check that one and only one source is present and valid.
+ * <p>
+ * Used by {@link #parse()}.
+ * <p>
+ * Subclasses might override this method, e.g. to support other source
+ * combinations, or to check if the sourceIri is resolvable.
+ *
+ * @throws IOException
+ * If a source file can't be read
+ */
+ protected void checkSource() throws IOException {
+ if (!sourceFile.isPresent() && !sourceInputStream.isPresent() && !sourceIri.isPresent()) {
+ throw new IllegalStateException("No source has been set");
+ }
+ if (sourceIri.isPresent() && sourceInputStream.isPresent()) {
+ throw new IllegalStateException("Both sourceIri and sourceInputStream have been set");
+ }
+ if (sourceIri.isPresent() && sourceFile.isPresent()) {
+ throw new IllegalStateException("Both sourceIri and sourceFile have been set");
+ }
+ if (sourceInputStream.isPresent() && sourceFile.isPresent()) {
+ throw new IllegalStateException("Both sourceInputStream and sourceFile have been set");
+ }
+ if (sourceFile.isPresent() && !sourceFile.filter(Files::isReadable).isPresent()) {
+ throw new IOException("Can't read file: " + sourceFile);
+ }
+ }
+
+ /**
+ * Check if base is required.
+ *
+ * @throws IllegalStateException
+ * if base is required, but not set.
+ */
+ protected void checkBaseRequired() throws IllegalStateException {
+ if (!base.isPresent() && sourceInputStream.isPresent()
+ && !contentTypeSyntax.filter(t -> t == RDFSyntax.NQUADS || t == RDFSyntax.NTRIPLES).isPresent()) {
+ throw new IllegalStateException("base iri required for inputstream source");
+ }
+ }
+
+ /**
+ * Reset all source* fields to Optional.empty()
+ * <p>
+ * Subclasses should override this and call <code>super.resetSource()</code>
+ * if they need to reset any additional source* fields.
+ *
+ */
+ protected void resetSource() {
+ sourceInputStream = Optional.empty();
+ sourceIri = Optional.empty();
+ sourceFile = Optional.empty();
+ }
+
+ /**
+ * Reset all optional target* fields to {@link Optional#empty()}.
+ * <p>
+ * Note that the consumer set for {@link #getTarget()} is
+ * <strong>note</strong> reset.
+ * <p>
+ * Subclasses should override this and call <code>super.resetTarget()</code>
+ * if they need to reset any additional target* fields.
+ *
+ */
+ protected void resetTarget() {
+ targetDataset = Optional.empty();
+ targetGraph = Optional.empty();
+ }
+
+ /**
+ * Parse {@link #sourceInputStream}, {@link #sourceFile} or
+ * {@link #sourceIri}.
+ * <p>
+ * One of the source fields MUST be present, as checked by
+ * {@link #checkSource()}.
+ * <p>
+ * {@link #checkBaseRequired()} is called to verify if {@link #getBase()} is
+ * required.
+ *
+ * @throws IOException
+ * If the source could not be read
+ * @throws RDFParseException
+ * If the source could not be parsed (e.g. a .ttl file was not
+ * valid Turtle)
+ */
+ protected abstract void parseSynchronusly() throws IOException, RDFParseException;
+
+ /**
+ * Prepare a clone of this RDFParser which have been checked and completed.
+ * <p>
+ * The returned clone will always have {@link #getTarget()} and
+ * {@link #getRdfTermFactory()} present.
+ * <p>
+ * If the {@link #getSourceFile()} is present, but the {@link #getBase()} is
+ * not present, the base will be set to the <code>file:///</code> IRI for
+ * the Path's real path (e.g. resolving any symbolic links).
+ *
+ * @return A completed and checked clone of this RDFParser
+ * @throws IOException
+ * If the source was not accessible (e.g. a file was not found)
+ * @throws IllegalStateException
+ * If the parser was not in a compatible setting (e.g.
+ * contentType was an invalid string)
+ */
+ protected T prepareForParsing() throws IOException, IllegalStateException {
+ checkSource();
+ checkBaseRequired();
+ checkContentType();
+ checkTarget();
+
+ // We'll make a clone of our current state which will be passed to
+ // parseSynchronously()
+ AbstractRDFParser<T> c = clone();
+
+ // Use a fresh SimpleRDF for each parse
+ if (!c.rdfTermFactory.isPresent()) {
+ c.rdfTermFactory = Optional.of(createRDFTermFactory());
+ }
+ // sourceFile, but no base? Let's follow any symlinks and use
+ // the file:/// URI
+ if (c.sourceFile.isPresent() && !c.base.isPresent()) {
+ URI baseUri = c.sourceFile.get().toRealPath().toUri();
+ c.base = Optional.of(internalRdfTermFactory.createIRI(baseUri.toString()));
+ }
+
+ return c.asT();
+ }
+
+ /**
+ * Subclasses can override this method to check the target is valid.
+ * <p>
+ * The default implementation throws an IllegalStateException if the target
+ * has not been set.
+ */
+ protected void checkTarget() {
+ if (target == null) {
+ throw new IllegalStateException("target has not been set");
+ }
+ if (targetGraph.isPresent() && targetDataset.isPresent()) {
+ // This should not happen as each target(..) method resets the
+ // optionals
+ throw new IllegalStateException("targetGraph and targetDataset can't both be set");
+ }
+ }
+
+ /**
+ * Subclasses can override this method to check compatibility with the
+ * contentType setting.
+ *
+ * @throws IllegalStateException
+ * if the {@link #getContentType()} or
+ * {@link #getContentTypeSyntax()} is not compatible or invalid
+ */
+ protected void checkContentType() throws IllegalStateException {
+ }
+
+ /**
+ * Guess RDFSyntax from a local file's extension.
+ * <p>
+ * This method can be used by subclasses if {@link #getContentType()} is not
+ * present and {@link #getSourceFile()} is set.
+ *
+ * @param path
+ * Path which extension should be checked
+ * @return The {@link RDFSyntax} which has a matching
+ * {@link RDFSyntax#fileExtension}, otherwise
+ * {@link Optional#empty()}.
+ */
+ protected static Optional<RDFSyntax> guessRDFSyntax(Path path) {
+ return fileExtension(path).flatMap(RDFSyntax::byFileExtension);
+ }
+
+ /**
+ * Return the file extension of a Path - if any.
+ * <p>
+ * The returned file extension includes the leading <code>.</code>
+ * <p>
+ * Note that this only returns the last extension, e.g. the file extension
+ * for <code>archive.tar.gz</code> would be <code>.gz</code>
+ *
+ * @param path
+ * Path which filename might contain an extension
+ * @return File extension (including the leading <code>.</code>, or
+ * {@link Optional#empty()} if the path has no extension
+ */
+ private static Optional<String> fileExtension(Path path) {
+ Path fileName = path.getFileName();
+ if (fileName == null) {
+ return Optional.empty();
+ }
+ String filenameStr = fileName.toString();
+ int last = filenameStr.lastIndexOf(".");
+ if (last > -1) {
+ return Optional.of(filenameStr.substring(last));
+ }
+ return Optional.empty();
+ }
+
+ /**
+ * Create a new {@link RDF} for a parse session.
+ * <p>
+ * This is called by {@link #parse()} to set {@link #rdfTermFactory(RDF)} if
+ * it is {@link Optional#empty()}.
+ * <p>
+ * As parsed blank nodes might be made with
+ * {@link RDF#createBlankNode(String)}, each call to this method SHOULD
+ * return a new RDF instance.
+ *
+ * @return A new {@link RDF}
+ */
+ protected RDF createRDFTermFactory() {
+ return new SimpleRDF();
+ }
+
+ @Override
+ public Future<ParseResult> parse() throws IOException, IllegalStateException {
+ final AbstractRDFParser<T> c = prepareForParsing();
+ return threadpool.submit(() -> {
+ c.parseSynchronusly();
+ return null;
+ });
+ }
+
+ @Override
+ public T target(Consumer<Quad> consumer) {
+ AbstractRDFParser<T> c = clone();
+ c.resetTarget();
+ c.target = consumer;
+ return c.asT();
+ }
+
+ @Override
+ public T target(Dataset dataset) {
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ AbstractRDFParser<T> c = (AbstractRDFParser) RDFParser.super.target(dataset);
+ c.resetTarget();
+ c.targetDataset = Optional.of(dataset);
+ return c.asT();
+ }
+
+ @Override
+ public T target(Graph graph) {
+ @SuppressWarnings({ "rawtypes", "unchecked" }) // super calls our
+ // .clone()
+ AbstractRDFParser<T> c = (AbstractRDFParser) RDFParser.super.target(graph);
+ c.resetTarget();
+ c.targetGraph = Optional.of(graph);
+ return c.asT();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/RDFParseException.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/RDFParseException.java b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/RDFParseException.java
index cb3ad82..aedab78 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/experimental/RDFParseException.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/experimental/RDFParseException.java
@@ -21,30 +21,30 @@ package org.apache.commons.rdf.simple.experimental;
import org.apache.commons.rdf.experimental.RDFParser;
public class RDFParseException extends Exception {
- private static final long serialVersionUID = 5427752643780702976L;
- private RDFParser builder;
-
- public RDFParseException(RDFParser builder) {
- super();
- this.builder = builder;
- }
-
- public RDFParseException(RDFParser builder, String message, Throwable cause) {
- super(message, cause);
- this.builder = builder;
- }
-
- public RDFParseException(RDFParser builder, String message) {
- super(message);
- this.builder = builder;
- }
-
- public RDFParseException(RDFParser builder, Throwable cause) {
- super(cause);
- this.builder = builder;
- }
-
- public RDFParser getRDFParserBuilder() {
- return builder;
- }
+ private static final long serialVersionUID = 5427752643780702976L;
+ private RDFParser builder;
+
+ public RDFParseException(RDFParser builder) {
+ super();
+ this.builder = builder;
+ }
+
+ public RDFParseException(RDFParser builder, String message, Throwable cause) {
+ super(message, cause);
+ this.builder = builder;
+ }
+
+ public RDFParseException(RDFParser builder, String message) {
+ super(message);
+ this.builder = builder;
+ }
+
+ public RDFParseException(RDFParser builder, Throwable cause) {
+ super(cause);
+ this.builder = builder;
+ }
+
+ public RDFParser getRDFParserBuilder() {
+ return builder;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java b/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java
index f536594..782c7d5 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/package-info.java
@@ -19,17 +19,15 @@
* A simple in-memory implementation of the Commons RDF API.
* <p>
* This package contains a simple (if not naive) implementation of
- * {@link org.apache.commons.rdf.api}
- * using in-memory POJO objects.
+ * {@link org.apache.commons.rdf.api} using in-memory POJO objects.
* <p>
- * Note that although this module fully implements the commons-rdf API,
- * it should <strong>not</strong> be considered a reference implementation.
- * It is <strong>not thread-safe</strong> nor scalable, but may be useful for
- * testing and simple usage (e.g. prototyping).
+ * Note that although this module fully implements the commons-rdf API, it
+ * should <strong>not</strong> be considered a reference implementation. It is
+ * <strong>not thread-safe</strong> nor scalable, but may be useful for testing
+ * and simple usage (e.g. prototyping).
* <p>
* To use this implementation, create an instance of
- * {@link org.apache.commons.rdf.simple.SimpleRDF}
- * and use methods like
+ * {@link org.apache.commons.rdf.simple.SimpleRDF} and use methods like
* {@link org.apache.commons.rdf.simple.SimpleRDF#createGraph} and
* {@link org.apache.commons.rdf.simple.SimpleRDF#createIRI(String)}.
* <p>
@@ -38,5 +36,3 @@
*
*/
package org.apache.commons.rdf.simple;
-
-
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java b/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java
index af91978..afb2129 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/DummyRDFParserBuilder.java
@@ -28,71 +28,66 @@ import org.apache.commons.rdf.experimental.RDFParser;
import org.apache.commons.rdf.simple.experimental.AbstractRDFParser;
import org.apache.commons.rdf.simple.experimental.RDFParseException;
-/**
- * For test purposes - a {@link RDFParser} that inserts information
- * about what it has been asked to parse instead of actually parsing anything.
+/**
+ * For test purposes - a {@link RDFParser} that inserts information about what
+ * it has been asked to parse instead of actually parsing anything.
* <p>
* This always insert at least the triple equivalent to:
+ *
* <pre>
* <urn:uuid:b7ac3fcc-4d86-4d28-8358-a1cd094974a6> <http://example.com/greeting> "Hello world" .
* </pre>
- * Additional triples match the corresponding getter in AbstractRDFParser,
- * e.g.:
+ *
+ * Additional triples match the corresponding getter in AbstractRDFParser, e.g.:
+ *
* <pre>
* <urn:uuid:b7ac3fcc-4d86-4d28-8358-a1cd094974a6> <http://example.com/base> <http://www.example.org/> .
- * <urn:uuid:b7ac3fcc-4d86-4d28-8358-a1cd094974a6> <http://example.com/sourceFile> "/tmp/file.ttl" .
- * </pre>
+ * <urn:uuid:b7ac3fcc-4d86-4d28-8358-a1cd094974a6> <http://example.com/sourceFile> "/tmp/file.ttl" .
+ * </pre>
*
*
*/
public class DummyRDFParserBuilder extends AbstractRDFParser<DummyRDFParserBuilder> {
-
- @Override
- protected void parseSynchronusly() throws IOException, IllegalStateException, RDFParseException {
- // From parseSynchronusly both of these are always present
- RDF factory = getRdfTermFactory().get();
- Consumer<Quad> t = getTarget();
-
- // well - each parsing is unique. This should hopefully
- // catch any accidental double parsing
- IRI parsing = factory.createIRI("urn:uuid:" + UUID.randomUUID());
- t.accept(factory.createQuad(null, parsing, factory.createIRI("http://example.com/greeting"),
- factory.createLiteral("Hello world")));
-
- // Now we'll expose the finalized AbstractRDFParser settings
- // so they can be inspected by the junit test
- if (getSourceIri().isPresent()) {
- t.accept(factory.createQuad(null, parsing,
- factory.createIRI("http://example.com/source"),
- getSourceIri().get()));
- }
- if (getSourceFile().isPresent()) {
- t.accept(factory.createQuad(null, parsing,
- factory.createIRI("http://example.com/source"),
- factory.createIRI(getSourceFile().get().toUri().toString())));
- }
- if (getSourceInputStream().isPresent()) {
- t.accept(factory.createQuad(null, parsing,
- factory.createIRI("http://example.com/source"),
- factory.createBlankNode()));
- }
+ @Override
+ protected void parseSynchronusly() throws IOException, IllegalStateException, RDFParseException {
+ // From parseSynchronusly both of these are always present
+ RDF factory = getRdfTermFactory().get();
+ Consumer<Quad> t = getTarget();
+
+ // well - each parsing is unique. This should hopefully
+ // catch any accidental double parsing
+ IRI parsing = factory.createIRI("urn:uuid:" + UUID.randomUUID());
+ t.accept(factory.createQuad(null, parsing, factory.createIRI("http://example.com/greeting"),
+ factory.createLiteral("Hello world")));
+
+ // Now we'll expose the finalized AbstractRDFParser settings
+ // so they can be inspected by the junit test
+
+ if (getSourceIri().isPresent()) {
+ t.accept(factory.createQuad(null, parsing, factory.createIRI("http://example.com/source"),
+ getSourceIri().get()));
+ }
+ if (getSourceFile().isPresent()) {
+ t.accept(factory.createQuad(null, parsing, factory.createIRI("http://example.com/source"),
+ factory.createIRI(getSourceFile().get().toUri().toString())));
+ }
+ if (getSourceInputStream().isPresent()) {
+ t.accept(factory.createQuad(null, parsing, factory.createIRI("http://example.com/source"),
+ factory.createBlankNode()));
+ }
- if (getBase().isPresent()) {
- t.accept(factory.createQuad(null, parsing,
- factory.createIRI("http://example.com/base"),
- getBase().get()));
- }
- if (getContentType().isPresent()) {
- t.accept(factory.createQuad(null, parsing,
- factory.createIRI("http://example.com/contentType"),
- factory.createLiteral(getContentType().get())));
- }
- if (getContentTypeSyntax().isPresent()) {
- t.accept(factory.createQuad(null, parsing,
- factory.createIRI("http://example.com/contentTypeSyntax"),
- factory.createLiteral(getContentTypeSyntax().get().name())));
- }
- }
+ if (getBase().isPresent()) {
+ t.accept(factory.createQuad(null, parsing, factory.createIRI("http://example.com/base"), getBase().get()));
+ }
+ if (getContentType().isPresent()) {
+ t.accept(factory.createQuad(null, parsing, factory.createIRI("http://example.com/contentType"),
+ factory.createLiteral(getContentType().get())));
+ }
+ if (getContentTypeSyntax().isPresent()) {
+ t.accept(factory.createQuad(null, parsing, factory.createIRI("http://example.com/contentTypeSyntax"),
+ factory.createLiteral(getContentTypeSyntax().get().name())));
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
index f207424..bbbad55 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleGraphTest.java
@@ -37,13 +37,10 @@ public class SimpleGraphTest extends AbstractGraphTest {
@Test
public void graphToString() {
Assume.assumeNotNull(aliceName, companyName);
- //System.out.println(graph);
- assertTrue(graph
- .toString()
- .contains(
- "<http://example.com/alice> <http://xmlns.com/foaf/0.1/name> \"Alice\" ."));
- assertTrue(graph.toString().contains(
- " <http://xmlns.com/foaf/0.1/name> \"A company\" ."));
+ // System.out.println(graph);
+ assertTrue(
+ graph.toString().contains("<http://example.com/alice> <http://xmlns.com/foaf/0.1/name> \"Alice\" ."));
+ assertTrue(graph.toString().contains(" <http://xmlns.com/foaf/0.1/name> \"A company\" ."));
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDTest.java
index abec6c0..a1a59ed 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleNoRelativeIRIRDTest.java
@@ -26,11 +26,10 @@ import java.net.URI;
/**
* Test simple IRI without relative IRI support.
* <p>
- * Ensures that {@link AbstractRDFTest#testCreateIRIRelative()} is
- * correctly skipped (without causing an error).
+ * Ensures that {@link AbstractRDFTest#testCreateIRIRelative()} is correctly
+ * skipped (without causing an error).
*/
-public class SimpleNoRelativeIRIRDTest extends
- AbstractRDFTest {
+public class SimpleNoRelativeIRIRDTest extends AbstractRDFTest {
@Override
public RDF createFactory() {
return new SimpleRDF() {
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
index 8ec0649..4e37199 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/SimpleServiceLoaderTest.java
@@ -31,10 +31,10 @@ public class SimpleServiceLoaderTest {
public void testServiceLoaderLookup() {
ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class);
for (RDF impl : loader) {
- if (impl instanceof SimpleRDF) {
- return; // yay
- }
+ if (impl instanceof SimpleRDF) {
+ return; // yay
+ }
}
- fail("SimpleRDF not found in ServiceLoader");
+ fail("SimpleRDF not found in ServiceLoader");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
index ca4925f..3badaf7 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
@@ -68,20 +68,13 @@ public class TestWritingGraph {
Collections.shuffle(types);
for (int i = 0; i < TRIPLES; i++) {
if (i % 11 == 0) {
- graph.add(subject, predicate,
- factory.createBlankNode("Example " + i));
+ graph.add(subject, predicate, factory.createBlankNode("Example " + i));
} else if (i % 5 == 0) {
- graph.add(subject, predicate,
- factory.createLiteral("Example " + i, "en"));
+ graph.add(subject, predicate, factory.createLiteral("Example " + i, "en"));
} else if (i % 3 == 0) {
- graph.add(
- subject,
- predicate,
- factory.createLiteral("Example " + i,
- types.get(i % types.size())));
+ graph.add(subject, predicate, factory.createLiteral("Example " + i, types.get(i % types.size())));
} else {
- graph.add(subject, predicate,
- factory.createLiteral("Example " + i));
+ graph.add(subject, predicate, factory.createLiteral("Example " + i));
}
}
}
@@ -101,16 +94,14 @@ public class TestWritingGraph {
public void countQuery() {
IRI subject = factory.createIRI("subj");
IRI predicate = factory.createIRI("pred");
- long count = graph.stream(subject, predicate, null).unordered()
- .parallel().count();
- //System.out.println("Counted - " + count);
+ long count = graph.stream(subject, predicate, null).unordered().parallel().count();
+ // System.out.println("Counted - " + count);
assertEquals(count, TRIPLES);
}
public static String tripleAsString(Triple t) {
- return t.getSubject().ntriplesString() + " "
- + t.getPredicate().ntriplesString() + " " +
- t.getObject().ntriplesString() + " .";
+ return t.getSubject().ntriplesString() + " " + t.getPredicate().ntriplesString() + " "
+ + t.getObject().ntriplesString() + " .";
}
@Test
@@ -137,8 +128,7 @@ public class TestWritingGraph {
IRI subject = factory.createIRI("subj");
IRI predicate = factory.createIRI("pred");
- Stream<CharSequence> stream = graph
- .stream(subject, predicate, null).map(TestWritingGraph::tripleAsString);
+ Stream<CharSequence> stream = graph.stream(subject, predicate, null).map(TestWritingGraph::tripleAsString);
Files.write(graphFile, stream::iterator, StandardCharsets.UTF_8);
}
@@ -154,8 +144,7 @@ public class TestWritingGraph {
IRI subject = factory.createIRI("nonexistent");
IRI predicate = factory.createIRI("pred");
- Stream<CharSequence> stream = graph
- .stream(subject, predicate, null).map(Object::toString);
+ Stream<CharSequence> stream = graph.stream(subject, predicate, null).map(Object::toString);
Files.write(graphFile, stream::iterator, StandardCharsets.UTF_8);
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/test/java/org/apache/commons/rdf/simple/TypesTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/TypesTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/TypesTest.java
index 056091e..f199d9e 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/TypesTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/TypesTest.java
@@ -29,13 +29,12 @@ import org.junit.Test;
public class TypesTest {
/**
- * Test method for {@link org.apache.commons.rdf.simple.Types#getIRIString()}
- * .
+ * Test method for
+ * {@link org.apache.commons.rdf.simple.Types#getIRIString()} .
*/
@Test
public final void testGetIRIString() {
- assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",
- Types.RDF_LANGSTRING.getIRIString());
+ assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", Types.RDF_LANGSTRING.getIRIString());
}
/**
@@ -44,8 +43,7 @@ public class TypesTest {
*/
@Test
public final void testNtriplesString() {
- assertEquals("<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>",
- Types.RDF_LANGSTRING.ntriplesString());
+ assertEquals("<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>", Types.RDF_LANGSTRING.ntriplesString());
}
/**
@@ -55,17 +53,10 @@ public class TypesTest {
*/
@Test
public final void testGet() {
- assertTrue(Types.get(
- new IRIImpl("http://www.w3.org/2001/XMLSchema#boolean"))
- .isPresent());
- assertEquals(
- "http://www.w3.org/2001/XMLSchema#boolean",
- Types.get(
- new IRIImpl("http://www.w3.org/2001/XMLSchema#boolean"))
- .get().getIRIString());
- assertFalse(Types.get(
- new IRIImpl("http://www.w3.org/2001/XMLSchema#nonExistent"))
- .isPresent());
+ assertTrue(Types.get(new IRIImpl("http://www.w3.org/2001/XMLSchema#boolean")).isPresent());
+ assertEquals("http://www.w3.org/2001/XMLSchema#boolean",
+ Types.get(new IRIImpl("http://www.w3.org/2001/XMLSchema#boolean")).get().getIRIString());
+ assertFalse(Types.get(new IRIImpl("http://www.w3.org/2001/XMLSchema#nonExistent")).isPresent());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/413dd09a/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
index fed76b3..12e58bd 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java
@@ -48,209 +48,203 @@ import org.junit.rules.ExpectedException;
public class AbstractRDFParserTest {
- private RDF factory = new SimpleRDF();
-
- private DummyRDFParserBuilder dummyParser = new DummyRDFParserBuilder();
- private Path testNt;
- private Path testTtl;
- private Path testXml;
+ private RDF factory = new SimpleRDF();
+
+ private DummyRDFParserBuilder dummyParser = new DummyRDFParserBuilder();
+ private Path testNt;
+ private Path testTtl;
+ private Path testXml;
+
+ @Before
+ public void createTempFile() throws IOException {
+ testNt = Files.createTempFile("test", ".nt");
+ testTtl = Files.createTempFile("test", ".ttl");
+ testXml = Files.createTempFile("test", ".xml");
+
+ // No need to populate the files as the dummy parser
+ // doesn't actually read anything
+ }
+
+ @After
+ public void deleteTempFiles() throws IOException {
+ Files.deleteIfExists(testNt);
+ Files.deleteIfExists(testTtl);
+ Files.deleteIfExists(testXml);
+ }
+
+ @Test
+ public void guessRDFSyntax() throws Exception {
+ assertEquals(RDFSyntax.NTRIPLES, AbstractRDFParser.guessRDFSyntax(testNt).get());
+ assertEquals(RDFSyntax.TURTLE, AbstractRDFParser.guessRDFSyntax(testTtl).get());
+ assertFalse(AbstractRDFParser.guessRDFSyntax(testXml).isPresent());
+ }
+
+ private void checkGraph(Graph g) throws Exception {
+ assertTrue(g.size() > 0);
+ IRI greeting = factory.createIRI("http://example.com/greeting");
+ // Should only have parsed once!
+ assertEquals(1, g.stream(null, greeting, null).count());
+ Triple triple = g.stream(null, greeting, null).findAny().get();
+ assertTrue(triple.getSubject() instanceof IRI);
+ IRI parsing = (IRI) triple.getSubject();
+ assertTrue(parsing.getIRIString().startsWith("urn:uuid:"));
+
+ assertEquals("http://example.com/greeting", triple.getPredicate().getIRIString());
+
+ assertTrue(triple.getObject() instanceof Literal);
+ Literal literal = (Literal) triple.getObject();
+ assertEquals("Hello world", literal.getLexicalForm());
+ assertFalse(literal.getLanguageTag().isPresent());
+ assertEquals(Types.XSD_STRING, literal.getDatatype());
+
+ // Check uniqueness of properties that are always present
+ assertEquals(1, g.stream(null, factory.createIRI("http://example.com/source"), null).count());
+
+ // Check optional properties that are unique
+ assertTrue(2 > g.stream(null, factory.createIRI("http://example.com/base"), null).count());
+ assertTrue(2 > g.stream(null, factory.createIRI("http://example.com/contentType"), null).count());
+ assertTrue(2 > g.stream(null, factory.createIRI("http://example.com/contentTypeSyntax"), null).count());
+ }
+
+ @Test
+ public void parseFile() throws Exception {
+ Graph g = factory.createGraph();
+ RDFParser parser = dummyParser.source(testNt).target(g);
+ parser.parse().get(5, TimeUnit.SECONDS);
+ checkGraph(g);
+ // FIXME: this could potentially break if the equivalent of /tmp
+ // includes
+ // international characters
+ assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source"));
+ // Should be set to the file path
+ assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base"));
+
+ // Should NOT have guessed the content type
+ assertNull(firstPredicate(g, "contentType"));
+ assertNull(firstPredicate(g, "contentTypeSyntax"));
+ }
+
+ @Test
+ public void parseNoSource() throws Exception {
+ thrown.expect(IllegalStateException.class);
+ dummyParser.parse();
+ }
+
+ @Test
+ public void parseBaseAndContentTypeNoSource() throws Exception {
+ // Can set the other options, even without source()
+ IRI base = dummyParser.createRDFTermFactory().createIRI("http://www.example.org/test.rdf");
+ RDFParser parser = dummyParser.base(base).contentType(RDFSyntax.RDFXML);
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("No source has been set");
+ // but .parse() should fail
+ parser.parse();
+ }
+
+ @Test
+ public void parseFileMissing() throws Exception {
+ Files.delete(testNt);
+ // This should not fail yet
+ RDFParser parser = dummyParser.source(testNt);
+ // but here:
+ thrown.expect(IOException.class);
+ parser.parse();
+ }
+
+ @Test
+ public void parseFileContentType() throws Exception {
+ Graph g = factory.createGraph();
+ RDFParser parser = dummyParser.source(testNt).contentType(RDFSyntax.NTRIPLES).target(g);
+ parser.parse().get(5, TimeUnit.SECONDS);
+ checkGraph(g);
+ // FIXME: this could potentially break if the equivalent of /tmp
+ // includes
+ // international characters
+ assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source"));
+ assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base"));
+ assertEquals("\"NTRIPLES\"", firstPredicate(g, "contentTypeSyntax"));
+ assertEquals("\"application/n-triples\"", firstPredicate(g, "contentType"));
+ }
+
+ private String firstPredicate(Graph g, String pred) {
+ return g.stream(null, factory.createIRI("http://example.com/" + pred), null).map(Triple::getObject)
+ .map(RDFTerm::ntriplesString).findAny().orElse(null);
+ }
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void parseInputStreamFailsIfBaseMissing() throws Exception {
+ InputStream inputStream = new ByteArrayInputStream(new byte[0]);
+ // Should not fail at this point
+ RDFParser parser = dummyParser.source(inputStream);
+ // but here:
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("base iri required for inputstream source");
+ parser.parse();
+ }
+
+ @Test
+ public void parseInputStreamWithBase() throws Exception {
+ InputStream inputStream = new ByteArrayInputStream(new byte[0]);
+ IRI base = dummyParser.createRDFTermFactory().createIRI("http://www.example.org/test.rdf");
+ Graph g = factory.createGraph();
+ RDFParser parser = dummyParser.source(inputStream).base(base).target(g);
+ parser.parse().get(5, TimeUnit.SECONDS);
+ checkGraph(g);
+ assertEquals("<http://www.example.org/test.rdf>", firstPredicate(g, "base"));
+ // in our particular debug output,
+ // bnode source indicates InputStream
+ assertTrue(firstPredicate(g, "source").startsWith("_:"));
+ assertNull(firstPredicate(g, "contentType"));
+ assertNull(firstPredicate(g, "contentTypeSyntax"));
+ }
+
+ @Test
+ public void parseInputStreamWithNQuads() throws Exception {
+ InputStream inputStream = new ByteArrayInputStream(new byte[0]);
+ Graph g = factory.createGraph();
+ RDFParser parser = dummyParser.source(inputStream).contentType(RDFSyntax.NQUADS).target(g);
+ parser.parse().get(5, TimeUnit.SECONDS);
+ checkGraph(g);
+ assertNull(firstPredicate(g, "base"));
+ // in our particular debug output,
+ // bnode source indicates InputStream
+ assertTrue(firstPredicate(g, "source").startsWith("_:"));
+ assertEquals("\"application/n-quads\"", firstPredicate(g, "contentType"));
+ assertEquals("\"NQUADS\"", firstPredicate(g, "contentTypeSyntax"));
+ }
+
+ @Test
+ public void parseIRI() throws Exception {
+ IRI iri = dummyParser.createRDFTermFactory().createIRI("http://www.example.net/test.ttl");
+ Graph g = factory.createGraph();
+ RDFParser parser = dummyParser.source(iri).target(g);
+ parser.parse().get(5, TimeUnit.SECONDS);
+ checkGraph(g);
+ assertEquals("<http://www.example.net/test.ttl>", firstPredicate(g, "source"));
+ // No base - assuming the above IRI is always
+ // the base would break server-supplied base from
+ // any HTTP Location redirects and Content-Location header
+ assertNull(firstPredicate(g, "base"));
+ // ".ttl" in IRI string does not imply any content type
+ assertNull(firstPredicate(g, "contentType"));
+ assertNull(firstPredicate(g, "contentTypeSyntax"));
+
+ }
+
+ @Test
+ public void parseIRIBaseContentType() throws Exception {
+ IRI iri = dummyParser.createRDFTermFactory().createIRI("http://www.example.net/test.ttl");
+ Graph g = factory.createGraph();
+ RDFParser parser = dummyParser.source(iri).base(iri).contentType(RDFSyntax.TURTLE).target(g);
+ parser.parse().get(5, TimeUnit.SECONDS);
+ checkGraph(g);
+ assertEquals("<http://www.example.net/test.ttl>", firstPredicate(g, "source"));
+ assertEquals("<http://www.example.net/test.ttl>", firstPredicate(g, "base"));
+ assertEquals("\"TURTLE\"", firstPredicate(g, "contentTypeSyntax"));
+ assertEquals("\"text/turtle\"", firstPredicate(g, "contentType"));
+ }
- @Before
- public void createTempFile() throws IOException {
- testNt = Files.createTempFile("test", ".nt");
- testTtl = Files.createTempFile("test", ".ttl");
- testXml = Files.createTempFile("test", ".xml");
-
- // No need to populate the files as the dummy parser
- // doesn't actually read anything
- }
-
- @After
- public void deleteTempFiles() throws IOException {
- Files.deleteIfExists(testNt);
- Files.deleteIfExists(testTtl);
- Files.deleteIfExists(testXml);
- }
-
- @Test
- public void guessRDFSyntax() throws Exception {
- assertEquals(RDFSyntax.NTRIPLES, AbstractRDFParser.guessRDFSyntax(testNt).get());
- assertEquals(RDFSyntax.TURTLE, AbstractRDFParser.guessRDFSyntax(testTtl).get());
- assertFalse(AbstractRDFParser.guessRDFSyntax(testXml).isPresent());
- }
-
- private void checkGraph(Graph g) throws Exception {
- assertTrue(g.size() > 0);
- IRI greeting = factory.createIRI("http://example.com/greeting");
- // Should only have parsed once!
- assertEquals(1, g.stream(null, greeting, null).count());
- Triple triple = g.stream(null, greeting, null).findAny().get();
- assertTrue(triple.getSubject() instanceof IRI);
- IRI parsing = (IRI) triple.getSubject();
- assertTrue(parsing.getIRIString().startsWith("urn:uuid:"));
-
- assertEquals("http://example.com/greeting", triple.getPredicate().getIRIString());
-
- assertTrue(triple.getObject() instanceof Literal);
- Literal literal = (Literal) triple.getObject();
- assertEquals("Hello world", literal.getLexicalForm());
- assertFalse(literal.getLanguageTag().isPresent());
- assertEquals(Types.XSD_STRING, literal.getDatatype());
-
- // Check uniqueness of properties that are always present
- assertEquals(1,
- g.stream(null, factory.createIRI("http://example.com/source"), null).count());
-
- // Check optional properties that are unique
- assertTrue(2 > g.stream(null, factory.createIRI("http://example.com/base"), null).count());
- assertTrue(2 > g.stream(null, factory.createIRI("http://example.com/contentType"), null).count());
- assertTrue(2 > g.stream(null, factory.createIRI("http://example.com/contentTypeSyntax"), null).count());
- }
-
- @Test
- public void parseFile() throws Exception {
- Graph g = factory.createGraph();
- RDFParser parser = dummyParser.source(testNt).target(g);
- parser.parse().get(5, TimeUnit.SECONDS);
- checkGraph(g);
- // FIXME: this could potentially break if the equivalent of /tmp includes
- // international characters
- assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source"));
- // Should be set to the file path
- assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base"));
-
- // Should NOT have guessed the content type
- assertNull(firstPredicate(g, "contentType"));
- assertNull(firstPredicate(g, "contentTypeSyntax"));
- }
-
-
- @Test
- public void parseNoSource() throws Exception {
- thrown.expect(IllegalStateException.class);
- dummyParser.parse();
- }
-
- @Test
- public void parseBaseAndContentTypeNoSource() throws Exception {
- // Can set the other options, even without source()
- IRI base = dummyParser.createRDFTermFactory().createIRI("http://www.example.org/test.rdf");
- RDFParser parser = dummyParser.base(base).contentType(RDFSyntax.RDFXML);
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("No source has been set");
- // but .parse() should fail
- parser.parse();
- }
-
- @Test
- public void parseFileMissing() throws Exception {
- Files.delete(testNt);
- // This should not fail yet
- RDFParser parser = dummyParser.source(testNt);
- // but here:
- thrown.expect(IOException.class);
- parser.parse();
- }
-
-
- @Test
- public void parseFileContentType() throws Exception {
- Graph g = factory.createGraph();
- RDFParser parser = dummyParser
- .source(testNt)
- .contentType(RDFSyntax.NTRIPLES)
- .target(g);
- parser.parse().get(5, TimeUnit.SECONDS);
- checkGraph(g);
- // FIXME: this could potentially break if the equivalent of /tmp includes
- // international characters
- assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source"));
- assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base"));
- assertEquals("\"NTRIPLES\"", firstPredicate(g, "contentTypeSyntax"));
- assertEquals("\"application/n-triples\"", firstPredicate(g, "contentType"));
- }
-
- private String firstPredicate(Graph g, String pred) {
- return g.stream(null, factory.createIRI("http://example.com/" + pred), null)
- .map(Triple::getObject).map(RDFTerm::ntriplesString).findAny().orElse(null);
- }
-
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void parseInputStreamFailsIfBaseMissing() throws Exception {
- InputStream inputStream = new ByteArrayInputStream(new byte[0]);
- // Should not fail at this point
- RDFParser parser = dummyParser.source(inputStream);
- // but here:
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("base iri required for inputstream source");
- parser.parse();
- }
-
- @Test
- public void parseInputStreamWithBase() throws Exception {
- InputStream inputStream = new ByteArrayInputStream(new byte[0]);
- IRI base = dummyParser.createRDFTermFactory().createIRI("http://www.example.org/test.rdf");
- Graph g = factory.createGraph();
- RDFParser parser = dummyParser.source(inputStream).base(base).target(g);
- parser.parse().get(5, TimeUnit.SECONDS);
- checkGraph(g);
- assertEquals("<http://www.example.org/test.rdf>", firstPredicate(g, "base"));
- // in our particular debug output,
- // bnode source indicates InputStream
- assertTrue(firstPredicate(g, "source").startsWith("_:"));
- assertNull(firstPredicate(g, "contentType"));
- assertNull(firstPredicate(g, "contentTypeSyntax"));
- }
-
- @Test
- public void parseInputStreamWithNQuads() throws Exception {
- InputStream inputStream = new ByteArrayInputStream(new byte[0]);
- Graph g = factory.createGraph();
- RDFParser parser = dummyParser.source(inputStream).contentType(RDFSyntax.NQUADS).target(g);
- parser.parse().get(5, TimeUnit.SECONDS);
- checkGraph(g);
- assertNull(firstPredicate(g, "base"));
- // in our particular debug output,
- // bnode source indicates InputStream
- assertTrue(firstPredicate(g, "source").startsWith("_:"));
- assertEquals("\"application/n-quads\"", firstPredicate(g, "contentType"));
- assertEquals("\"NQUADS\"", firstPredicate(g, "contentTypeSyntax"));
- }
-
- @Test
- public void parseIRI() throws Exception {
- IRI iri = dummyParser.createRDFTermFactory().createIRI("http://www.example.net/test.ttl");
- Graph g = factory.createGraph();
- RDFParser parser = dummyParser.source(iri).target(g);
- parser.parse().get(5, TimeUnit.SECONDS);
- checkGraph(g);
- assertEquals("<http://www.example.net/test.ttl>", firstPredicate(g, "source"));
- // No base - assuming the above IRI is always
- // the base would break server-supplied base from
- // any HTTP Location redirects and Content-Location header
- assertNull(firstPredicate(g, "base"));
- // ".ttl" in IRI string does not imply any content type
- assertNull(firstPredicate(g, "contentType"));
- assertNull(firstPredicate(g, "contentTypeSyntax"));
-
- }
-
- @Test
- public void parseIRIBaseContentType() throws Exception {
- IRI iri = dummyParser.createRDFTermFactory().createIRI("http://www.example.net/test.ttl");
- Graph g = factory.createGraph();
- RDFParser parser = dummyParser.source(iri).base(iri).contentType(RDFSyntax.TURTLE).target(g);
- parser.parse().get(5, TimeUnit.SECONDS);
- checkGraph(g);
- assertEquals("<http://www.example.net/test.ttl>", firstPredicate(g, "source"));
- assertEquals("<http://www.example.net/test.ttl>", firstPredicate(g, "base"));
- assertEquals("\"TURTLE\"", firstPredicate(g, "contentTypeSyntax"));
- assertEquals("\"text/turtle\"", firstPredicate(g, "contentType"));
- }
-
-
}