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