X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop%2Fsrc%2Forg%2Fsimantics%2Finterop%2Ftest%2FGraphComparator.java;fp=org.simantics.interop%2Fsrc%2Forg%2Fsimantics%2Finterop%2Ftest%2FGraphComparator.java;h=7ea8f4db055c02fa00d8c685c47e9621113e2294;hb=88fcf43b9eb2e217b50bf67cee58edaef4637a59;hp=d8750b2c5f2c5a4ed9b8a833e9b1cc03fcfc4151;hpb=b2bf3445afe9519017f07e41da3c6bc2bccedc6f;p=simantics%2Finterop.git diff --git a/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java b/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java index d8750b2..7ea8f4d 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java @@ -95,6 +95,8 @@ public class GraphComparator { private ReadGraph g; private Layer0 b; + private boolean mapLiterals = true; + public GraphComparator(Resource r1, Resource r2) { this.r1 = r1; this.r2 = r2; @@ -204,7 +206,15 @@ public class GraphComparator { this.maxIter = maxIter; } - public void clear() { + public boolean isMapLiterals() { + return mapLiterals; + } + + public void setMapLiterals(boolean mapLiterals) { + this.mapLiterals = mapLiterals; + } + + private void clear() { changes1.clear(); changes1Set.clear(); changes2.clear(); @@ -216,6 +226,28 @@ public class GraphComparator { processedResources.clear(); } + public void dispose() { + changes1 = null; + changes1Set = null; + changes2 = null; + changes2Set = null; + comparableResources = null; + comparableStatements = null; + comparator = null; + modifications = null; + modificationsSet = null; + processedResources = null; + nonMatchedLeft = null; + nonMatchedRight = null; + nonTested = null; + nonTraversed = null; + ss1 = null; + ss2 = null; + strong = null; + tested = null; + traversed = null; + } + public void test(ReadGraph g) throws DatabaseException { test(g,null); } @@ -683,6 +715,7 @@ public class GraphComparator { subjectRight.add(s.getSubject(),s); objectRight.add(s.getObject(),s); } + Set> processed = new HashSet>(); for (Resource ol : objectLeft.getKeys()) { if (maxIter > 0 && iter > maxIter) break; @@ -698,12 +731,29 @@ public class GraphComparator { } if (sLeft.size() == 1 && sRight.size() == 1) { - List ss1 = new ArrayList(subjectLeft.getValues(sLeft.iterator().next())); - List ss2 = new ArrayList(subjectRight.getValues(sRight.iterator().next())); + Resource sl = sLeft.iterator().next(); + Resource sr = sRight.iterator().next(); + Pair p = new Pair(sl, sr); + if (processed.contains(p)) + continue; + processed.add(p); + List ss1 = new ArrayList(subjectLeft.getValuesSnapshot(sl)); + List ss2 = new ArrayList(subjectRight.getValuesSnapshot(sr)); + for (int i = ss1.size() -1; i >= 0; i--) { + if (!unreliableLeft.contains(ss1.get(i))) + ss1.remove(i); + } + for (int i = ss2.size() -1; i >= 0; i--) { + if (!unreliableRight.contains(ss2.get(i))) + ss2.remove(i); + } + + int ccount = comparableStatements.size(); + int lcount = changes1.size(); + int rcount = changes2.size(); - int count = comparableStatements.size(); compareStatements(ss1, ss2, objectsLeft, objectsRight,unreliableLeft,unreliableRight); - if (comparableStatements.size() > count) { + if (comparableStatements.size() > ccount) { didSomething = true; for (Entry entry : comparableStatements.getEntries()) { unreliableLeft.remove(entry.getKey()); @@ -711,6 +761,20 @@ public class GraphComparator { iter++; } } + if (changes1.size() > lcount) { + didSomething = true; + for (Statement stm : changes1) { + unreliableLeft.remove(stm); + iter++; + } + } + if (changes2.size() > rcount) { + didSomething = true; + for (Statement stm : changes2) { + unreliableRight.remove(stm); + iter++; + } + } } } return didSomething; @@ -1451,7 +1515,7 @@ public class GraphComparator { if (!eq) { addModification(r1,s1,r2,s2); } - if (!a1 && !a2) + if (mapLiterals && !a1 && !a2) addComparable(s1, s2); } else { // Non literal properties.