20d1f5af01bd44c3dd2259eff76a0a8e044edd86
[smartthings-infrastructure.git] / TemperatureMeasurement / TemperatureMeasurements.groovy
1 //Create a class for temperature measurement
2 package TemperatureMeasurement
3 import Timer.SimulatedTimer
4
5 //JPF's Verify API
6 import gov.nasa.jpf.vm.Verify
7
8 public class TemperatureMeasurements {
9         private int deviceNumbers
10         private List temperatureMeasurements
11         def sendEvent
12
13         //For one device(We cannot have obj.id)-> We should have obj[0].id
14         private String id = "temperatureMeasurementID0"
15         private String label = "temperatureMeasurement0"
16         private String displayName = "temperatureMeasurement0"
17         private int temperature = 50
18 <<<<<<< HEAD
19         private int currentTemperature = 50
20
21 =======
22 >>>>>>> a02c9807815a35c0f57241ee6510a3d312499049
23         
24         TemperatureMeasurements(Closure sendEvent, int deviceNumbers) {
25                 this.sendEvent = sendEvent              
26                 this.deviceNumbers = deviceNumbers
27                 this.temperatureMeasurements = []
28
29                 //def initTemp = Verify.getIntFromList(30, 50, 70)
30                 //this.temperature = initTemp
31         
32                 temperatureMeasurements.add(new TemperatureMeasurement(id, label, displayName, this.temperature))
33         }
34
35         //By Model Checker
36         def setValue(LinkedHashMap eventDataMap) {
37                 if (eventDataMap["value"].toInteger() != temperatureMeasurements[0].temperature) {
38                         this.temperature = eventDataMap["value"].toInteger()
39                         this.currentTemperature = eventDataMap["value"].toInteger()
40                         temperatureMeasurements[0].setValue(eventDataMap["value"])
41                         sendEvent(eventDataMap)
42                 }
43         }
44
45         //Methods for closures
46         def count(Closure Input) {
47                 temperatureMeasurements.count(Input)
48         }
49         def size() {
50                 temperatureMeasurements.size()
51         }
52         def each(Closure Input) {
53                 temperatureMeasurements.each(Input)
54         }
55         def find(Closure Input) {
56                 temperatureMeasurements.find(Input)
57         }
58         def sort(Closure Input) {
59                 temperatureMeasurements.sort(Input)
60         }
61         def collect(Closure Input) {
62                 temperatureMeasurements.collect(Input)
63         }
64
65         def getAt(int ix) {
66                 temperatureMeasurements[ix]
67         }
68 }