Java EnumSet Usage getDataFromEnum(Class enumClass)

Here you can find the source of getDataFromEnum(Class enumClass)

Description

This method return all enums in class.

License

Open Source License

Parameter

Parameter Description
enumClass from which will be extracted enums.

Return

HashMap of value in enum. Key is enum name and concrete value is Enum.toString() result.

Declaration

private static <E extends Enum<E>> HashMap<String, String> getDataFromEnum(Class<E> enumClass) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.EnumSet;
import java.util.HashMap;

public class Main {
    /**/*from www  . j ava 2 s .c  om*/
     * This method return all enums in class.
     * @param enumClass from which will be extracted enums.
     * @return HashMap of value in enum. Key is enum name and concrete value is Enum.toString() result.
     */
    private static <E extends Enum<E>> HashMap<String, String> getDataFromEnum(Class<E> enumClass) {
        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;
    }
}

Related

  1. copyOf(Collection src, Class type)
  2. deepCloneEnumSet(final EnumSet set)
  3. encode(EnumSet set)
  4. extractTypes(final Class type)
  5. findEnumIgnoreCase(Class enumClass, String string, T defValue)
  6. getDataInEnumClass(String enumClassName)
  7. getEnumFromString(Class enumClass, String enumValue, boolean compareByValue)
  8. nativeLoadEnumDefaultValues(Class enumType)
  9. nextEnum(T ce)