Java Utililty Methods EnumSet Usage

List of utility methods to do EnumSet Usage

Description

The list of methods to do EnumSet Usage are organized into topic(s).

Method

voidawaitThreadState(Thread thread, long maxWaitMillis, Thread.State first, Thread.State... rest)
await Thread State
EnumSet<Thread.State> set = EnumSet.of(first, rest);
long deadline = maxWaitMillis + System.currentTimeMillis();
Thread.State currentState;
do {
    currentState = thread.getState();
    if (System.currentTimeMillis() > deadline) {
        throw new AssertionError("Timed out waiting for thread state of <" + set + ">: " + thread
                + " (state = " + thread.getState() + ")");
...
EnumSetcopyOf(Collection src, Class type)
copy Of
if (src.isEmpty()) {
    return EnumSet.noneOf(type);
} else {
    return EnumSet.copyOf(src);
SetdeepCloneEnumSet(final EnumSet set)
deepCloneEnumSet
if (set == null) {
    return null;
return set.clone();
intencode(EnumSet set)
encode
int ret = 0;
for (E val : set) {
    ret |= 1 << val.ordinal();
return ret;
List>extractTypes(final Class type)
A convenient method for extracting type information from all enum value for a specified enum type.
final List<Class<?>> result = new ArrayList<>();
result.add(type);
final EnumSet<E> mnemonicEnumSet = EnumSet.allOf(type);
for (final E value : mnemonicEnumSet) {
    result.add(value.getClass());
return result;
TfindEnumIgnoreCase(Class enumClass, String string, T defValue)
find Enum Ignore Case
for (T value : EnumSet.allOf(enumClass))
    if (value.toString().equalsIgnoreCase(string))
        return value;
return defValue;
HashMapgetDataFromEnum(Class enumClass)
This method return all enums in class.
HashMap<String, String> enumValues = new HashMap<String, String>();
for (E enumField : EnumSet.allOf(enumClass)) {
    String key = enumField.name();
    String value = enumField.toString();
    enumValues.put(key, value);
return enumValues;
HashMapgetDataInEnumClass(String enumClassName)
get Data In Enum Class
try {
    @SuppressWarnings("rawtypes")
    Class clazz = Class.forName(enumClassName);
    if (clazz.isEnum()) {
        return getDataFromEnum(clazz);
} catch (ClassNotFoundException e) {
return new HashMap<String, String>();
EnumgetEnumFromString(Class enumClass, String enumValue, boolean compareByValue)
This method return Enum which name values is equals to String, which is given as parameter.
if (enumClass == null || enumValue == null || enumValue.isEmpty()) {
    throw new IllegalArgumentException(
            "Class shouldn't be null and value to compare shouldn't be null or empty.");
for (E enumField : EnumSet.allOf(enumClass)) {
    if (compareByValue) {
        if (enumField.toString().equalsIgnoreCase(enumValue)) {
            return enumField;
...
ListnativeLoadEnumDefaultValues(Class enumType)
native Load Enum Default Values
List<?> result = null;
EnumSet values = (enumType != null ? EnumSet.allOf(enumType) : null);
if (values != null) {
    result = new ArrayList();
    result.addAll(values);
return result;