net.sf.beanlib.utils
Class EnumUtils

java.lang.Object
  extended by net.sf.beanlib.utils.EnumUtils

public class EnumUtils
extends Object

Enum Utilities.

Author:
Joe D. Velopar

Nested Class Summary
private static class EnumUtils.LazyExternal
          Contains a lazily initialized internal map used for implementing fromExternal().
private static class EnumUtils.LazyOrdinal
          Contains a lazily initialized internal map used for implementing fromOrdinal().
private static class EnumUtils.LazyToString
          Contains a lazily initialized internal map used for implementing fromString().
 
Constructor Summary
private EnumUtils()
           
 
Method Summary
private static
<T extends Enum<T> & External<E>,E>
Map<E,T>
enumConstantDirectory(Class<T> enumType)
          Returns a map from the externalized object of type E to enum constant for the specified T, which has a type of both Enum and External.
private static
<T extends Enum<T>>
Map<Integer,T>
enumOrdinalConstantDirectory(Class<T> enumType)
          Returns a map from the ordinal() return value to the enum constant for the specified T, which is an Enum.
private static
<T extends Enum<T>>
Map<String,T>
enumStringConstantDirectory(Class<T> enumType)
          Returns a map from the toString() return value to the enum constant for the specified T, which is an Enum.
static
<T extends Enum<T> & External<E>,E>
T
fromExternal(Class<T> enumType, E externalized)
          Returns the enum constant of the specified Enum and External type with the specified externalized object; or null if no such enum constant exists.
static
<T extends Enum<T>>
T
fromOrdinal(Class<T> enumType, int ordinal)
          Returns the enum constant of the specified Enum with the specified ordinal() return value of the enum constant; or null if no such enum constant exists.
static
<T extends Enum<T>>
T
fromString(Class<T> enumType, String s)
          Returns the enum constant of the specified Enum with the specified toString() return value of the enum constant; or null if no such enum constant exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumUtils

private EnumUtils()
Method Detail

fromExternal

public static <T extends Enum<T> & External<E>,E> T fromExternal(Class<T> enumType,
                                                                E externalized)
Returns the enum constant of the specified Enum and External type with the specified externalized object; or null if no such enum constant exists. Note this method may break unless E is immutable.


fromString

public static <T extends Enum<T>> T fromString(Class<T> enumType,
                                               String s)
Returns the enum constant of the specified Enum with the specified toString() return value of the enum constant; or null if no such enum constant exists.


fromOrdinal

public static <T extends Enum<T>> T fromOrdinal(Class<T> enumType,
                                                int ordinal)
Returns the enum constant of the specified Enum with the specified ordinal() return value of the enum constant; or null if no such enum constant exists.


enumConstantDirectory

private static <T extends Enum<T> & External<E>,E> Map<E,T> enumConstantDirectory(Class<T> enumType)
Returns a map from the externalized object of type E to enum constant for the specified T, which has a type of both Enum and External. This private method is used internally to implement
  
     public static <T extends Enum<T> & External<E>> T fromExternal(Class<T>, E)
 
efficiently. Note that the map returned by this method is created lazily on first use. Typically it won't ever get created.


enumStringConstantDirectory

private static <T extends Enum<T>> Map<String,T> enumStringConstantDirectory(Class<T> enumType)
Returns a map from the toString() return value to the enum constant for the specified T, which is an Enum. This private method is used internally to implement
  
     public static <T extends Enum<T>> T fromString(Class<T>, String)
 
efficiently. Note that the map returned by this method is created lazily on first use. Typically it won't ever get created.


enumOrdinalConstantDirectory

private static <T extends Enum<T>> Map<Integer,T> enumOrdinalConstantDirectory(Class<T> enumType)
Returns a map from the ordinal() return value to the enum constant for the specified T, which is an Enum. This private method is used internally to implement
  
     public static <T extends Enum<T>> T fromOrdinal(Class<T>, int)
 
efficiently. Note that the map returned by this method is created lazily on first use. Typically it won't ever get created.