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); } }