|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjcmdline.AbstractParameter
jcmdline.StringParam
public class StringParam
Encapsulate a command line parameter whose value will be a 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| Field Summary | |
|---|---|
static java.lang.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. |
| 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 | |
|---|---|
StringParam(java.lang.String tag,
java.lang.String desc)
constructor - creates single-valued, optional, parameter accepting a string value of any length |
|
StringParam(java.lang.String tag,
java.lang.String desc,
boolean optional)
constructor - creates single-valued, parameter accepting a string value of any length, and either optional or required, as specified. |
|
StringParam(java.lang.String tag,
java.lang.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(java.lang.String tag,
java.lang.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(java.lang.String tag,
java.lang.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(java.lang.String tag,
java.lang.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(java.lang.String tag,
java.lang.String desc,
java.lang.String[] acceptableValues)
constructor - creates a single-valued, optional, string parameter whose value must be one of the specified values. |
|
StringParam(java.lang.String tag,
java.lang.String desc,
java.lang.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(java.lang.String tag,
java.lang.String desc,
java.lang.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(java.lang.String tag,
java.lang.String desc,
java.lang.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. |
|
| Method Summary | |
|---|---|
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(java.lang.String val)
Validates a prospective value with regards to the minimum and maximum values and the acceptableValues - called by add/setValue(s)(). |
| Methods inherited from class jcmdline.AbstractParameter |
|---|
addValue, 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 |
| Field Detail |
|---|
public static final java.lang.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
| Constructor Detail |
|---|
public StringParam(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 tag
or setTag(),
setDesc()
public StringParam(java.lang.String tag,
java.lang.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 required
java.lang.IllegalArgumentException - if any of the specified
parameters are invalid.setTag(),
setDesc()
public StringParam(java.lang.String tag,
java.lang.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 limit
java.lang.IllegalArgumentException - if any parameter is
invalid.setTag(),
setDesc(),
setMinValLen(),
setMaxValLen()
public StringParam(java.lang.String tag,
java.lang.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 required
java.lang.IllegalArgumentException - if any parameter is
invalid.setTag(),
setDesc(),
setMinValLen(),
setMaxValLen(),
OPTIONAL,
REQUIRED
public StringParam(java.lang.String tag,
java.lang.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 value
java.lang.IllegalArgumentException - if any parameter is
invalid.setTag(),
setDesc(),
setMinValLen(),
setMaxValLen(),
OPTIONAL,
REQUIRED,
SINGLE_VALUED,
MULTI_VALUED
public StringParam(java.lang.String tag,
java.lang.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.
java.lang.IllegalArgumentException - if any parameter is
invalid.setTag(),
setDesc(),
setMinValLen(),
setMaxValLen(),
OPTIONAL,
REQUIRED,
SINGLE_VALUED,
MULTI_VALUED,
HIDDEN,
PUBLIC
public StringParam(java.lang.String tag,
java.lang.String desc,
java.lang.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 parameter
java.lang.IllegalArgumentException - if any parameter is
invalid.setTag(),
setDesc(),
setAcceptableValues(),
setMinValLen()
public StringParam(java.lang.String tag,
java.lang.String desc,
java.lang.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 required
java.lang.IllegalArgumentException - if any parameter is
invalid.setTag(),
setDesc(),
setAcceptableValues(),
setMinValLen(),
OPTIONAL,
REQUIRED
public StringParam(java.lang.String tag,
java.lang.String desc,
java.lang.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 value
java.lang.IllegalArgumentException - if any parameter is
invalid.setTag(),
setDesc(),
setAcceptableValues(),
setMinValLen(),
OPTIONAL,
REQUIRED,
SINGLE_VALUED,
MULTI_VALUED
public StringParam(java.lang.String tag,
java.lang.String desc,
java.lang.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.
java.lang.IllegalArgumentException - if any parameter is
invalid.setTag(),
setDesc(),
setAcceptableValues(),
setMinValLen(),
OPTIONAL,
REQUIRED,
SINGLE_VALUED,
MULTI_VALUED,
HIDDEN,
PUBLIC| Method Detail |
|---|
public void validateValue(java.lang.String val)
throws CmdLineException
validateValue in interface ParametervalidateValue in class AbstractParameterval - the prospective value to validate
CmdLineException - if
value
is not valid with regard to the minimum and
maximum lengths, and the acceptableValues.public int getMinValLen()
public void setMinValLen(int minValLen)
minValLen - the minimum acceptable length
java.lang.IllegalArgumentException - if
minValLen
less than 0, or is greater than maxValLen
.public int getMaxValLen()
public void setMaxValLen(int maxValLen)
maxValLen - the maximum acceptable length
java.lang.IllegalArgumentException - if maxValLen
less than 0, or is less than minValLen
.public void setMaxLength(int maxValLen)
maxValLen - the maximum acceptable length
java.lang.IllegalArgumentException - if maxValLen
less than 0, or is less than minValLen
.setMaxValLen()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||