-package org.simantics.graph.compiler.internal.procedures;\r
-\r
-import gnu.trove.list.array.TIntArrayList;\r
-import gnu.trove.map.hash.TIntObjectHashMap;\r
-\r
-import java.util.Collection;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.type.Datatype;\r
-import org.simantics.graph.compiler.internal.store.PreValueStore;\r
-import org.simantics.graph.query.IDataTypeQuery;\r
-import org.simantics.graph.query.IGraph;\r
-import org.simantics.graph.query.Paths;\r
-import org.simantics.graph.store.GraphStore;\r
-import org.simantics.graph.store.StatementStore;\r
-import org.simantics.graph.store.ValueStore;\r
-import org.simantics.ltk.Problem;\r
-\r
-public class ConvertPreValues implements Runnable {\r
-\r
- IGraph cg;\r
- GraphStore store;\r
- Collection<Problem> problems;\r
- \r
- public ConvertPreValues(IGraph cg, GraphStore store,\r
- Collection<Problem> problems) {\r
- this.cg = cg;\r
- this.store = store;\r
- this.problems = problems;\r
- }\r
-\r
- @Override\r
- public void run() {\r
- PreValueStore preValues = store.getStore(PreValueStore.class);\r
- preValues.convertPreValues(store.values, new IDataTypeQuery() { \r
- \r
- Paths paths = cg.getPaths();\r
- StatementStore statements = store.statements;\r
- ValueStore values = store.values;\r
- int HasDatatype = store.identities.createPathToId(paths.HasDatatype);\r
- int InstanceOf = store.identities.createPathToId(paths.InstanceOf);\r
- \r
- @Override\r
- public Binding getDataType(int id) {\r
- TIntArrayList objects = statements.getObjects(id, HasDatatype);\r
- if(objects.isEmpty()) {\r
- objects = statements.getObjects(id, InstanceOf);\r
- for(int i=0;i<objects.size();++i) {\r
- int type = objects.getQuick(i);\r
- Binding binding = getDatatypeForType(type);\r
- if(binding != null)\r
- return binding;\r
- }\r
- return null;\r
- }\r
- else {\r
- Datatype dt = values.getDatatypeValue(objects.getQuick(0));\r
- if(dt == null)\r
- return null;\r
- else\r
- return Bindings.getBinding(dt);\r
- } \r
- }\r
-\r
- TIntObjectHashMap<Binding> typeBindingCache = new TIntObjectHashMap<Binding>();\r
- private Binding getDatatypeForType(int type) {\r
- if(typeBindingCache.containsKey(type))\r
- return typeBindingCache.get(type);\r
- else {\r
- Datatype dt = cg.getAssertedDatatype(store.idToRes(type));\r
- Binding binding = dt == null ? null : Bindings.getBinding(dt);\r
- typeBindingCache.put(type, binding);\r
- return binding;\r
- } \r
- }\r
- }, problems);\r
- } \r
-\r
-}\r
+package org.simantics.graph.compiler.internal.procedures;
+
+import gnu.trove.list.array.TIntArrayList;
+import gnu.trove.map.hash.TIntObjectHashMap;
+
+import java.util.Collection;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.type.Datatype;
+import org.simantics.graph.compiler.internal.store.PreValueStore;
+import org.simantics.graph.query.IDataTypeQuery;
+import org.simantics.graph.query.IGraph;
+import org.simantics.graph.query.Paths;
+import org.simantics.graph.store.GraphStore;
+import org.simantics.graph.store.StatementStore;
+import org.simantics.graph.store.ValueStore;
+import org.simantics.ltk.Problem;
+
+public class ConvertPreValues implements Runnable {
+
+ IGraph cg;
+ GraphStore store;
+ Collection<Problem> problems;
+
+ public ConvertPreValues(IGraph cg, GraphStore store,
+ Collection<Problem> problems) {
+ this.cg = cg;
+ this.store = store;
+ this.problems = problems;
+ }
+
+ @Override
+ public void run() {
+ PreValueStore preValues = store.getStore(PreValueStore.class);
+ preValues.convertPreValues(store.values, new IDataTypeQuery() {
+
+ Paths paths = cg.getPaths();
+ StatementStore statements = store.statements;
+ ValueStore values = store.values;
+ int HasDatatype = store.identities.createPathToId(paths.HasDatatype);
+ int InstanceOf = store.identities.createPathToId(paths.InstanceOf);
+
+ @Override
+ public Binding getDataType(int id) {
+ TIntArrayList objects = statements.getObjects(id, HasDatatype);
+ if(objects.isEmpty()) {
+ objects = statements.getObjects(id, InstanceOf);
+ for(int i=0;i<objects.size();++i) {
+ int type = objects.getQuick(i);
+ Binding binding = getDatatypeForType(type);
+ if(binding != null)
+ return binding;
+ }
+ return null;
+ }
+ else {
+ Datatype dt = values.getDatatypeValue(objects.getQuick(0));
+ if(dt == null)
+ return null;
+ else
+ return Bindings.getBinding(dt);
+ }
+ }
+
+ TIntObjectHashMap<Binding> typeBindingCache = new TIntObjectHashMap<Binding>();
+ private Binding getDatatypeForType(int type) {
+ if(typeBindingCache.containsKey(type))
+ return typeBindingCache.get(type);
+ else {
+ Datatype dt = cg.getAssertedDatatype(store.idToRes(type));
+ Binding binding = dt == null ? null : Bindings.getBinding(dt);
+ typeBindingCache.put(type, binding);
+ return binding;
+ }
+ }
+ }, problems);
+ }
+
+}