View Javadoc
1   package org.pojomatic.internal;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import org.objectweb.asm.Opcodes;
7   
8   class Primitives {
9     private final static Map<Class<?>, Class<?>> WRAPPER_CLASSES = new HashMap<>();
10    private final static Map<Class<?>, Integer> OPCODES = new HashMap<>();
11  
12    static {
13      register(void.class, Void.class, Opcodes.NULL);
14      register(boolean.class, Boolean.class, Opcodes.INTEGER);
15      register(byte.class, Byte.class, Opcodes.INTEGER);
16      register(char.class, Character.class, Opcodes.INTEGER);
17      register(short.class, Short.class, Opcodes.INTEGER);
18      register(int.class, Integer.class, Opcodes.INTEGER);
19      register(long.class, Long.class, Opcodes.LONG);
20      register(float.class, Float.class, Opcodes.FLOAT);
21      register(double.class, Double.class, Opcodes.DOUBLE);
22    }
23  
24    static Class<?> getWrapperClass(Class<?> primitiveClass) {
25      return WRAPPER_CLASSES.get(primitiveClass);
26    }
27  
28    static Integer getOpcode(Class<?> primitiveClass) {
29      return OPCODES.get(primitiveClass);
30    }
31  
32    private static <T> void register(Class<T> clazz, Class<? extends T> wrapperClass, Integer opcode) {
33      WRAPPER_CLASSES.put(clazz, wrapperClass);
34      OPCODES.put(clazz, opcode);
35    }
36  }