public class BooleanParam extends AbstractParameter<Boolean> implements OptionTakesNoValue
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()) {
....
}
CmdLineParseracceptableValues, desc, hidden, ignoreRequired, multiValued, optional, optionLabel, set, tag, valuesHIDDEN, MULTI_VALUED, OPTIONAL, PUBLIC, REQUIRED, SINGLE_VALUED| Constructor and Description |
|---|
BooleanParam(String tag,
String desc)
constructor - creates a public boolean parameter
|
BooleanParam(String tag,
String desc,
boolean hidden)
constructor - creates a boolean parameter that is public or hidden, as
specified
|
| Modifier and Type | Method and Description |
|---|---|
void |
addValue(Boolean value)
Replaces any current value with that specified.
|
Boolean |
convertValue(String strVal)
Converts a String value to the type associated with the Parameter.
|
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.
|
addStringValue, getAcceptableValues, getDesc, getIgnoreRequired, getOptionLabel, getTag, getValue, getValues, isHidden, isMultiValued, isOptional, isSet, setAcceptableValues, setAcceptableValues, setDesc, setHidden, setIgnoreRequired, setMultiValued, setOptional, setOptionLabel, setTag, setValue, setValues, setValues, validateValuepublic BooleanParam(String tag, String desc)
tag - a unique identifier for this parameterdesc - a description of the parameter, suitable for display in a
usage statementIllegalArgumentException - if any specified parameter is invalid.setTag(),
setDesc()public BooleanParam(String tag, 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.IllegalArgumentException - if any specified parameter is invalid.setTag(),
setDesc(),
HIDDEN,
PUBLICpublic void addValue(Boolean value) throws CmdLineException
addValue in interface Parameter<Boolean>addValue in class AbstractParameter<Boolean>value - the value to be addedCmdLineException - 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 Boolean convertValue(String strVal) throws CmdLineException
AbstractParameterconvertValue in class AbstractParameter<Boolean>strVal - the String value of the ParameterCmdLineException - if the conversion cannot be madeAbstractParameter.convertValue(java.lang.String)public String getDefaultValue()
getDefaultValue in interface OptionTakesNoValueBoolean.TRUEOptionTakesNoValuepublic boolean isTrue()
Copyright © 2017. All rights reserved.