public class EnumUtils extends Object
| Constructor and Description |
|---|
EnumUtils() |
| 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>> |
getEnumIgnoreCase(Class<E> enumClass,
String enumName)
Gets the enum for the class, returning
null 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)
获取枚举字符串值和枚举对象的Map对应,使用LinkedHashMap保证有序
结果中键为枚举名,值为枚举对象 |
static List<Object> |
getFieldValues(Class<? extends Enum<?>> clazz,
String fieldName)
获得枚举类中各枚举对象下指定字段的值
|
static Map<String,Object> |
getNameFieldMap(Class<? extends Enum<?>> clazz,
String fieldName)
获得枚举名对应指定字段值的Map
键为枚举名,值为字段值 |
static List<String> |
getNames(Class<? extends Enum<?>> clazz)
枚举类中所有枚举对象的name列表
|
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>, java.lang.Iterable<? extends 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>, java.lang.Iterable<? extends E>) into the set of
enum values that it represents. |
public static List<String> getNames(Class<? extends Enum<?>> clazz)
clazz - 枚举类public static List<Object> getFieldValues(Class<? extends Enum<?>> clazz, String fieldName)
clazz - 枚举类fieldName - 字段名,最终调用getXXX方法public static <E extends Enum<E>> LinkedHashMap<String,E> getEnumMap(Class<E> enumClass)
E - 对象enumClass - 枚举类public static Map<String,Object> getNameFieldMap(Class<? extends Enum<?>> clazz, String fieldName)
clazz - 枚举类fieldName - 字段名,最终调用getXXX方法public static <E extends Enum<E>> List<E> getEnumList(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 Enum<E>> boolean isValidEnum(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 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 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 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 Enum<E>> E getEnum(Class<E> enumClass, 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 Enum<E>> E getEnumIgnoreCase(Class<E> enumClass, 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 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.
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 nullNullPointerException - if enumClass or values is nullIllegalArgumentException - if enumClass is not an enum class or has more than 64 values,
or if any values nullgenerateBitVectors(Class, Iterable)public 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 many 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 nullNullPointerException - if enumClass or values is nullIllegalArgumentException - if enumClass is not an enum class, or if any values nullpublic 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.
E - the type of the enumerationenumClass - the class of the enum we are working with, not nullvalues - the values we want to convert, not nullNullPointerException - if enumClass or values is nullIllegalArgumentException - if enumClass is not an enum class or has more than 64 valuesgenerateBitVectors(Class, Iterable)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 many 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 nullNullPointerException - if enumClass or values is nullIllegalArgumentException - if enumClass is not an enum class, or if any values nullpublic static <E extends Enum<E>> EnumSet<E> processBitVector(Class<E> enumClass, long value)
Convert a long value created by generateBitVector(java.lang.Class<E>, java.lang.Iterable<? extends 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 valuesNullPointerException - if enumClass is nullIllegalArgumentException - if enumClass is not an enum class or has more than 64 valuespublic static <E extends Enum<E>> EnumSet<E> processBitVectors(Class<E> enumClass, long... values)
Convert a long[] created by generateBitVectors(java.lang.Class<E>, java.lang.Iterable<? extends 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, least significant digits rightmost, not nullNullPointerException - if enumClass is nullIllegalArgumentException - if enumClass is not an enum classCopyright © 2019. All rights reserved.