commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [19/50] incubator-commonsrdf git commit: Hide implementations - expose JsonLd* interfaces
Date Tue, 04 Oct 2016 01:30:40 GMT
Hide implementations - expose JsonLd* interfaces


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

Branch: refs/heads/rdf4j
Commit: 80ad999d72217d4aeb6375bbe7a78e2427f41df5
Parents: 44031f3
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Thu Sep 8 16:27:45 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Thu Sep 8 16:31:12 2016 +0100

----------------------------------------------------------------------
 .../commons/rdf/jsonldjava/JsonLdBlankNode.java |  64 +++++-----
 .../commons/rdf/jsonldjava/JsonLdIRI.java       |  68 +++++-----
 .../commons/rdf/jsonldjava/JsonLdLiteral.java   | 128 ++++++++++---------
 .../commons/rdf/jsonldjava/JsonLdQuad.java      |  61 +++++----
 .../commons/rdf/jsonldjava/JsonLdQuadLike.java  |  73 ++++++-----
 .../rdf/jsonldjava/JsonLdRDFTermFactory.java    |  42 +++---
 .../commons/rdf/jsonldjava/JsonLdTerm.java      |  26 +++-
 .../commons/rdf/jsonldjava/JsonLdTriple.java    |  49 ++++---
 8 files changed, 281 insertions(+), 230 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/80ad999d/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 f93d3b4..e54c894 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
@@ -21,38 +21,42 @@ import org.apache.commons.rdf.api.BlankNode;
 
 import com.github.jsonldjava.core.RDFDataset.Node;
 
