a72c38d87e43a65498ec02bcc189f775d9cfcfb9
[iot2.git] / iotjava / iotrmi / Java / IoTRMITypes.java
1 package iotrmi.Java;
2
3 /** Class IoTRMITypes is a class that provides type translations.
4  *  <p>
5  *  It stores C++ and Java types.
6  *
7  * @author      Rahmadi Trimananda <rtrimana @ uci.edu>
8  * @version     1.0
9  * @since       2016-10-03
10  */
11
12 import java.util.HashMap;
13 import java.util.Map;
14
15 public class IoTRMITypes {
16
17         /**
18          * Primitive data types in Java
19          */
20         public final static String[] primitivesJava = new String[] {
21
22                 "byte",                 // 1 byte
23                 "Byte",                 // 1 byte
24                 "short",                // 2 bytes
25                 "Short",                // 2 bytes
26                 "int",                  // 4 bytes
27                 "Integer",              // 4 bytes
28                 "long",                 // 8 bytes
29                 "Long",                 // 8 bytes
30                 "float",                // 4 bytes
31                 "Float",                // 4 bytes
32                 "double",               // 8 bytes
33                 "Double",               // 8 bytes
34                 "boolean",              // 1 bytes
35                 "Boolean",              // 1 bytes
36                 "char",                 // 2 bytes
37                 "Character",    // 2 bytes
38                 "string",               // indefinite
39                 "String",               // indefinite
40                 "void"                  // 0 byte
41         };
42
43
44         /**
45          * Primitive data types in C++ to map the primitives list
46          */
47         public final static String[] primitivesCplus = new String[] {
48
49                 "char",                 // 1 byte
50                 "char",                 // 1 byte
51                 "short",                // 2 bytes
52                 "short",                // 2 bytes
53                 "int",                  // 4 bytes
54                 "int",                  // 4 bytes
55                 "long",                 // 4 bytes
56                 "long",                 // 4 bytes
57                 "float",                // 4 bytes
58                 "float",                // 4 bytes
59                 "double",               // 8 bytes
60                 "double",               // 8 bytes
61                 "bool",                 // 1 byte
62                 "bool",                 // 1 byte
63                 "char",                 // 1 byte
64                 "char",                 // 1 byte
65                 "string",               // indefinite
66                 "string",               // indefinite
67                 "void"                  // 0 byte
68         };
69
70
71         /**
72          * Primitive sizes in Java - Long is 8 bytes and char is 2 bytes
73          */
74         public final static Integer[] primitivesJavaSizes = new Integer[] {
75
76                 1, 1, 2, 2, 4, 4, 8, 8, 4, 4, 8, 8, 1, 1, 2, 2, -1, -1, 0
77         };
78
79
80         /**
81          * Primitive sizes in Cplus - Long is 4 bytes and char is 1 byte
82          */
83         public final static Integer[] primitivesCplusSizes = new Integer[] {
84
85                 1, 1, 2, 2, 4, 4, 4, 4, 4, 4, 8, 8, 1, 1, 1, 1, -1, -1, 0
86         };
87
88
89         /**
90          * Non-primitive Java data types
91          */
92         public final static String[] nonPrimitivesJava = new String[] {
93
94                 "Set",
95                 "HashSet",
96                 "Map",
97                 "HashMap",
98                 "List",
99                 "ArrayList"
100         };
101
102
103         /**
104          * Non-primitive C++ data types
105          */
106         public final static String[] nonPrimitivesCplus = new String[] {
107
108                 "set",
109                 "unordered_set",
110                 "map",
111                 "unordered_map",
112                 "list",
113                 "list"
114         };
115
116
117         /**================
118          * Helper functions
119          **================
120          */
121         // Inserting array members into a Map object
122         // that maps arrKey to arrVal objects
123         public static void arraysToMap(Map<String,String> map, String[] arrKey, String[] arrVal) {
124
125                 for(int i = 0; i < arrKey.length; i++) {
126
127                         map.put(arrKey[i], arrVal[i]);
128                 }
129         }
130
131         // Inserting array members into a Map object
132         // that maps arrKey to arrVal objects
133         public static void arraysToMap(Map<String,Integer> map, String[] arrKey, Integer[] arrVal) {
134
135                 for(int i = 0; i < arrKey.length; i++) {
136
137                         map.put(arrKey[i], arrVal[i]);
138                 }
139         }
140
141         // Inserting array members into a Map object
142         // that maps arrKey to arrVal objects
143         public static void arraysToMap(Map<Object,Object> map, Object[] arrKey, Object[] arrVal) {
144
145                 for(int i = 0; i < arrKey.length; i++) {
146
147                         map.put(arrKey[i], arrVal[i]);
148                 }
149         }
150 }