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