-package org.simantics.document.linking.report.templates;\r
-\r
-import java.util.Comparator;\r
-import java.util.List;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.utils.strings.AlphanumComparator;\r
-\r
-public class PathComparator implements Comparator<List<Resource>>{\r
- \r
- private ReadGraph graph;\r
- \r
- public PathComparator(ReadGraph graph) {\r
- this.graph = graph;\r
- }\r
- \r
- @Override\r
- public int compare(List<Resource> o1, List<Resource> o2) {\r
- int common = Math.min(o1.size(), o2.size());\r
- for (int i = 0; i < common; i++) {\r
- if (o1.get(i).equals(o2.get(i)))\r
- continue;\r
- try {\r
- Resource r1 = o1.get(i);\r
- Resource r2 = o2.get(i);\r
- String l1 = getText(r1);\r
- String l2 = getText(r2);\r
- int c = AlphanumComparator.COMPARATOR.compare(l1, l2);\r
- if (c == 0) {\r
- if (r1.getResourceId() > r2.getResourceId())\r
- return 1;\r
- if (r1.getResourceId() < r2.getResourceId())\r
- return -1;\r
- return 0;\r
- }\r
- return c;\r
- } catch (DatabaseException e) {\r
- return 0;\r
- }\r
- }\r
- return o1.size() - o2.size();\r
- }\r
- \r
- public String getText(Resource r) throws DatabaseException {\r
- String l1 = NameUtils.getSafeLabel(graph, r);\r
- if (l1.length() == 0)\r
- l1 = NameUtils.getSafeName(graph, r);\r
- return l1;\r
- }\r
-\r
-}\r
+package org.simantics.document.linking.report.templates;
+
+import java.util.Comparator;
+import java.util.List;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.utils.strings.AlphanumComparator;
+
+public class PathComparator implements Comparator<List<Resource>>{
+
+ private ReadGraph graph;
+
+ public PathComparator(ReadGraph graph) {
+ this.graph = graph;
+ }
+
+ @Override
+ public int compare(List<Resource> o1, List<Resource> o2) {
+ int common = Math.min(o1.size(), o2.size());
+ for (int i = 0; i < common; i++) {
+ if (o1.get(i).equals(o2.get(i)))
+ continue;
+ try {
+ Resource r1 = o1.get(i);
+ Resource r2 = o2.get(i);
+ String l1 = getText(r1);
+ String l2 = getText(r2);
+ int c = AlphanumComparator.COMPARATOR.compare(l1, l2);
+ if (c == 0) {
+ if (r1.getResourceId() > r2.getResourceId())
+ return 1;
+ if (r1.getResourceId() < r2.getResourceId())
+ return -1;
+ return 0;
+ }
+ return c;
+ } catch (DatabaseException e) {
+ return 0;
+ }
+ }
+ return o1.size() - o2.size();
+ }
+
+ public String getText(Resource r) throws DatabaseException {
+ String l1 = NameUtils.getSafeLabel(graph, r);
+ if (l1.length() == 0)
+ l1 = NameUtils.getSafeName(graph, r);
+ return l1;
+ }
+
+}