*******************************************************************************/\r
package org.simantics.interop.test;\r
\r
-import java.math.MathContext;\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
import java.util.Collection;\r
List<Statement> ss1 = new ArrayList<Statement>();\r
List<Statement> ss2 = new ArrayList<Statement>();\r
\r
- Stack<Statement> unreliableLeft = new Stack<Statement>();\r
- Stack<Statement> unreliableRight = new Stack<Statement>();\r
+ Set<Statement> unreliableLeft = new HashSet<Statement>();\r
+ Set<Statement> unreliableRight = new HashSet<Statement>();\r
\r
while (!objectsLeft.isEmpty()) {\r
Resource r1 = objectsLeft.pop();\r
}\r
}\r
\r
- private void compareStatements(List<Statement> ss1, List<Statement> ss2, Stack<Resource> objectsLeft, Stack<Resource> objectsRight,Stack<Statement> unreliableLeft, Stack<Statement> unreliableRight) throws DatabaseException {\r
+ private void compareStatements(List<Statement> ss1, List<Statement> ss2, Stack<Resource> objectsLeft, Stack<Resource> objectsRight, Collection<Statement> unreliableLeft, Collection<Statement> unreliableRight) throws DatabaseException {\r
sortStatement(ss1, ss2);\r
\r
int i1 = 0;\r
}\r
}\r
\r
- private void compareUnreliableStatements(List<Statement> ss1, List<Statement> ss2) throws DatabaseException {\r
- sortStatement(ss1, ss2);\r
- \r
- int i1 = 0;\r
- int i2 = 0;\r
- \r
- while (true) {\r
- if (i1 >= ss1.size()) {\r
- if (i2 >= ss2.size()) {\r
- break;\r
- } else {\r
- while (i2 < ss2.size()) {\r
- System.out.println("Compare Statements diff2 " + printStatement(g,ss2.get(i2)));\r
- \r
- addAddition(ss2.get(i2));\r
- i2++;\r
- }\r
- break;\r
- }\r
- } else if (i2 >= ss2.size()) {\r
- while (i1 < ss1.size()) {\r
- System.out.println("Compare Statements diff1 " + printStatement(g,ss1.get(i1)));\r
- addDeletion(ss1.get(i1));\r
- i1++;\r
- }\r
- break;\r
- }\r
- int same1 = sameRel(ss1, i1);\r
- int same2 = sameRel(ss2, i2);\r
- int c = rcomp.compare(ss1.get(i1).getPredicate(),ss2.get(i2).getPredicate());\r
- if (c == 0) {\r
- compareStatements(ss1, i1, same1, ss2, i2, same2,null, null, null, null);\r
- i1+=same1;\r
- i2+=same2;\r
- } else if (c < 0) {\r
- for (int i = 0; i < same1; i++) {\r
- System.out.println("Compare Statements diff1 " + printStatement(g,ss1.get(i+i1)));\r
- addDeletion(ss1.get(i+i1));\r
- }\r
- i1 += same1;\r
- } else {\r
- for (int i = 0; i < same2; i++) {\r
- System.out.println("Compare Statements diff2 " + printStatement(g,ss2.get(i+i2)));\r
- addAddition(ss2.get(i+i2));\r
- }\r
- \r
- i2 += same2;\r
- }\r
- \r
- }\r
- }\r
+\r
\r
private int sameRel(List<Statement> statements, int off) {\r
if (statements.size() <= off)\r
return comparator.compare(g, o1, o2);\r
}\r
\r
- private void compareStatements(List<Statement> ss1, int off1, int len1, List<Statement> ss2, int off2, int len2, Stack<Resource> objectsLeft, Stack<Resource> objectsRight, Stack<Statement> unreliableLeft, Stack<Statement> unreliableRight) throws DatabaseException {\r
+ private void compareStatements(List<Statement> ss1, int off1, int len1, List<Statement> ss2, int off2, int len2, Collection<Resource> objectsLeft, Collection<Resource> objectsRight, Collection<Statement> unreliableLeft, Collection<Statement> unreliableRight) throws DatabaseException {\r
boolean[] used1 = new boolean[len1];\r
for (int i = 0; i < used1.length; i++) {\r
used1[i] = false;\r
if (pri == Integer.MAX_VALUE) {\r
\r
} else if (pri == 0) {\r
- Set<Statement> s1s = new HashSet<Statement>();\r
- Set<Statement> s2s = new HashSet<Statement>();\r
- List<Integer> i1s = priorities.getValues(pri);\r
- for (Integer i1 : i1s) {\r
-\r
- List<Integer> i2diff = differences.get(i1);\r
- for (int i2 = 0; i2 < i2diff.size(); i2++) {\r
- if (i2diff.get(i2) == pri) {\r
- used1[i1] = true;\r
- used2[i2] = true;\r
- Statement s1 = ss1.get(i1+off1);\r
- Statement s2 = ss2.get(i2+off2);\r
- s1s.add(s1);\r
- s2s.add(s2);\r
- }\r
- }\r
- }\r
- if (unreliableLeft != null) {\r
- unreliableLeft.addAll(s1s);\r
- unreliableRight.addAll(s2s);\r
- }\r
- continue;\r
+ \r
} else {\r
List<Integer> i1s = priorities.getValues(pri);\r
for (Integer i1 : i1s) {\r
}\r
}\r
}\r
+ \r
+ for (Integer pri : pris) {\r
+ if (pri != 0)\r
+ continue;\r
+ Set<Statement> s1s = new HashSet<Statement>();\r
+ Set<Statement> s2s = new HashSet<Statement>();\r
+ Set<Integer> s1i = new HashSet<Integer>();\r
+ Set<Integer> s2i = new HashSet<Integer>();\r
+ List<Integer> i1s = priorities.getValues(pri);\r
+ for (Integer i1 : i1s) {\r
+ if (used1[i1])\r
+ continue;\r
+ List<Integer> i2diff = differences.get(i1);\r
+ for (int i2 = 0; i2 < i2diff.size(); i2++) {\r
+ if (i2diff.get(i2) == pri) {\r
+ if (used2[i2])\r
+ continue;\r
+ Statement s1 = ss1.get(i1+off1);\r
+ Statement s2 = ss2.get(i2+off2);\r
+ s1s.add(s1);\r
+ s2s.add(s2);\r
+ s1i.add(i1);\r
+ s2i.add(i2);\r
+ }\r
+ }\r
+ }\r
+ if (unreliableLeft != null) {\r
+ unreliableLeft.addAll(s1s);\r
+ unreliableRight.addAll(s2s);\r
+ }\r
+ for (Integer i : s1i)\r
+ used1[i] = true;\r
+ for (Integer i : s2i)\r
+ used2[i] = true;\r
+\r
+ }\r
for (int i1 = off1; i1 < off1 + len1; i1++) {\r
if (!used1[i1-off1]) {\r
System.out.println("Compare Object diff1 " + printStatement(g,ss1.get(i1)));\r