E
- Enum that will make use of this helper classpublic class EnumValueOfHelper<E extends Enum<E>> extends Object
EnumValueOfHelper.valueOf(String)
method as a replacement for the implicitly declared enum function
valueOf(String)
, which has the advantage of not throwing exceptions when the name
argument
is null
or cannot be found in the enum's values. The EnumValueOfHelper.valueOf(String)
method performs a
case-insensitive lookup of a corresponding enum name
, and a default value can be specified for when
there is no matching name
.
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 and Description |
---|
EnumValueOfHelper(E[] values)
Constructor with
null default value. |
EnumValueOfHelper(E[] values,
E defaultValue)
Constructor with an explicit default value.
|
public EnumValueOfHelper(E[] values)
null
default value.values
- One or more enum valuesCopyright © 2010-2018, ForgeRock All Rights Reserved.