//Create a class for color control package ColorControl import Timer.SimulatedTimer public class ColorControls { private int deviceNumbers private List colorControls def sendEvent //For one device(We cannot have obj.id)-> We should have obj[0].id private String id = "colorControlID0" private String label = "colorControl0" private String displayName = "colorControl0" private String color = "red" private int hue = 50 private int saturation = 50 ColorControls(Closure sendEvent, int deviceNumbers) { this.sendEvent = sendEvent this.deviceNumbers = deviceNumbers this.colorControls = [] colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation)) } //Methods for closures def count(Closure Input) { colorControls.count(Input) } def size() { colorControls.size() } def each(Closure Input) { colorControls.each(Input) } def find(Closure Input) { colorControls.find(Input) } def collect(Closure Input) { colorControls.collect(Input) } //By model checker def setValue(LinkedHashMap eventDataMap) { if (eventDataMap["name"] == "color") { if (eventDataMap["value"] != colorControls[0].color) { colorControls[0].setValue(eventDataMap["value"], "color") this.color = colorControls[0].color sendEvent(eventDataMap) } } else if (eventDataMap["name"] == "hue") { if (eventDataMap["value"] != colorControls[0].hue) { colorControls[0].setValue(eventDataMap["value"], "hue") this.hue = colorControls[0].hue sendEvent(eventDataMap) } } else { if (eventDataMap["value"] != colorControls[0].saturation) { colorControls[0].setValue(eventDataMap["value"], "saturation") this.saturation = colorControls[0].saturation sendEvent(eventDataMap) } } } //methods def setColor(String color) { colorControls[0].setColor(color) this.color = color } def setHue(int hue) { colorControls[0].setHue(hue) this.hue = hue } def setSaturation(int saturation) { colorControls[0].setSaturation(saturation) this.saturation = saturation } def currentValue(String deviceFeature) { colorControls[0].currentValue(deviceFeature) } def getAt(int ix) { colorControls[ix] } }