Class CaseInsensitiveEnumArgumentType<T extends java.lang.Enum<T>>
- java.lang.Object
-
- net.sourceforge.argparse4j.impl.type.CaseInsensitiveEnumArgumentType<T>
-
- All Implemented Interfaces:
ArgumentType<T>,MetavarInference
- Direct Known Subclasses:
CaseInsensitiveEnumNameArgumentType,CaseInsensitiveEnumStringArgumentType
public class CaseInsensitiveEnumArgumentType<T extends java.lang.Enum<T>> extends java.lang.Object implements ArgumentType<T>, MetavarInference
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.LocalelowerCasingLocale_protected java.lang.Class<T>type_
-
Constructor Summary
Constructors Modifier Constructor Description CaseInsensitiveEnumArgumentType(java.lang.Class<T> type)Deprecated.Use one of the subclasses, which always convert case correctly.protectedCaseInsensitiveEnumArgumentType(java.lang.Class<T> type, java.util.Locale lowerCasingLocale)Create an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tconvert(ArgumentParser parser, Argument arg, java.lang.String value)Convertsvalueto appropriate type.protected java.lang.Object[]getStringRepresentations()Get the objects to be used to generate the String representations of all enum constants.java.lang.String[]inferMetavar()Infers metavar based on given type.private java.lang.StringtoCaseInsensitiveForm(java.lang.String value)Get the String representation of the given value.protected java.lang.StringtoStringRepresentation(T t)Convert the given enum value to its string representation.
-
-
-
Constructor Detail
-
CaseInsensitiveEnumArgumentType
@Deprecated public CaseInsensitiveEnumArgumentType(java.lang.Class<T> type)
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
protected CaseInsensitiveEnumArgumentType(java.lang.Class<T> type, java.util.Locale lowerCasingLocale)
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 Detail
-
convert
public T convert(ArgumentParser parser, Argument arg, java.lang.String value) throws ArgumentParserException
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 java.lang.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
protected java.lang.String toStringRepresentation(T t)
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
public java.lang.String[] 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:
MetavarInference.inferMetavar()
-
getStringRepresentations
protected java.lang.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.- Returns:
- The objects used to generate String representations.
- Since:
- 0.8.0
-
toCaseInsensitiveForm
private java.lang.String toCaseInsensitiveForm(java.lang.String value)
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.
-
-