1 package org.simantics.db.layer0.genericrelation;
\r
3 import org.simantics.databoard.Bindings;
\r
4 import org.simantics.datatypes.literal.GUID;
\r
5 import org.simantics.db.ReadGraph;
\r
6 import org.simantics.db.Resource;
\r
7 import org.simantics.db.common.request.TypeString;
\r
8 import org.simantics.db.exception.DatabaseException;
\r
9 import org.simantics.layer0.Layer0;
\r
11 class Entry implements Comparable<Entry> {
\r
13 Entry(Resource parent, Resource resource, String name, String types, String id) {
\r
14 this.parent = parent;
\r
15 this.resource = resource;
\r
21 Entry(ReadGraph graph, Layer0 L0, Resource resource) throws DatabaseException {
\r
22 this.parent = graph.getPossibleObject(resource, L0.PartOf);
\r
23 this.resource = resource;
\r
24 this.name = graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING);
\r
25 this.types = graph.syncRequest(new TypeString(L0, graph.getTypes(resource)));
\r
26 this.id = idFromGUID(graph.getPossibleRelatedValue(resource, L0.identifier, GUID.BINDING));
\r
29 private static String idFromGUID(GUID guid) {
\r
30 if(guid == null) return "";
\r
31 return guid.indexString();
\r
34 Entry(ReadGraph graph, Resource resource) throws DatabaseException {
\r
35 this(graph, Layer0.getInstance(graph), resource);
\r
38 final Resource parent;
\r
39 final Resource resource;
\r
44 Resource principalType;
\r
47 public int compareTo(Entry o) {
\r
48 int names = name.compareTo(o.name);
\r
49 if(names != 0) return names;
\r
50 int resources = resource.compareTo(o.resource);
\r
51 if(resources != 0) return resources;
\r
52 return id.compareTo(o.id);
\r
56 public int hashCode() {
\r
57 return resource.hashCode();
\r
61 public boolean equals(Object obj) {
\r
62 Entry other = (Entry)obj;
\r
63 return resource.equals(other.resource);
\r