You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by re...@apache.org on 2013/09/18 18:06:19 UTC

svn commit: r1524471 - in /stanbol/branches/commons-ng/commons/indexedgraph: ./ src/main/java/org/apache/stanbol/commons/indexedgraph/IndexedTripleCollection.java src/test/java/org/apache/stanbol/commons/indexedgraph/IndexedGraphTest.java

Author: reto
Date: Wed Sep 18 16:06:19 2013
New Revision: 1524471

URL: http://svn.apache.org/r1524471
Log:
STANBOL-1097: merged down indexedgraph

Modified:
    stanbol/branches/commons-ng/commons/indexedgraph/   (props changed)
    stanbol/branches/commons-ng/commons/indexedgraph/src/main/java/org/apache/stanbol/commons/indexedgraph/IndexedTripleCollection.java
    stanbol/branches/commons-ng/commons/indexedgraph/src/test/java/org/apache/stanbol/commons/indexedgraph/IndexedGraphTest.java

Propchange: stanbol/branches/commons-ng/commons/indexedgraph/
------------------------------------------------------------------------------
    svn:mergeinfo = /stanbol/trunk/commons/indexedgraph:1487448-1524470

Modified: stanbol/branches/commons-ng/commons/indexedgraph/src/main/java/org/apache/stanbol/commons/indexedgraph/IndexedTripleCollection.java
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/indexedgraph/src/main/java/org/apache/stanbol/commons/indexedgraph/IndexedTripleCollection.java?rev=1524471&r1=1524470&r2=1524471&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/indexedgraph/src/main/java/org/apache/stanbol/commons/indexedgraph/IndexedTripleCollection.java (original)
+++ stanbol/branches/commons-ng/commons/indexedgraph/src/main/java/org/apache/stanbol/commons/indexedgraph/IndexedTripleCollection.java Wed Sep 18 16:06:19 2013
@@ -446,11 +446,21 @@ class IndexedTripleCollection extends Ab
                 }
             } else { //handle BNodes
                 //sort BNodes based on hashCode
-                int ah = System.identityHashCode(a);
-                int bh = System.identityHashCode(b);
+                int ah = a.hashCode();
+                int bh = b.hashCode();
                 if(ah == bh){
                     if(!a.equals(b)){
-                        return resolveBNodeHashConflict(a, b, confictsMap);
+                        //if implementations hash is the same, but the instances
+                        //are not equals, try to sort them by identity hash code
+                        int ash = System.identityHashCode(a);
+                        int bsh = System.identityHashCode(b);
+                        if(ash == bsh){ //if those are still the same, we need
+                            //to resolve the hashCode conflict by memorise the
+                            //decision in a confilctMap
+                            return resolveBNodeHashConflict(a, b, confictsMap);
+                        } else {
+                            return ash < bsh ? -1 : 1;
+                        }
                     } else { //same hash and equals
                         return 0;
                     }

Modified: stanbol/branches/commons-ng/commons/indexedgraph/src/test/java/org/apache/stanbol/commons/indexedgraph/IndexedGraphTest.java
URL: http://svn.apache.org/viewvc/stanbol/branches/commons-ng/commons/indexedgraph/src/test/java/org/apache/stanbol/commons/indexedgraph/IndexedGraphTest.java?rev=1524471&r1=1524470&r2=1524471&view=diff
==============================================================================
--- stanbol/branches/commons-ng/commons/indexedgraph/src/test/java/org/apache/stanbol/commons/indexedgraph/IndexedGraphTest.java (original)
+++ stanbol/branches/commons-ng/commons/indexedgraph/src/test/java/org/apache/stanbol/commons/indexedgraph/IndexedGraphTest.java Wed Sep 18 16:06:19 2013
@@ -67,6 +67,47 @@ public class IndexedGraphTest  extends M
         return new IndexedMGraph();
     }
     @Test
+    public void bNodeConsitency() {
+        MGraph mGraph = getEmptyMGraph();
+        final BNode bNode = new BNode() {
+
+            @Override
+            public int hashCode() {
+                return -1;
+            }
+
+            @Override
+            public boolean equals(Object o) {
+                return o instanceof BNode;
+            }
+            
+        
+        };
+        
+        final BNode bNodeClone = new BNode() {
+
+            @Override
+            public int hashCode() {
+                return -1;
+            }
+
+            @Override
+            public boolean equals(Object o) {
+                return o instanceof BNode; 
+            }
+            
+        
+        };
+
+        mGraph.add(new TripleImpl(bNode, uriRef1, uriRef2));
+        mGraph.add(new TripleImpl(bNodeClone, uriRef2, uriRef3));
+        NonLiteral bNodeBack = mGraph.filter(null, uriRef1, uriRef2).next().getSubject();
+        Assert.assertEquals("The bnode we get back is not equals to the one we added", bNode, bNodeBack);
+        NonLiteral bNodeBack2 = mGraph.filter(null, uriRef2, uriRef3).next().getSubject();
+        Assert.assertEquals("The returnned bnodes are no longer equals", bNodeBack, bNodeBack2);
+        Assert.assertTrue("Not finding a triple when searching with equal bNode", mGraph.filter(bNodeBack, uriRef2, null).hasNext());
+    }
+    @Test
     public void iteratorRemove() {
         TripleCollection itc = new IndexedTripleCollection();
         itc.add(triple1);