]> gerrit.simantics Code Review - simantics/interop.git/blob - org.simantics.interop/src/org/simantics/interop/test/NameComparator.java
abc2ab2cbd29263538d869b719416c53c189fb0c
[simantics/interop.git] / org.simantics.interop / src / org / simantics / interop / test / NameComparator.java
1 package org.simantics.interop.test;\r
2 \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
7 \r
8 /**\r
9  * * Object comparator that uses type and name of objects to check if objects are comparable. \r
10  * \r
11  * Difference value is amount of properties that have different values.\r
12  * \r
13  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
14  *\r
15  */\r
16 public class NameComparator extends TypeComparator {\r
17         \r
18         @Override\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
23                 }\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
28                         if (!n1.equals(n2))\r
29                                 return Integer.MAX_VALUE;\r
30                 } else if (n1 == null && n2 == null) {\r
31                         \r
32                 } else {\r
33                         return Integer.MAX_VALUE;\r
34                 }\r
35                 return propsDiffCount(g,o1, o2);\r
36         }\r
37 \r
38 }\r