X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2Fstore%2FPreValueStore.java;fp=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2Fstore%2FPreValueStore.java;h=8691588138e5dce4a258844a42ad03aae70fc937;hp=923fd9698d29003ea89d67a39e78995c4f37f1dd;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/store/PreValueStore.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/store/PreValueStore.java index 923fd9698..869158813 100644 --- a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/store/PreValueStore.java +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/store/PreValueStore.java @@ -1,76 +1,76 @@ -package org.simantics.graph.compiler.internal.store; - -import gnu.trove.map.hash.TIntIntHashMap; -import gnu.trove.map.hash.TIntObjectHashMap; -import gnu.trove.procedure.TIntObjectProcedure; -import gnu.trove.set.hash.TIntHashSet; - -import java.util.ArrayList; -import java.util.Collection; - -import org.simantics.databoard.Bindings; -import org.simantics.databoard.binding.Binding; -import org.simantics.databoard.binding.mutable.Variant; -import org.simantics.graph.compiler.internal.values.TreeValue; -import org.simantics.graph.query.IDataTypeQuery; -import org.simantics.graph.store.IStore; -import org.simantics.graph.store.IndexMappingUtils; -import org.simantics.graph.store.ValueStore; -import org.simantics.ltk.Problem; - -public class PreValueStore implements IStore { - - TIntObjectHashMap preValues = new TIntObjectHashMap(); - TIntHashSet collisions = new TIntHashSet(); - - @Override - public void map(TIntIntHashMap map) { - preValues = IndexMappingUtils.map(map, preValues, collisions); - } - - public void setValue(int id, IPreValue value) { - preValues.put(id, value); - } - - public void convertPreValues(final ValueStore values, final IDataTypeQuery dtq, final Collection problems) { - preValues.forEachEntry(new TIntObjectProcedure() { - @Override - public boolean execute(int resource, IPreValue preValue) { - try { - Binding binding = dtq.getDataType(resource); - if(binding == null) { - problems.add(new Problem( - preValue.getLocation(), - "Literal does not have a data type." - )); - return true; - } - Object value = preValue.toValue(binding, problems); - values.setValue(resource, - new Variant(binding, value) - ); - } catch(Exception e) { - e.printStackTrace(); - } - return true; - } - }); - preValues.clear(); - } - - public void forEachPreValue(TIntObjectProcedure procedure) { - preValues.forEachEntry(procedure); - } - - public String getStringValue(int i) { - IPreValue value = preValues.get(i); - if(value == null || !(value instanceof TreeValue)) - return null; - ArrayList problems = new ArrayList(); - String v = (String) ((TreeValue)value).toValue(Bindings.STRING, problems); - if(v == null || problems.size()>0) - return null; - return v; - } - -} +package org.simantics.graph.compiler.internal.store; + +import gnu.trove.map.hash.TIntIntHashMap; +import gnu.trove.map.hash.TIntObjectHashMap; +import gnu.trove.procedure.TIntObjectProcedure; +import gnu.trove.set.hash.TIntHashSet; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.graph.compiler.internal.values.TreeValue; +import org.simantics.graph.query.IDataTypeQuery; +import org.simantics.graph.store.IStore; +import org.simantics.graph.store.IndexMappingUtils; +import org.simantics.graph.store.ValueStore; +import org.simantics.ltk.Problem; + +public class PreValueStore implements IStore { + + TIntObjectHashMap preValues = new TIntObjectHashMap(); + TIntHashSet collisions = new TIntHashSet(); + + @Override + public void map(TIntIntHashMap map) { + preValues = IndexMappingUtils.map(map, preValues, collisions); + } + + public void setValue(int id, IPreValue value) { + preValues.put(id, value); + } + + public void convertPreValues(final ValueStore values, final IDataTypeQuery dtq, final Collection problems) { + preValues.forEachEntry(new TIntObjectProcedure() { + @Override + public boolean execute(int resource, IPreValue preValue) { + try { + Binding binding = dtq.getDataType(resource); + if(binding == null) { + problems.add(new Problem( + preValue.getLocation(), + "Literal does not have a data type." + )); + return true; + } + Object value = preValue.toValue(binding, problems); + values.setValue(resource, + new Variant(binding, value) + ); + } catch(Exception e) { + e.printStackTrace(); + } + return true; + } + }); + preValues.clear(); + } + + public void forEachPreValue(TIntObjectProcedure procedure) { + preValues.forEachEntry(procedure); + } + + public String getStringValue(int i) { + IPreValue value = preValues.get(i); + if(value == null || !(value instanceof TreeValue)) + return null; + ArrayList problems = new ArrayList(); + String v = (String) ((TreeValue)value).toValue(Bindings.STRING, problems); + if(v == null || problems.size()>0) + return null; + return v; + } + +}