public class EnumUtils
extends java.lang.Object
#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>> |
generateBitVector(java.lang.Class<E> enumClass,
E... values)
Creates a long bit vector representation of the given array of Enum values.
|
static <E extends java.lang.Enum<E>> |
generateBitVector(java.lang.Class<E> enumClass,
java.lang.Iterable<? extends E> values)
Creates a long bit vector representation of the given subset of an Enum.
|
static <E extends java.lang.Enum<E>> |
generateBitVectors(java.lang.Class<E> enumClass,
E... values)
Creates a bit vector representation of the given subset of an Enum using as many
longs as needed. |
static <E extends java.lang.Enum<E>> |
generateBitVectors(java.lang.Class<E> enumClass,
java.lang.Iterable<? extends E> values)
Creates a bit vector representation of the given subset of an Enum using as many
longs as needed. |
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>,K> |
getEnumMap(java.lang.Class<E> enumClass,
java.util.function.Function<E,K> keyFunction)
Gets the
Map of enums by name. |
static <E extends java.lang.Enum<E>> |
getEnumSystemProperty(java.lang.Class<E> enumClass,
java.lang.String propName,
E defaultEnum)
Gets the enum for the class in a system property, returning
defaultEnum if not found. |
static <E extends java.lang.Enum<E>> |
getFirstEnumIgnoreCase(java.lang.Class<E> enumClass,
java.lang.String enumName,
java.util.function.Function<E,java.lang.String> stringFunction,
E defaultEnum)
Gets the enum for the class, returning
defaultEnum if not found. |
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.
|
static <E extends java.lang.Enum<E>> |
processBitVector(java.lang.Class<E> enumClass,
long value)
Convert a long value created by
generateBitVector(java.lang.Class<E>, E...) into the set of
enum values that it represents. |
static <E extends java.lang.Enum<E>> |
processBitVectors(java.lang.Class<E> enumClass,
long... values)
Convert a
long[] created by generateBitVectors(java.lang.Class<E>, E...) into the set of
enum values that it represents. |
public EnumUtils()
@SafeVarargs
public static <E extends java.lang.Enum<E>> long generateBitVector(java.lang.Class<E> enumClass,
E... values)
This generates a value that is usable by processBitVector(java.lang.Class<E>, long).
Do not use this method if you have more than 64 values in your Enum, as this would create a value greater than a long can hold.
E - the type of the enumerationenumClass - the class of the enum we are working with, not nullvalues - the values we want to convert, not nulljava.lang.NullPointerException - if enumClass or values is nulljava.lang.IllegalArgumentException - if enumClass is not an enum class or has more than 64 valuesgenerateBitVectors(Class, Iterable)public static <E extends java.lang.Enum<E>> long generateBitVector(java.lang.Class<E> enumClass,
java.lang.Iterable<? extends E> values)
This generates a value that is usable by processBitVector(java.lang.Class<E>, long).
Do not use this method if you have more than 64 values in your Enum, as this would create a value greater than a long can hold.
E - the type of the enumerationenumClass - the class of the enum we are working with, not nullvalues - the values we want to convert, not null, neither containing nulljava.lang.NullPointerException - if enumClass or values is nulljava.lang.IllegalArgumentException - if enumClass is not an enum class or has more than 64 values,
or if any values nullgenerateBitVectors(Class, Iterable)@SafeVarargs
public static <E extends java.lang.Enum<E>> long[] generateBitVectors(java.lang.Class<E> enumClass,
E... values)
longs as needed.
This generates a value that is usable by processBitVectors(java.lang.Class<E>, long...).
Use this method if you have more than 64 values in your Enum.
E - the type of the enumerationenumClass - the class of the enum we are working with, not nullvalues - the values we want to convert, not null, neither containing nulljava.lang.NullPointerException - if enumClass or values is nulljava.lang.IllegalArgumentException - if enumClass is not an enum class, or if any values nullpublic static <E extends java.lang.Enum<E>> long[] generateBitVectors(java.lang.Class<E> enumClass,
java.lang.Iterable<? extends E> values)
longs as needed.
This generates a value that is usable by processBitVectors(java.lang.Class<E>, long...).
Use this method if you have more than 64 values in your Enum.
E - the type of the enumerationenumClass - the class of the enum we are working with, not nullvalues - the values we want to convert, not null, neither containing nulljava.lang.NullPointerException - if enumClass or values is nulljava.lang.IllegalArgumentException - if enumClass is not an enum class, or if any values nullpublic static <E extends java.lang.Enum<E>> E getEnum(java.lang.Class<E> enumClass,
java.lang.String enumName)
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)
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)
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)
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)
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)
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>,K> java.util.Map<K,E> getEnumMap(java.lang.Class<E> enumClass,
java.util.function.Function<E,K> keyFunction)
Map of enums by name.
This method is useful when you need a map of enums by name.
E - the type of enumerationK - the type of the map keyenumClass - the class of the enum to query, not nullkeyFunction - the function to query for the key, not nullpublic static <E extends java.lang.Enum<E>> E getEnumSystemProperty(java.lang.Class<E> enumClass,
java.lang.String propName,
E defaultEnum)
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 nullpropName - the system property key for the enum name, null returns default enumdefaultEnum - the default enumpublic static <E extends java.lang.Enum<E>> E getFirstEnumIgnoreCase(java.lang.Class<E> enumClass,
java.lang.String enumName,
java.util.function.Function<E,java.lang.String> stringFunction,
E defaultEnum)
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 enumstringFunction - the function that gets the string for an enum for comparison to enumName.defaultEnum - the default enumpublic static <E extends java.lang.Enum<E>> boolean isValidEnum(java.lang.Class<E> enumClass,
java.lang.String enumName)
This method differs from Enum.valueOf(java.lang.Class<T>, java.lang.String) in that it 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)
This method differs from Enum.valueOf(java.lang.Class<T>, java.lang.String) in that it 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 falsepublic static <E extends java.lang.Enum<E>> java.util.EnumSet<E> processBitVector(java.lang.Class<E> enumClass,
long value)
generateBitVector(java.lang.Class<E>, E...) into the set of
enum values that it represents.
If you store this value, beware any changes to the enum that would affect ordinal values.
E - the type of the enumerationenumClass - the class of the enum we are working with, not nullvalue - the long value representation of a set of enum valuesjava.lang.NullPointerException - if enumClass is nulljava.lang.IllegalArgumentException - if enumClass is not an enum class or has more than 64 valuespublic static <E extends java.lang.Enum<E>> java.util.EnumSet<E> processBitVectors(java.lang.Class<E> enumClass,
long... values)
long[] created by generateBitVectors(java.lang.Class<E>, E...) into the set of
enum values that it represents.
If you store this value, beware any changes to the enum that would affect ordinal values.
E - the type of the enumerationenumClass - the class of the enum we are working with, not nullvalues - the long[] bearing the representation of a set of enum values, the least significant digits rightmost, not nulljava.lang.NullPointerException - if enumClass is nulljava.lang.IllegalArgumentException - if enumClass is not an enum classCopyright © 2010 - 2023 Adobe. All Rights Reserved