List of utility methods to do Reflection Enum
List> | getEnumConstants(Class> c) Returns all Enum Constants in an Enum return Arrays.asList(c.getEnumConstants());
|
String[] | getEnumNames(Class extends Enum>> e) get Enum Names return Arrays.toString(e.getEnumConstants()).replaceAll("\\[|]", "").split(", "); |
List | getEnumValues(Class It will parse the given Class as Enum , returns the list of values of given Enum if (isEnum(type)) { Class<Enum> enumClass = (Class<Enum>) type; List<String> values = new ArrayList<>(enumClass.getEnumConstants().length); for (Enum anEnum : enumClass.getEnumConstants()) { values.add(anEnum.name()); return values; } else { ... |
Map | getOptionsFromEnum(Class extends Enum>> enumClass) Get the label and value for select options of forms from the given enum class. Map<String, String> map = new HashMap<String, String>(); Enum<?>[] enumConstants = enumClass.getEnumConstants(); for (Enum<?> enumConstant : enumConstants) { map.put(enumConstant.toString(), getLabel(enumConstant.toString())); return map; |
boolean | isLegalEnum(Class clazz, Object enuValue) is Legal Enum boolean result = false; if (null == clazz || null == enuValue) { return result; if (clazz.isEnum()) { Enum[] enums = (Enum[]) clazz.getEnumConstants(); if (!isEmpty(enums)) { if (enuValue instanceof Enum) { ... |
Type | toEnum(Class to Enum try { return Type.valueOf(e, s); } catch (IllegalArgumentException ex) { return null; } catch (NullPointerException ex) { return null; |
String[] | toStrings(Class> clenum) to Strings synchronized (strings) { String[] result = strings.get(clenum); if (result == null) { try { Enum<?>[] values = (Enum<?>[]) clenum.getMethod("values").invoke(null); result = new String[values.length]; for (int i = 0; i < values.length; i++) { result[i] = values[i].toString(); ... |