X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=iotjava%2Fiotrmi%2FJava%2Fsample%2FTestClass.java;h=6d547ba518dea23b29193f274826312810057410;hb=0c354a510ae5b360f5f04ff328d3b9a94f471e56;hp=0b9f408e1d9f06e26818fc83022e49ec6f45d46f;hpb=599d490dfb2d36edde42dceda38b725e08e0485f;p=iot2.git diff --git a/iotjava/iotrmi/Java/sample/TestClass.java b/iotjava/iotrmi/Java/sample/TestClass.java index 0b9f408..6d547ba 100644 --- a/iotjava/iotrmi/Java/sample/TestClass.java +++ b/iotjava/iotrmi/Java/sample/TestClass.java @@ -1,8 +1,10 @@ package iotrmi.Java.sample; import java.util.Set; +import java.util.List; +import java.util.ArrayList; -public class TestClass { +public class TestClass implements TestClassInterface { /** * Class Properties @@ -11,6 +13,7 @@ public class TestClass { private float floatB; private String stringC; private CallBackInterface cb; + private List cblist; /** * Constructors @@ -21,6 +24,7 @@ public class TestClass { floatB = 2; stringC = "345"; cb = null; + cblist = new ArrayList(); } @@ -29,6 +33,8 @@ public class TestClass { intA = _int; floatB = _float; stringC = _string; + cb = null; + cblist = new ArrayList(); } @@ -81,19 +87,99 @@ public class TestClass { } + public void registerCallback(CallBackInterface[] _cb) { + + for (CallBackInterface cb : _cb) { + cblist.add(cb); + System.out.println("Registering callback object!"); + } + } + + + //public int callBack() { + // return cb.printInt(); + //} + + public int callBack() { - System.out.println("This callBack function is called inside TestClass!"); - return cb.printInt(); + int sum = 0; + for (CallBackInterface cb : cblist) { + sum = sum + cb.printInt(); + } + + /*final CallBackInterface cb1 = cblist.get(1); + final CallBackInterface cb2 = cblist.get(2); + + Thread thread1 = new Thread() { + public void run() { + try{ + for(int i = 0; i < 10; i++) { + cb1.printInt(); + Thread.sleep(1000); + } + } catch (Exception ex){ + ex.printStackTrace(); + throw new Error("Error running thread!"); + } + } + }; + thread1.start(); + + Thread thread2 = new Thread() { + public void run() { + try{ + for(int i = 0; i < 10; i++) { + cb2.printInt(); + Thread.sleep(1000); + } + } catch (Exception ex){ + ex.printStackTrace(); + throw new Error("Error running thread!"); + } + } + }; + thread2.start(); + + return 1;*/ + return sum; + } + + public StructJ[] handleStruct(StructJ[] data) { + + for (StructJ str : data) { + System.out.println("Name: " + str.name); + System.out.println("Value: " + str.value); + System.out.println("Year: " + str.year); + } + + StructJ test = new StructJ(); + test.name = "Anonymous"; + test.value = 1.33f; + test.year = 2016; + + data[0] = test; + + return data; + } + + + public EnumJ[] handleEnum(EnumJ[] en) { + + for (EnumJ e : en) { + System.out.println("Enum: " + e); + } + + return en; } public static void main(String[] args) { - TestClass tc = new TestClass(); - CallBack cb = new CallBack(3); + //TestClass tc = new TestClass(); + //CallBack cb = new CallBack(3); - tc.registerCallback(cb); - System.out.println("Return value: " + tc.callBack()); + //tc.registerCallback(cb); + //System.out.println("Return value: " + tc.callBack()); } }