X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop%2Fsrc%2Forg%2Fsimantics%2Finterop%2Ftest%2FGraphComparator.java;h=ba9bdf099397a90a8a2bc423c26d24354a29a2bf;hb=894fd479af4bd23016e38165b8ba3d6235d27125;hp=052a9a9ee19ad7bce23cba188e2bc923fbd76a2d;hpb=8b92927f87a7966d268ab7678d29992485752c21;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 052a9a9..ba9bdf0 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java @@ -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 filterAssertedDuplicates(Resource r, List in) throws DatabaseException { + List out = new ArrayList(); + 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 { @@ -850,8 +871,6 @@ public class GraphComparator { if (!changes1Set.contains(s)) { changes1Set.add(s); changes1.add(s); - if (s.getObject().getResourceId() == 532631L) - System.out.println(); } } @@ -1175,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; @@ -1185,16 +1207,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;