com.google.common.primitives
Class Primitives

java.lang.Object
  extended by com.google.common.primitives.Primitives

public final class Primitives
extends Object

Contains static utility methods pertaining to primitive types and their corresponding wrapper types.

Since:
2009.09.15 tentative
Author:
Kevin Bourrillion

Field Summary
static Map<Class<?>,Class<?>> PRIMITIVE_TO_WRAPPER_TYPE
          A map from primitive types to their corresponding wrapper types.
static Set<Class<?>> PRIMITIVE_TYPES
          All nine primitive types (including void).
static Map<Class<?>,Class<?>> WRAPPER_TO_PRIMITIVE_TYPE
          A map from wrapper types to their corresponding primitive types.
static Set<Class<?>> WRAPPER_TYPES
          All nine wrapper types (including Void).
 
Method Summary
static boolean isWrapperType(Class<?> type)
          Returns true if type is one of the nine primitive-wrapper types, such as Integer.
static
<T> Class<T>
unwrap(Class<T> type)
          Returns the corresponding primitive type of type if it is a wrapper type; otherwise returns type itself.
static
<T> Class<T>
wrap(Class<T> type)
          Returns the corresponding wrapper type of type if it is a primitive type; otherwise returns type itself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRIMITIVE_TO_WRAPPER_TYPE

public static final Map<Class<?>,Class<?>> PRIMITIVE_TO_WRAPPER_TYPE
A map from primitive types to their corresponding wrapper types.


WRAPPER_TO_PRIMITIVE_TYPE

public static final Map<Class<?>,Class<?>> WRAPPER_TO_PRIMITIVE_TYPE
A map from wrapper types to their corresponding primitive types.


PRIMITIVE_TYPES

public static final Set<Class<?>> PRIMITIVE_TYPES
All nine primitive types (including void).


WRAPPER_TYPES

public static final Set<Class<?>> WRAPPER_TYPES
All nine wrapper types (including Void).

Method Detail

isWrapperType

public static boolean isWrapperType(Class<?> type)
Returns true if type is one of the nine primitive-wrapper types, such as Integer.

See Also:
Class.isPrimitive()

wrap

public static <T> Class<T> wrap(Class<T> type)
Returns the corresponding wrapper type of type if it is a primitive type; otherwise returns type itself. Idempotent.
     wrap(int.class) == Integer.class
     wrap(Integer.class) == Integer.class
     wrap(String.class) == String.class
 


unwrap

public static <T> Class<T> unwrap(Class<T> type)
Returns the corresponding primitive type of type if it is a wrapper type; otherwise returns type itself. Idempotent.
     unwrap(Integer.class) == int.class
     unwrap(int.class) == int.class
     unwrap(String.class) == String.class