commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [47/50] incubator-commonsrdf git commit: Added JenaQuad
Date Mon, 04 Jul 2016 09:37:51 GMT
Added JenaQuad


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

Branch: refs/heads/jena
Commit: f371de8408166dc8c2054a815bfac09a8d292e7e
Parents: 3786f92
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Mon Jul 4 10:35:07 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Mon Jul 4 10:35:07 2016 +0100

----------------------------------------------------------------------
 .../org/apache/commons/rdf/jena/JenaQuad.java   |  26 +++++
 .../apache/commons/rdf/jena/impl/JCR_Quad.java  | 100 +++++++++++++++++++
 2 files changed, 126 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f371de84/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
new file mode 100644
index 0000000..532f481
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/JenaQuad.java
@@ -0,0 +1,26 @@
+/**
+ * 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.jena.sparql.core.Quad;
+
+/** Access the Jena quad backing this object */ 
+public interface JenaQuad extends org.apache.commons.rdf.api.Quad {
+    public Quad getQuad() ;
+}

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/f371de84/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Quad.java
----------------------------------------------------------------------
diff --git a/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Quad.java b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Quad.java
new file mode 100644
index 0000000..d64faf3
--- /dev/null
+++ b/jena/src/main/java/org/apache/commons/rdf/jena/impl/JCR_Quad.java
@@ -0,0 +1,100 @@
+package org.apache.commons.rdf.jena.impl;
+
+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;
+import org.apache.commons.rdf.api.Triple;
+import org.apache.commons.rdf.jena.JenaCommonsRDF;
+import org.apache.commons.rdf.jena.JenaQuad;
+
+public class JCR_Quad implements Quad, JenaQuad {
+
+	private final Optional<BlankNodeOrIRI> graphName;	
+    private final BlankNodeOrIRI subject ;
+    private final IRI predicate ;
+    private final RDFTerm object ;
+    private org.apache.jena.sparql.core.Quad quad = null ;
+
+    /* package */ JCR_Quad(Optional<BlankNodeOrIRI> graphName, BlankNodeOrIRI subject,
IRI predicate, RDFTerm object) {
+        this.graphName = Objects.requireNonNull(graphName);
+		this.subject = Objects.requireNonNull(subject) ;
+        this.predicate = Objects.requireNonNull(predicate) ;
+        this.object = Objects.requireNonNull(object) ;
+    }
+    
+    /* package */ JCR_Quad(org.apache.jena.sparql.core.Quad quad) {
+        this.quad = Objects.requireNonNull(quad) ;
+    	this.graphName = Optional.of((BlankNodeOrIRI)JCR_Factory.fromJena(quad.getGraph()))
;
+        this.subject = (BlankNodeOrIRI)JCR_Factory.fromJena(quad.getSubject()) ;
+        this.predicate = (IRI)JCR_Factory.fromJena(quad.getPredicate()) ;
+        this.object = JCR_Factory.fromJena(quad.getObject()) ;
+    }
+
+    @Override
+    public org.apache.jena.sparql.core.Quad getQuad() {
+        if ( quad == null ) {
+            quad = org.apache.jena.sparql.core.Quad.create(
+            		JenaCommonsRDF.toJena(graphName.orElse(null)), 
+            		JenaCommonsRDF.toJena(subject), 
+            		JenaCommonsRDF.toJena(predicate), 
+            		JenaCommonsRDF.toJena(object)) ;
+        }
+        return quad ;
+    }
+
+    @Override
+    public BlankNodeOrIRI getSubject() {
+        return subject ;
+    }
+
+    @Override
+    public IRI getPredicate() {
+        return predicate ;
+    }
+
+    @Override
+    public RDFTerm getObject() {
+        return object ;
+    }
+
+    @Override
+	public Optional<BlankNodeOrIRI> getGraphName() {
+		return graphName;
+	}
+    
+    @Override
+    public int hashCode() {
+        return Objects.hash(getSubject(), getPredicate(), getObject(), getGraphName()) ;
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        if ( other == this ) return true ;
+        if ( other == null ) return false ;
+        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 String toString() {
+    	// kind of nquad syntax
+		return getSubject().ntriplesString() + " " + 
+    			getPredicate().ntriplesString() + " " + 
+    			getObject().ntriplesString() + " " + 
+    			getGraphName().map(RDFTerm::ntriplesString).orElse("") +  ".";
+    }
+
+    @Override
+    public Triple asTriple() {
+    	return new JCR_Triple(getSubject(), getPredicate(), getObject());
+    }
+
+}


Mime
View raw message