public class StringParam extends AbstractParameter<String>
Usage:
public class Sample {
public static void main(String[] args) {
// command line arguments
StringParam patternArg =
new StringParam("pattern", "the pattern to match",
StringParam.REQUIRED);
// other param definitions omitted
.
.
CmdLineHandler cl =
new VersionCmdLineHandler("V 5.2",
new HelpCmdLineHandler(helpText,
"kindagrep",
"find lines in files containing a specified pattern",
new Parameter[] { ignorecaseOpt, listfilesOpt },
new Parameter[] { patternArg, filesArg } ));
cl.parse(args);
.
.
// don't need to check patternArg.isSet() because is REQUIRED
String pattern = patternArg.getValue();
CmdLineParser| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_OPTION_LABEL
the default label that will represent option values for this Parameter
when displaying usage.
|
protected int |
maxValLen
the maximum acceptable string length for the parameter value - if not
specified, defaults to StringParam.UNSPECIFIED_LENGTH, which permits the
value to be any length.
|
protected int |
minValLen
the minimum acceptable string length for the parameter value - if not
specified, defaults to 0.
|
static int |
UNSPECIFIED_LENGTH
the value of the minimum or maximum length if they have not been
explicitly specified.
|
acceptableValues, desc, hidden, ignoreRequired, multiValued, optional, optionLabel, set, tag, valuesHIDDEN, MULTI_VALUED, OPTIONAL, PUBLIC, REQUIRED, SINGLE_VALUED| Constructor and Description |
|---|
StringParam(String tag,
String desc)
constructor - creates single-valued, optional, parameter accepting a
string value of any length
|
StringParam(String tag,
String desc,
boolean optional)
constructor - creates single-valued, parameter accepting a string value
of any length, and either optional or required, as specified.
|
StringParam(String tag,
String desc,
int minValLen,
int maxValLen)
constructor - creates a single-valued, optional, parameter accepting a
value whose length is within the specified minimum and maximum lengths.
|
StringParam(String tag,
String desc,
int minValLen,
int maxValLen,
boolean optional)
constructor - creates a single-valued, parameter accepting a value whose
length is within the specified minimum and maximum lengths, and is
optional or required, as specified.
|
StringParam(String tag,
String desc,
int minValLen,
int maxValLen,
boolean optional,
boolean multiValued)
constructor - creates a single-valued, parameter accepting a value whose
length is within the specified minimum and maximum lengths, and optional
and/or multi-valued, as specified
|
StringParam(String tag,
String desc,
int minValLen,
int maxValLen,
boolean optional,
boolean multiValued,
boolean hidden)
constructor - creates a single-valued, parameter accepting a value whose
length is within the specified minimum and maximum lengths, with all
other options specified.
|
StringParam(String tag,
String desc,
String[] acceptableValues)
constructor - creates a single-valued, optional, string parameter whose
value must be one of the specified values.
|
StringParam(String tag,
String desc,
String[] acceptableValues,
boolean optional)
constructor - creates a single-valued, string parameter whose value must
be a specified value, and which is optional or required, as specified.
|
StringParam(String tag,
String desc,
String[] acceptableValues,
boolean optional,
boolean multiValued)
constructor - creates a string parameter whose value must be a specified
value and is optional and/or * multi-valued, as specified.
|
StringParam(String tag,
String desc,
String[] acceptableValues,
boolean optional,
boolean multiValued,
boolean hidden)
constructor - creates a string parameter whose value must be a specified
value and all other options are as specified.
|
| Modifier and Type | Method and Description |
|---|---|
String |
convertValue(String strVal)
Converts a String value to the type associated with the Parameter.
|
int |
getMaxValLen()
gets the value of the maximum acceptable length for the string value
|
int |
getMinValLen()
gets the value of the minimum acceptable length for the string value
|
void |
setMaxLength(int maxValLen)
Deprecated.
This method deprecated in favor of setMaxValLen(), which is
more in line with the naming convetions used elsewhere in
this class.
|
void |
setMaxValLen(int maxValLen)
sets the value of the maximum acceptable length for the string value
|
void |
setMinValLen(int minValLen)
sets the value of the minimum acceptable length for the string value
|
void |
validateValue(String val)
Validates a prospective value with regards to the minimum and maximum
values and the acceptableValues - called by add/setValue(s)().
|
addStringValue, addValue, getAcceptableValues, getDesc, getIgnoreRequired, getOptionLabel, getTag, getValue, getValues, isHidden, isMultiValued, isOptional, isSet, setAcceptableValues, setAcceptableValues, setDesc, setHidden, setIgnoreRequired, setMultiValued, setOptional, setOptionLabel, setTag, setValue, setValues, setValuespublic static final String DEFAULT_OPTION_LABEL
suffix <s> Specifies the file suffix to use for all output files
produced by this program.
setOptionLabel(),
"StringParam.defaultOptionLabel in 'strings' properties file"public static final int UNSPECIFIED_LENGTH
protected int maxValLen
protected int minValLen
public StringParam(String tag, String desc)
tag - a unique identifier for this parameterdesc - a description of the parameter, suitable for display in a
usage statementIllegalArgumentException - if tag or desc are invalid.setTag(),
setDesc()public StringParam(String tag, String desc, boolean optional)
tag - a unique identifier for this parameterdesc - a description of the parameter, suitable for display in a
usage statementoptional - OPTIONAL if optional,
REQUIRED if requiredIllegalArgumentException - if any of the specified parameters are invalid.setTag(),
setDesc()public StringParam(String tag, String desc, int minValLen, int maxValLen)
tag - a unique identifier for this parameterdesc - a description of the parameter, suitable for display in a
usage statementminValLen - the minimum acceptable lengthmaxValLen - the maximum acceptable length, or a negative number if there
is no maximum length limitIllegalArgumentException - if any parameter is invalid.setTag(),
setDesc(),
setMinValLen(),
setMaxValLen()public StringParam(String tag, String desc, int minValLen, int maxValLen, boolean optional)
tag - a unique identifier for this parameterdesc - a description of the parameter, suitable for display in a
usage statementminValLen - the minimum acceptable lengthmaxValLen - the maximum acceptable length, or a negative number if there
is no maximum length limitoptional - OPTIONAL if optional,
REQUIRED if requiredIllegalArgumentException - if any parameter is invalid.setTag(),
setDesc(),
setMinValLen(),
setMaxValLen(),
OPTIONAL,
REQUIREDpublic StringParam(String tag, String desc, int minValLen, int maxValLen, boolean optional, boolean multiValued)
tag - a unique identifier for this parameterdesc - a description of the parameter, suitable for display in a
usage statementminValLen - the minimum acceptable lengthmaxValLen - the maximum acceptable length, or a negative number if there
is no maximum length limitoptional - OPTIONAL if optional,
REQUIRED if requiredmultiValued - MULTI_VALUED if the parameter
can accept multiple values, SINGLE_VALUED if the parameter can contain only a single
valueIllegalArgumentException - if any parameter is invalid.setTag(),
setDesc(),
setMinValLen(),
setMaxValLen(),
OPTIONAL,
REQUIRED,
SINGLE_VALUED,
MULTI_VALUEDpublic StringParam(String tag, String desc, int minValLen, int maxValLen, boolean optional, boolean multiValued, boolean hidden)
tag - a unique identifier for this parameterdesc - a description of the parameter, suitable for display in a
usage statementminValLen - the minimum acceptable lengthmaxValLen - the maximum acceptable length, or a negative number if there
is no maximum length limitoptional - OPTIONAL if optional,
REQUIRED if requiredmultiValued - MULTI_VALUED if the parameter
can accept multiple values, SINGLE_VALUED if the parameter can contain only a single
valuehidden - HIDDEN if parameter is not to be
listed in the usage, PUBLIC
otherwise.IllegalArgumentException - if any parameter is invalid.setTag(),
setDesc(),
setMinValLen(),
setMaxValLen(),
OPTIONAL,
REQUIRED,
SINGLE_VALUED,
MULTI_VALUED,
HIDDEN,
PUBLICpublic StringParam(String tag, String desc, String[] acceptableValues)
tag - the tag associated with this parameterdesc - a description of the parameter, suitable for display in a
usage statementacceptableValues - the acceptable values for the parameterIllegalArgumentException - if any parameter is invalid.setTag(),
setDesc(),
setAcceptableValues(),
setMinValLen()public StringParam(String tag, String desc, String[] acceptableValues, boolean optional)
tag - the tag associated with this parameterdesc - a description of the parameter, suitable for display in a
usage statementacceptableValues - the acceptable values for the parameteroptional - OPTIONAL if optional,
REQUIRED if requiredIllegalArgumentException - if any parameter is invalid.setTag(),
setDesc(),
setAcceptableValues(),
setMinValLen(),
OPTIONAL,
REQUIREDpublic StringParam(String tag, String desc, String[] acceptableValues, boolean optional, boolean multiValued)
tag - the tag associated with this parameterdesc - a description of the parameter, suitable for display in a
usage statementacceptableValues - the acceptable values for the parameteroptional - OPTIONAL if optional,
REQUIRED if requiredmultiValued - MULTI_VALUED if the parameter
can accept multiple values, SINGLE_VALUED if the parameter can contain only a single
valueIllegalArgumentException - if any parameter is invalid.setTag(),
setDesc(),
setAcceptableValues(),
setMinValLen(),
OPTIONAL,
REQUIRED,
SINGLE_VALUED,
MULTI_VALUEDpublic StringParam(String tag, String desc, String[] acceptableValues, boolean optional, boolean multiValued, boolean hidden)
tag - the tag associated with this parameterdesc - a description of the parameter, suitable for display in a
usage statementacceptableValues - the acceptable values for the parameteroptional - OPTIONAL if optional,
REQUIRED if requiredmultiValued - MULTI_VALUED if the parameter
can accept multiple values, SINGLE_VALUED if the parameter can contain only a single
valuehidden - HIDDEN if parameter is not to be
listed in the usage, PUBLIC
otherwise.IllegalArgumentException - if any parameter is invalid.setTag(),
setDesc(),
setAcceptableValues(),
setMinValLen(),
OPTIONAL,
REQUIRED,
SINGLE_VALUED,
MULTI_VALUED,
HIDDEN,
PUBLICpublic String convertValue(String strVal) throws CmdLineException
AbstractParameterconvertValue in class AbstractParameter<String>strVal - the String value of the ParameterCmdLineException - if the conversion cannot be madeAbstractParameter.convertValue(java.lang.String)public int getMaxValLen()
public int getMinValLen()
public void setMaxLength(int maxValLen)
maxValLen - the maximum acceptable lengthIllegalArgumentException - if maxValLen
less than 0, or is less than
minValLen
.setMaxValLen()public void setMaxValLen(int maxValLen)
maxValLen - the maximum acceptable lengthIllegalArgumentException - if maxValLen
less than 0, or is less than
minValLen
.public void setMinValLen(int minValLen)
minValLen - the minimum acceptable lengthIllegalArgumentException - if minValLen less than 0, or is greater than
maxValLen
.public void validateValue(String val) throws CmdLineException
validateValue in class AbstractParameter<String>val - the prospective value to validateCmdLineException - if value
is not valid with regard to
the minimum and maximum lengths, and the acceptableValues.Copyright © 2017. All rights reserved.