Testing more complex struct and enum declarations; fixing subtle bugs
[iot2.git] / iotjava / iotrmi / Java / basics / TestClass.java
index 6373238874d12ff8784608bd284c0e812cb2db18..42e53c2cdefdde17047629f3e3eb9a98514f6ca1 100644 (file)
@@ -1,6 +1,7 @@
 import java.util.Set;
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Arrays;
 
 public class TestClass implements TestClassInterface {
 
@@ -10,6 +11,7 @@ public class TestClass implements TestClassInterface {
        private int intA;
        private float floatB;
        private String stringC;
+       private List<CallBackInterfaceWithCallBack> cblist;
 
        /**
         * Constructors
@@ -19,6 +21,7 @@ public class TestClass implements TestClassInterface {
                intA = 1;
                floatB = 2;
                stringC = "345";
+               cblist = new ArrayList<CallBackInterfaceWithCallBack>();
        }
 
 
@@ -27,6 +30,44 @@ public class TestClass implements TestClassInterface {
                intA = _int;
                floatB = _float;
                stringC = _string;
+               cblist = new ArrayList<CallBackInterfaceWithCallBack>();
+       }
+
+
+       // Callback
+       //public void registerCallback(CallBackInterface _cb) {
+       public void registerCallback(CallBackInterfaceWithCallBack _cb) {
+
+               cblist.add(_cb);
+               System.out.println("Registering callback object!");
+       }
+
+
+       public void registerCallbackArray(CallBackInterfaceWithCallBack _cb[]) {
+
+               for (CallBackInterfaceWithCallBack cb : _cb) {
+                       cblist.add(cb);
+                       System.out.println("Registering callback objects in array!");
+               }
+       }
+
+
+       public void registerCallbackList(List<CallBackInterfaceWithCallBack> _cb) {
+
+               for (CallBackInterfaceWithCallBack cb : _cb) {
+                       cblist.add(cb);
+                       System.out.println("Registering callback objects in list!");
+               }
+       }
+
+
+       public int callBack() {
+
+               int sum = 0;
+               for (CallBackInterfaceWithCallBack cb : cblist) {
+                       sum = sum + cb.printInt();
+               }
+               return sum;
        }
 
 
@@ -184,6 +225,149 @@ public class TestClass implements TestClassInterface {
        }
 
 
+       // Enum
+       public Enum handleEnum(Enum en) {
+
+               System.out.println("Enum: " + en);
+                               
+               return en;
+       }
+
+
+       public Enum[] handleEnumArray(Enum[] en) {
+
+               for (Enum e : en) {
+                       System.out.println("Enum: " + e);
+               }
+               
+               return en;
+       }
+
+
+       public List<Enum> handleEnumList(List<Enum> en) {
+
+               for (Enum e : en) {
+                       System.out.println("Enum: " + e);
+               }
+               
+               return en;
+       }
+
+
+       public Enum handleEnumComplex(Enum en, int i, char c) {
+
+               System.out.println("Enum: " + en);
+               System.out.println("Integer: " + i);
+               System.out.println("Char: " + c);
+               
+               return en;
+       }
+
+
+       public Enum[] handleEnumComplex2(Enum[] en, int in, char c) {
+
+               for (Enum e : en) {
+                       System.out.println("Enum: " + e);
+               }
+               System.out.println("Integer: " + in);
+               System.out.println("Char: " + c);
+               
+               return en;
+       }
+
+
+       // Struct
+       public Struct handleStruct(Struct str) {
+
+               System.out.println("Name: " + str.name);
+               System.out.println("Value: " + str.value);
+               System.out.println("Year: " + str.year);
+
+
+               Struct test = new Struct();
+               test.name = "Anonymous";
+               test.value = 1.33f;
+               test.year = 2016;
+
+               str = test;
+
+               return str;
+       }
+
+
+       public Struct[] handleStructArray(Struct str[]) {
+
+               for (Struct st : str) {
+                       System.out.println("Name: " + st.name);
+                       System.out.println("Value: " + st.value);
+                       System.out.println("Year: " + st.year);
+               }
+
+               Struct test = new Struct();
+               test.name = "Anonymous";
+               test.value = 1.33f;
+               test.year = 2016;
+
+               str[0] = test;
+
+               return str;
+       }
+
+
+       public List<Struct> handleStructList(List<Struct> str) {
+
+               for (Struct st : str) {
+                       System.out.println("Name: " + st.name);
+                       System.out.println("Value: " + st.value);
+                       System.out.println("Year: " + st.year);
+               }
+
+               Struct test = new Struct();
+               test.name = "Tests";
+               test.value = 1.34f;
+               test.year = 2017;
+
+               str.add(test);
+
+               return str;
+       }
+
+
+       public Struct handleStructComplex(int in, char c, Struct str) {
+
+               System.out.println("Name: " + str.name);
+               System.out.println("Value: " + str.value);
+               System.out.println("Year: " + str.year);
+
+               System.out.println("Integer: " + in);
+               System.out.println("Char: " + c);
+
+               Struct test = new Struct();
+               test.name = "Anonymous";
+               test.value = 1.33f;
+               test.year = 2016;
+
+               str = test;
+
+               return str;
+       }
+
+
+       public List<Struct> handleStructComplex2(int in, char c, Struct str[]) {
+
+               for (Struct st : str) {
+                       System.out.println("Name: " + st.name);
+                       System.out.println("Value: " + st.value);
+                       System.out.println("Year: " + st.year);
+               }
+
+               System.out.println("Integer: " + in);
+               System.out.println("Char: " + c);
+
+               return new ArrayList<Struct>(Arrays.asList(str));
+       }
+
+
        // Getters
        public String sumArray(String[] newA) {