Class EnumUtils
#ThreadSafe#
- Since:
- 3.0
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic <E extends Enum<E>>
 longgenerateBitVector(Class<E> enumClass, E... values) Creates a long bit vector representation of the given array of Enum values.static <E extends Enum<E>>
 longgenerateBitVector(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>>
 long[]generateBitVectors(Class<E> enumClass, E... values) Creates a bit vector representation of the given subset of an Enum using as manylongs as needed.static <E extends Enum<E>>
 long[]generateBitVectors(Class<E> enumClass, Iterable<? extends E> values) Creates a bit vector representation of the given subset of an Enum using as manylongs as needed.static <E extends Enum<E>>
 EGets the enum for the class, returningnullif not found.static <E extends Enum<E>>
 EGets the enum for the class, returningdefaultEnumif not found.static <E extends Enum<E>>
 EgetEnumIgnoreCase(Class<E> enumClass, String enumName) Gets the enum for the class, returningnullif not found.static <E extends Enum<E>>
 EgetEnumIgnoreCase(Class<E> enumClass, String enumName, E defaultEnum) Gets the enum for the class, returningdefaultEnumif not found.getEnumList(Class<E> enumClass) Gets theListof enums.getEnumMap(Class<E> enumClass) Gets theMapof enums by name.getEnumMap(Class<E> enumClass, Function<E, K> keyFunction) Gets theMapof enums by name.static <E extends Enum<E>>
 EgetEnumSystemProperty(Class<E> enumClass, String propName, E defaultEnum) Gets the enum for the class in a system property, returningdefaultEnumif not found.static <E extends Enum<E>>
 EgetFirstEnum(Class<E> enumClass, int value, ToIntFunction<E> toIntFunction, E defaultEnum) Gets the enum for the class and value, returningdefaultEnumif not found.static <E extends Enum<E>>
 EgetFirstEnumIgnoreCase(Class<E> enumClass, String enumName, Function<E, String> stringFunction, E defaultEnum) Gets the enum for the class, returningdefaultEnumif not found.static <E extends Enum<E>>
 booleanisValidEnum(Class<E> enumClass, String enumName) Checks if the specified name is a valid enum for the class.static <E extends Enum<E>>
 booleanisValidEnumIgnoreCase(Class<E> enumClass, String enumName) Checks if the specified name is a valid enum for the class.processBitVector(Class<E> enumClass, long value) Convert a long value created bygenerateBitVector(java.lang.Class<E>, E...)into the set of enum values that it represents.processBitVectors(Class<E> enumClass, long... values) Convert along[]created bygenerateBitVectors(java.lang.Class<E>, E...)into the set of enum values that it represents.static <T> Stream<T>Returns a sequential ordered stream whose elements are the given class' enum values.
- 
Constructor Details- 
EnumUtilsDeprecated.TODO Make private in 4.0.This constructor is public to permit tools that require a JavaBean instance to operate.
 
- 
- 
Method Details- 
generateBitVector@SafeVarargs public static <E extends Enum<E>> long generateBitVector(Class<E> enumClass, E... values) Creates a long bit vector representation of the given array of Enum 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. - Type Parameters:
- E- the type of the enumeration.
- Parameters:
- enumClass- the class of the enum we are working with, not- null.
- values- the values we want to convert, not- null.
- Returns:
- a long whose value provides a binary representation of the given set of enum values.
- Throws:
- NullPointerException- if- enumClassor- valuesis- null.
- IllegalArgumentException- if- enumClassis not an enum class or has more than 64 values.
- Since:
- 3.0.1
- See Also:
 
- 
generateBitVectorpublic static <E extends Enum<E>> long generateBitVector(Class<E> enumClass, Iterable<? extends E> values) Creates a long bit vector representation of the given subset of an Enum.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. - Type Parameters:
- E- the type of the enumeration.
- Parameters:
- enumClass- the class of the enum we are working with, not- null.
- values- the values we want to convert, not- null, neither containing- null.
- Returns:
- a long whose value provides a binary representation of the given set of enum values.
- Throws:
- NullPointerException- if- enumClassor- valuesis- null.
- IllegalArgumentException- if- enumClassis not an enum class or has more than 64 values, or if any- values- null.
- Since:
- 3.0.1
- See Also:
 
- 
generateBitVectors@SafeVarargs public static <E extends Enum<E>> long[] generateBitVectors(Class<E> enumClass, E... values) Creates a bit vector representation of the given subset of an Enum using as manylongs 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. - Type Parameters:
- E- the type of the enumeration.
- Parameters:
- enumClass- the class of the enum we are working with, not- null.
- values- the values we want to convert, not- null, neither containing- null.
- Returns:
- a long[] whose values provide a binary representation of the given set of enum values with the least significant digits rightmost.
- Throws:
- NullPointerException- if- enumClassor- valuesis- null.
- IllegalArgumentException- if- enumClassis not an enum class, or if any- values- null.
- Since:
- 3.2
 
- 
generateBitVectorspublic static <E extends Enum<E>> long[] generateBitVectors(Class<E> enumClass, Iterable<? extends E> values) Creates a bit vector representation of the given subset of an Enum using as manylongs 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. - Type Parameters:
- E- the type of the enumeration.
- Parameters:
- enumClass- the class of the enum we are working with, not- null.
- values- the values we want to convert, not- null, neither containing- null.
- Returns:
- a long[] whose values provide a binary representation of the given set of enum values with the least significant digits rightmost.
- Throws:
- NullPointerException- if- enumClassor- valuesis- null.
- IllegalArgumentException- if- enumClassis not an enum class, or if any- values- null.
- Since:
- 3.2
 
- 
getEnumGets the enum for the class, returningnullif 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.- Type Parameters:
- E- the type of the enumeration.
- Parameters:
- enumClass- the class of the enum to query, not null.
- enumName- the enum name, null returns null.
- Returns:
- the enum, null if not found.
 
- 
getEnumGets the enum for the class, returningdefaultEnumif 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.- Type Parameters:
- E- the type of the enumeration.
- Parameters:
- enumClass- the class of the enum to query, null returns default enum.
- enumName- the enum name, null returns default enum.
- defaultEnum- the default enum.
- Returns:
- the enum, default enum if not found.
- Since:
- 3.10
 
- 
getEnumIgnoreCaseGets the enum for the class, returningnullif 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.- Type Parameters:
- E- the type of the enumeration.
- Parameters:
- enumClass- the class of the enum to query, may be null.
- enumName- the enum name, null returns null.
- Returns:
- the enum, null if not found.
- Since:
- 3.8
 
- 
getEnumIgnoreCasepublic static <E extends Enum<E>> E getEnumIgnoreCase(Class<E> enumClass, String enumName, E defaultEnum) Gets the enum for the class, returningdefaultEnumif 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.- Type Parameters:
- E- the type of the enumeration.
- Parameters:
- enumClass- the class of the enum to query, null returns default enum.
- enumName- the enum name, null returns default enum.
- defaultEnum- the default enum.
- Returns:
- the enum, default enum if not found.
- Since:
- 3.10
 
- 
getEnumListGets theListof enums.This method is useful when you need a list of enums rather than an array. - Type Parameters:
- E- the type of the enumeration.
- Parameters:
- enumClass- the class of the enum to query, not null.
- Returns:
- the modifiable list of enums, never null.
 
- 
getEnumMapGets theMapof enums by name.This method is useful when you need a map of enums by name. - Type Parameters:
- E- the type of the enumeration.
- Parameters:
- enumClass- the class of the enum to query, not null.
- Returns:
- the modifiable map of enum names to enums, never null.
 
- 
getEnumMappublic static <E extends Enum<E>,K> Map<K,E> getEnumMap(Class<E> enumClass, Function<E, K> keyFunction) Gets theMapof enums by name.This method is useful when you need a map of enums by name. - Type Parameters:
- E- the type of enumeration.
- K- the type of the map key.
- Parameters:
- enumClass- the class of the enum to query, not null.
- keyFunction- the function to query for the key, not null.
- Returns:
- the modifiable map of enums, never null.
- Since:
- 3.13.0
 
- 
getEnumSystemPropertypublic static <E extends Enum<E>> E getEnumSystemProperty(Class<E> enumClass, String propName, E defaultEnum) Gets the enum for the class in a system property, returningdefaultEnumif 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 SecurityExceptionis caught, the return value isnull.- Type Parameters:
- E- the type of the enumeration.
- Parameters:
- 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.
- Returns:
- the enum, default enum if not found.
- Since:
- 3.13.0
 
- 
getFirstEnumpublic static <E extends Enum<E>> E getFirstEnum(Class<E> enumClass, int value, ToIntFunction<E> toIntFunction, E defaultEnum) Gets the enum for the class and value, returningdefaultEnumif 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.- Type Parameters:
- E- the type of the enumeration.
- Parameters:
- 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.
- Returns:
- an enum, default enum if not found.
- Since:
- 3.18.0
 
- 
getFirstEnumIgnoreCasepublic static <E extends Enum<E>> E getFirstEnumIgnoreCase(Class<E> enumClass, String enumName, Function<E, String> stringFunction, E defaultEnum) Gets the enum for the class, returningdefaultEnumif 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.- Type Parameters:
- E- the type of the enumeration.
- Parameters:
- 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.
- Returns:
- an enum, default enum if not found.
- Since:
- 3.13.0
 
- 
isValidEnumChecks 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 it checks if the name is a valid enum without needing to catch the exception.- Type Parameters:
- E- the type of the enumeration.
- Parameters:
- enumClass- the class of the enum to query, null returns false.
- enumName- the enum name, null returns false.
- Returns:
- true if the enum name is valid, otherwise false.
 
- 
isValidEnumIgnoreCasepublic static <E extends Enum<E>> boolean isValidEnumIgnoreCase(Class<E> enumClass, 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 it checks if the name is a valid enum without needing to catch the exception and performs case insensitive matching of the name.- Type Parameters:
- E- the type of the enumeration.
- Parameters:
- enumClass- the class of the enum to query, null returns false.
- enumName- the enum name, null returns false.
- Returns:
- true if the enum name is valid, otherwise false.
- Since:
- 3.8
 
- 
processBitVectorConvert a long value created bygenerateBitVector(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. - Type Parameters:
- E- the type of the enumeration.
- Parameters:
- enumClass- the class of the enum we are working with, not- null.
- value- the long value representation of a set of enum values.
- Returns:
- a set of enum values.
- Throws:
- NullPointerException- if- enumClassis- null.
- IllegalArgumentException- if- enumClassis not an enum class or has more than 64 values.
- Since:
- 3.0.1
 
- 
processBitVectorsConvert along[]created bygenerateBitVectors(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. - Type Parameters:
- E- the type of the enumeration.
- Parameters:
- 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.
- Returns:
- a set of enum values.
- Throws:
- NullPointerException- if- enumClassis- null.
- IllegalArgumentException- if- enumClassis not an enum class.
- Since:
- 3.2
 
- 
streamReturns a sequential ordered stream whose elements are the given class' enum values.- Type Parameters:
- T- the type of stream elements.
- Parameters:
- clazz- the class containing the enum values, may be null.
- Returns:
- the new stream, empty of clazzis null.
- Since:
- 3.18.0
- See Also:
 
 
-