Author: rwesten
Date: Fri Jun 28 15:13:36 2013
New Revision: 1497805
URL: http://svn.apache.org/r1497805
Log:
fix for STANBOL-1130: The comparator now uses the hashcode of the actual bNode
instance and checks for equality in case the hashcode is the same. In case of
hashcode conflics (same hashcode, but not equals) the System.identityHashcode
is used for sorting. Only if this is also the same, the conflict is resolved by
memorising the sorting in a confictsMap. Before the identityHashcode was used
from the beginning and by that causing the issue reported by this issue.
Modified:
stanbol/trunk/commons/indexedgraph/src/main/java/org/apache/stanbol/commons/indexedgraph/IndexedTripleCollection.java
stanbol/trunk/commons/indexedgraph/src/test/java/org/apache/stanbol/commons/indexedgraph/IndexedGraphTest.java
Modified:
stanbol/trunk/commons/indexedgraph/src/main/java/org/apache/stanbol/commons/indexedgraph/IndexedTripleCollection.java
URL:
http://svn.apache.org/viewvc/stanbol/trunk/commons/indexedgraph/src/main/java/org/apache/stanbol/commons/indexedgraph/IndexedTripleCollection.java?rev=1497805&r1=1497804&r2=1497805&view=diff
==============================================================================
---
stanbol/trunk/commons/indexedgraph/src/main/java/org/apache/stanbol/commons/indexedgraph/IndexedTripleCollection.java
(original)
+++
stanbol/trunk/commons/indexedgraph/src/main/java/org/apache/stanbol/commons/indexedgraph/IndexedTripleCollection.java
Fri Jun 28 15:13:36 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/trunk/commons/indexedgraph/src/test/java/org/apache/stanbol/commons/indexedgraph/IndexedGraphTest.java
URL:
http://svn.apache.org/viewvc/stanbol/trunk/commons/indexedgraph/src/test/java/org/apache/stanbol/commons/indexedgraph/IndexedGraphTest.java?rev=1497805&r1=1497804&r2=1497805&view=diff
==============================================================================
---
stanbol/trunk/commons/indexedgraph/src/test/java/org/apache/stanbol/commons/indexedgraph/IndexedGraphTest.java
(original)
+++
stanbol/trunk/commons/indexedgraph/src/test/java/org/apache/stanbol/commons/indexedgraph/IndexedGraphTest.java
Fri Jun 28 15:13:36 2013
@@ -66,7 +66,6 @@ public class IndexedGraphTest extends M
protected MGraph getEmptyMGraph() {
return new IndexedMGraph();
}
- /* FAILING die to STANBOL-1130
@Test
public void bNodeConsitency() {
MGraph mGraph = getEmptyMGraph();
@@ -99,6 +98,7 @@ public class IndexedGraphTest extends M
};
+
mGraph.add(new TripleImpl(bNode, uriRef1, uriRef2));
mGraph.add(new TripleImpl(bNodeClone, uriRef2, uriRef3));
NonLiteral bNodeBack = mGraph.filter(null, uriRef1,
uriRef2).next().getSubject();
@@ -107,7 +107,6 @@ public class IndexedGraphTest extends M
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();