commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [3/9] incubator-commonsrdf git commit: non-static fromJena methods
Date Fri, 08 Jul 2016 11:53:47 GMT
non-static fromJena methods

which uses the factory's salt


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

Branch: refs/heads/jena
Commit: ed89a1b9659dc62af77bc84565d2043cc30b6c2e
Parents: 3547988
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Fri Jul 8 09:39:55 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Fri Jul 8 09:39:55 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/jena/RDFTermFactoryJena.java    | 48 ++++++++++++++++----
 .../apache/commons/rdf/jena/impl/GraphImpl.java |  5 +-
 .../commons/rdf/jena/impl/JenaFactory.java      |  4 ++
 3 files changed, 45 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ed89a1b9/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java b/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
index 12b0904..820884c 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/RDFTermFactoryJena.java
@@ -22,7 +22,16 @@ import java.util.Optional;
 import java.util.UUID;
 import java.util.function.Consumer;
 
-import org.apache.commons.rdf.api.*;
+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.Quad;
+import org.apache.commons.rdf.api.RDFSyntax;
+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.impl.JenaFactory;
 import org.apache.jena.datatypes.RDFDatatype;
 import org.apache.jena.datatypes.xsd.XSDDatatype;
@@ -45,7 +54,15 @@ import org.apache.jena.sparql.graph.GraphFactory;
  */
 public final class RDFTermFactoryJena implements RDFTermFactory {
 
-	private UUID salt = UUID.randomUUID();
+	private UUID salt;
+
+	public RDFTermFactoryJena() { 
+		this.salt = UUID.randomUUID();
+	}
+	
+	public RDFTermFactoryJena(UUID salt) {
+		this.salt = salt;
+	}
 
 	@Override
 	public BlankNode createBlankNode() {
@@ -186,7 +203,7 @@ public final class RDFTermFactoryJena implements RDFTermFactory {
 	/**
 	 * Adapt an existing Jena Triple to CommonsRDF {@link Triple}.
 	 * 
-	 * @param salt
+	 * @param triple Jena triple
 	 */
 	public Triple fromJena(org.apache.jena.graph.Triple triple) {
 		return JenaFactory.fromJena(triple, salt);
@@ -195,19 +212,30 @@ public final class RDFTermFactoryJena implements RDFTermFactory {
 	/**
 	 * Adapt an existing Jena Triple to CommonsRDF {@link Triple}.
 	 * 
-	 * @param salt
+	 * @param triple Jena triple
+	 * @param salt A {@link UUID} salt for adapting any {@link BlankNode}s 
 	 */
 	public static Triple fromJena(org.apache.jena.graph.Triple triple, UUID salt) {
 		return JenaFactory.fromJena(triple, salt);
 	}
+	
+	public Quad fromJena(org.apache.jena.sparql.core.Quad quad) {
+		return JenaFactory.fromJena(quad, salt);
+	}
+
+	public static Quad fromJena(org.apache.jena.sparql.core.Quad quad, UUID salt) {
+		return JenaFactory.fromJena(quad, salt);
+	}
+	
 
 	/**
 	 * Adapt an existring Jena Graph to CommonsRDF {@link Graph}. This does not
 	 * take a copy. Changes to the CommonsRDF Graph are reflected in the jena
 	 * graph.
 	 */
-	public static Graph fromJena(org.apache.jena.graph.Graph graph) {
-		return fromJena(new RDFTermFactoryJena(), graph);
+	public static Graph fromJena(org.apache.jena.graph.Graph graph) {	
+		// NOTE: This generates a new UUID salt per graph
+		return JenaFactory.fromJena(graph);
 	}
 	
 	/**
@@ -215,13 +243,13 @@ public final class RDFTermFactoryJena implements RDFTermFactory {
 	 * 
 	 * @param salt
 	 */
-	public static RDFTerm fromJena(RDFTermFactory factory, Node node, UUID salt) {
+	public static RDFTerm fromJena(RDFTermFactory factory, Node node) {
 		if (node == null) {
 			return null;
 		}
 		if (factory instanceof RDFTermFactoryJena) {
-			// No need to convert, just wrap (we'll use the parameter-provided salt)
-			return fromJena(node, salt);
+			// No need to convert, just wrap
+			return ((RDFTermFactoryJena)factory).fromJena(node);
 		}
 		if (node.isURI())
 			return factory.createIRI(node.getURI());
@@ -288,7 +316,7 @@ public final class RDFTermFactoryJena implements RDFTermFactory {
 	public static Quad fromJena(RDFTermFactory factory, org.apache.jena.sparql.core.Quad quad)
{
 		if (factory instanceof RDFTermFactoryJena) {
 			// No need to convert, just wrap
-			return fromJena(quad);
+			return ((RDFTermFactoryJena)factory).fromJena(quad);
 		}
 		BlankNodeOrIRI graphName = (BlankNodeOrIRI) (fromJena(factory, quad.getGraph()));
 		BlankNodeOrIRI subject = (BlankNodeOrIRI) (fromJena(factory, quad.getSubject()));

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/ed89a1b9/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java
index f1243f1..ed16b4c 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/GraphImpl.java
@@ -92,12 +92,13 @@ public class GraphImpl implements Graph, JenaGraph {
 
     @Override
     public Stream<? extends Triple> stream() {
-    	return Iter.asStream(graph.find(null, null, null), true).map(RDFTermFactoryJena::fromJena);
+    	RDFTermFactoryJena factory = new RDFTermFactoryJena(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) {
-    	RDFTermFactoryJena factory = new RDFTermFactoryJena();
+    	RDFTermFactoryJena factory = new RDFTermFactoryJena(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/ed89a1b9/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java
index b94e3bd..a856d07 100644
--- a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JenaFactory.java
@@ -80,6 +80,10 @@ public class JenaFactory {
 		return new GraphImpl(graph, UUID.randomUUID());
 	}
 
+	public static Graph fromJena(org.apache.jena.graph.Graph graph, UUID salt) {
+		return new GraphImpl(graph, salt);
+	}
+	
 	public static RDFTerm fromJena(Node node, UUID salt) {
 		if (node.isURI())
 			return new IRIImpl(node);


Mime
View raw message