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