Repository: incubator-commonsrdf
Updated Branches:
  refs/heads/jsonld-java 0928ddbaa -> 492ea2302


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/jsonld-java
Commit: de7fe8a2bfccc3619c87c7f3903a09f95870ab60
Parents: 9782a58
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Mon Sep 12 19:01:17 2016 +0100
Committer: Stian Soiland-Reyes <st...@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();
     }

Reply via email to