commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [49/50] incubator-commonsrdf git commit: Common superclass JsonLdQuadLike
Date Thu, 08 Sep 2016 15:32:17 GMT
Common superclass JsonLdQuadLike


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

Branch: refs/heads/jsonld-java
Commit: 44031f3752ae41dd08e390ef180f851e9d62842e
Parents: a118697
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Thu Sep 8 16:03:40 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Thu Sep 8 16:04:08 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/jsonldjava/JsonLdQuad.java      | 33 +---------
 .../commons/rdf/jsonldjava/JsonLdQuadLike.java  | 64 ++++++++++++++++++++
 .../commons/rdf/jsonldjava/JsonLdTriple.java    | 25 +-------
 3 files changed, 70 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/44031f37/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 e8dbfbd..ce2cb09 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
@@ -18,47 +18,20 @@
 package org.apache.commons.rdf.jsonldjava;
 
 import java.util.Objects;
-import java.util.Optional;
 
 import org.apache.commons.rdf.api.BlankNodeOrIRI;
 import org.apache.commons.rdf.api.IRI;
 import org.apache.commons.rdf.api.Quad;
 import org.apache.commons.rdf.api.RDFTerm;
 
-final class JsonLdQuad implements org.apache.commons.rdf.api.Quad {
-	private final com.github.jsonldjava.core.RDFDataset.Quad quad;
-	private String blankNodePrefix;
-
-	private static JsonLdRDFTermFactory rdfTermFactory = new JsonLdRDFTermFactory();
+final class JsonLdQuad	extends JsonLdQuadLike<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI>

+	implements org.apache.commons.rdf.api.Quad {
 	
 	JsonLdQuad(com.github.jsonldjava.core.RDFDataset.Quad quad, String blankNodePrefix) {
-		this.quad = quad;
-		this.blankNodePrefix = blankNodePrefix;			
-	}
-
-	@Override
-	public BlankNodeOrIRI getSubject() {
-		return (BlankNodeOrIRI) rdfTermFactory.asTerm(quad.getSubject(), blankNodePrefix);
-	}
-
-	@Override
-	public IRI getPredicate() {
-		return (IRI) rdfTermFactory.asTerm(quad.getPredicate(), blankNodePrefix);
+		super(quad, blankNodePrefix);			
 	}
 
 	@Override
-	public RDFTerm getObject() {
-		return rdfTermFactory.asTerm(quad.getObject(), blankNodePrefix);
-	}
-
-	@Override
-	public Optional<BlankNodeOrIRI> getGraphName() {
-		BlankNodeOrIRI g = (BlankNodeOrIRI) rdfTermFactory.asTerm(quad.getGraph(), 
-				blankNodePrefix);
-		return Optional.ofNullable(g);
-	}
-	
-	@Override
 	public boolean equals(Object obj) {
 		if (obj == this) {
 			return true;

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/44031f37/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
new file mode 100644
index 0000000..6290812
--- /dev/null
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdQuadLike.java
@@ -0,0 +1,64 @@
+/**
+ * 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.util.Optional;
+
+import org.apache.commons.rdf.api.QuadLike;
+import org.apache.commons.rdf.api.RDFTerm;
+
+import com.github.jsonldjava.core.RDFDataset.Quad;
+
+class JsonLdQuadLike<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends
RDFTerm> implements QuadLike<S,P,O,G> {
+	
+	private final Quad quad;
+	private String blankNodePrefix;
+
+	private static JsonLdRDFTermFactory rdfTermFactory = new JsonLdRDFTermFactory();
+	
+	JsonLdQuadLike(Quad jsonldQuad, String blankNodePrefix) {
+		this.quad = jsonldQuad;
+		this.blankNodePrefix = blankNodePrefix;			
+	}
+
+	@SuppressWarnings("unchecked")	
+	@Override
+	public Optional<G> getGraphName() {
+		G g = (G) rdfTermFactory.asTerm(quad.getGraph(), blankNodePrefix);
+		return Optional.ofNullable(g);
+	}
+	
+	@SuppressWarnings("unchecked")
+	@Override
+	public S getSubject() {
+		return (S) rdfTermFactory.asTerm(quad.getSubject(), blankNodePrefix);
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public P getPredicate() {
+		return (P) rdfTermFactory.asTerm(quad.getPredicate(), blankNodePrefix);
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public O getObject() {
+		return (O) rdfTermFactory.asTerm(quad.getObject(), blankNodePrefix);
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/44031f37/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 49e95e3..a14dbb4 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
@@ -26,30 +26,11 @@ import org.apache.commons.rdf.api.Triple;
 
 import com.github.jsonldjava.core.RDFDataset.Quad;
 
-final class JsonLdTriple implements Triple {
-	private final Quad quad;
-	private String blankNodePrefix;
-
-	private static JsonLdRDFTermFactory rdfTermFactory = new JsonLdRDFTermFactory();
+final class JsonLdTriple extends JsonLdQuadLike<BlankNodeOrIRI, IRI, RDFTerm, RDFTerm>
+	implements Triple {
 	
 	JsonLdTriple(Quad quad, String blankNodePrefix) {
-		this.quad = quad;
-		this.blankNodePrefix = blankNodePrefix;			
-	}
-
-	@Override
-	public BlankNodeOrIRI getSubject() {
-		return (BlankNodeOrIRI) rdfTermFactory.asTerm(quad.getSubject(), blankNodePrefix);
-	}
-
-	@Override
-	public IRI getPredicate() {
-		return (IRI) rdfTermFactory.asTerm(quad.getPredicate(), blankNodePrefix);
-	}
-
-	@Override
-	public RDFTerm getObject() {
-		return rdfTermFactory.asTerm(quad.getObject(), blankNodePrefix);
+		super(quad, blankNodePrefix);
 	}
 
 	@Override


Mime
View raw message