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=1467404b2808e9910bbf354c0fcbed10420ce180;hb=8eb962de0cace69cc401dd05d980c0a1501ca260;hp=125d05912b6d443a7687f8635b9d2023b7759bf0;hpb=e6b171dde507f78b977b08cb481a24221ef2c56f;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 125d059..1467404 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/NameComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/NameComparator.java @@ -1,59 +1,58 @@ -package org.simantics.interop.test; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; -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. - * If objects have no name, compare returns unreliable as result. - * - * - * Difference value is amount of properties that have different values. - * - * @author Marko Luukkainen - * - */ -public class NameComparator extends TypeComparator { - - @Override - public int compare(ReadGraph g, Resource o1, Resource o2) - throws DatabaseException { - if (!compareType(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; - - } - - protected boolean compareName(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 n1.equals(n2); - if (n1 == null && n2 == null) - return true; - 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; - - } - -} +package org.simantics.interop.test; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; + +/** + * 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. + * + * @author Marko Luukkainen + * + */ +public class NameComparator extends TypeComparator { + + @Override + public int compare(ReadGraph g, Resource o1, Resource o2) + throws DatabaseException { + if (!compareType(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; + + } + + protected boolean compareName(ReadGraph g, Resource o1, Resource o2) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + String n1 = g.getPossibleRelatedValue(o1, l0.HasName, Bindings.STRING); + String n2 = g.getPossibleRelatedValue(o2, l0.HasName, Bindings.STRING); + if (n1 != null && n2 != null) + return n1.equals(n2); + if (n1 == null && n2 == null) + return true; + return false; + + } + + protected boolean hasName(ReadGraph g, Resource o1, Resource o2) throws DatabaseException { + Layer0 l0 = Layer0.getInstance(g); + String n1 = g.getPossibleRelatedValue(o1, l0.HasName, Bindings.STRING); + String n2 = g.getPossibleRelatedValue(o2, l0.HasName, Bindings.STRING); + if (n1 != null && n2 != null) + return true; + return false; + + } + +}