1 package org.simantics.interop.test;
3 import org.simantics.databoard.Bindings;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.layer0.Layer0;
10 * Object comparator that uses type and name of objects to check if objects are comparable.
11 * If objects have no name, compare returns unreliable as result.
14 * Difference value is amount of properties that have different values.
16 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
19 public class NameComparator extends TypeComparator {
22 public int compare(ReadGraph g, Resource o1, Resource o2)
23 throws DatabaseException {
24 if (!compareType(g,o1, o2)) {
27 if (hasName(g, o1, o2)) {
28 if(!compareName(g, o1, o2))
30 return propsDiffCount(g,o1, o2);
36 protected boolean compareName(ReadGraph g, Resource o1, Resource o2) throws DatabaseException {
37 Layer0 l0 = Layer0.getInstance(g);
38 String n1 = g.getPossibleRelatedValue(o1, l0.HasName, Bindings.STRING);
39 String n2 = g.getPossibleRelatedValue(o2, l0.HasName, Bindings.STRING);
40 if (n1 != null && n2 != null)
42 if (n1 == null && n2 == null)
48 protected boolean hasName(ReadGraph g, Resource o1, Resource o2) throws DatabaseException {
49 Layer0 l0 = Layer0.getInstance(g);
50 String n1 = g.getPossibleRelatedValue(o1, l0.HasName, Bindings.STRING);
51 String n2 = g.getPossibleRelatedValue(o2, l0.HasName, Bindings.STRING);
52 if (n1 != null && n2 != null)