]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java
Process changes in smaller chunks
[simantics/interop.git] / org.simantics.interop / src / org / simantics / interop / test / GraphComparator.java
index d8750b2c5f2c5a4ed9b8a833e9b1cc03fcfc4151..7ea8f4db055c02fa00d8c685c47e9621113e2294 100644 (file)
@@ -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<Pair<Resource, Resource>> processed = new HashSet<Pair<Resource,Resource>>();
                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<Statement> ss1 = new ArrayList<Statement>(subjectLeft.getValues(sLeft.iterator().next()));
-                               List<Statement> ss2 = new ArrayList<Statement>(subjectRight.getValues(sRight.iterator().next()));
+                               Resource sl = sLeft.iterator().next();
+                               Resource sr = sRight.iterator().next();
+                               Pair<Resource, Resource> p = new Pair<Resource, Resource>(sl, sr);
+                               if (processed.contains(p))
+                                       continue;
+                               processed.add(p);
+                               List<Statement> ss1 = new ArrayList<Statement>(subjectLeft.getValuesSnapshot(sl));
+                               List<Statement> ss2 = new ArrayList<Statement>(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<Statement, Statement> 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.