-final class JsonLdBlankNode extends JsonLdTerm implements BlankNode {
-	private String blankNodePrefix;
-
-	JsonLdBlankNode(Node node, String blankNodePrefix) {
-		super(node);
-		this.blankNodePrefix = blankNodePrefix;
-		if (! node.isBlankNode()) {
-			throw new IllegalArgumentException("Node is not a BlankNode:" + 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() {
-		return node.getValue();
-	}
-
-	@Override
-	public String uniqueReference() {					
-		return blankNodePrefix + node.getValue();
-	}
-
-	@Override
-	public boolean equals(Object obj) {
-		if (! ( obj instanceof BlankNode)) {
-			return false;
+	
+		@Override
+		public String ntriplesString() {
+			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();
 		}
-		BlankNode other = (BlankNode) obj;
-		return uniqueReference().equals(other.uniqueReference());
 	}
 
-	@Override
-	public int hashCode() {
-		return uniqueReference().hashCode();
-	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/80ad999d/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 e21f55c..aac13e6 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
@@ -22,40 +22,44 @@ import org.apache.commons.rdf.api.IRI;
 import com.github.jsonldjava.core.RDFDataset;
 import com.github.jsonldjava.core.RDFDataset.Node;
 
-final class JsonLdIRI extends JsonLdTerm implements IRI {
+public interface JsonLdIRI extends JsonLdTerm, IRI {
 
-	JsonLdIRI(Node node) {
-		super(node);
-		if (! node.isIRI()) {
-			throw new IllegalArgumentException("Node is not an IRI:" + node);
+	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());
 		}
 	}
 
-	public JsonLdIRI(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());
-	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/80ad999d/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 e492486..025128e 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
@@ -26,72 +26,74 @@ import org.apache.commons.rdf.simple.Types;
 
 import com.github.jsonldjava.core.RDFDataset.Node;
 
-public class JsonLdLiteral extends JsonLdTerm implements Literal {
-
-	JsonLdLiteral(Node node) {
-		super(node);
-		if (! node.isLiteral()) {
-			throw new IllegalArgumentException("Node is not a Literal:" + 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 JsonLdIRI(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 asNode().compareTo(other.asNode()) == 0;
+		@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();
 		}
-		if (obj instanceof Literal) {
-			Literal other = (Literal) obj;
-			return getLexicalForm().equals(other.getLexicalForm()) &&
-					getDatatype().equals(other.getDatatype()) &&
-					getLanguageTag().equals(other.getLanguageTag());
+	
+		@Override
+		public IRI getDatatype() {
+			return new JsonLdIRI.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());
 		}
-		return false;
 		
+		@Override
+		public boolean equals(Object obj) {
+			if (obj instanceof JsonLdLiteral) {
+				JsonLdLiteral other = (JsonLdLiteral) obj;
+				return asNode().compareTo(other.asNode()) == 0;
+			}
+			if (obj instanceof Literal) {
+				Literal other = (Literal) obj;
+				return getLexicalForm().equals(other.getLexicalForm()) &&
+						getDatatype().equals(other.getDatatype()) &&
+						getLanguageTag().equals(other.getLanguageTag());
+			}
+			return false;
+			
+		}	
 	}
-	
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/80ad999d/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 ce2cb09..524f43c 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
@@ -21,34 +21,45 @@ import java.util.Objects;
 
 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;
+// Note: To avoid confusion - don't import either Quad
+import org.apache.commons.rdf.jsonldjava.JsonLdQuadLike.JsonLdQuadLikeImpl;
 
-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) {
-		super(quad, blankNodePrefix);			
-	}
+public interface JsonLdQuad extends org.apache.commons.rdf.api.Quad {
 
-	@Override
-	public boolean equals(Object obj) {
-		if (obj == this) {
-			return true;
+	/**
+	 * 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();
+	
+	final class JsonLdQuadImpl extends JsonLdQuadLikeImpl<BlankNodeOrIRI,IRI,RDFTerm,BlankNodeOrIRI>

+		implements JsonLdQuad {
+		
+		JsonLdQuadImpl(com.github.jsonldjava.core.RDFDataset.Quad quad, String blankNodePrefix)
{
+			super(quad, blankNodePrefix);			
 		}
-		if (! (obj instanceof Quad)) {
-			return false;
+	
+		@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());
 		}
-		Quad other = (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());
-	}
-
+	
+		@Override
+		public int hashCode() {
+			return Objects.hash(getGraphName(), getSubject(), getPredicate(), getObject());
+		}	
+	}	
+		
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/80ad999d/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 6290812..753e332 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
@@ -24,41 +24,50 @@ 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> {
+public interface JsonLdQuadLike<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm,
G extends RDFTerm> extends QuadLike<S,P,O,G> {
 	
-	private final Quad quad;
-	private String blankNodePrefix;
-
-	private static JsonLdRDFTermFactory rdfTermFactory = new JsonLdRDFTermFactory();
+	public Quad asJsonLdQuad();
 	
-	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);
-	}
+	class JsonLdQuadLikeImpl<S extends RDFTerm, P extends RDFTerm, O extends RDFTerm, G extends
RDFTerm> implements JsonLdQuadLike<S,P,O,G> {
+		
+		private static JsonLdRDFTermFactory rdfTermFactory = new JsonLdRDFTermFactory();
+		
+		private final Quad quad;
+		private String blankNodePrefix;
+		
+		JsonLdQuadLikeImpl(Quad jsonldQuad, String blankNodePrefix) {
+			this.quad = jsonldQuad;
+			this.blankNodePrefix = blankNodePrefix;			
+		}
 	
-	@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);
+		@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);
+		}
+	
+		public Quad asJsonLdQuad() {
+			return quad;
+		}
 	}
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/80ad999d/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
index f57eb86..5ac360a 100644
--- a/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
+++ b/jsonld-java/src/main/java/org/apache/commons/rdf/jsonldjava/JsonLdRDFTermFactory.java
@@ -24,11 +24,9 @@ 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.QuadLike;
 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.api.TripleLike;
 import org.apache.commons.rdf.simple.Types;
 
@@ -54,44 +52,44 @@ final class JsonLdRDFTermFactory implements RDFTermFactory {
 	}
 	
 	@Override
-	public IRI createIRI(String iri) {
-		return new JsonLdIRI(iri);
+	public JsonLdIRI createIRI(String iri) {
+		return new JsonLdIRI.JsonLdIRIImpl(iri);
 	}
 	
 	@Override
-	public BlankNode createBlankNode() {
+	public JsonLdBlankNode createBlankNode() {
 		String id = "_:" + UUID.randomUUID().toString();
-		return new JsonLdBlankNode(new RDFDataset.BlankNode(id), bnodePrefix);
+		return new JsonLdBlankNode.JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
 	}
 	
 	@Override
-	public BlankNode createBlankNode(String name) {
+	public JsonLdBlankNode createBlankNode(String name) {
 		String id = "_:" + name;
 		// TODO: Check if name is valid JSON-LD BlankNode identifier
-		return new JsonLdBlankNode(new RDFDataset.BlankNode(id), bnodePrefix);
+		return new JsonLdBlankNode.JsonLdBlankNodeImpl(new RDFDataset.BlankNode(id), bnodePrefix);
 	}
 	
 	@Override
-	public Triple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
-		return new JsonLdTriple(asJsonLdQuad(subject, predicate, object), bnodePrefix);
+	public JsonLdTriple createTriple(BlankNodeOrIRI subject, IRI predicate, RDFTerm object)
{
+		return new JsonLdTriple.JsonLdTripleImpl(asJsonLdQuad(subject, predicate, object), bnodePrefix);
 	}
 	
 	@Override
-	public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate,
RDFTerm object)
+	public JsonLdQuad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, IRI predicate,
RDFTerm object)
 			throws IllegalArgumentException, UnsupportedOperationException {
-		return new JsonLdQuad(asJsonLdQuad(graphName, subject, predicate, object), bnodePrefix);
+		return new JsonLdQuad.JsonLdQuadImpl(asJsonLdQuad(graphName, subject, predicate, object),
bnodePrefix);
 	}
 	
 	@Override
-	public Literal createLiteral(String literal) {		
-		return new JsonLdLiteral(new RDFDataset.Literal(literal, null, null));
+	public JsonLdLiteral createLiteral(String literal) {		
+		return new JsonLdLiteral.JsonLdLiteralImpl(new RDFDataset.Literal(literal, null, null));
 	}
 	@Override
-	public Literal createLiteral(String literal, IRI dataType) {
-		return new JsonLdLiteral(new RDFDataset.Literal(literal, dataType.getIRIString(), null));
}
+	public JsonLdLiteral createLiteral(String literal, IRI dataType) {
+		return new JsonLdLiteral.JsonLdLiteralImpl(new RDFDataset.Literal(literal, dataType.getIRIString(),
null));	}
 	@Override
-	public Literal createLiteral(String literal, String language) {
-		return new JsonLdLiteral(new RDFDataset.Literal(literal, Types.RDF_LANGSTRING.getIRIString(),
language));		
+	public JsonLdLiteral createLiteral(String literal, String language) {
+		return new JsonLdLiteral.JsonLdLiteralImpl(new RDFDataset.Literal(literal, Types.RDF_LANGSTRING.getIRIString(),
language));		
 	}
 
 
@@ -131,7 +129,7 @@ final class JsonLdRDFTermFactory implements RDFTermFactory {
 		return new RDFDataset.Quad(asJsonLdNode(subject), asJsonLdNode(predicate), asJsonLdNode(object),
graph);
 	}
 	
-	@SuppressWarnings("rawtypes")
+	@SuppressWarnings({ "rawtypes", "unchecked" })
 	public RDFDataset.Quad asJsonLdQuad(TripleLike tripleOrQuad) {
 		RDFTerm g = null;	
 		if (tripleOrQuad instanceof QuadLike) {
@@ -141,14 +139,14 @@ final class JsonLdRDFTermFactory implements RDFTermFactory {
 		return asJsonLdQuad(g, tripleOrQuad.getSubject(), tripleOrQuad.getPredicate(), tripleOrQuad.getObject());
 	}
 	
-	RDFTerm asTerm(final Node node, String blankNodePrefix) {	
+	JsonLdTerm asTerm(final Node node, String blankNodePrefix) {	
 		if (node == null) {
 			return null; // e.g. default graph
 		}
 		if (node.isIRI()) {
-			return new JsonLdIRI(node);
+			return new JsonLdIRI.JsonLdIRIImpl(node);
 		} else if (node.isBlankNode()) {
-			return new JsonLdBlankNode(node, blankNodePrefix);
+			return new JsonLdBlankNode.JsonLdBlankNodeImpl(node, blankNodePrefix);
 		} else if (node.isLiteral()) {
 			// TODO: Our own JsonLdLiteral
 			if (node.getLanguage() != null) {

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/80ad999d/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 39ef1a6..80a7b56 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
@@ -17,15 +17,27 @@
  */
 package org.apache.commons.rdf.jsonldjava;
 
+import org.apache.commons.rdf.api.RDFTerm;
+
 import com.github.jsonldjava.core.RDFDataset.Node;
 
-public abstract class JsonLdTerm {
-	final Node node;
-	JsonLdTerm(Node node) {
-		this.node = node;
-	}
-	public Node asNode() {
-		return node;
+public interface JsonLdTerm extends RDFTerm {
+	
+	/**
+	 * Return the underlying JsonLd {@link Node}.
+	 *  
+	 * @return JsonLd {@link Node}
+	 */
+	Node asNode();
+	
+	abstract class JsonLdTermImpl implements JsonLdTerm {
+		final Node node;
+		JsonLdTermImpl(Node node) {
+			this.node = node;
+		}
+		public Node asNode() {
+			return node;
+		}
 	}
 	
 }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/80ad999d/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 a14dbb4..18e271c 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
@@ -23,29 +23,40 @@ 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.Triple;
+import org.apache.commons.rdf.jsonldjava.JsonLdQuadLike.JsonLdQuadLikeImpl;
 
 import com.github.jsonldjava.core.RDFDataset.Quad;
 
-final class JsonLdTriple extends JsonLdQuadLike<BlankNodeOrIRI, IRI, RDFTerm, RDFTerm>
-	implements Triple {
-	
-	JsonLdTriple(Quad quad, String blankNodePrefix) {
-		super(quad, blankNodePrefix);
-	}
+public interface JsonLdTriple extends Triple {
 
-	@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());
-	}
+	/**
+	 * 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();
 
-	@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());
+		}
 	}
 }
\ No newline at end of file


Mime
View raw message