X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop%2Fsrc%2Forg%2Fsimantics%2Finterop%2Ftest%2FNameComparator.java;fp=org.simantics.interop%2Fsrc%2Forg%2Fsimantics%2Finterop%2Ftest%2FNameComparator.java;h=125d05912b6d443a7687f8635b9d2023b7759bf0;hb=499167aa0bcc2cab0066b87ef4a690c16ea92754;hp=5bdb3f041f55f954f271059ee93864185b7bfa00;hpb=8f1ee72ae165c01b208423cd2d18a6afc1819a3f;p=simantics%2Finterop.git diff --git a/org.simantics.interop/src/org/simantics/interop/test/NameComparator.java b/org.simantics.interop/src/org/simantics/interop/test/NameComparator.java index 5bdb3f0..125d059 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/NameComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/NameComparator.java @@ -8,7 +8,9 @@ import org.simantics.db.exception.ServiceException; import org.simantics.layer0.Layer0; /** - * * Object comparator that uses type and name of objects to check if objects are comparable. + * Object comparator that uses type and name of objects to check if objects are comparable. + * If objects have no name, compare returns unreliable as result. + * * * Difference value is amount of properties that have different values. * @@ -23,10 +25,13 @@ public class NameComparator extends TypeComparator { if (!compareType(g,o1, o2)) { return Integer.MAX_VALUE; } - if(!compareName(g, o1, o2)) - return Integer.MAX_VALUE; + if (hasName(g, o1, o2)) { + if(!compareName(g, o1, o2)) + return Integer.MAX_VALUE; + return propsDiffCount(g,o1, o2); + } + return 0; - return propsDiffCount(g,o1, o2); } protected boolean compareName(ReadGraph g, Resource o1, Resource o2) throws ManyObjectsForFunctionalRelationException, ServiceException { @@ -40,5 +45,15 @@ public class NameComparator extends TypeComparator { return false; } + + protected boolean hasName(ReadGraph g, Resource o1, Resource o2) throws ManyObjectsForFunctionalRelationException, ServiceException { + Layer0 l0 = Layer0.getInstance(g); + String n1 = g.getPossibleRelatedValue(o1, l0.HasName); + String n2 = g.getPossibleRelatedValue(o2, l0.HasName); + if (n1 != null && n2 != null) + return true; + return false; + + } }