Adjusting and cleaning up ZigbeeTest to install Vigilia ZigBee gateway and devices.
[iot2.git] / iotjava / iotrmi / Java / sample / TestClass.java
1 package iotrmi.Java.sample;
2
3 import java.util.Set;
4 import java.util.List;
5 import java.util.ArrayList;
6
7 public class TestClass implements TestClassInterface {
8
9         /**
10          * Class Properties
11          */
12         private int intA;
13         private float floatB;
14         private String stringC;
15         private CallBackInterface cb;
16         private List<CallBackInterface> cblist;
17
18         /**
19          * Constructors
20          */
21         public TestClass() {
22
23                 intA = 1;
24                 floatB = 2;
25                 stringC = "345";
26                 cb = null;
27                 cblist = new ArrayList<CallBackInterface>();
28         }
29
30
31         public TestClass(int _int, float _float, String _string) {
32
33                 intA = _int;
34                 floatB = _float;
35                 stringC = _string;
36                 cb = null;
37                 cblist = new ArrayList<CallBackInterface>();
38         }
39
40
41         public void setA(int _int) {
42
43                 intA = _int;
44         }
45
46
47         public void setB(float _float) {
48
49                 floatB = _float;
50         }
51
52
53         public void setC(String _string) {
54
55                 stringC = _string;
56         }
57
58
59         // Getters
60         public String sumArray(String[] newA) {
61
62                 String sum = "";
63                 for (String i : newA) 
64                         sum = sum + i;
65                 return sum;
66         }
67
68
69         public int setAndGetA(int newA) {
70
71                 intA = newA;
72                 return intA;
73         }
74
75
76         public int setACAndGetA(String newC, int newA) {
77
78                 stringC = newC;
79                 intA = newA;
80                 return intA;
81         }
82
83
84         public void registerCallback(CallBackInterface _cb) {
85
86                 cb = _cb;
87         }
88
89
90         public void registerCallback(CallBackInterface[] _cb) {
91
92                 for (CallBackInterface cb : _cb) {
93                         cblist.add(cb);
94                         System.out.println("Registering callback object!");
95                 }
96         }
97
98
99         //public int callBack() {
100         //      return cb.printInt();
101         //}
102
103
104         public int callBack() {
105
106                 int sum = 0;
107                 for (CallBackInterface cb : cblist) {
108                         sum = sum + cb.printInt();
109                 }
110                 
111                 /*final CallBackInterface cb1 = cblist.get(1);
112                 final CallBackInterface cb2 = cblist.get(2);
113
114                 Thread thread1 = new Thread() {
115                         public void run() {
116                     try{
117                                         for(int i = 0; i < 10; i++) {
118                                                 cb1.printInt();
119                                                 Thread.sleep(1000);
120                                         }
121                                 } catch (Exception ex){
122                                         ex.printStackTrace();
123                                         throw new Error("Error running thread!");
124                     }
125                 }
126             };
127                 thread1.start();
128
129                 Thread thread2 = new Thread() {
130                         public void run() {
131                     try{
132                                         for(int i = 0; i < 10; i++) {
133                                                 cb2.printInt();
134                                                 Thread.sleep(1000);
135                                         }
136                                 } catch (Exception ex){
137                                         ex.printStackTrace();
138                                         throw new Error("Error running thread!");
139                     }
140                 }
141             };
142                 thread2.start();
143
144                 return 1;*/
145                 return sum;
146         }
147
148         public StructJ[] handleStruct(StructJ[] data) {
149
150                 for (StructJ str : data) {
151                         System.out.println("Name: " + str.name);
152                         System.out.println("Value: " + str.value);
153                         System.out.println("Year: " + str.year);
154                 }
155
156                 StructJ test = new StructJ();
157                 test.name = "Anonymous";
158                 test.value = 1.33f;
159                 test.year = 2016;
160
161                 data[0] = test;
162
163                 return data;
164         }
165
166
167         public EnumJ[] handleEnum(EnumJ[] en) {
168
169                 for (EnumJ e : en) {
170                         System.out.println("Enum: " + e);
171                 }
172                 
173                 return en;
174         }
175
176
177         public static void main(String[] args) {
178
179                 //TestClass tc = new TestClass();
180                 //CallBack cb = new CallBack(3);
181
182                 //tc.registerCallback(cb);
183                 //System.out.println("Return value: " + tc.callBack());
184         }
185 }