|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjcmdline.AbstractParameter<java.lang.Boolean>
jcmdline.BooleanParam
public class BooleanParam
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()) { .... }
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 |
---|
public BooleanParam(java.lang.String tag, java.lang.String desc)
tag
- a unique identifier for this parameterdesc
- a description of the parameter, suitable for display in a
usage statement
java.lang.IllegalArgumentException
- if any specified parameter is invalid.setTag()
,
setDesc()
public BooleanParam(java.lang.String tag, java.lang.String desc, boolean hidden)
tag
- a unique identifier for this parameterdesc
- a description of the parameter, suitable for display in a
usage statementhidden
- HIDDEN
if parameter is not to be
listed in the usage, PUBLIC
otherwise.
java.lang.IllegalArgumentException
- if any specified parameter is invalid.setTag()
,
setDesc()
,
HIDDEN
,
PUBLIC
Method Detail |
---|
public void addValue(java.lang.Boolean value) throws CmdLineException
addValue
in interface Parameter<java.lang.Boolean>
addValue
in class AbstractParameter<java.lang.Boolean>
value
- the value to be added
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.AbstractParameter.addValue(java.lang.Object)
public java.lang.Boolean convertValue(java.lang.String strVal) throws CmdLineException
AbstractParameter
convertValue
in class AbstractParameter<java.lang.Boolean>
strVal
- the String value of the Parameter
CmdLineException
- if the conversion cannot be madeAbstractParameter.convertValue(java.lang.String)
public java.lang.String getDefaultValue()
getDefaultValue
in interface OptionTakesNoValue
Boolean.TRUE
OptionTakesNoValue
public boolean isTrue()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |