org.opengts.util
Class EnumTools

java.lang.Object
  extended by org.opengts.util.EnumTools

public class EnumTools
extends java.lang.Object

Contains tools for custom enumerated types.


Nested Class Summary
static interface EnumTools.BitMask
          BitMask interface
static interface EnumTools.DoubleValue
          DoubleValue interface
static interface EnumTools.IntValue
          IntValue interface
static interface EnumTools.IsDefault
          IsDefault interface
static interface EnumTools.LongValue
          LongValue interface
static interface EnumTools.StringLocale
          StringLocale interface
static interface EnumTools.StringValue
          StringValue interface
static class EnumTools.TestEnum
           
 
Constructor Summary
EnumTools()
           
 
Method Summary
static
<T extends java.lang.Enum<T>>
T
getDefault(java.lang.Class<T> enumClass)
          Returns the default enum constant of the specified enum type.
static java.lang.Class<? extends java.lang.Enum> getEnumClass(java.lang.Class enumContainerClass, java.lang.String name)
          Returns the registered Enum class for the specified name
static java.lang.Class<? extends java.lang.Enum> getEnumClass(java.lang.String name)
          Returns the registered Enum class for the specified name
static
<T extends java.lang.Enum<T>>
java.util.Map<java.lang.Integer,java.lang.String>
getIntValueMap(java.lang.Class<T> enumClass)
          Returns a String array of enumerated type 'toString()' values for the specified Enum type class
static
<T extends java.lang.Enum<T>>
java.util.Map<java.lang.Integer,java.lang.String>
getIntValueMap(java.lang.Class<T> enumClass, java.util.Locale loc)
          Returns a localized String array of enumerated type 'toString()' values for the specified Enum type class
static
<T extends java.lang.Enum<T>>
java.util.Map<java.lang.String,java.lang.String>
getValueMap(java.lang.Class<T> enumClass)
          Returns a String array of enumerated type 'toString()' values for the specified Enum type class
static
<T extends java.lang.Enum<T>>
java.util.Map<java.lang.String,java.lang.String>
getValueMap(java.lang.Class<T> enumClass, java.util.Locale loc)
          Returns a localized String array of enumerated type 'toString()' values for the specified Enum type class
static
<T extends java.lang.Enum<T>>
java.util.Map<java.lang.String,java.lang.String>
getValueMap(java.lang.Class<T> enumClass, T[] list, java.util.Locale loc)
          Returns a localized String array of enumerated type 'toString()' values for the specified Enum type class
static
<T extends java.lang.Enum<T>>
long
getValueMask(java.lang.Class<T> enumClass)
          For 'BitMask' enumerated types, this method returns the logical 'OR' or all values.
static
<T extends java.lang.Enum<T>>
java.lang.String[]
getValueNames(java.lang.Class<T> enumClass)
          Returns a String array of enumerated type 'toString()' values for the specified Enum type class
static
<T extends java.lang.Enum<T>>
java.lang.String[]
getValueNames(java.lang.Class<T> enumClass, java.util.Locale loc)
          Returns a localized String array of enumerated type 'toString()' values for the specified Enum type class
static
<T extends java.lang.Enum<T>>
java.lang.String[]
getValueNames(java.lang.Class<T> enumClass, T[] list, java.util.Locale loc)
          Returns a localized String array of enumerated type 'toString()' values for the specified Enum type class
static
<T extends java.lang.Enum<T>>
T
getValueOf(java.lang.Class<T> enumClass, int value)
          Returns the enum constant of the specified enum type with the specified integer value.
static
<T extends java.lang.Enum<T>>
T
getValueOf(java.lang.Class<T> enumClass, int value, T dft)
          Returns the enum constant of the specified enum type with the specified integer value.
static
<T extends java.lang.Enum<T>>
T
getValueOf(java.lang.Class<T> enumClass, int value, T dft, boolean rtnDefault)
          Returns the enum constant of the specified enum type with the specified integer value.
static
<T extends java.lang.Enum<T>>
T
getValueOf(java.lang.Class<T> enumClass, java.lang.String name)
          Returns the enum constant of the specified enum type with the specified name or 'toString()' value.
