X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fgenericrelation%2FEntry.java;h=50d723ec9b1ae7d77a8c54ce4358cdafd89e8bb6;hb=refs%2Fchanges%2F58%2F3758%2F1;hp=733a805bca00078e72d0d5eb723927bb17a2802e;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/Entry.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/Entry.java index 733a805bc..50d723ec9 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/Entry.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/Entry.java @@ -1,66 +1,66 @@ -package org.simantics.db.layer0.genericrelation; - -import org.simantics.databoard.Bindings; -import org.simantics.datatypes.literal.GUID; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.TypeString; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; - -class Entry implements Comparable { - - Entry(Resource parent, Resource resource, String name, String types, String id) { - this.parent = parent; - this.resource = resource; - this.name = name; - this.types = types; - this.id = id; - } - - Entry(ReadGraph graph, Layer0 L0, Resource resource) throws DatabaseException { - this.parent = graph.getPossibleObject(resource, L0.PartOf); - this.resource = resource; - this.name = graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING); - this.types = graph.syncRequest(new TypeString(L0, graph.getTypes(resource))); - this.id = idFromGUID(graph.getPossibleRelatedValue(resource, L0.identifier, GUID.BINDING)); - } - - private static String idFromGUID(GUID guid) { - if(guid == null) return ""; - return guid.indexString(); - } - - Entry(ReadGraph graph, Resource resource) throws DatabaseException { - this(graph, Layer0.getInstance(graph), resource); - } - - final Resource parent; - final Resource resource; - - String types; - String name; - String id; - Resource principalType; - - @Override - public int compareTo(Entry o) { - int names = name.compareTo(o.name); - if(names != 0) return names; - int resources = resource.compareTo(o.resource); - if(resources != 0) return resources; - return id.compareTo(o.id); - } - - @Override - public int hashCode() { - return resource.hashCode(); - } - - @Override - public boolean equals(Object obj) { - Entry other = (Entry)obj; - return resource.equals(other.resource); - } - +package org.simantics.db.layer0.genericrelation; + +import java.util.Set; + +import org.simantics.databoard.Bindings; +import org.simantics.datatypes.literal.GUID; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.TypeString; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; + +class Entry implements Comparable { + + Entry(Resource parent, Resource resource, String name, String types, String id) { + this.parent = parent; + this.resource = resource; + this.name = name; + this.types = types; + this.id = id; + } + + Entry(ReadGraph graph, Layer0 L0, Resource resource) throws DatabaseException { + this.parent = graph.getPossibleObject(resource, L0.PartOf); + this.resource = resource; + this.name = graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING); + Set typeSet = graph.getTypes(resource); + this.types = graph.syncRequest(new TypeString(L0, typeSet)); + this.id = IndexQueries.idFromGUID(graph.getPossibleRelatedValue(resource, L0.identifier, GUID.BINDING)); + this.typeId = IndexQueries.toResourceIdString(typeSet); + } + + Entry(ReadGraph graph, Resource resource) throws DatabaseException { + this(graph, Layer0.getInstance(graph), resource); + } + + final Resource parent; + final Resource resource; + + String types; + String name; + String id; + String typeId; + Resource principalType; + + @Override + public int compareTo(Entry o) { + int names = name.compareTo(o.name); + if(names != 0) return names; + int resources = resource.compareTo(o.resource); + if(resources != 0) return resources; + return id.compareTo(o.id); + } + + @Override + public int hashCode() { + return resource.hashCode(); + } + + @Override + public boolean equals(Object obj) { + Entry other = (Entry)obj; + return resource.equals(other.resource); + } + } \ No newline at end of file