Testing callbacks for Java and C++; fixing a few bugs; more bugs to tackle: 1) Need...
[iot2.git] / iotjava / iotrmi / Java / basics / TestClass.java
1 import java.util.Set;
2 import java.util.List;
3 import java.util.ArrayList;
4
5 public class TestClass implements TestClassInterface {
6
7         /**
8          * Class Properties
9          */
10         private int intA;
11         private float floatB;
12         private String stringC;
13         private List<CallBackInterfaceWithCallBack> cblist;
14
15         /**
16          * Constructors
17          */
18         public TestClass() {
19
20                 intA = 1;
21                 floatB = 2;
22                 stringC = "345";
23                 cblist = new ArrayList<CallBackInterfaceWithCallBack>();
24         }
25
26
27         public TestClass(int _int, float _float, String _string) {
28
29                 intA = _int;
30                 floatB = _float;
31                 stringC = _string;
32                 cblist = new ArrayList<CallBackInterfaceWithCallBack>();
33         }
34
35
36         // Callback
37         //public void registerCallback(CallBackInterface _cb) {
38         public void registerCallback(CallBackInterfaceWithCallBack _cb) {
39
40                 cblist.add(_cb);
41                 System.out.println("Registering callback object!");
42         }
43
44
45         public void registerCallbackArray(CallBackInterfaceWithCallBack _cb[]) {
46
47                 for (CallBackInterfaceWithCallBack cb : _cb) {
48                         cblist.add(cb);
49                         System.out.println("Registering callback objects in array!");
50                 }
51         }
52
53
54         public void registerCallbackList(List<CallBackInterfaceWithCallBack> _cb) {
55
56                 for (CallBackInterfaceWithCallBack cb : _cb) {
57                         cblist.add(cb);
58                         System.out.println("Registering callback objects in list!");
59                 }
60         }
61
62
63         public int callBack() {
64
65                 int sum = 0;
66                 for (CallBackInterfaceWithCallBack cb : cblist) {
67                         sum = sum + cb.printInt();
68                 }
69                 return sum;
70         }
71
72
73         // Single variables
74         public byte getByte(byte in) {
75
76                 return in;
77         }
78
79
80         public short getShort(short in) {
81
82                 return in;
83         }
84
85
86         public long getLong(long in) {
87
88                 return in;
89         }
90
91
92         public float getFloat(float in) {
93
94                 return in;
95         }
96
97
98         public double getDouble(double in) {
99
100                 return in;
101         }
102
103
104         public boolean getBoolean(boolean in) {
105
106                 return in;
107         }
108
109
110         public char getChar(char in) {
111
112                 return in;
113         }
114
115
116         // Arrays
117         public byte[] getByteArray(byte[] in) {
118
119                 return in;
120         }
121
122
123         public short[] getShortArray(short[] in) {
124
125                 return in;
126         }
127
128
129         public long[] getLongArray(long[] in) {
130
131                 return in;
132         }
133
134
135         public float[] getFloatArray(float[] in) {
136
137                 return in;
138         }
139
140
141         public double[] getDoubleArray(double[] in) {
142
143                 return in;
144         }
145
146
147         public boolean[] getBooleanArray(boolean[] in) {
148
149                 return in;
150         }
151
152
153         public char[] getCharArray(char[] in) {
154
155                 return in;
156         }
157
158
159         // Lists
160         public List<Byte> getByteList(List<Byte> in) {
161
162                 return in;
163         }
164
165
166         public List<Short> getShortList(List<Short> in) {
167
168                 return in;
169         }
170
171
172         public List<Long> getLongList(List<Long> in) {
173
174                 return in;
175         }
176
177
178         public List<Float> getFloatList(List<Float> in) {
179
180                 return in;
181         }
182
183
184         public List<Double> getDoubleList(List<Double> in) {
185
186                 return in;
187         }
188
189
190         public List<Boolean> getBooleanList(List<Boolean> in) {
191
192                 return in;
193         }
194
195
196         public List<Character> getCharList(List<Character> in) {
197
198                 return in;
199         }
200
201
202         // Other functions
203         public int getA() {
204
205                 return intA;
206         }
207
208
209         public void setA(int _int) {
210
211                 intA = _int;
212         }
213
214
215         public void setB(float _float) {
216
217                 floatB = _float;
218         }
219
220
221         public void setC(String _string) {
222
223                 stringC = _string;
224         }
225
226
227         // Enum
228         public Enum handleEnum(Enum en) {
229
230                 System.out.println("Enum: " + en);
231                                 
232                 return en;
233         }
234
235
236         public Enum[] handleEnumArray(Enum[] en) {
237
238                 for (Enum e : en) {
239                         System.out.println("Enum: " + e);
240                 }
241                 
242                 return en;
243         }
244
245
246         public List<Enum> handleEnumList(List<Enum> en) {
247
248                 for (Enum e : en) {
249                         System.out.println("Enum: " + e);
250                 }
251                 
252                 return en;
253         }
254
255
256         // Struct
257         public Struct handleStruct(Struct str) {
258
259                 System.out.println("Name: " + str.name);
260                 System.out.println("Value: " + str.value);
261                 System.out.println("Year: " + str.year);
262
263
264                 Struct test = new Struct();
265                 test.name = "Anonymous";
266                 test.value = 1.33f;
267                 test.year = 2016;
268
269                 str = test;
270
271                 return str;
272         }
273
274
275         public Struct[] handleStructArray(Struct str[]) {
276
277                 for (Struct st : str) {
278                         System.out.println("Name: " + st.name);
279                         System.out.println("Value: " + st.value);
280                         System.out.println("Year: " + st.year);
281                 }
282
283                 Struct test = new Struct();
284                 test.name = "Anonymous";
285                 test.value = 1.33f;
286                 test.year = 2016;
287
288                 str[0] = test;
289
290                 return str;
291         }
292
293
294         public List<Struct> handleStructList(List<Struct> str) {
295
296                 for (Struct st : str) {
297                         System.out.println("Name: " + st.name);
298                         System.out.println("Value: " + st.value);
299                         System.out.println("Year: " + st.year);
300                 }
301
302                 Struct test = new Struct();
303                 test.name = "Tests";
304                 test.value = 1.34f;
305                 test.year = 2017;
306
307                 str.add(test);
308
309                 return str;
310         }
311
312
313         // Getters
314         public String sumArray(String[] newA) {
315
316                 String sum = "";
317                 for (String i : newA) 
318                         sum = sum + i;
319                 return sum;
320         }
321
322
323         public int setAndGetA(int newA) {
324
325                 intA = newA;
326                 return intA;
327         }
328
329
330         public int setACAndGetA(String newC, int newA) {
331
332                 stringC = newC;
333                 intA = newA;
334                 return intA;
335         }
336 }