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.db.exception.ManyObjectsForFunctionalRelationException;
\r
7 import org.simantics.db.exception.ServiceException;
\r
8 import org.simantics.layer0.Layer0;
\r
11 * * Object comparator that uses type and name of objects to check if objects are comparable.
\r
13 * Difference value is amount of properties that have different values.
\r
15 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
\r
18 public class NameComparator extends TypeComparator {
\r
21 public int compare(ReadGraph g, Resource o1, Resource o2)
\r
22 throws DatabaseException {
\r
23 if (!compareType(g,o1, o2)) {
\r
24 return Integer.MAX_VALUE;
\r
26 if(!compareName(g, o1, o2))
\r
27 return Integer.MAX_VALUE;
\r
29 return propsDiffCount(g,o1, o2);
\r
32 protected boolean compareName(ReadGraph g, Resource o1, Resource o2) throws ManyObjectsForFunctionalRelationException, ServiceException {
\r
33 Layer0 l0 = Layer0.getInstance(g);
\r
34 String n1 = g.getPossibleRelatedValue(o1, l0.HasName);
\r
35 String n2 = g.getPossibleRelatedValue(o2, l0.HasName);
\r
36 if (n1 != null && n2 != null)
\r
37 return n1.equals(n2);
\r
38 if (n1 == null && n2 == null)
\r