X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iot2.git;a=blobdiff_plain;f=iotjava%2Fiotrmi%2FJava%2FIoTRMIUtil.java;h=a382b0c2329cc0135a55a7f6a2bd11bcbe661672;hp=91496ed6f38eeec902a24a3120de7061618a58f5;hb=ef69794d7b791f13acb42fa1449c24b1a26bf356;hpb=2b62575aedf9d2c0e7d5a056b87bc390330b9a07 diff --git a/iotjava/iotrmi/Java/IoTRMIUtil.java b/iotjava/iotrmi/Java/IoTRMIUtil.java index 91496ed..a382b0c 100644 --- a/iotjava/iotrmi/Java/IoTRMIUtil.java +++ b/iotjava/iotrmi/Java/IoTRMIUtil.java @@ -195,15 +195,15 @@ public class IoTRMIUtil { retObj = getParamObjectArray(type, paramBytes); // Set // e.g. Set - type = Set.class, genTypeVal = String.class - } else if (type == Set.class) { - retObj = getParamSetObject(genTypeVal, paramBytes); + /*} else if (type == Set.class) { + retObj = getParamSetObject(genTypeVal, paramBytes);*/ // List } else if (type == List.class) { retObj = getParamListObject(genTypeVal, paramBytes); // Map // e.g. Map - type = Map.class, genTypeKey = String.class, genTypeVal = Integer.class - } else if (type == Map.class) { - retObj = getParamMapObject(genTypeKey, genTypeVal, paramBytes); + /*} else if (type == Map.class) { + retObj = getParamMapObject(genTypeKey, genTypeVal, paramBytes);*/ } else throw new Error("IoTRMIUtil: Unrecognizable type: " + type.getName()); @@ -268,6 +268,13 @@ public class IoTRMIUtil { } else if ( (type == String[].class) || (type == String.class)) { retObj = (Object) byteArrayToStringArray(paramBytes); + } else if (type.isArray()) { + // This is an array but it's more than 1 dimension, e.g. 2-dimensional, + // 3-dimensional, etc. + // for loop to check inner array perhaps using object + // then call this function recursively + // combine the result altogether + } else throw new Error("IoTRMIUtil: Unrecognizable type: " + type.getName()); @@ -303,14 +310,14 @@ public class IoTRMIUtil { } else if (obj.getClass().isArray()) { retObjBytes = getArrayObjectBytes(obj); // Set and its implementations - } else if (obj instanceof Set) { - retObjBytes = setToByteArray((Set) obj); + /*} else if (obj instanceof Set) { + retObjBytes = setToByteArray((Set) obj);*/ // List and its implementations } else if (obj instanceof List) { retObjBytes = listToByteArray((List) obj); // Map and its implementations - } else if (obj instanceof Map) { - retObjBytes = mapToByteArray((Map) obj); + /*} else if (obj instanceof Map) { + retObjBytes = mapToByteArray((Map) obj);*/ } else throw new Error("IoTRMIUtil: Unrecognizable object: " + obj.getClass()); @@ -366,7 +373,7 @@ public class IoTRMIUtil { // Collection data structures - public static byte[] setToByteArray(Set set) { + /*public static byte[] setToByteArray(Set set) { // Find out the class of the type Iterator it = set.iterator(); @@ -396,7 +403,7 @@ public class IoTRMIUtil { byte[] arrObjBytes = getArrayObjectBytes(arrObj); return arrObjBytes; - } + }*/ public static byte[] listToByteArray(List list) { @@ -433,7 +440,7 @@ public class IoTRMIUtil { // Convert keySet of a Map - public static byte[] mapKeyToByteArray(Map map) { + /*public static byte[] mapKeyToByteArray(Map map) { // Map // Find out the class of the type for K @@ -555,7 +562,7 @@ public class IoTRMIUtil { throw new Error("IoTRMIUtil: Unrecognizable object: " + genericType.getSimpleName()); return retSet; - } + }*/ // Get a List object from bytes @@ -598,7 +605,7 @@ public class IoTRMIUtil { // Get a Key array for Map object from bytes - public static Object getParamMapObject(Class genTypeKey, Class genTypeVal, byte[] paramBytes) { + /*public static Object getParamMapObject(Class genTypeKey, Class genTypeVal, byte[] paramBytes) { // The complete set of bytes always consists of all keys followed by all values - pairs // Calculate number of elements @@ -620,7 +627,7 @@ public class IoTRMIUtil { IoTRMITypes.arraysToMap(retMap, retObjKey, retObjVal); return retMap; - } + }*/ /** @@ -1305,17 +1312,39 @@ public class IoTRMIUtil { //boolean data = false; //char data = 'c'; - float data = 1234.123f; +// float data = 1234.123f; //double data = 12.51231234; //long data = 1234l; //short data = 1234; //int data = 12345678; - byte[] result = floatToByteArray(data); - System.out.println("Result: " + Arrays.toString(result)); - System.out.println("Converted back: " + byteArrayToFloat(result)); +// byte[] result = floatToByteArray(data); +// System.out.println("Result: " + Arrays.toString(result)); +// System.out.println("Converted back: " + byteArrayToFloat(result)); + + //String str = "methodA(int,string,float,double,double)"; + //int hash = str.hashCode(); + //System.out.println("Hash value: " + hash); + + int[][] multi = new int[][] { + { 1, 2, 3 }, + { 6, 5, 4}, + { 11, 17, 13} + }; + + for (int[] inner : multi ) { + System.out.println("New row!"); + for (Object i : inner) { + System.out.println("Element i: " + i); + } + System.out.println("Change row!\n"); + } + + int[] int1 = { 1, 2, 3 }; + int[] int2 = { 6, 5, 4 }; + int[] result = new int[int1.length + int2.length]; + System.arraycopy(int1, 0, result, 0, int1.length); + System.arraycopy(int2, 0, result, int1.length, int2.length); - String str = "methodA(int,string,float,double,double)"; - int hash = str.hashCode(); - System.out.println("Hash value: " + hash); + System.out.println("Combined array: " + Arrays.toString(result)); } }