From 8f1ee72ae165c01b208423cd2d18a6afc1819a3f Mon Sep 17 00:00:00 2001 From: luukkainen Date: Tue, 27 Sep 2011 12:21:07 +0000 Subject: [PATCH] Fix git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@22435 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../interop/test/GraphComparator.java | 120 ++++++------------ 1 file changed, 42 insertions(+), 78 deletions(-) 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 c84a8f9..e52a3bf 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.simantics.interop.test; -import java.math.MathContext; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -172,8 +171,8 @@ public class GraphComparator { List ss1 = new ArrayList(); List ss2 = new ArrayList(); - Stack unreliableLeft = new Stack(); - Stack unreliableRight = new Stack(); + Set unreliableLeft = new HashSet(); + Set unreliableRight = new HashSet(); while (!objectsLeft.isEmpty()) { Resource r1 = objectsLeft.pop(); @@ -484,7 +483,7 @@ public class GraphComparator { } } - private void compareStatements(List ss1, List ss2, Stack objectsLeft, Stack objectsRight,Stack unreliableLeft, Stack unreliableRight) throws DatabaseException { + private void compareStatements(List ss1, List ss2, Stack objectsLeft, Stack objectsRight, Collection unreliableLeft, Collection unreliableRight) throws DatabaseException { sortStatement(ss1, ss2); int i1 = 0; @@ -536,57 +535,7 @@ public class GraphComparator { } } - private void compareUnreliableStatements(List ss1, List ss2) throws DatabaseException { - sortStatement(ss1, ss2); - - int i1 = 0; - int i2 = 0; - - while (true) { - if (i1 >= ss1.size()) { - if (i2 >= ss2.size()) { - break; - } else { - while (i2 < ss2.size()) { - System.out.println("Compare Statements diff2 " + printStatement(g,ss2.get(i2))); - - addAddition(ss2.get(i2)); - i2++; - } - break; - } - } else if (i2 >= ss2.size()) { - while (i1 < ss1.size()) { - System.out.println("Compare Statements diff1 " + printStatement(g,ss1.get(i1))); - addDeletion(ss1.get(i1)); - i1++; - } - break; - } - int same1 = sameRel(ss1, i1); - int same2 = sameRel(ss2, i2); - int c = rcomp.compare(ss1.get(i1).getPredicate(),ss2.get(i2).getPredicate()); - if (c == 0) { - compareStatements(ss1, i1, same1, ss2, i2, same2,null, null, null, null); - i1+=same1; - i2+=same2; - } else if (c < 0) { - for (int i = 0; i < same1; i++) { - System.out.println("Compare Statements diff1 " + printStatement(g,ss1.get(i+i1))); - addDeletion(ss1.get(i+i1)); - } - i1 += same1; - } else { - for (int i = 0; i < same2; i++) { - System.out.println("Compare Statements diff2 " + printStatement(g,ss2.get(i+i2))); - addAddition(ss2.get(i+i2)); - } - - i2 += same2; - } - - } - } + private int sameRel(List statements, int off) { if (statements.size() <= off) @@ -613,7 +562,7 @@ public class GraphComparator { return comparator.compare(g, o1, o2); } - private void compareStatements(List ss1, int off1, int len1, List ss2, int off2, int len2, Stack objectsLeft, Stack objectsRight, Stack unreliableLeft, Stack unreliableRight) throws DatabaseException { + private void compareStatements(List ss1, int off1, int len1, List ss2, int off2, int len2, Collection objectsLeft, Collection objectsRight, Collection unreliableLeft, Collection unreliableRight) throws DatabaseException { boolean[] used1 = new boolean[len1]; for (int i = 0; i < used1.length; i++) { used1[i] = false; @@ -652,28 +601,7 @@ public class GraphComparator { if (pri == Integer.MAX_VALUE) { } else if (pri == 0) { - Set s1s = new HashSet(); - Set s2s = new HashSet(); - List i1s = priorities.getValues(pri); - for (Integer i1 : i1s) { - - List i2diff = differences.get(i1); - for (int i2 = 0; i2 < i2diff.size(); i2++) { - if (i2diff.get(i2) == pri) { - used1[i1] = true; - used2[i2] = true; - Statement s1 = ss1.get(i1+off1); - Statement s2 = ss2.get(i2+off2); - s1s.add(s1); - s2s.add(s2); - } - } - } - if (unreliableLeft != null) { - unreliableLeft.addAll(s1s); - unreliableRight.addAll(s2s); - } - continue; + } else { List i1s = priorities.getValues(pri); for (Integer i1 : i1s) { @@ -703,6 +631,42 @@ public class GraphComparator { } } } + + for (Integer pri : pris) { + if (pri != 0) + continue; + Set s1s = new HashSet(); + Set s2s = new HashSet(); + Set s1i = new HashSet(); + Set s2i = new HashSet(); + List i1s = priorities.getValues(pri); + for (Integer i1 : i1s) { + if (used1[i1]) + continue; + List i2diff = differences.get(i1); + for (int i2 = 0; i2 < i2diff.size(); i2++) { + if (i2diff.get(i2) == pri) { + if (used2[i2]) + continue; + Statement s1 = ss1.get(i1+off1); + Statement s2 = ss2.get(i2+off2); + s1s.add(s1); + s2s.add(s2); + s1i.add(i1); + s2i.add(i2); + } + } + } + if (unreliableLeft != null) { + unreliableLeft.addAll(s1s); + unreliableRight.addAll(s2s); + } + for (Integer i : s1i) + used1[i] = true; + for (Integer i : s2i) + used2[i] = true; + + } for (int i1 = off1; i1 < off1 + len1; i1++) { if (!used1[i1-off1]) { System.out.println("Compare Object diff1 " + printStatement(g,ss1.get(i1))); -- 2.47.1