X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Frepresentation%2FTransferableGraphUtils.java;h=4646116dc37d784255466ad55f1914e94c545596;hp=82ac178fbdca32113993e7b2201ec2a81377aa71;hb=refs%2Fchanges%2F51%2F351%2F13;hpb=081bf7e08a67c0af23c5846e163be39bb19f12cb diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java b/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java index 82ac178fb..4646116dc 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java @@ -4,6 +4,14 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.adapter.AdaptException; + +import gnu.trove.list.array.TIntArrayList; +import gnu.trove.map.TIntObjectMap; +import gnu.trove.map.hash.TIntObjectHashMap; public class TransferableGraphUtils { @@ -67,36 +75,89 @@ public class TransferableGraphUtils { } + public static Identity getIdentity(TransferableGraph1 tg, int resource) { + for(Identity id : tg.identities) { + if(id.resource == resource) return id; + } + return null; + } + + public static TIntArrayList getStatements(TransferableGraph1 tg, int resource) { + TIntArrayList result = new TIntArrayList(); + for(int i=0;i getChildren(TransferableGraph1 tg, Identity parent) { - ArrayList result = new ArrayList(); - System.err.println("children for " + parent.resource); + TreeMap result = new TreeMap<>(); for(Identity id : tg.identities) { if(id.definition instanceof Internal) { Internal internal = (Internal)id.definition; - System.err.println("internal with parent " + internal.parent); - if(internal.parent == parent.resource) result.add(id); + if(internal.parent == parent.resource) result.put(internal.name, id); + } + } + Identity consistsOf = findExternal(tg, "http://www.simantics.org/Layer0-1.1/ConsistsOf"); + Identity hasName = findExternal(tg, "http://www.simantics.org/Layer0-1.1/HasName"); + for(int i=0;i getNames(TransferableGraph1 tg, Collection ids) { Map result = new HashMap(); @@ -159,11 +220,11 @@ public class TransferableGraphUtils { else return getURI(resourceCount, identities, def.parent) + "/" + def.name; } else if(definition instanceof Root) { Root def = (Root)definition; + if(def.name.isEmpty()) return "http:/"; return def.name; } else if (definition instanceof Internal) { Internal def = (Internal)definition; - System.err.println("External URI error: parent was internal '" + def.name + "'"); - return ""; + return getURI(resourceCount, identities, def.parent) + "/" + def.name; } else { return ""; } @@ -171,5 +232,39 @@ public class TransferableGraphUtils { } return ":"; } - + + public static TIntObjectMap mapIdentities(TransferableGraph1 tg) { + return mapIdentities(tg.identities); + } + + public static TIntObjectMap mapIdentities(Identity[] identities) { + // Integer.MIN_VALUE cannot be the value of Identity.resource + TIntObjectMap map = new TIntObjectHashMap<>(identities.length, 0.5f, Integer.MIN_VALUE); + for (Identity id : identities) + map.put(id.resource, id); + return map; + } + + public static String getURI(int resourceCount, TIntObjectMap identities, int id) { + Identity identity = identities.get(id); + if(identity != null) { + IdentityDefinition definition = identity.definition; + if(definition instanceof External) { + External def = (External)definition; + if(def.parent == -1) return "http:/"; + else return getURI(resourceCount, identities, def.parent) + "/" + def.name; + } else if(definition instanceof Root) { + Root def = (Root)definition; + if(def.name.isEmpty()) return "http:/"; + return def.name; + } else if (definition instanceof Internal) { + Internal def = (Internal)definition; + return getURI(resourceCount, identities, def.parent) + "/" + def.name; + } else { + return ""; + } + } + return ":"; + } + }