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
- * * Object comparator that uses type and name of objects to check if objects are comparable. \r
+ * Object comparator that uses type and name of objects to check if objects are comparable.\r
+ * If objects have no name, compare returns unreliable as result.\r
+ * \r
* \r
* Difference value is amount of properties that have different values.\r
* \r
if (!compareType(g,o1, o2)) {\r
return Integer.MAX_VALUE;\r
}\r
+ if (hasName(g, o1, o2)) {\r
+ if(!compareName(g, o1, o2))\r
+ return Integer.MAX_VALUE;\r
+ return propsDiffCount(g,o1, o2);\r
+ }\r
+ return 0;\r
+ \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
+ }\r
+ \r
+ protected boolean hasName(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
+ return true;\r
+ return false;\r
\r
- } else {\r
- return Integer.MAX_VALUE;\r
- }\r
- return propsDiffCount(g,o1, o2);\r
}\r
\r
}\r