Java Utililty Methods EnumSet Usage

List of utility methods to do EnumSet Usage

  1. HOME
  2. Java
  3. E
  4. EnumSet Usage

Description

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

Method

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 src, Class type)
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 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;
T findEnumIgnoreCase(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;
HashMap getDataFromEnum(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;
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 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;
...
List nativeLoadEnumDefaultValues(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;


AltStyle によって変換されたページ (->オリジナル) /