MCPcopy Create free account
hub / github.com/antlr/codebuff / Primitives

Class Primitives

output/java_guava/1.4.17/Primitives.java:33–150  ·  view source on GitHub ↗

Contains static utility methods pertaining to primitive types and their corresponding wrapper types. @author Kevin Bourrillion @since 1.0

Source from the content-addressed store, hash-verified

31
32
33@GwtIncompatible
34public final class Primitives {
35
36 private Primitives() {}
37
38 /** A map from primitive types to their corresponding wrapper types. */
39
40 private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_TYPE;
41
42 /** A map from wrapper types to their corresponding primitive types. */
43 private static final Map<Class<?>, Class<?>> WRAPPER_TO_PRIMITIVE_TYPE;
44
45 // Sad that we can't use a BiMap. :(
46
47 static {
48 Map<Class<?>, Class<?>> primToWrap = new HashMap<Class<?>, Class<?>>(16);
49 Map<Class<?>, Class<?>> wrapToPrim = new HashMap<Class<?>, Class<?>>(16);
50 add(primToWrap, wrapToPrim, boolean.class, Boolean.class);
51 add(primToWrap, wrapToPrim, byte.class, Byte.class);
52 add(primToWrap, wrapToPrim, char.class, Character.class);
53 add(primToWrap, wrapToPrim, double.class, Double.class);
54 add(primToWrap, wrapToPrim, float.class, Float.class);
55 add(primToWrap, wrapToPrim, int.class, Integer.class);
56 add(primToWrap, wrapToPrim, long.class, Long.class);
57 add(primToWrap, wrapToPrim, short.class, Short.class);
58 add(primToWrap, wrapToPrim, void.class, Void.class);
59 PRIMITIVE_TO_WRAPPER_TYPE = Collections.unmodifiableMap(primToWrap);
60 WRAPPER_TO_PRIMITIVE_TYPE = Collections.unmodifiableMap(wrapToPrim);
61 }
62
63
64 private static void add(
65 Map<Class<?>, Class<?>> forward,
66 Map<Class<?>, Class<?>> backward,
67 Class<?> key,
68 Class<?> value) {
69 forward.put(key, value);
70 backward.put(value, key);
71 }
72
73 /**
74 * Returns an immutable set of all nine primitive types (including {@code
75 * void}). Note that a simpler way to test whether a {@code Class} instance is a member of this
76 * set is to call {@link Class#isPrimitive}.
77 *
78 * @since 3.0
79 */
80
81
82 public static Set<Class<?>> allPrimitiveTypes() {
83 return PRIMITIVE_TO_WRAPPER_TYPE.keySet();
84 }
85
86 /**
87 * Returns an immutable set of all nine primitive-wrapper types (including {@link Void}).
88 *
89 * @since 3.0
90 */

Callers

nothing calls this directly

Calls 2

addMethod · 0.95
unmodifiableMapMethod · 0.45

Tested by

no test coverage detected