public class EnumStringParser<E extends Enum<E>> extends StringParser
StringParser that makes the user choose among
items of a Java enum.
Optionally, parsed strings can be normalized to upper case. Thus, if the enum elements are defined in uppercase, the parser will be in practice case-independent.
A typical usage example for an ExampleEnum with an item A that is going to be the default:
new FlaggedOption("example",
EnumStringParser.getParser(ExampleEnum.class, true),
ExampleEnum.A.name(), JSAP.NOT_REQUIRED, 'e', "example",
Arrays.toString(ExampleEnum.values()))
| Modifier and Type | Method and Description |
|---|---|
static <E extends Enum<E>> |
getParser(Class<E> enumClass)
Returns an enum parser that does not normalize to upper case.
|
static <E extends Enum<E>> |
getParser(Class<E> enumClass,
boolean toUpper)
Returns an enum parser.
|
E |
parse(String s)
Returns the enum item obtained by passing the argument to
Enum.valueOf(Class, String). |
setUp, tearDownpublic E parse(String s) throws ParseException
Enum.valueOf(Class, String).parse in class StringParsers - an enum item name.Enum.valueOf(Class, String) (possibly
after upper casing s).ParseExceptionpublic static <E extends Enum<E>> EnumStringParser<E> getParser(Class<E> enumClass, boolean toUpper) throws IllegalArgumentException
enumClass - an enum class whose valuestoUpper - tells the parser to upper case the strings to be parsed.IllegalArgumentExceptionpublic static <E extends Enum<E>> EnumStringParser<E> getParser(Class<E> enumClass) throws IllegalArgumentException
enumClass - an enum class whose valuesIllegalArgumentException