Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[smartthings-infrastructure.git] / Button / Buttons.groovy
1 //Create a class for button
2 package Button
3 import Timer.SimulatedTimer
4
5 //JPF's Verify API
6 import gov.nasa.jpf.vm.Verify
7
8 public class Buttons {
9         private int deviceNumbers
10         private List buttons
11         def sendEvent
12
13         //For one device(We cannot have obj.id)-> We should have obj[0].id
14         private String id = "buttonID0"
15         private String label = "button0"
16         private String displayName = "button0"
17         private String button = "pushed"
18         private int numberOfButtons = 4
19         
20                 
21         Buttons(Closure sendEvent, int deviceNumbers) {
22                 this.sendEvent = sendEvent              
23                 this.deviceNumbers = deviceNumbers
24                 this.buttons = []
25
26                 buttons.add(new Button(id, label, displayName, button, numberOfButtons))
27         }
28
29         //By Model Checker
30         def setValue(LinkedHashMap eventDataMap) {
31                 buttons[0].setValue(eventDataMap)
32                 sendEvent(eventDataMap)
33         }
34
35         //Methods for closures
36         def count(Closure Input) {
37                 buttons.count(Input)
38         }
39         def size() {
40                 buttons.size()
41         }
42         def each(Closure Input) {
43                 buttons.each(Input)
44         }
45         def sort(Closure Input) {
46                 buttons.sort(Input)
47         }
48         def find(Closure Input) {
49                 buttons.find(Input)
50         }
51         def collect(Closure Input) {
52                 buttons.collect(Input)
53         }
54
55
56         //methods
57         def eventsSince(Date dateObj) {
58                 return buttons[0].eventsSince()
59         }
60
61
62         def getAt(int ix) {
63                 buttons[ix]
64         }
65 }