public class EnumUtils
extends java.lang.Object
Utility library to provide helper methods for Java enums.
#ThreadSafe#
| Constructor and Description |
|---|
EnumUtils()
This constructor is public to permit tools that require a JavaBean
instance to operate.
|
| Modifier and Type | Method and Description |
|---|---|
static <E extends java.lang.Enum<E>> |
getEnum(java.lang.Class<E> enumClass,
java.lang.String enumName)
Gets the enum for the class, returning
null if not found. |
static <E extends java.lang.Enum<E>> |
getEnum(java.lang.Class<E> enumClass,
java.lang.String enumName,
E defaultEnum)
Gets the enum for the class, returning
defaultEnum if not found. |
static <E extends java.lang.Enum<E>> |
getEnumIgnoreCase(java.lang.Class<E> enumClass,
java.lang.String enumName)
Gets the enum for the class, returning
null if not found. |
static <E extends java.lang.Enum<E>> |
getEnumIgnoreCase(java.lang.Class<E> enumClass,
java.lang.String enumName,
E defaultEnum)
Gets the enum for the class, returning
defaultEnum if not found. |
static <E extends java.lang.Enum<E>> |
getEnumList(java.lang.Class<E> enumClass)
Gets the
List of enums. |
static <E extends java.lang.Enum<E>> |
getEnumMap(java.lang.Class<E> enumClass)
Gets the
Map of enums by name. |
static <E extends java.lang.Enum<E>> |
isValidEnum(java.lang.Class<E> enumClass,
java.lang.String enumName)
Checks if the specified name is a valid enum for the class.
|
static <E extends java.lang.Enum<E>> |
isValidEnumIgnoreCase(java.lang.Class<E> enumClass,
java.lang.String enumName)
Checks if the specified name is a valid enum for the class.
|
public EnumUtils()
public static <E extends java.lang.Enum<E>> E getEnum(java.lang.Class<E> enumClass,
java.lang.String enumName)
Gets the enum for the class, returning null if not found.
This method differs from Enum.valueOf(java.lang.Class<T>, java.lang.String) in that it does not throw an exception
for an invalid enum name.
E - the type of the enumerationenumClass - the class of the enum to query, not nullenumName - the enum name, null returns nullpublic static <E extends java.lang.Enum<E>> E getEnum(java.lang.Class<E> enumClass,
java.lang.String enumName,
E defaultEnum)
Gets the enum for the class, returning defaultEnum if not found.
This method differs from Enum.valueOf(java.lang.Class<T>, java.lang.String) in that it does not throw an exception
for an invalid enum name.
E - the type of the enumerationenumClass - the class of the enum to query, not nullenumName - the enum name, null returns default enumdefaultEnum - the default enumpublic static <E extends java.lang.Enum<E>> E getEnumIgnoreCase(java.lang.Class<E> enumClass,
java.lang.String enumName)
Gets the enum for the class, returning null if not found.
This method differs from Enum.valueOf(java.lang.Class<T>, java.lang.String) in that it does not throw an exception
for an invalid enum name and performs case insensitive matching of the name.
E - the type of the enumerationenumClass - the class of the enum to query, not nullenumName - the enum name, null returns nullpublic static <E extends java.lang.Enum<E>> E getEnumIgnoreCase(java.lang.Class<E> enumClass,
java.lang.String enumName,
E defaultEnum)
Gets the enum for the class, returning defaultEnum if not found.
This method differs from Enum.valueOf(java.lang.Class<T>, java.lang.String) in that it does not throw an exception
for an invalid enum name and performs case insensitive matching of the name.
E - the type of the enumerationenumClass - the class of the enum to query, not nullenumName - the enum name, null returns default enumdefaultEnum - the default enumpublic static <E extends java.lang.Enum<E>> java.util.List<E> getEnumList(java.lang.Class<E> enumClass)
Gets the List of enums.
This method is useful when you need a list of enums rather than an array.
E - the type of the enumerationenumClass - the class of the enum to query, not nullpublic static <E extends java.lang.Enum<E>> java.util.Map<java.lang.String,E> getEnumMap(java.lang.Class<E> enumClass)
Gets the Map of enums by name.
This method is useful when you need a map of enums by name.
E - the type of the enumerationenumClass - the class of the enum to query, not nullpublic static <E extends java.lang.Enum<E>> boolean isValidEnum(java.lang.Class<E> enumClass,
java.lang.String enumName)
Checks if the specified name is a valid enum for the class.
This method differs from Enum.valueOf(java.lang.Class<T>, java.lang.String) in that checks if the name is
a valid enum without needing to catch the exception.
E - the type of the enumerationenumClass - the class of the enum to query, not nullenumName - the enum name, null returns falsepublic static <E extends java.lang.Enum<E>> boolean isValidEnumIgnoreCase(java.lang.Class<E> enumClass,
java.lang.String enumName)
Checks if the specified name is a valid enum for the class.
This method differs from Enum.valueOf(java.lang.Class<T>, java.lang.String) in that checks if the name is
a valid enum without needing to catch the exception
and performs case insensitive matching of the name.
E - the type of the enumerationenumClass - the class of the enum to query, not nullenumName - the enum name, null returns false