commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [6/7] incubator-commonsrdf git commit: Add RDF4JTripleLike
Date Fri, 03 Jun 2016 13:28:40 GMT
Add RDF4JTripleLike

recognized by asStatement to return original statement


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/712eec6f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/712eec6f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/712eec6f

Branch: refs/heads/rdf4j
Commit: 712eec6fa18bf779cc56d1296d539a350858da1f
Parents: b90f9fc
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Fri Jun 3 10:37:21 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Fri Jun 3 10:37:21 2016 +0100

----------------------------------------------------------------------
 .../org/apache/commons/rdf/rdf4j/RDF4JQuad.java |  9 +----
 .../commons/rdf/rdf4j/RDF4JTermFactory.java     |  9 ++++-
 .../apache/commons/rdf/rdf4j/RDF4JTriple.java   |  9 +----
 .../commons/rdf/rdf4j/RDF4JTripleLike.java      | 42 ++++++++++++++++++++
 .../apache/commons/rdf/rdf4j/impl/QuadImpl.java |  5 +++
 5 files changed, 56 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/712eec6f/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 acbcedc..621d34f 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
@@ -18,18 +18,11 @@
 package org.apache.commons.rdf.rdf4j;
 
 import org.apache.commons.rdf.api.Quad;
-import org.eclipse.rdf4j.model.Statement;
 
 /**
  * Marker interface for RDF4J implementations of Quad.
  * 
  */
-public interface RDF4JQuad extends Quad {
+public interface RDF4JQuad extends Quad, RDF4JTripleLike {
 	
-	/**
-	 * 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/712eec6f/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
index 24d2d86..3df7de9 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTermFactory.java
@@ -152,6 +152,11 @@ public class RDF4JTermFactory implements RDFTermFactory {
 	}
 	
 	public Statement asStatement(Triple triple) {
+		if (triple instanceof RDF4JTripleLike) { 
+			// This covers both RDF4JQuad and RDF4JTriple
+			RDF4JTripleLike rdf4jTriple = (RDF4JTriple) triple;
+			return rdf4jTriple.asStatement();
+		}
 		return valueFactory.createStatement(
 				(org.eclipse.rdf4j.model.Resource) asValue(triple.getSubject()), 
 				(org.eclipse.rdf4j.model.IRI) asValue(triple.getPredicate()), 
@@ -162,7 +167,7 @@ public class RDF4JTermFactory implements RDFTermFactory {
 		return valueFactory.createStatement(
 				(org.eclipse.rdf4j.model.Resource) asValue(quad.getSubject()), 
 				(org.eclipse.rdf4j.model.IRI) asValue(quad.getPredicate()), 
-				asValue(quad.getObject()), 
+				asValue(quad.getObject()), 				
 				(org.eclipse.rdf4j.model.Resource) asValue(quad.getGraphName().orElse(null))
 				);
 	}	
@@ -248,7 +253,7 @@ public class RDF4JTermFactory implements RDFTermFactory {
 			// 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?
+			// does it have to be in RDF4J?
 			return valueFactory.createBNode(blankNode.uniqueReference());
 		}
 		throw new IllegalArgumentException("RDFTerm was not an IRI, Literal or BlankNode: " + term.getClass());

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/712eec6f/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 ed0b4b0..4e09f19 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
@@ -18,18 +18,11 @@
 package org.apache.commons.rdf.rdf4j;
 
 import org.apache.commons.rdf.api.Triple;
-import org.eclipse.rdf4j.model.Statement;
 
 /**
  * Marker interface for RDF4J implementations of Triple.
  * 
  */
-public interface RDF4JTriple extends Triple {
+public interface RDF4JTriple extends Triple, RDF4JTripleLike {
 	
-	/**
-	 * 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/712eec6f/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
new file mode 100644
index 0000000..36f4fa7
--- /dev/null
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTripleLike.java
@@ -0,0 +1,42 @@
+/**
+ * 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.BlankNodeOrIRI;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.RDFTerm;
+import org.apache.commons.rdf.api.TripleLike;
+import org.eclipse.rdf4j.model.Statement;
+
+/**
+ * Marker interface for RDF4J implementations of TripleLike statements.
+ * <p>
+ * This is backed by a {@link Statement} retrievable with {@link #asStatement()}.
+ * 
+ * @see RDF4JTriple
+ * @see RDF4JQuad
+ */
+public interface RDF4JTripleLike extends TripleLike<BlankNodeOrIRI, IRI, RDFTerm> {
+	
+	/**
+	 * 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/712eec6f/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 7111fd2..0e11eb2 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
@@ -73,4 +73,9 @@ public final class QuadImpl implements Quad, RDF4JQuad {
 			BlankNodeOrIRI g = (BlankNodeOrIRI) RDF4JTermFactory.asRDFTerm(statement.getContext(),
salt);
 			return Optional.of(g);
 		}
+		
+		@Override
+		public Triple asTriple() {
+			return new TripleImpl(statement, salt);
+		}
 }
\ No newline at end of file


Mime
View raw message