//Create a class for step sensor package StepSensor import Timer.SimulatedTimer //JPF's Verify API import gov.nasa.jpf.vm.Verify public class StepSensors { private int deviceNumbers private List stepSensors def sendEvent //For one device(We cannot have obj.id)-> We should have obj[0].id private String id = "stepSensorID0" private String label = "stepSensor0" private String displayName = "stepSensor0" private int goal = 1000 private int steps = 0 StepSensors(Closure sendEvent, int deviceNumbers) { this.sendEvent = sendEvent this.deviceNumbers = deviceNumbers this.stepSensors = [] /*def initGoal = Verify.getIntFromList(1000, 2000, 3000) this.goal = initGoal def initSteps = Verify.getIntFromList(0, 1, 2) this.steps = initSteps*/ stepSensors.add(new StepSensor(id, label, displayName, this.steps, this.goal)) } //By Model Checker def setValue(LinkedHashMap eventDataMap) { if (eventDataMap["name"] == "steps") { if (eventDataMap["value"].toInteger() != stepSensors[0].steps) { this.steps = eventDataMap["value"].toInteger() stepSensors[0].setValue(eventDataMap["value"], "steps") sendEvent(eventDataMap) } } else if (eventDataMap["name"] == "goal") { if (eventDataMap["value"].toInteger() != stepSensors[0].goal) { this.goal = eventDataMap["value"].toInteger() stepSensors[0].setValue(eventDataMap["value"], "goal") sendEvent(eventDataMap) } } } //Methods for closures def count(Closure Input) { stepSensors.count(Input) } def size() { stepSensors.size() } def each(Closure Input) { stepSensors.each(Input) } def find(Closure Input) { stepSensors.find(Input) } def sort(Closure Input) { stepSensors.sort(Input) } def collect(Closure Input) { stepSensors.collect(Input) } def currentValue(String deviceFeature) { stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device } def latestValue(String deviceFeature) { stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device } def getAt(int ix) { stepSensors[ix] } }