org.dellroad.stuff.java
Enum Primitive

java.lang.Object
  extended by java.lang.Enum<Primitive>
      extended by org.dellroad.stuff.java.Primitive
All Implemented Interfaces:
Serializable, Comparable<Primitive>

public enum Primitive
extends Enum<Primitive>

Simple utility enumeration for working Java Class instances representing primitive types.

Instances of this class represent one of the eight Java primitive types.


Enum Constant Summary
BOOLEAN
           
BYTE
           
CHARACTER
           
DOUBLE
           
FLOAT
           
INTEGER
           
LONG
           
SHORT
           
 
Method Summary
static Primitive get(Class<?> c)
          Get the value corresponding to the given Java primitive or primitive wrapper type.
 char getLetter()
          Get the single character descriptor for this primitive type, e.g., "I".
 String getLongName()
          Get the long name for this primitive type, e.g., "Integer".
 String getName()
          Get the short name for this primitive type, e.g., "int".
 Class<?> getType()
          Get the Class object representing this primitive type, e.g., Integer.TYPE.
 Method getUnwrapMethod()
          Get the wrapper class' "unwrap" method for this primitive type, e.g., Integer.intValue().
 Class<?> getWrapperType()
          Get the wrapper Class object for this primitive type, e.g., Integer.class.
 Object parseValue(String string)
          Parse a string value using the type's valueOf method.
static Primitive valueOf(String name)
          Returns the enum constant of this type with the specified name.
static Primitive[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
abstract
<R> R
visit(PrimitiveSwitch<R> pswitch)
           
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

BOOLEAN

public static final Primitive BOOLEAN

BYTE

public static final Primitive BYTE

CHARACTER

public static final Primitive CHARACTER

SHORT

public static final Primitive SHORT

INTEGER

public static final Primitive INTEGER

FLOAT

public static final Primitive FLOAT

LONG

public static final Primitive LONG

DOUBLE

public static final Primitive DOUBLE
Method Detail

values

public static Primitive[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (Primitive c : Primitive.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static Primitive valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

visit

public abstract <R> R visit(PrimitiveSwitch<R> pswitch)

getName

public String getName()
Get the short name for this primitive type, e.g., "int".


getLongName

public String getLongName()
Get the long name for this primitive type, e.g., "Integer".


getLetter

public char getLetter()
Get the single character descriptor for this primitive type, e.g., "I".


getType

public Class<?> getType()
Get the Class object representing this primitive type, e.g., Integer.TYPE.


getWrapperType

public Class<?> getWrapperType()
Get the wrapper Class object for this primitive type, e.g., Integer.class.


getUnwrapMethod

public Method getUnwrapMethod()
Get the wrapper class' "unwrap" method for this primitive type, e.g., Integer.intValue().


parseValue

public Object parseValue(String string)
Parse a string value using the type's valueOf method.

Parameters:
string - string representation of a value
Throws:
IllegalArgumentException - if string cannot be parsed
IllegalArgumentException - if string is null

get

public static Primitive get(Class<?> c)
Get the value corresponding to the given Java primitive or primitive wrapper type.

Returns:
the Primitive corresponding to c, or null if c is not a primitive or primitive wrapper type