X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.structural.synchronization%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2Fprotocol%2FSerializedVariable.java;fp=bundles%2Forg.simantics.structural.synchronization%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fsynchronization%2Fprotocol%2FSerializedVariable.java;h=f1888e1012fac8a314fa0329f59b70e3551a05b3;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/protocol/SerializedVariable.java b/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/protocol/SerializedVariable.java new file mode 100644 index 000000000..f1888e101 --- /dev/null +++ b/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/protocol/SerializedVariable.java @@ -0,0 +1,68 @@ +package org.simantics.structural.synchronization.protocol; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.simantics.databoard.binding.mutable.Variant; + +public class SerializedVariable { + + private Map children; + private Map properties; + final public Variant value; + final public String name; + + public SerializedVariable(String name, Variant value) { + this.name = name; + this.value = value; + } + + @SuppressWarnings("unchecked") + public T getPossiblePropertyValue(String name) { + if(properties == null) return null; + SerializedVariable p = properties.get(name); + if(p == null) return null; + else return (T)p.value.getValue(); + } + + @SuppressWarnings("unchecked") + public T getPropertyValue(String name) { + if(properties == null) throw new AssertionError("Property '" + name + "' does not exist."); + SerializedVariable p = properties.get(name); + if(p == null) throw new AssertionError("Property '" + name + "' does not exist."); + else return (T)p.value.getValue(); + } + + public Collection getProperties(){ + if(properties == null) return Collections.emptyList(); + return properties.values(); + } + + public static String print(SerializedVariable var, int indent) { + StringBuilder b = new StringBuilder(); + b.append(var.name + " " + var.value.getValue()); + if(var.children != null) { + for(Map.Entry child : var.children.entrySet()) { + b.append("\n"); + for(int i=0;i property : var.properties.entrySet()) { + b.append("\n"); + for(int i=0;i(); + properties.put(name, property); + } + +}