public class EnumUtils extends Object
| Constructor and Description |
|---|
EnumUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <E> Map<String,E> |
createNames(E[] values)
Creates a lookup map for the enum names, intended for use with the
fromString(Map, String) method. |
static <E> E |
fromString(Map<String,E> names,
String name)
Creates an enum value from a string using a lookup map (usually created
by
createNames(Object[]). |
public static <E> E fromString(Map<String,E> names, String name)
createNames(Object[]).
Typical implementation:
public static MyEnum fromString(String name) {
return EnumUtils.fromString(names, name);
}
null, returns null.IllegalArgumentException - if the name is not
null and does not match any enum value.public static <E> Map<String,E> createNames(E[] values)
fromString(Map, String) method. It uses the Object.toString()
method to build the lookup map. This is intended to be used in a static
initializer.
private static Map<String, MyEnum> names;
static {
names = EnumUtils.createNames(values());
}
values - The enum values, as provided by values().Copyright © 2015 EVRYTHNG Ltd London / Zurich. All rights reserved.