]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Allow type comparator to compare types, not just instances. 04/4904/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 4 Mar 2022 17:29:21 +0000 (19:29 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 4 Mar 2022 17:29:21 +0000 (19:29 +0200)
Comparing inheritance by default was causing "interesting" issues.

gitlab #36

Change-Id: I69be20b0086a78090965539d494c82b7c98e406e

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

index 6a05562961d230551220f10deb913b97fbd3528e..a8cefa3a5ee4a9175dd0802d07b606602dd85920 100644 (file)
@@ -59,14 +59,7 @@ public class TypeComparator extends ResourceComparator {
                        rs2.clear();
                        return false;
                }
-               if (rs1.size() == 0) {
-                       rs1.addAll(g.getObjects(r1, l0.Inherits));
-                       rs2.addAll(g.getObjects(r2, l0.Inherits));
-               }
-               if (rs1.size() == 0) {
-                       rs1.addAll(g.getObjects(r1, l0.SubrelationOf));
-                       rs2.addAll(g.getObjects(r2, l0.SubrelationOf));
-               }
+               
                Comparator<Resource> rcomp = getComparator().getResourceComparator();
                if (rs1.size() == 0) {
                        return rcomp.compare(r1, r2) == 0;
@@ -99,6 +92,48 @@ public class TypeComparator extends ResourceComparator {
                return true;
        }
        
+       protected boolean compareInheritance(ReadGraph g, Resource r1, Resource r2) throws DatabaseException {
+               Layer0 l0 = Layer0.getInstance(g);
+               
+               rs1.addAll(g.getObjects(r1, l0.Inherits));
+               rs2.addAll(g.getObjects(r2, l0.Inherits));
+               
+               if (rs1.size() != rs2.size()) {
+                       rs1.clear();
+                       rs2.clear();
+                       return false;
+               }
+               if (rs1.size() == 0) {
+                       rs1.addAll(g.getObjects(r1, l0.SubrelationOf));
+                       rs2.addAll(g.getObjects(r2, l0.SubrelationOf));
+               }
+               if (rs1.size() != rs2.size()) {
+                       rs1.clear();
+                       rs2.clear();
+                       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++) {
+                       int c = rcomp.compare(rs1.get(i), rs2.get(i));
+                       if (c != 0) {
+                               rs1.clear();
+                               rs2.clear();
+                               return false;
+                       }
+               }
+               
+               rs1.clear();
+               rs2.clear();
+               
+               return true;
+       }
+       
        
        protected int propsDiffCount(ReadGraph g, Resource r1, Resource r2) throws DatabaseException {
                Layer0 l0 = Layer0.getInstance(g);