public class CaseInsensitiveEnumArgumentType<T extends Enum<T>> extends Object implements ArgumentType<T>, MetavarInference
Modifier | Constructor and Description |
---|---|
|
CaseInsensitiveEnumArgumentType(Class<T> type)
Deprecated.
Use one of the subclasses, which always convert case
correctly.
|
protected |
CaseInsensitiveEnumArgumentType(Class<T> type,
Locale lowerCasingLocale)
Create an instance.
|
Modifier and Type | Method and Description |
---|---|
T |
convert(ArgumentParser parser,
Argument arg,
String value)
Converts
value to appropriate type. |
protected Object[] |
getStringRepresentations()
Get the objects to be used to generate the String representations of all
enum constants.
|
String[] |
inferMetavar()
Infers metavar based on given type.
|
protected String |
toStringRepresentation(T t)
Convert the given enum value to its string representation.
|
@Deprecated public CaseInsensitiveEnumArgumentType(Class<T> type)
Do not use. This constructor creates a case insensitive enum name argument type, but converts the enum names and the values passed on the command line to lower case in a way that depends on the current user locale. This may result in values not matching an enum name if the program is run by a user with a different locale.
type
- the enum type.protected CaseInsensitiveEnumArgumentType(Class<T> type, Locale lowerCasingLocale)
Create an instance.
type
- the enum type.lowerCasingLocale
- the locale to use for converting to lower case. Sub classes
should always pass Locale.ROOT
.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.protected String toStringRepresentation(T t)
Convert the given enum value to its string representation.
t
- the enum value to convert.t
.public String[] inferMetavar()
Infers metavar based on given type.
The inferred metavar contains all enum constant string representation.
inferMetavar
in interface MetavarInference
MetavarInference.inferMetavar()
protected Object[] getStringRepresentations()
Get the objects to be used to generate the String representations of all
enum constants. Object.toString()
will be invoked on these
objects to obtain the actual String representation.
Copyright © 2012–2017. All rights reserved.