]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop/src/org/simantics/interop/test/NameComparator.java
Allow defining matching resources (Comparing models with structural components)
[simantics/interop.git] / org.simantics.interop / src / org / simantics / interop / test / NameComparator.java
index abc2ab2cbd29263538d869b719416c53c189fb0c..5bdb3f041f55f954f271059ee93864185b7bfa00 100644 (file)
@@ -3,6 +3,8 @@ package org.simantics.interop.test;
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
+import org.simantics.db.exception.ServiceException;\r
 import org.simantics.layer0.Layer0;\r
 \r
 /**\r
@@ -21,18 +23,22 @@ public class NameComparator extends TypeComparator {
                if (!compareType(g,o1, o2)) {\r
                        return Integer.MAX_VALUE;\r
                }\r
+               if(!compareName(g, o1, o2))\r
+                       return Integer.MAX_VALUE;\r
+               \r
+               return propsDiffCount(g,o1, o2);\r
+       }\r
+       \r
+       protected boolean compareName(ReadGraph g, Resource o1, Resource o2) throws ManyObjectsForFunctionalRelationException, ServiceException {\r
                Layer0 l0 = Layer0.getInstance(g);\r
                String n1 = g.getPossibleRelatedValue(o1, l0.HasName);\r
                String n2 = g.getPossibleRelatedValue(o2, l0.HasName);\r
-               if (n1 != null && n2 != null) {\r
-                       if (!n1.equals(n2))\r
-                               return Integer.MAX_VALUE;\r
-               } else if (n1 == null && n2 == null) {\r
+               if (n1 != null && n2 != null)\r
+                       return n1.equals(n2);\r
+               if (n1 == null && n2 == null)\r
+                       return true;\r
+               return false;\r
                        \r
-               } else {\r
-                       return Integer.MAX_VALUE;\r
-               }\r
-               return propsDiffCount(g,o1, o2);\r
        }\r
 \r
 }\r