]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/PartialIC.java
Merge branch 'master' into private/eclipse-4.7
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / PartialIC.java
1 package org.simantics.modeling;
2
3 import java.util.Arrays;
4
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
13 public class PartialIC {
14
15         public static Binding BINDING = Bindings.getBindingUnchecked(PartialIC.class);
16         
17         public RVI[] rvis = {};
18         public Variant[] variants = {};
19         
20         //public TreeMap<RVI, Variant> values = new TreeMap<RVI, Variant>(); 
21         
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;
27         
28                 //values.put(rvi, value);
29         }
30         
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);
36 //                      if(v != null) {
37 ////                            System.err.println("apply " + v.getURI(graph) + " => " + variant);
38 //                              v.setValue(graph, variant.getValue(), variant.getBinding());
39 //                      } else {
40 //                              System.err.println("failed to resolve " + rvi);
41 //                      }
42 //              }
43             
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));
46             }
47             
48             for (int i = 0; i < rvis.length; i++) {
49                 RVI rvi = rvis[i];
50                 Variant variant = variants[i];
51                 Variable v = rvi.resolvePossible(graph, base);
52                 if (v != null) {
53 //              System.err.println("apply " + v.getURI(graph) + " => " + variant);
54                 v.setValue(graph, variant.getValue(), variant.getBinding());
55             } else {
56                 System.err.println("failed to resolve " + rvi);
57             }
58         }
59             
60         }
61         
62 }