List of utility methods to do EnumSet Usage
void | awaitThreadState(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() + ")"); ... |
EnumSet | copyOf(Collection copy Of if (src.isEmpty()) { return EnumSet.noneOf(type); } else { return EnumSet.copyOf(src); |
Set | deepCloneEnumSet(final EnumSet set) deepCloneEnumSet if (set == null) { return null; return set.clone(); |
int | encode(EnumSet encode int ret = 0; for (E val : set) { ret |= 1 << val.ordinal(); return ret; |
List | extractTypes(final Class 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; |
T | findEnumIgnoreCase(Class find Enum Ignore Case for (T value : EnumSet.allOf(enumClass)) if (value.toString().equalsIgnoreCase(string)) return value; return defValue; |
HashMap | getDataFromEnum(Class 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; |
HashMap | getDataInEnumClass(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>(); |
Enum | getEnumFromString(Class 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; ... |
List> | nativeLoadEnumDefaultValues(Class 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; |