Class BooleanArgumentType
- All Implemented Interfaces:
ArgumentType<Boolean>
,MetavarInference
BooleanArgumentType provides strict conversion from input string to Boolean value.
Passing Boolean
class to Argument.type(Class)
can achieve
boolean conversion as well, but its conversion relies on
Boolean.valueOf(String)
. That is any strings which matches "true" in
case-insensitive fashion are converted to Boolean.TRUE
. The other
strings are converted to Boolean.FALSE
.
On the other hand, BooleanArgumentType is strict when conversion is made.
That is only the string which is defined as true value is converted to
Boolean.TRUE
. Similarly, only the string which is defined as false
value is converted to Boolean.FALSE
. The comparison is made in
case-sensitive manner.
When BooleanArgumentType is created by the default constructor,
BooleanArgumentType()
, the true value is "true",
and the false value is "false". Probably, this is the most common use case.
The another constructor,
BooleanArgumentType(String, String)
can take 2
strings, and application can specify what strings are used as true or false
value.
- Since:
- 0.7.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates BooleanArgumentType with "true" as true value, and "false" as false value.BooleanArgumentType
(String trueValue, String falseValue) Creates BooleanArgumentType with given values. -
Method Summary
Modifier and TypeMethodDescriptionconvert
(ArgumentParser parser, Argument arg, String value) Convertsvalue
to appropriate type.String[]
Infers metavar based on given strings.
-
Field Details
-
trueValue_
-
falseValue_
-
-
Constructor Details
-
BooleanArgumentType
public BooleanArgumentType()Creates BooleanArgumentType with "true" as true value, and "false" as false value. -
BooleanArgumentType
Creates BooleanArgumentType with given values.- Parameters:
trueValue
- string used as true valuefalseValue
- string used as false value
-
-
Method Details
-
convert
public Boolean convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException Description copied from interface: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 inArgumentParserException
and give simple error message to explain what happened briefly.- Specified by:
convert
in interfaceArgumentType<Boolean>
- 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 strings.
- Specified by:
inferMetavar
in interfaceMetavarInference
- Returns:
- inferred array of metavar strings, or null if there is no metavar inferred.
- See Also:
-