commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [1/9] incubator-commonsrdf git commit: internally map on simple graph.contains()
Date Wed, 28 Sep 2016 13:30:46 GMT
Repository: incubator-commonsrdf
Updated Branches:
  refs/heads/rdf4j be220ea64 -> 0a9c075e9


internally map on simple graph.contains()

.. so we get consistent BlankNode mapping


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

Branch: refs/heads/rdf4j
Commit: de7fe8a2bfccc3619c87c7f3903a09f95870ab60
Parents: 9782a58
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Mon Sep 12 19:01:17 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Mon Sep 12 19:01:17 2016 +0100

----------------------------------------------------------------------
 .../apache/commons/rdf/simple/GraphImpl.java    | 39 +++++++++++---------
 1 file changed, 21 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/de7fe8a2/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index 1f19d57..779b1ad 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -55,21 +55,7 @@ final class GraphImpl implements Graph {
 
     @Override
     public void add(Triple triple) {
-        BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(triple
-                .getSubject());
-        IRI newPredicate = (IRI) internallyMap(triple.getPredicate());
-        RDFTerm newObject = internallyMap(triple.getObject());
-        // Check if any of the object references changed during the mapping, to
-        // avoid creating a new Triple object if possible
-        if (newSubject == triple.getSubject()
-                && newPredicate == triple.getPredicate()
-                && newObject == triple.getObject()) {
-            triples.add(triple);
-        } else {
-            Triple result = factory.createTriple(newSubject, newPredicate,
-                    newObject);
-            triples.add(result);
-        }
+    	triples.add(internallyMap(triple));
     }
 
     private <T extends RDFTerm> RDFTerm internallyMap(T object) {
@@ -103,6 +89,23 @@ final class GraphImpl implements Graph {
         }
     }
 
+    private Triple internallyMap(Triple triple) {
+        BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(triple
+                .getSubject());
+        IRI newPredicate = (IRI) internallyMap(triple.getPredicate());
+        RDFTerm newObject = internallyMap(triple.getObject());
+        // Check if any of the object references changed during the mapping, to
+        // avoid creating a new Triple object if possible
+        if (newSubject == triple.getSubject()
+                && newPredicate == triple.getPredicate()
+                && newObject == triple.getObject()) {
+            return triple;
+        } else {
+            return factory.createTriple(newSubject, newPredicate,
+                    newObject);
+        }
+    }
+
     @Override
     public void clear() {
         triples.clear();
@@ -116,10 +119,10 @@ final class GraphImpl implements Graph {
 
     @Override
     public boolean contains(Triple triple) {
-        return triples.contains(Objects.requireNonNull(triple));
+    	return triples.contains(internallyMap(triple));
     }
-
-    @Override
+    
+	@Override
     public Stream<Triple> stream() {
         return triples.parallelStream().unordered();
     }


Mime
View raw message