//Create a class for acceleration sensor package AccelerationSensor import Timer.SimulatedTimer public class AccelerationSensor { private String id private String label private String displayName private String acceleration private String currentAcceleration private String accelerationLatestValue private List states = [] private List timeOfStates = [] AccelerationSensor(String id, String label, String displayName, String acceleration, String accelerationLatestValue) { this.id = id this.label = label this.displayName = displayName this.acceleration = acceleration this.currentAcceleration = acceleration this.accelerationLatestValue = accelerationLatestValue } def setValue(String value) { println("the acceleration sensor with id:$id is triggered to $value!") this.accelerationLatestValue = value this.acceleration = value this.currentAcceleration = value this.states.add(value) this.timeOfStates.add(System.currentTimeMillis()) } def statesSince(String info, Date dateObj) { def List happenedStates = [] def sinceThen = dateObj.time for (int i = 0;i < timeOfStates.size();i++) { if (timeOfStates[i]>=sinceThen) happenedStates.add(states[i]) } return happenedStates } def currentValue(String deviceFeature) { if (deviceFeature == "acceleration") { return acceleration } } def latestValue(String deviceFeature) { if (deviceFeature == "acceleration") { return accelerationLatestValue } } }