1 package org.simantics.modeling;
3 import java.util.Arrays;
5 import org.simantics.databoard.Bindings;
6 import org.simantics.databoard.binding.Binding;
7 import org.simantics.databoard.binding.mutable.Variant;
8 import org.simantics.db.WriteGraph;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.db.layer0.variable.RVI;
11 import org.simantics.db.layer0.variable.Variable;
13 public class PartialIC {
15 public static Binding BINDING = Bindings.getBindingUnchecked(PartialIC.class);
17 public RVI[] rvis = {};
18 public Variant[] variants = {};
20 //public TreeMap<RVI, Variant> values = new TreeMap<RVI, Variant>();
22 public void add(RVI rvi, Variant value) {
23 rvis = Arrays.copyOf(rvis, rvis.length + 1);
24 rvis[rvis.length - 1] = rvi;
25 variants = Arrays.copyOf(variants, variants.length + 1);
26 variants[rvis.length - 1] = value;
28 //values.put(rvi, value);
31 public void apply(WriteGraph graph, Variable base) throws DatabaseException {
32 // for(Map.Entry<RVI,Variant> entry : values.entrySet()) {
33 // RVI rvi = entry.getKey();
34 // Variant variant = entry.getValue();
35 // Variable v = rvi.resolvePossible(graph, base);
37 //// System.err.println("apply " + v.getURI(graph) + " => " + variant);
38 // v.setValue(graph, variant.getValue(), variant.getBinding());
40 // System.err.println("failed to resolve " + rvi);
44 if (rvis.length != variants.length) {
45 throw new DatabaseException("PartialIC has broken RVI and Variant data arrays. Tried to apply to " + base.getURI(graph));
48 for (int i = 0; i < rvis.length; i++) {
50 Variant variant = variants[i];
51 Variable v = rvi.resolvePossible(graph, base);
53 // System.err.println("apply " + v.getURI(graph) + " => " + variant);
54 v.setValue(graph, variant.getValue(), variant.getBinding());
56 System.err.println("failed to resolve " + rvi);