Class BooleanArgumentType

java.lang.Object
net.sourceforge.argparse4j.impl.type.BooleanArgumentType
All Implemented Interfaces:
ArgumentType<Boolean>, MetavarInference

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.

Since:
0.7.0
  • Field Details

    • trueValue_

      private final String trueValue_
    • falseValue_

      private final String falseValue_
  • Constructor Details

    • BooleanArgumentType

      public BooleanArgumentType()
      Creates BooleanArgumentType with "true" as true value, and "false" as false value.
    • BooleanArgumentType

      public BooleanArgumentType(String trueValue, String falseValue)
      Creates BooleanArgumentType with given values.
      Parameters:
      trueValue - string used as true value
      falseValue - string used as false value
  • Method Details