From: Marko Luukkainen Date: Fri, 4 Mar 2022 17:29:21 +0000 (+0200) Subject: Allow type comparator to compare types, not just instances. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=d990eb34629f49c2c3fe6ecb9819d5c44ae19303;p=simantics%2Finterop.git Allow type comparator to compare types, not just instances. Comparing inheritance by default was causing "interesting" issues. gitlab #36 Change-Id: I69be20b0086a78090965539d494c82b7c98e406e --- diff --git a/org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java b/org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java index 6a05562..a8cefa3 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java @@ -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 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 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);