Class EnumStringArgumentType<T extends Enum<T>>
java.lang.Object
net.sourceforge.argparse4j.impl.type.EnumStringArgumentType<T>
- Type Parameters:
T- Type of enum
- All Implemented Interfaces:
ArgumentType<T>, MetavarInference
public 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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconvert(ArgumentParser parser, Argument arg, String value) Convertsvalueto appropriate type.static <T extends Enum<T>>
EnumStringArgumentType<T> Creates anEnumStringArgumentTypefor the given enum type.String[]Infers metavar based on given type.
-
Field Details
-
type_
-
-
Constructor Details
-
EnumStringArgumentType
-
-
Method Details
-
forEnum
Creates an
EnumStringArgumentTypefor the given enum type.- Type Parameters:
T- The type of the enum- Parameters:
type- type of the enum theEnumStringArgumentTypeshould convert to- Returns:
- an
EnumStringArgumentTypethat converts Strings totype
-
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.
-
inferMetavar
Infers metavar based on given type.
The inferred metavar contains all enum constant string representation, obtained by calling their
Object.toString()method.- Specified by:
inferMetavarin interfaceMetavarInference- Returns:
- inferred array of metavar strings, or null if there is no metavar inferred.
- Since:
- 0.7.0
- See Also:
-