Class EnumStringParser<E extends Enum<E>>
java.lang.Object
com.martiansoftware.jsap.StringParser
it.unimi.dsi.lang.EnumStringParser<E>
A
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()))
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends Enum<E>>
EnumStringParser<E> Returns an enum parser that does not normalize to upper case.static <E extends Enum<E>>
EnumStringParser<E> Returns an enum parser.Returns the enum item obtained by passing the argument toEnum.valueOf(Class, String).Methods inherited from class com.martiansoftware.jsap.StringParser
setUp, tearDown
-
Method Details
-
parse
Returns the enum item obtained by passing the argument toEnum.valueOf(Class, String).- Specified by:
parsein classcom.martiansoftware.jsap.StringParser- Parameters:
s- an enum item name.- Returns:
- the enum item returned by
Enum.valueOf(Class, String)(possibly after upper casings). - Throws:
com.martiansoftware.jsap.ParseException
-
getParser
public static <E extends Enum<E>> EnumStringParser<E> getParser(Class<E> enumClass, boolean toUpper) throws IllegalArgumentException Returns an enum parser.- Parameters:
enumClass- anenumclass whose valuestoUpper- tells the parser to upper case the strings to be parsed.- Throws:
IllegalArgumentException
-
getParser
public static <E extends Enum<E>> EnumStringParser<E> getParser(Class<E> enumClass) throws IllegalArgumentException Returns an enum parser that does not normalize to upper case.- Parameters:
enumClass- anenumclass whose values- Throws:
IllegalArgumentException
-