]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Prevent TypeComparator from matching different type resources. 12/4612/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 11 Nov 2020 16:57:02 +0000 (18:57 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 11 Nov 2020 16:57:02 +0000 (18:57 +0200)
gitlab #27

Change-Id: I7b92eb0eaacaa9377b6b67b4848e8f4bfcf62bef

org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java

index 2ea03d38f8d12ce0e4519b8b5a2328e906d084e1..a2a37226cbaf9dd538d7c4fef5873b25dfcdc5f2 100644 (file)
@@ -40,6 +40,16 @@ public class TypeComparator extends ResourceComparator {
                return propsDiffCount(g,o1, o2);
        }
        
+       /**
+        * Compares resources based on L0.InstaceOf relations.
+        * If there are no L0.InstanceOf relations, uses ResourceComparator for comparison.
+        *  
+        * @param g
+        * @param r1
+        * @param r2
+        * @return
+        * @throws DatabaseException
+        */
        protected boolean compareType(ReadGraph g,Resource r1, Resource r2) throws DatabaseException {
                Layer0 l0 = Layer0.getInstance(g);
                rs1.addAll(g.getObjects(r1, l0.InstanceOf));
@@ -50,6 +60,10 @@ public class TypeComparator extends ResourceComparator {
                        return false;
                }
                Comparator<Resource> rcomp = getComparator().getResourceComparator();
+               if (rs1.size() == 0) {
+                       return rcomp.compare(r1, r2) == 0;
+               }
+       
                getComparator().sortResource(rs1, rs2);
 
                for (int i = 0; i < rs1.size(); i++) {
@@ -77,6 +91,7 @@ public class TypeComparator extends ResourceComparator {
                return true;
        }
        
+       
        protected int propsDiffCount(ReadGraph g, Resource r1, Resource r2) throws DatabaseException {
                Layer0 l0 = Layer0.getInstance(g);
                ArrayList<Statement> ss1 = new ArrayList<Statement>();
@@ -128,15 +143,10 @@ public class TypeComparator extends ResourceComparator {
                                        boolean b2 = g.hasValue(s2.getObject());
                                        if (b1 == b2) {
                                                if (b1) {
-//                                                     Object v1 = g.getValue(s1.getObject());
-//                                                     Object v2 = g.getValue(s2.getObject());
-//                                                     boolean eq = GraphComparator.compareValue(v1, v2);
                                                        boolean eq = GraphComparator.compareValue(g, l0 , s1.getObject(), s2.getObject());
-                                                       
                                                        if (!eq) {
                                                                count++;
                                                        }
-                                                       //System.out.println("Prop count values " + v1 + " " + v2);
                                                } else {
                                                        count += propsDiffCount(g,s1.getObject(), s2.getObject());
                                                }