public class EnumUtils extends Object
#ThreadSafe#
| Constructor and Description |
|---|
EnumUtils()
Deprecated.
TODO Make private in 4.0.
|
| Modifier and Type | Method and Description |
|---|---|
static <E extends Enum<E>> |
generateBitVector(Class<E> enumClass,
E... values)
Creates a long bit vector representation of the given array of Enum values.
|
static <E extends Enum<E>> |
generateBitVector(Class<E> enumClass,
Iterable<? extends E> values)
Creates a long bit vector representation of the given subset of an Enum.
|
static <E extends Enum<E>> |
generateBitVectors(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 Enum<E>> |
generateBitVectors(Class<E> enumClass,
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 Enum<E>> |
getEnum(Class<E> enumClass,
String enumName)
Gets the enum for the class, returning
null if not found. |
static <E extends Enum<E>> |
getEnum(Class<E> enumClass,
String enumName,
E defaultEnum)
Gets the enum for the class, returning
defaultEnum if not found. |
static <E extends Enum<E>> |
getEnumIgnoreCase(Class<E> enumClass,
String enumName)
Gets the enum for the class, returning
null if not found. |
static <E extends Enum<E>> |
getEnumIgnoreCase(Class<E> enumClass,
String enumName,
E defaultEnum)
Gets the enum for the class, returning
defaultEnum if not found. |
static <E extends Enum<E>> |
getEnumList(Class<E> enumClass)
Gets the
List of enums. |
static <E extends Enum<E>> |
getEnumMap(Class<E> enumClass)
Gets the
Map of enums by name. |
static <E extends Enum<E>,K> |
getEnumMap(Class<E> enumClass,
Function<E,K> keyFunction)
Gets the
Map of enums by name. |
static <E extends Enum<E>> |
getEnumSystemProperty(Class<E> enumClass,
String propName,
E defaultEnum)
Gets the enum for the class in a system property, returning
defaultEnum if not found. |
static <E extends Enum<E>> |
getFirstEnum(Class<E> enumClass,
int value,
ToIntFunction<E> toIntFunction,
E defaultEnum)
Gets the enum for the class and value, returning
defaultEnum if not found. |
static <E extends Enum<E>> |
getFirstEnumIgnoreCase(Class<E> enumClass,
String enumName,
Function<E,String> stringFunction,
E defaultEnum)
Gets the enum for the class, returning
defaultEnum if not found. |
static <E extends Enum<E>> |
isValidEnum(Class<E> enumClass,
String enumName)
Checks if the specified name is a valid enum for the class.
|
static <E extends Enum<E>> |
isValidEnumIgnoreCase(Class<E> enumClass,
String enumName)
Checks if the specified name is a valid enum for the class.
|
static <E extends Enum<E>> |
processBitVector(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 Enum<E>> |
processBitVectors(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. |
static <T> Stream<T> |
stream(Class<T> clazz)
Returns a sequential ordered stream whose elements are the given class' enum values.
|
@Deprecated public EnumUtils()
@SafeVarargs public static <E extends Enum<E>> long generateBitVector(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 enumeration.enumClass - the class of the enum we are working with, not null.values - the values we want to convert, not null.NullPointerException - if enumClass or values is null.IllegalArgumentException - if enumClass is not an enum class or has more than 64 values.generateBitVectors(Class, Iterable)public static <E extends Enum<E>> long generateBitVector(Class<E> enumClass, 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 enumeration.enumClass - the class of the enum we are working with, not null.values - the values we want to convert, not null, neither containing null.NullPointerException - if enumClass or values is null.IllegalArgumentException - if enumClass is not an enum class or has more than 64 values,
or if any values null.generateBitVectors(Class, Iterable)@SafeVarargs public static <E extends Enum<E>> long[] generateBitVectors(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 enumeration.enumClass - the class of the enum we are working with, not null.values - the values we want to convert, not null, neither containing null.NullPointerException - if enumClass or values is null.IllegalArgumentException - if enumClass is not an enum class, or if any values null.public static <E extends Enum<E>> long[] generateBitVectors(Class<E> enumClass, 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 enumeration.enumClass - the class of the enum we are working with, not null.values - the values we want to convert, not null, neither containing null.NullPointerException - if enumClass or values is null.IllegalArgumentException - if enumClass is not an enum class, or if any values null.public static <E extends Enum<E>> E getEnum(Class<E> enumClass, 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 enumeration.enumClass - the class of the enum to query, not null.enumName - the enum name, null returns null.public static <E extends Enum<E>> E getEnum(Class<E> enumClass, 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 enumeration.enumClass - the class of the enum to query, null returns default enum.enumName - the enum name, null returns default enum.defaultEnum - the default enum.public static <E extends Enum<E>> E getEnumIgnoreCase(Class<E> enumClass, 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 enumeration.enumClass - the class of the enum to query, may be null.enumName - the enum name, null returns null.public static <E extends Enum<E>> E getEnumIgnoreCase(Class<E> enumClass, 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 enumeration.enumClass - the class of the enum to query, null returns default enum.enumName - the enum name, null returns default enum.defaultEnum - the default enum.public static <E extends Enum<E>> List<E> getEnumList(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 enumeration.enumClass - the class of the enum to query, not null.public static <E extends Enum<E>> Map<String,E> getEnumMap(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 enumeration.enumClass - the class of the enum to query, not null.public static <E extends Enum<E>,K> Map<K,E> getEnumMap(Class<E> enumClass, 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 enumeration.K - the type of the map key.enumClass - the class of the enum to query, not null.keyFunction - the function to query for the key, not null.public static <E extends Enum<E>> E getEnumSystemProperty(Class<E> enumClass, 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.
If a SecurityException is caught, the return value is null.
E - the type of the enumeration.enumClass - the class of the enum to query, not null.propName - the system property key for the enum name, null returns default enum.defaultEnum - the default enum.public static <E extends Enum<E>> E getFirstEnum(Class<E> enumClass, int value, ToIntFunction<E> toIntFunction, 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 enumeration.enumClass - the class of the enum to query, not null.value - the enum name, null returns default enum.toIntFunction - the function that gets an int for an enum for comparison to value.defaultEnum - the default enum.public static <E extends Enum<E>> E getFirstEnumIgnoreCase(Class<E> enumClass, String enumName, Function<E,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 enumeration.enumClass - the class of the enum to query, null returns default enum.enumName - the enum name, null returns default enum.stringFunction - the function that gets the string for an enum for comparison to enumName.defaultEnum - the default enum.public static <E extends Enum<E>> boolean isValidEnum(Class<E> enumClass, 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 enumeration.enumClass - the class of the enum to query, null returns false.enumName - the enum name, null returns false.public static <E extends Enum<E>> boolean isValidEnumIgnoreCase(Class<E> enumClass, 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 enumeration.enumClass - the class of the enum to query, null returns false.enumName - the enum name, null returns false.public static <E extends Enum<E>> EnumSet<E> processBitVector(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 enumeration.enumClass - the class of the enum we are working with, not null.value - the long value representation of a set of enum values.NullPointerException - if enumClass is null.IllegalArgumentException - if enumClass is not an enum class or has more than 64 values.public static <E extends Enum<E>> EnumSet<E> processBitVectors(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 enumeration.enumClass - the class of the enum we are working with, not null.values - the long[] bearing the representation of a set of enum values, the least significant digits rightmost, not null.NullPointerException - if enumClass is null.IllegalArgumentException - if enumClass is not an enum class.public static <T> Stream<T> stream(Class<T> clazz)
T - the type of stream elements.clazz - the class containing the enum values, may be null.clazz is null.Class.getEnumConstants()Copyright © 2001–2025 The Apache Software Foundation. All rights reserved.