package org.simantics.graph.store;
+import java.util.ArrayList;
+import java.util.regex.Pattern;
+
+import org.simantics.graph.query.Path;
+import org.simantics.graph.query.PathChild;
+import org.simantics.graph.query.PathRoot;
+import org.simantics.graph.representation.External;
+import org.simantics.graph.representation.Identity;
+import org.simantics.graph.representation.Internal;
+import org.simantics.graph.representation.Optional;
+import org.simantics.graph.representation.Root;
+
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.hash.THashMap;
import gnu.trove.map.hash.TIntIntHashMap;
import gnu.trove.set.hash.THashSet;
import gnu.trove.set.hash.TIntHashSet;
-import java.util.ArrayList;
-import java.util.regex.Pattern;
-
-import org.simantics.graph.query.Path;
-import org.simantics.graph.query.PathChild;
-import org.simantics.graph.query.PathRoot;
-import org.simantics.graph.representation.External;
-import org.simantics.graph.representation.Identity;
-import org.simantics.graph.representation.Internal;
-import org.simantics.graph.representation.Root;
-
public class IdentityStore implements IStore {
private static int[] EMPTY_INT_ARRAY = new int[0];
new TIntObjectHashMap<THashMap<String, ConsistsOf>>();
TIntObjectHashMap<ConsistsOf> childMap = new TIntObjectHashMap<ConsistsOf>();
TIntHashSet newResources = new TIntHashSet();
+ TIntHashSet optionalResources = new TIntHashSet();
int resourceCount = 0;
TIntIntHashMap unifications = new TIntIntHashMap();
TIntHashSet collisions = new TIntHashSet();
public boolean markNew(int resource) {
return newResources.add(resource);
}
-
+
+ public boolean markOptional(int resource) {
+ return optionalResources.add(resource);
+ }
+
public int[] getNewResources() {
return newResources.toArray();
}
@Override
public boolean execute(String a, ConsistsOf b) {
- if(newResources.contains(b.child))
- identities.add(new Identity(b.child, new Internal(parent, a)));
+ int child = b.child;
+ if(newResources.contains(child))
+ identities.add(new Identity(child, new Internal(parent, a)));
+ else if(optionalResources.contains(child))
+ identities.add(new Identity(child, new Optional(parent, a)));
else
- identities.add(new Identity(b.child, new External(parent, a)));
+ identities.add(new Identity(child, new External(parent, a)));
collectIdentities(b.child, identities);
return true;
}
return newResources.contains(id);
}
+ public boolean isOptionalResource(int id) {
+ return optionalResources.contains(id);
+ }
+
+ public boolean isRoot(int id) {
+ return invRoots.contains(id);
+ }
+
public Identity[] toArray() {
final ArrayList<Identity> identities = new ArrayList<Identity>();
collectIdentities(identities);
return childMap.containsKey(id);
}
+ public int getParent(int id) {
+ ConsistsOf consistsOf = childMap.get(id);
+ if(consistsOf == null)
+ return -1;
+ return consistsOf.parent;
+ }
+
public void definePath(Path path, int resource) {
if(path instanceof PathChild) {
PathChild child = (PathChild)path;
map.put(name, consistsOf);
childMap.put(child, consistsOf);
}
-
+
+ public void removeOptionalMark(int id) {
+ optionalResources.remove(id);
+ }
+
}