]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java
Asserted properties caused wrong change reports.
[simantics/interop.git] / org.simantics.interop / src / org / simantics / interop / test / GraphComparator.java
index ac39e2f4f8f5d3b92c2176500c8751e31f8775d7..ba9bdf099397a90a8a2bc423c26d24354a29a2bf 100644 (file)
@@ -52,7 +52,7 @@ import org.simantics.utils.datastructures.Pair;
  */
 public class GraphComparator {
        
-       private static final boolean DEBUG = true;
+       private static final boolean DEBUG = false;
 
        private Resource r1;
        private Resource r2;
@@ -308,8 +308,6 @@ public class GraphComparator {
                        
                        if (r1.equals(r2))
                                continue;
-                       if (r1.getResourceId() == 610446L)
-                               System.out.println();
                        if (processedResources.contains(r1))
                                continue;
                        processedResources.add(r1);
@@ -789,8 +787,6 @@ 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);
-                               if (left.getResourceId() == 610381L)
-                                       System.out.println();
                                comparableResources.map(left, right);
                        }
                }
@@ -807,6 +803,31 @@ public class GraphComparator {
                return out;
        }
        
+       public List<Statement> filterAssertedDuplicates(Resource r, List<Statement> in) throws DatabaseException {
+               List<Statement> out = new ArrayList<Statement>();
+               for (int i = 0; i < in.size(); i++) {
+                       Statement s = in.get(i);
+                       if (!s.isAsserted(r))
+                               out.add(s);
+                       else {
+                               boolean has = false;
+                               if (i > 1 && in.get(i-1).getPredicate().equals(s.getPredicate()))
+                                       has = true;
+                               else if (i < in.size()-1 && in.get(i+1).getPredicate().equals(s.getPredicate()))
+                                       has = true;
+                               if (!has)
+                                       out.add(s);
+                       }
+                       
+               }
+               for (Statement s : in) {
+                       if (!s.isAsserted(r))
+                               out.add(s);
+                       
+               }
+               return out;
+       }
+       
        
 
        private String printStatement(ReadGraph graph, Statement s) throws DatabaseException {
@@ -1173,6 +1194,9 @@ public class GraphComparator {
                ss1 = filterNonTested(ss1);
                ss2 = filterNonTested(ss2);
                sortStatement(ss1, ss2);
+               // getStatements(r1, b.HasProperty) returns both instance and asserted statements for the same property relation. 
+               ss1 = filterAssertedDuplicates(r1, ss1);
+               ss2 = filterAssertedDuplicates(r2, ss2);
                
                int i1 = 0; 
                int i2 = 0;