//Create a class for contact sensor package ContactSensor import Timer.SimulatedTimer public class ContactSensors { private int deviceNumbers private List contacts def sendEvent //For one device(We cannot have obj.id)-> We should have obj[0].id private int id = 10 private String label = "contactSensor" private String displayName = "contactSensor" private String contactState = "closed" private String contactLatestValue = "closed" ContactSensors(Closure sendEvent, int deviceNumbers) { this.sendEvent = sendEvent this.deviceNumbers = deviceNumbers this.contacts = [] for (int i = 0;i < deviceNumbers;i++) { contacts.add(new ContactSensor(i+10, label+i.toString(), displayName+i.toString(), this.contactState, this.contactLatestValue)) } } //Methods for closures def count(Closure Input) { contacts.count(Input) } def size() { contacts.size() } def each(Closure Input) { contacts.each(Input) } //By Model Checker def setValue(LinkedHashMap eventDataMap) { contacts[eventDataMap["deviceId"]].setValue(eventDataMap["value"]) if (deviceNumbers == 1) this.contactLatestValue = contacts[eventDataMap["deviceId"]].contactLatestValue this.contactState = contacts[eventDataMap["deviceId"]].contactState sendEvent(eventDataMap) } def currentValue(String deviceFeature) { if (deviceNumbers == 1) contacts[0].currentValue(deviceFeature)//It is called if we have only one device else contacts*.currentValue(deviceFeature) } def latestValue(String deviceFeature) { if (deviceNumbers == 1) contacts[0].latestValue(deviceFeature)//It is called if we have only one device else contacts*.latestValue(deviceFeature) } def getAt(int ix) { contacts[ix] } }