1 package org.simantics.graph.compiler.internal.store;
3 import gnu.trove.map.hash.TIntIntHashMap;
4 import gnu.trove.map.hash.TIntObjectHashMap;
5 import gnu.trove.procedure.TIntObjectProcedure;
6 import gnu.trove.set.hash.TIntHashSet;
8 import java.util.ArrayList;
9 import java.util.Collection;
11 import org.simantics.databoard.Bindings;
12 import org.simantics.databoard.binding.Binding;
13 import org.simantics.databoard.binding.mutable.Variant;
14 import org.simantics.graph.compiler.internal.values.TreeValue;
15 import org.simantics.graph.query.IDataTypeQuery;
16 import org.simantics.graph.store.IStore;
17 import org.simantics.graph.store.IndexMappingUtils;
18 import org.simantics.graph.store.ValueStore;
19 import org.simantics.ltk.Problem;
21 public class PreValueStore implements IStore {
23 TIntObjectHashMap<IPreValue> preValues = new TIntObjectHashMap<IPreValue>();
24 TIntHashSet collisions = new TIntHashSet();
27 public void map(TIntIntHashMap map) {
28 preValues = IndexMappingUtils.map(map, preValues, collisions);
31 public void setValue(int id, IPreValue value) {
32 preValues.put(id, value);
35 public void convertPreValues(final ValueStore values, final IDataTypeQuery dtq, final Collection<Problem> problems) {
36 preValues.forEachEntry(new TIntObjectProcedure<IPreValue>() {
38 public boolean execute(int resource, IPreValue preValue) {
40 Binding binding = dtq.getDataType(resource);
42 problems.add(new Problem(
43 preValue.getLocation(),
44 "Literal does not have a data type."
48 Object value = preValue.toValue(binding, problems);
49 values.setValue(resource,
50 new Variant(binding, value)
52 } catch(Exception e) {
61 public void forEachPreValue(TIntObjectProcedure<IPreValue> procedure) {
62 preValues.forEachEntry(procedure);
65 public String getStringValue(int i) {
66 IPreValue value = preValues.get(i);
67 if(value == null || !(value instanceof TreeValue))
69 ArrayList<Problem> problems = new ArrayList<Problem>();
70 String v = (String) ((TreeValue)value).toValue(Bindings.STRING, problems);
71 if(v == null || problems.size()>0)