static
<T extends java.lang.Enum<T>>
T
getValueOf(java.lang.Class<T> enumClass, java.lang.String name, java.util.Locale loc)
          Returns the enum constant of the specified enum type with the specified name or 'toString()' value.
protected static
<T extends java.lang.Enum<T>>
T
getValueOf(java.lang.Class<T> enumClass, java.lang.String name, java.util.Locale loc, T dft, boolean rtnDefault)
          Returns the enum constant of the specified enum type with the specified name or 'toString()' value.
static
<T extends java.lang.Enum<T>>
T
getValueOf(java.lang.Class<T> enumClass, java.lang.String name, T dft)
          Returns the enum constant of the specified enum type with the specified name or 'toString()' value.
static
<T extends java.lang.Enum<T>>
T
getValueOf(java.lang.Class<T> enumClass, T value)
          Returns the enum constant of the specified enum type with the specified integer value.
static
<T extends java.lang.Enum<T>>
T
getValueOf(java.lang.Class<T> enumClass, T value, T dft)
          Returns the specified enum constant or a default if the enum constant is null.
static
<T extends java.lang.Enum<T>>
T
getValueOf(java.lang.Class<T> enumClass, T value, T dft, boolean rtnDefault)
          Returns the specified enum constant or a default if the enum constant is null.
static
<T extends java.lang.Enum<T>>
T[]
getValuesForMask(java.lang.Class<T> enumClass, long mask)
          Returns a list of Enumerated BitMask values for the specified mask
static void main(java.lang.String[] argv)
          Main entry point for testing/debugging
static
<T extends java.lang.Enum>
void
registerEnumClass(java.lang.Class<T> enumClass)
          Registers the specified Enum classes
static
<T extends java.lang.Enum>
void
registerEnumClass(java.lang.String name, java.lang.Class<T> enumClass)
          Registers the specified Enum classes
static void registerPublicEnumClasses(java.lang.Class<?> enumContainerClass)
          Registers all public Enum classes defined within the specified class.
