1
2
3
4
5
6 package mockit.internal.util;
7
8 import edu.umd.cs.findbugs.annotations.NonNull;
9 import edu.umd.cs.findbugs.annotations.Nullable;
10
11 import java.util.HashMap;
12 import java.util.Map;
13
14 public final class AutoBoxing {
15 private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER = new HashMap<>();
16 private static final Map<Class<?>, Class<?>> WRAPPER_TO_PRIMITIVE = new HashMap<>();
17
18 static {
19 WRAPPER_TO_PRIMITIVE.put(Boolean.class, boolean.class);
20 WRAPPER_TO_PRIMITIVE.put(Character.class, char.class);
21 WRAPPER_TO_PRIMITIVE.put(Byte.class, byte.class);
22 WRAPPER_TO_PRIMITIVE.put(Short.class, short.class);
23 WRAPPER_TO_PRIMITIVE.put(Integer.class, int.class);
24 WRAPPER_TO_PRIMITIVE.put(Float.class, float.class);
25 WRAPPER_TO_PRIMITIVE.put(Long.class, long.class);
26 WRAPPER_TO_PRIMITIVE.put(Double.class, double.class);
27
28 PRIMITIVE_TO_WRAPPER.put(boolean.class, Boolean.class);
29 PRIMITIVE_TO_WRAPPER.put(char.class, Character.class);
30 PRIMITIVE_TO_WRAPPER.put(byte.class, Byte.class);
31 PRIMITIVE_TO_WRAPPER.put(short.class, Short.class);
32 PRIMITIVE_TO_WRAPPER.put(int.class, Integer.class);
33 PRIMITIVE_TO_WRAPPER.put(float.class, Float.class);
34 PRIMITIVE_TO_WRAPPER.put(long.class, Long.class);
35 PRIMITIVE_TO_WRAPPER.put(double.class, Double.class);
36 }
37
38 private AutoBoxing() {
39 }
40
41 public static boolean isWrapperOfPrimitiveType(@NonNull Class<?> type) {
42 return WRAPPER_TO_PRIMITIVE.containsKey(type);
43 }
44
45 @Nullable
46 public static Class<?> getPrimitiveType(@NonNull Class<?> wrapperType) {
47 return WRAPPER_TO_PRIMITIVE.get(wrapperType);
48 }
49
50 @Nullable
51 public static Class<?> getWrapperType(@NonNull Class<?> primitiveType) {
52 return PRIMITIVE_TO_WRAPPER.get(primitiveType);
53 }
54 }