1 package org.simantics.db.layer0.genericrelation;
5 import org.simantics.databoard.Bindings;
6 import org.simantics.datatypes.literal.GUID;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.TypeString;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.layer0.Layer0;
13 class Entry implements Comparable<Entry> {
15 Entry(Resource parent, Resource resource, String name, String types, String id) {
17 this.resource = resource;
23 Entry(ReadGraph graph, Layer0 L0, Resource resource) throws DatabaseException {
24 this.parent = graph.getPossibleObject(resource, L0.PartOf);
25 this.resource = resource;
26 this.name = graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING);
27 Set<Resource> typeSet = graph.getTypes(resource);
28 this.types = graph.syncRequest(new TypeString(L0, typeSet));
29 this.id = IndexQueries.idFromGUID(graph.getPossibleRelatedValue(resource, L0.identifier, GUID.BINDING));
30 this.typeId = IndexQueries.toResourceIdString(typeSet);
33 Entry(ReadGraph graph, Resource resource) throws DatabaseException {
34 this(graph, Layer0.getInstance(graph), resource);
37 final Resource parent;
38 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);