This is used to allow referencing an enumerated type by name (ie.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumTools

public EnumTools()
Method Detail

getValueMap

public static <T extends java.lang.Enum<T>> java.util.Map<java.lang.String,java.lang.String> getValueMap(java.lang.Class<T> enumClass,
                                                                                                         T[] list,
                                                                                                         java.util.Locale loc)
Returns a localized String array of enumerated type 'toString()' values for the specified Enum type class

Parameters:
enumClass - The enumerated type class
list - The array of enumerated types from which the localized Strings will be extracted
loc - The Locale
Returns:
A String array of enumerated type String values

getValueMap

public static <T extends java.lang.Enum<T>> java.util.Map<java.lang.String,java.lang.String> getValueMap(java.lang.Class<T> enumClass,
                                                                                                         java.util.Locale loc)
Returns a localized String array of enumerated type 'toString()' values for the specified Enum type class

Parameters:
enumClass - The enumerated type class
loc - The Locale
Returns:
A String array of enumerated type String values

getValueMap

public static <T extends java.lang.Enum<T>> java.util.Map<java.lang.String,java.lang.String> getValueMap(java.lang.Class<T> enumClass)
Returns a String array of enumerated type 'toString()' values for the specified Enum type class

Parameters:
enumClass - The enumerated type class
Returns:
A String array of enumerated type String values

getIntValueMap

public static <T extends java.lang.Enum<T>> java.util.Map<java.lang.Integer,java.lang.String> getIntValueMap(java.lang.Class<T> enumClass,
                                                                                                             java.util.Locale loc)
Returns a localized String array of enumerated type 'toString()' values for the specified Enum type class

Parameters:
enumClass - The enumerated type class
loc - The Locale
Returns:
A String array of enumerated type String values

getIntValueMap

public static <T extends java.lang.Enum<T>> java.util.Map<java.lang.Integer,java.lang.String> getIntValueMap(java.lang.Class<T> enumClass)
Returns a String array of enumerated type 'toString()' values for the specified Enum type class

Parameters:
enumClass - The enumerated type class
Returns:
A String array of enumerated type String values

getValueNames

public static <T extends java.lang.Enum<T>> java.lang.String[] getValueNames(java.lang.Class<T> enumClass,
                                                                             T[] list,
                                                                             java.util.Locale loc)
Returns a localized String array of enumerated type 'toString()' values for the specified Enum type class

Parameters:
enumClass - The enumerated type class
list - The array of enumerated types from which the localized Strings will be extracted
loc - The Locale
Returns:
A String array of enumerated type String values

getValueNames

public static <T extends java.lang.Enum<T>> java.lang.String[] getValueNames(java.lang.Class<T> enumClass,
                                                                             java.util.Locale loc)
Returns a localized String array of enumerated type 'toString()' values for the specified Enum type class

Parameters:
enumClass - The enumerated type class
loc - The Locale
Returns:
A String array of enumerated type String values

getValueNames

public static <T extends java.lang.Enum<T>> java.lang.String[] getValueNames(java.lang.Class<T> enumClass)
Returns a String array of enumerated type 'toString()' values for the specified Enum type class

Parameters:
enumClass - The enumerated type class
Returns:
A String array of enumerated type String values

getDefault

public static <T extends java.lang.Enum<T>> T getDefault(java.lang.Class<T> enumClass)
Returns the default enum constant of the specified enum type. Currently, the 'default' constant is defined to be the first constant in the list.

Parameters:
enumClass - The Class object of the enum type from which to return a constant
Returns:
The default enum constant of the specified enum type.

getValueOf

public static <T extends java.lang.Enum<T>> T getValueOf(java.lang.Class<T> enumClass,
                                                         java.lang.String name)
Returns the enum constant of the specified enum type with the specified name or 'toString()' value. The default (first) constant will be returned, if the name is not found.

Parameters:
enumClass - The Class object of the enum type from which to return a constant
name - The name of the constant to return
Returns:
The enum constant of the specified enum type with the specified name or 'toString()' value

getValueOf

public static <T extends java.lang.Enum<T>> T getValueOf(java.lang.Class<T> enumClass,
                                                         java.lang.String name,
                                                         T dft)
Returns the enum constant of the specified enum type with the specified name or 'toString()' value.

Parameters:
enumClass - The Class object of the enum type from which to return a constant
name - The name of the constant to return
dft - The default type to return if the name was not found
Returns:
The enum constant of the specified enum type with the specified name or 'toString()' value

getValueOf

public static <T extends java.lang.Enum<T>> T getValueOf(java.lang.Class<T> enumClass,
                                                         java.lang.String name,
                                                         java.util.Locale loc)
Returns the enum constant of the specified enum type with the specified name or 'toString()' value. The default (first) constant will be returned, if the name is not found.

Parameters:
enumClass - The Class object of the enum type from which to return a constant
name - The name of the constant to return
loc - The Locale
Returns:
The enum constant of the specified enum type with the specified name or 'toString()' value

getValueOf

protected static <T extends java.lang.Enum<T>> T getValueOf(java.lang.Class<T> enumClass,
                                                            java.lang.String name,
                                                            java.util.Locale loc,
                                                            T dft,
                                                            boolean rtnDefault)
Returns the enum constant of the specified enum type with the specified name or 'toString()' value.

Parameters:
enumClass - The Class object of the enum type from which to return a constant
name - The name of the constant to return
loc - The Locale
dft - The default type to return if the name was not found, and 'rtnDefault' is false.
rtnDefault - True to return the first constant if name was not found and 'dft' is null.
Returns:
The enum constant of the specified enum type with the specified name or 'toString()' value

getValueOf

public static <T extends java.lang.Enum<T>> T getValueOf(java.lang.Class<T> enumClass,
                                                         int value)
Returns the enum constant of the specified enum type with the specified integer value. The default (first) constant will be returned, if the name is not found.

Parameters:
enumClass - The Class object of the enum type from which to return a constant
value - The integer value of the constant to return
Returns:
The enum constant of the specified enum type with the specified integer value

getValueOf

public static <T extends java.lang.Enum<T>> T getValueOf(java.lang.Class<T> enumClass,
                                                         int value,
                                                         T dft)
Returns the enum constant of the specified enum type with the specified integer value.

Parameters:
enumClass - The Class object of the enum type from which to return a constant
value - The integer value of the constant to return
dft - The default type to return if the integer value was not found, and 'rtnDefault' is false.
Returns:
The enum constant of the specified enum type with the specified integer value

getValueOf

public static <T extends java.lang.Enum<T>> T getValueOf(java.lang.Class<T> enumClass,
                                                         int value,
                                                         T dft,
                                                         boolean rtnDefault)
Returns the enum constant of the specified enum type with the specified integer value.

Parameters:
enumClass - The Class object of the enum type from which to return a constant
value - The integer value of the constant to return
dft - The default type to return if the integer value was not found, and 'rtnDefault' is false.
rtnDefault - True to return the first constant if integer value was not found and 'dft' is null.
Returns:
The enum constant of the specified enum type with the specified integer value

getValueOf

public static <T extends java.lang.Enum<T>> T getValueOf(java.lang.Class<T> enumClass,
                                                         T value)
Returns the enum constant of the specified enum type with the specified integer value. The default (first) constant will be returned, if the specified value is null.

Parameters:
enumClass - The Class object of the enum type from which to return a constant
value - The enum type value to return
Returns:
The enum constant of the specified enum type

getValueOf

public static <T extends java.lang.Enum<T>> T getValueOf(java.lang.Class<T> enumClass,
                                                         T value,
                                                         T dft)
Returns the specified enum constant or a default if the enum constant is null.

Parameters:
enumClass - The Class object of the enum type from which to return a constant
value - The enum type value to return
dft - The default type to return if the integer value was not found, and 'rtnDefault' is false.
Returns:
The enum constant of the specified enum type

getValueOf

public static <T extends java.lang.Enum<T>> T getValueOf(java.lang.Class<T> enumClass,
                                                         T value,
                                                         T dft,
                                                         boolean rtnDefault)
Returns the specified enum constant or a default if the enum constant is null.

Parameters:
enumClass - The Class object of the enum type from which to return a constant
value - The enum type value to return
dft - The default type to return if the enum type value is null, and 'rtnDefault' is false.
rtnDefault - True to return the first constant if the enum type value was not found and 'dft' is null.
Returns:
The enum constant of the specified enum type

getValuesForMask

public static <T extends java.lang.Enum<T>> T[] getValuesForMask(java.lang.Class<T> enumClass,
                                                                 long mask)
Returns a list of Enumerated BitMask values for the specified mask

Parameters:
enumClass - The Class object of the enum type from which to return constants
mask - The bitmask
Returns:
A list of enumerated bitmask types, or null if the Enum class type is not a bitmask

getValueMask

public static <T extends java.lang.Enum<T>> long getValueMask(java.lang.Class<T> enumClass)
For 'BitMask' enumerated types, this method returns the logical 'OR' or all values.

Parameters:
enumClass - The Class object of the enum type from which to return the bitmask
Returns:
The logical 'OR" of all enumerated types for the specified Enum class

registerPublicEnumClasses

public static void registerPublicEnumClasses(java.lang.Class<?> enumContainerClass)
Registers all public Enum classes defined within the specified class.
This is used to allow referencing an enumerated type by name (ie. for the purpose of obtaining a localized list of String representations).

Parameters:
enumContainerClass - The class which defined Enum inner classes

registerEnumClass

public static <T extends java.lang.Enum> void registerEnumClass(java.lang.Class<T> enumClass)
Registers the specified Enum classes

Parameters:
enumClass - The Enum class to register. The default name used in the registration will be the name of the class with the package name removed.

registerEnumClass

public static <T extends java.lang.Enum> void registerEnumClass(java.lang.String name,
                                                                java.lang.Class<T> enumClass)
Registers the specified Enum classes

Parameters:
name - The name under which the Enum class will be registered
enumClass - The Enum class to register.

getEnumClass

public static java.lang.Class<? extends java.lang.Enum> getEnumClass(java.lang.String name)
Returns the registered Enum class for the specified name

Parameters:
name - The register Enum class name
Returns:
The registered Enum class for the specified name, or null if the name does not exist.

getEnumClass

public static java.lang.Class<? extends java.lang.Enum> getEnumClass(java.lang.Class enumContainerClass,
                                                                     java.lang.String name)
Returns the registered Enum class for the specified name

Parameters:
enumContainerClass - The parent class in which the specified name is defined
name - The register Enum class name
Returns:
The registered Enum class for the specified name, or null if the name does not exist.

main

public static void main(java.lang.String[] argv)
Main entry point for testing/debugging

Parameters:
argv - Comand-line arguments