1 package org.simantics.interop.test;
\r
3 import org.simantics.db.ReadGraph;
\r
4 import org.simantics.db.Resource;
\r
5 import org.simantics.db.exception.DatabaseException;
\r
6 import org.simantics.layer0.Layer0;
\r
9 * * Object comparator that uses type and name of objects to check if objects are comparable.
\r
11 * Difference value is amount of properties that have different values.
\r
13 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
\r
16 public class NameComparator extends TypeComparator {
\r
19 public int compare(ReadGraph g, Resource o1, Resource o2)
\r
20 throws DatabaseException {
\r
21 if (!compareType(g,o1, o2)) {
\r
22 return Integer.MAX_VALUE;
\r
24 Layer0 l0 = Layer0.getInstance(g);
\r
25 String n1 = g.getPossibleRelatedValue(o1, l0.HasName);
\r
26 String n2 = g.getPossibleRelatedValue(o2, l0.HasName);
\r
27 if (n1 != null && n2 != null) {
\r
29 return Integer.MAX_VALUE;
\r
30 } else if (n1 == null && n2 == null) {
\r
33 return Integer.MAX_VALUE;
\r
35 return propsDiffCount(g,o1, o2);
\r