]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java
Necessary changes for UC change management support
[simantics/interop.git] / org.simantics.interop / src / org / simantics / interop / test / GraphComparator.java
index 61d7128c5de031a9d3aa83f5e0756cb8b0ed2b28..ac39e2f4f8f5d3b92c2176500c8751e31f8775d7 100644 (file)
@@ -52,7 +52,7 @@ import org.simantics.utils.datastructures.Pair;
  */
 public class GraphComparator {
        
-       private static final boolean DEBUG = false;
+       private static final boolean DEBUG = true;
 
        private Resource r1;
        private Resource r2;
@@ -152,10 +152,16 @@ public class GraphComparator {
        }
        
        public void addComparableResources(Resource r1, Resource r2) {
+               if (DEBUG)
+                       System.out.println("Preset " + r1 + " = " + r2);
                comparableResources.map(r1, r2);
        }
        
        public void addComparableResources(BijectionMap<Resource, Resource> matching) {
+               if (DEBUG) {
+                       for (Entry<Resource, Resource> entry : matching.getEntries())
+                               System.out.println("Preset " + entry.getKey() + " = " + entry.getValue());
+               }
                comparableResources.addAll(matching);
        }
        
@@ -269,6 +275,11 @@ public class GraphComparator {
                                                // These cases have longer path than one to identified objects.
                                                processUnreliableDeep(unreliableLeft, unreliableRight, objectsLeft, objectsRight);
                                        }
+                                       if (objectsLeft.isEmpty() && unreliableLeft.size() > 0 && unreliableRight.size() > 0) {
+                                               // comparison is ending, but we have still unprocessed unidentified resources left.
+                                               // These cases have longer path than one to identified objects.
+                                               processUnreliableDeep(unreliableLeft, unreliableRight, objectsLeft, objectsRight);
+                                       }
                                }
                        });
                        
@@ -277,8 +288,6 @@ public class GraphComparator {
                }
                for (Statement s : unreliableLeft) {
                        if (!comparableStatements.containsLeft(s))
-                               if (s.getObject().getResourceId() == 303248)
-                                       System.out.println();
                                addDeletion(s);
                }
                for (Statement s : unreliableRight) {
@@ -299,7 +308,8 @@ public class GraphComparator {
                        
                        if (r1.equals(r2))
                                continue;
-                       
+                       if (r1.getResourceId() == 610446L)
+                               System.out.println();
                        if (processedResources.contains(r1))
                                continue;
                        processedResources.add(r1);
@@ -779,7 +789,9 @@ public class GraphComparator {
                                throw new DatabaseException("Comparator error: Trying to map " + left + " to " + right + " while mappings " + left + " to " + comparableResources.getRight(left) + " and " + comparableResources.getLeft(right) + " to " + right + " exist.");
                        } else {
                                if (DEBUG) System.out.println(left + " = " + right);
-                               comparableResources.map(left, right);   
+                               if (left.getResourceId() == 610381L)
+                                       System.out.println();
+                               comparableResources.map(left, right);
                        }
                }
                
@@ -1171,16 +1183,20 @@ public class GraphComparator {
                                        break;
                                else {
                                        while (i2 < ss2.size()) {
-                                               if (DEBUG) System.out.println("Compare Prop diff2 " + printStatement(g,ss2.get(i2)));
-                                               addAddition(ss2.get(i2));
+                                               Statement s = ss2.get(i2);
+                                               if (DEBUG) System.out.println("Compare Prop diff2 " + printStatement(g,s));
+                                               if (!s.isAsserted(r2))
+                                                       addAddition(s);
                                                i2++;
                                        }
                                        break;
                                }
                        } else if (i2 >= ss2.size()) {
                                while (i1 < ss1.size()) {
-                                       if (DEBUG) System.out.println("Compare Prop diff1 " + printStatement(g,ss1.get(i1)));
-                                       addDeletion(ss1.get(i1));
+                                       Statement s = ss1.get(i1);
+                                       if (DEBUG) System.out.println("Compare Prop diff1 " + printStatement(g,s));
+                                       if (!s.isAsserted(r1))
+                                               addDeletion(s);
                                        i1++;
                                }
                                break;