jcmdline
Class BooleanParam

java.lang.Object
  extended byjcmdline.AbstractParameter
      extended byjcmdline.BooleanParam
All Implemented Interfaces:
OptionTakesNoValue, Parameter

public class BooleanParam
extends AbstractParameter
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. 1.0.3 $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.String value)
          Sets the specified string as a value for this BooleanParam.
 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.
 void validateValue(java.lang.String value)
          Verifies that value is either "true" or "false" - called by add/setValue(s)().
 
Methods inherited from class jcmdline.AbstractParameter
getAcceptableValues, getDesc, getIgnoreRequired, getOptionLabel, getTag, getValue, getValues, isHidden, isMultiValued, isOptional, isSet, setAcceptableValues, setAcceptableValues, setDesc, setHidden, setIgnoreRequired, setMultiValued, setOptional, setOptionLabel, setTag, setValue, setValues, setValues
 
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.String value)
              throws CmdLineException
Sets the specified string as a value for this BooleanParam. Any previously set value will be discarded.

Specified by:
addValue in interface Parameter
Overrides:
addValue in class AbstractParameter
Parameters:
value - the value to be set
Throws:
CmdLineException - if validateValue() detects a problem.

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 default value of this Parameter
See Also:
OptionTakesNoValue

isTrue

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

Returns:
the parameter value as a boolean

validateValue

public void validateValue(java.lang.String value)
                   throws CmdLineException
Verifies that value is either "true" or "false" - called by add/setValue(s)().

Specified by:
validateValue in interface Parameter
Overrides:
validateValue in class AbstractParameter
Parameters:
value - the value to be validated
Throws:
CmdLineException - if value is not valid.