T
- Type of enumpublic class EnumStringArgumentType<T extends Enum<T>> extends Object implements ArgumentType<T>, MetavarInference
ArgumentType subclass for enum type.
Uses Enum.toString()
instead of Enum.name()
as the String
representation of the enum. For enums that do not override Enum.toString()
,
this behaves the same as ReflectArgumentType
.
Constructor and Description |
---|
EnumStringArgumentType(Class<T> type) |
Modifier and Type | Method and Description |
---|---|
T |
convert(ArgumentParser parser,
Argument arg,
String value)
Converts
value to appropriate type. |
static <T extends Enum<T>> |
forEnum(Class<T> type)
Creates an
EnumStringArgumentType for the given enum type. |
String[] |
inferMetavar()
Infers metavar based on given type.
|
public static <T extends Enum<T>> EnumStringArgumentType<T> forEnum(Class<T> type)
Creates an EnumStringArgumentType
for the given enum type.
type
- type of the enum the EnumStringArgumentType
should convert toEnumStringArgumentType
that converts Strings to type
public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException
ArgumentType
Converts value
to appropriate type.
If the objects derived from RuntimeException
are thrown in
conversion because of invalid input from command line, subclass must
catch these exceptions and wrap them in ArgumentParserException
and give simple error message to explain what happened briefly.
convert
in interface ArgumentType<T extends Enum<T>>
parser
- The parser.arg
- The argument this type attached to.value
- The attribute value.ArgumentParserException
- If conversion fails.public String[] inferMetavar()
Infers metavar based on given type.
The inferred metavar contains all enum constant string representation,
obtained by calling their Object.toString()
method.
inferMetavar
in interface MetavarInference
MetavarInference.inferMetavar()
Copyright © 2012–2017. All rights reserved.