public class BooleanArgumentType extends Object implements 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.
Constructor and Description |
---|
BooleanArgumentType()
Creates BooleanArgumentType with "true" as true value, and "false" as
false value.
|
BooleanArgumentType(String trueValue,
String falseValue)
Creates BooleanArgumentType with given values.
|
Modifier and Type | Method and Description |
---|---|
Boolean |
convert(ArgumentParser parser,
Argument arg,
String value)
Converts
value to appropriate type. |
String[] |
inferMetavar()
Infers metavar based on given strings.
|
public BooleanArgumentType()
public Boolean 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<Boolean>
parser
- The parser.arg
- The argument this type attached to.value
- The attribute value.ArgumentParserException
- If conversion fails.public String[] inferMetavar()
Infers metavar based on given strings.
inferMetavar
in interface MetavarInference
MetavarInference.inferMetavar()
Copyright © 2012–2017. All rights reserved.