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;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
15 public class PartialIC {
17 private static final Logger LOGGER = LoggerFactory.getLogger(PartialIC.class);
18 public static Binding BINDING = Bindings.getBindingUnchecked(PartialIC.class);
20 public RVI[] rvis = {};
21 public Variant[] variants = {};
23 //public TreeMap<RVI, Variant> values = new TreeMap<RVI, Variant>();
25 public void add(RVI rvi, Variant value) {
26 rvis = Arrays.copyOf(rvis, rvis.length + 1);
27 rvis[rvis.length - 1] = rvi;
28 variants = Arrays.copyOf(variants, variants.length + 1);
29 variants[rvis.length - 1] = value;
31 //values.put(rvi, value);
34 public void apply(WriteGraph graph, Variable base) throws DatabaseException {
35 // for(Map.Entry<RVI,Variant> entry : values.entrySet()) {
36 // RVI rvi = entry.getKey();
37 // Variant variant = entry.getValue();
38 // Variable v = rvi.resolvePossible(graph, base);
40 //// LOGGER.warn("apply " + v.getURI(graph) + " => " + variant);
41 // v.setValue(graph, variant.getValue(), variant.getBinding());
43 // LOGGER.warn("failed to resolve " + rvi);
47 if (rvis.length != variants.length) {
48 throw new DatabaseException("PartialIC has broken RVI and Variant data arrays. Tried to apply to " + base.getURI(graph));
51 for (int i = 0; i < rvis.length; i++) {
53 Variant variant = variants[i];
54 Variable v = rvi.resolvePossible(graph, base);
56 // LOGGER.warn("apply " + v.getURI(graph) + " => " + variant);
57 v.setValue(graph, variant.getValue(), variant.getBinding());
59 LOGGER.warn("failed to resolve " + rvi);