Package org.forgerock.util
Class EnumValueOfHelper<E extends Enum<E>>
- java.lang.Object
 - 
- org.forgerock.util.EnumValueOfHelper<E>
 
 
- 
- Type Parameters:
 E- Enum that will make use of this helper class
public class EnumValueOfHelper<E extends Enum<E>> extends Object
Provides avalueOf(String)method as a replacement for the implicitly declared enum functionvalueOf(String), which has the advantage of not throwing exceptions when thenameargument isnullor cannot be found in the enum's values. ThevalueOf(String)method performs a case-insensitive lookup of a corresponding enumname, and a default value can be specified for when there is no matchingname.Usage:
public enum Pet { CAT, DOG; private static final EnumValueOfHelper<Pets> helper = new EnumValueOfHelper<>(values(), DOG); public static Pet getPet(final String name) { return helper.valueOf(name); } } 
- 
- 
Constructor Summary
Constructors Constructor Description EnumValueOfHelper(E[] values)Constructor withnulldefault value.EnumValueOfHelper(E[] values, E defaultValue)Constructor with an explicit default value. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EvalueOf(String name)Fast lookup ofEnumValueOfHelperby itsname. 
 - 
 
- 
- 
Constructor Detail
- 
EnumValueOfHelper
public EnumValueOfHelper(E[] values)
Constructor withnulldefault value.- Parameters:
 values- One or more enum values
 
 - 
 
- 
Method Detail
- 
valueOf
public E valueOf(String name)
Fast lookup ofEnumValueOfHelperby itsname.- Parameters:
 name- Case-insensitive name of an enum value, ornull- Returns:
 - Requested value or the default value if not found
 
 
 - 
 
 -