]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@22965...
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 26 Oct 2011 12:44:20 +0000 (12:44 +0000)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 2 Feb 2017 09:22:17 +0000 (11:22 +0200)
org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java

index ab9c67943d481fce82f8f64a73217790341c7ae8..ab0d437f496cbca99041ef14aeb2c0f6ca5ec169 100644 (file)
@@ -68,7 +68,7 @@ public class GraphComparator {
 \r
        private BijectionMap<Statement, Statement> comparableStatements = new BijectionMap<Statement, Statement>();\r
        private BijectionMap<Resource, Resource> comparableResources = new BijectionMap<Resource, Resource>();\r
-       \r
+       private Set<Resource> processedResources = new HashSet<Resource>();\r
        \r
        private ResourceComparator comparator;\r
        \r
@@ -160,12 +160,6 @@ public class GraphComparator {
                strong.addAll(rels);\r
        }\r
        \r
-       public void clearRels() {\r
-               traversed.clear();\r
-               tested.clear();\r
-               nonTraversed.clear();\r
-               nonTested.clear();\r
-       }\r
        \r
        public void test(ReadGraph g) throws DatabaseException {\r
                this.g = g;\r
@@ -177,9 +171,6 @@ public class GraphComparator {
                objectsLeft.push(r1);\r
                objectsRight.push(r2);\r
                \r
-               \r
-               \r
-               \r
                Set<Statement> unreliableLeft = new HashSet<Statement>();\r
                Set<Statement> unreliableRight = new HashSet<Statement>();\r
                \r
@@ -221,23 +212,17 @@ public class GraphComparator {
                        Resource r1 = objectsLeft.pop();\r
                        Resource r2 = objectsRight.pop();\r
                        \r
-//                     if (r1.getResourceId() == 42543612 ||\r
-//                             r1.getResourceId() == 42729524 ||\r
-//                             r1.getResourceId() == 42729506) {\r
-//                             System.out.println("test " + r1 + " " + r2);\r
-//                     }\r
-                       \r
                        if (r1.equals(r2))\r
                                continue;\r
-               \r
-                       if (comparableResources.contains(r1, r2)) {\r
-                               //System.out.println("already tested " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2));\r
+                       \r
+                       if (processedResources.contains(r1))\r
                                continue;\r
-                       }\r
-                       if (comparableResources.containsLeft(r1) || comparableResources.containsRight(r2)) {\r
+                       processedResources.add(r1);\r
+                       \r
+               \r
+                       if(!comparableResources.contains(r1, r2) && (comparableResources.containsLeft(r1)||comparableResources.containsRight(r2))) {\r
                                throw new DatabaseException("Comparator error: Trying to map " + r1 + " to " + r2 + " while mappings " + r1 + " to " + comparableResources.getRight(r1) + " and " + comparableResources.getLeft(r2) + " to " + r2 + " exist.");\r
                        }\r
-                       comparableResources.map(r1, r2);\r
                        \r
                        //System.out.println("test " + NameUtils.getSafeName(g, r1) + " " + NameUtils.getSafeName(g, r2));\r
                        compareProps(r1, r2);\r
@@ -329,9 +314,6 @@ public class GraphComparator {
                }\r
                \r
                for (Resource ol : objectLeft.getKeys()) {\r
-//                     if (ol.getResourceId() == 42729506) {\r
-//                             System.out.println();\r
-//                     }\r
                        // all statements to the left side object\r
                        List<Statement> left = objectLeft.getValues(ol);\r
                        // all subjects that have statements to the left side object (ol)\r
@@ -462,7 +444,7 @@ public class GraphComparator {
                                List<Statement> right = matchingOR.getValues(or);\r
                                Pair<int[], int[]> indices = matchingStatements.get(or);\r
                                \r
-                               //comparableResources.map(ol, or);\r
+                               comparableResources.map(ol, or);\r
                                objectsLeft.add(ol);\r
                                objectsRight.add(or);\r
                                for (int l = 0; l < left.size(); l++) {\r
@@ -538,13 +520,14 @@ public class GraphComparator {
                                                Resource or = matchingPaths.keySet().iterator().next();\r
                                                objectsLeft.add(ol);\r
                                                objectsRight.add(or);\r
+                                               comparableResources.map(ol, or);\r
                                                Collection<Statement> statementsLeft = objectLeft.getValues(ol);\r
                                                Collection<Statement> statementsRight = objectRight.getValues(or);\r
                                                unreliableLeft.removeAll(statementsLeft);\r
                                                unreliableRight.removeAll(statementsRight);\r
-                                               System.out.println();\r
+                                               System.out.println("Compare not implemented");\r
                                        } else {\r
-                                               System.out.println();\r
+                                               System.out.println("Compare not implemented");\r
                                        }\r
                                }\r
                        }\r
@@ -606,15 +589,8 @@ public class GraphComparator {
        }\r
        \r
        private void addComparable(Statement left, Statement right, boolean process) {\r
-//             if (left.getObject().getResourceId() == 42543612 ||\r
-//                     left.getObject().getResourceId() == 42729524 ||\r
-//                     left.getObject().getResourceId() == 42729506) {\r
-//                             System.out.println("test " + r1 + " " + r2);\r
-//                     }\r
                comparableStatements.map(left, right);\r
-               if (!process) {\r
-                       comparableResources.map(left.getObject(), right.getObject());\r
-               }\r
+               comparableResources.map(left.getObject(), right.getObject());\r
        }\r
        \r
        public List<Statement> filterAsserted(Resource r, Collection<Statement> in) throws ServiceException {\r