jcmdline
Class BooleanParam

java.lang.Object
  extended by jcmdline.AbstractParameter<java.lang.Boolean>
      extended by jcmdline.BooleanParam
All Implemented Interfaces:
OptionTakesNoValue, Parameter<java.lang.Boolean>

public class BooleanParam
extends AbstractParameter<java.lang.Boolean>
implements OptionTakesNoValue

Encapsulate a boolean command line parameter. This parameter defaults to "false" if not set by the user.

Sample usage:

    BooleanParam deleteOpt =
        new BooleanParam("delete", "delete original file");
    FileParam outfileOpt =
        new FileParam("outfile", "the outfile file - defaults to stdout",
                      FileParam.DOESNT_EXIST);
    FileParam infileArg =
        new FileParam("infile", "the input file - defaults to stdin",
                      FileParam.IS_READABLE & FileParam.IS_FILE);
    CmdLineHandler clh = new DefaultCmdLineHandler(
        "filter",
        "filters files for obscenities",
        new Parameter[] { deleteOpt, outfileOpt },
        new Parameter[] { infileArg }
    );
    clh.parse(args);
    if (deleteOpt.isTrue()) {
        ....
    }
 

Version:
jcmdline Rel. 2.0.0 $Id: BooleanParam.java,v 1.2 2002/12/07 14:22:06 lglawrence Exp $
Author:
Lynne Lawrence
See Also:
CmdLineParser

Field Summary
 
Fields inherited from class jcmdline.AbstractParameter
acceptableValues, desc, hidden, ignoreRequired, multiValued, optional, optionLabel, set, tag, values
 
Fields inherited from interface jcmdline.Parameter
HIDDEN, MULTI_VALUED, OPTIONAL, PUBLIC, REQUIRED, SINGLE_VALUED
 
Constructor Summary
BooleanParam(java.lang.String tag, java.lang.String desc)
          constructor - creates a public boolean parameter
BooleanParam(java.lang.String tag, java.lang.String desc, boolean hidden)
          constructor - creates a boolean parameter that is public or hidden, as specified
 
Method Summary
 void addValue(java.lang.Boolean value)
          Replaces any current value with that specified.
 java.lang.Boolean convertValue(java.lang.String strVal)
          Converts a String value to the type associated with the Parameter.
 java.lang.String getDefaultValue()
          Gets the default value of this Parameter when used as a command line option, and specified just by its tag.
 boolean isTrue()
          Returns the value of the parameter as a boolean.
 
Methods inherited from class jcmdline.AbstractParameter
addStringValue, getAcceptableValues, getDesc, getIgnoreRequired, getOptionLabel, getTag, getValue, getValues, isHidden, isMultiValued, isOptional, isSet, setAcceptableValues, setAcceptableValues, setDesc, setHidden, setIgnoreRequired, setMultiValued, setOptional, setOptionLabel, setTag, setValue, setValues, setValues, validateValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BooleanParam

public BooleanParam(java.lang.String tag,
                    java.lang.String desc)
constructor - creates a public boolean parameter

Parameters:
tag - a unique identifier for this parameter
desc - a description of the parameter, suitable for display in a usage statement
Throws:
java.lang.IllegalArgumentException - if any specified parameter is invalid.
See Also:
setTag(), setDesc()

BooleanParam

public BooleanParam(java.lang.String tag,
                    java.lang.String desc,
                    boolean hidden)
constructor - creates a boolean parameter that is public or hidden, as specified

Parameters:
tag - a unique identifier for this parameter
desc - a description of the parameter, suitable for display in a usage statement
hidden - HIDDEN if parameter is not to be listed in the usage, PUBLIC otherwise.
Throws:
java.lang.IllegalArgumentException - if any specified parameter is invalid.
See Also:
setTag(), setDesc(), HIDDEN, PUBLIC
Method Detail

addValue

public void addValue(java.lang.Boolean value)
              throws CmdLineException
Replaces any current value with that specified.

Specified by:
addValue in interface Parameter<java.lang.Boolean>
Overrides:
addValue in class AbstractParameter<java.lang.Boolean>
Parameters:
value - the value to be added
Throws:
CmdLineException - if the value of the entity has already been set and multiValued is not true, or if the validation provided by the implementing class fails.
See Also:
AbstractParameter.addValue(java.lang.Object)

convertValue

public java.lang.Boolean convertValue(java.lang.String strVal)
                               throws CmdLineException
Description copied from class: AbstractParameter
Converts a String value to the type associated with the Parameter. All non-abstract subclasses must implement this method.

Specified by:
convertValue in class AbstractParameter<java.lang.Boolean>
Parameters:
strVal - the String value of the Parameter
Returns:
the parameter value converted to the Object type with which the Parameter is associated
Throws:
CmdLineException - if the conversion cannot be made
See Also:
AbstractParameter.convertValue(java.lang.String)

getDefaultValue

public java.lang.String getDefaultValue()
Gets the default value of this Parameter when used as a command line option, and specified just by its tag.

Specified by:
getDefaultValue in interface OptionTakesNoValue
Returns:
the String value of Boolean.TRUE
See Also:
OptionTakesNoValue

isTrue

public boolean isTrue()
Returns the value of the parameter as a boolean.

Returns:
the parameter value as a boolean