Class CaseInsensitiveEnumArgumentType<T extends Enum<T>>
- All Implemented Interfaces:
ArgumentType<T>,MetavarInference
- Direct Known Subclasses:
CaseInsensitiveEnumNameArgumentType,CaseInsensitiveEnumStringArgumentType
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionDeprecated.Use one of the subclasses, which always convert case correctly.protectedCaseInsensitiveEnumArgumentType(Class<T> type, Locale lowerCasingLocale) Create an instance. -
Method Summary
Modifier and TypeMethodDescriptionconvert(ArgumentParser parser, Argument arg, String value) Convertsvalueto appropriate type.protected Object[]Get the objects to be used to generate the String representations of all enum constants.String[]Infers metavar based on given type.private StringtoCaseInsensitiveForm(String value) Get the String representation of the given value.protected StringConvert the given enum value to its string representation.
-
Field Details
-
type_
-
lowerCasingLocale_
-
-
Constructor Details
-
CaseInsensitiveEnumArgumentType
Deprecated.Use one of the subclasses, which always convert case correctly.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.
- Parameters:
type- the enum type.
-
CaseInsensitiveEnumArgumentType
Create an instance.
- Parameters:
type- the enum type.lowerCasingLocale- the locale to use for converting to lower case. Sub classes should always passLocale.ROOT.- Since:
- 0.8.0
-
-
Method Details
-
convert
Description copied from interface:ArgumentTypeConverts
valueto appropriate type.If the objects derived from
RuntimeExceptionare thrown in conversion because of invalid input from command line, subclass must catch these exceptions and wrap them inArgumentParserExceptionand give simple error message to explain what happened briefly.- Specified by:
convertin interfaceArgumentType<T extends Enum<T>>- Parameters:
parser- The parser.arg- The argument this type attached to.value- The attribute value.- Returns:
- Converted object.
- Throws:
ArgumentParserException- If conversion fails.
-
toStringRepresentation
Convert the given enum value to its string representation.
- Parameters:
t- the enum value to convert.- Returns:
- the string representation of
t. - Since:
- 0.8.0
-
inferMetavar
Infers metavar based on given type.
The inferred metavar contains all enum constant string representation.
- Specified by:
inferMetavarin interfaceMetavarInference- Returns:
- inferred array of metavar strings, or null if there is no metavar inferred.
- Since:
- 0.7.0
- See Also:
-
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.- Returns:
- The objects used to generate String representations.
- Since:
- 0.8.0
-
toCaseInsensitiveForm
Get the String representation of the given value.- Parameters:
value- The value for which to get the String representation.- Returns:
- The String representation of
value.
-