jcmdline
Class IntParam

java.lang.Object
  extended by jcmdline.AbstractParameter<java.lang.Integer>
      extended by jcmdline.IntParam
All Implemented Interfaces:
Parameter<java.lang.Integer>

public class IntParam
extends AbstractParameter<java.lang.Integer>

Encapsulate a command line parameter whose value will be a signed integer in the same range as a java int.

Version:
jcmdline Rel. 2.0.0 $Id: IntParam.java,v 1.2 2002/12/07 14:22:06 lglawrence Exp $
Author:
Lynne Lawrence
See Also:
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 max
          the maximum acceptable number - defaults to Integer.MAX_VALUE
protected  int min
          the minimum acceptable number - defaults to Integer.MIN_VALUE
 
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
IntParam(java.lang.String tag, java.lang.String desc)
          constructor - creates single-valued, optional, public parameter which will accept an integer between Integer.MIN_VALUE and Integer.MAX_VALUE.
IntParam(java.lang.String tag, java.lang.String desc, boolean optional)
          constructor - creates single-valued, public parameter which will accept an integer between Integer.MIN_VALUE and Integer.MAX_VALUE, and will be either optional or required, as specified.
IntParam(java.lang.String tag, java.lang.String desc, boolean optional, boolean multiValued)
          constructor - creates a public parameter which will accept an integer between Integer.MIN_VALUE and Integer.MAX_VALUE, and will be either optional or required, and/or multi-valued, as specified.
IntParam(java.lang.String tag, java.lang.String desc, boolean optional, boolean multiValued, boolean hidden)
          constructor - creates a parameter which will accept an integer between Integer.MIN_VALUE and Integer.MAX_VALUE, and will be either optional or required, and/or multi-valued, as specified.
IntParam(java.lang.String tag, java.lang.String desc, java.lang.Integer[] acceptableValues)
          constructor - creates a single-valued, optional, public, number parameter whose value must be one of the specified values.
IntParam(java.lang.String tag, java.lang.String desc, java.lang.Integer[] acceptableValues, boolean optional)
          constructor - creates a single-valued, public, number parameter whose value must be one of the specified values, and which is required or optional, as specified.
IntParam(java.lang.String tag, java.lang.String desc, java.lang.Integer[] acceptableValues, boolean optional, boolean multiValued)
          constructor - creates a public number parameter whose value must be one of the specified values, and which is required or optional and/or multi-valued, as specified.
IntParam(java.lang.String tag, java.lang.String desc, java.lang.Integer[] acceptableValues, boolean optional, boolean multiValued, boolean hidden)
          constructor - creates a number parameter whose value must be one of the specified values, and all of whose other options are specified.
IntParam(java.lang.String tag, java.lang.String desc, int min, int max)
          constructor - creates a single-valued, optional, public, parameter that will accept an integer between the specifed minimum and maximum values.
IntParam(java.lang.String tag, java.lang.String desc, int min, int max, boolean optional)
          constructor - creates a single-valued, public parameter that will accept an integer between the specifed minimum and maximum values, and which is required or optional, as specified.
IntParam(java.lang.String tag, java.lang.String desc, int min, int max, boolean optional, boolean multiValued)
          constructor - creates a public parameter that will accept an integer between the specifed minimum and maximum values, and which is required or optional and/or multi-valued, as specified.
IntParam(java.lang.String tag, java.lang.String desc, int min, int max, boolean optional, boolean multiValued, boolean hidden)
          constructor - creates a parameter that will accept an integer between the specifed minimum and maximum values, and for which all other options are specified.
 
Method Summary
 java.lang.Integer convertValue(java.lang.String strVal)
          Converts a String value to the type associated with the Parameter.
 int getMax()
          gets the maximum acceptable value for the parameter
 int getMin()
          gets minimum acceptable value for the parameter's value
 void setMax(int max)
          Sets the maximum acceptable value for the parameter.
 void setMin(int min)
          Sets the minimum acceptable value for the parameter's value.
 void validateValue(java.lang.Integer 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
addStringValue, 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

DEFAULT_OPTION_LABEL

public static final java.lang.String DEFAULT_OPTION_LABEL
the default label that will represent option values for this Parameter when displaying usage. The following demonstrates a possible usage excerpt for a IntParam option, where the option label is '<n>':
    count <n>  Specifies the maximum number of files to be
               produced by this program.
 

See Also:
setOptionLabel(), "IntParam.defaultOptionLabel in 'strings' properties file"

max

protected int max
the maximum acceptable number - defaults to Integer.MAX_VALUE


min

protected int min
the minimum acceptable number - defaults to Integer.MIN_VALUE

Constructor Detail

IntParam

public IntParam(java.lang.String tag,
                java.lang.String desc)
constructor - creates single-valued, optional, public parameter which will accept an integer between Integer.MIN_VALUE and Integer.MAX_VALUE.

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 tag or are invalid.
See Also:
setTag(), setDesc()

IntParam

public IntParam(java.lang.String tag,
                java.lang.String desc,
                boolean optional)
constructor - creates single-valued, public parameter which will accept an integer between Integer.MIN_VALUE and Integer.MAX_VALUE, and will be either optional or required, as specified.

Parameters:
tag - a unique identifier for this parameter
desc - a description of the parameter, suitable for display in a usage statement
optional - OPTIONAL if optional, REQUIRED if required
Throws:
java.lang.IllegalArgumentException - if any of the specified parameters are invalid.
See Also:
setTag(), setDesc()

IntParam

public IntParam(java.lang.String tag,
                java.lang.String desc,
                boolean optional,
                boolean multiValued)
constructor - creates a public parameter which will accept an integer between Integer.MIN_VALUE and Integer.MAX_VALUE, and will be either optional or required, and/or multi-valued, as specified.

Parameters:
tag - a unique identifier for this parameter
desc - a description of the parameter, suitable for display in a usage statement
optional - OPTIONAL if optional, REQUIRED if required
multiValued - MULTI_VALUED if the parameter can accept multiple values, SINGLE_VALUED if the parameter can contain only a single value
Throws:
java.lang.IllegalArgumentException - if any of the specified parameters are invalid.
See Also:
setTag(), setDesc(), SINGLE_VALUED, MULTI_VALUED

IntParam

public IntParam(java.lang.String tag,
                java.lang.String desc,
                boolean optional,
                boolean multiValued,
                boolean hidden)
constructor - creates a parameter which will accept an integer between Integer.MIN_VALUE and Integer.MAX_VALUE, and will be either optional or required, and/or multi-valued, as specified.

Parameters:
tag - a unique identifier for this parameter
desc - a description of the parameter, suitable for display in a usage statement
optional - OPTIONAL if optional, REQUIRED if required
multiValued - MULTI_VALUED if the parameter can accept multiple values, SINGLE_VALUED if the parameter can contain only a single value
hidden - HIDDEN if parameter is not to be listed in the usage, PUBLIC otherwise.
Throws:
java.lang.IllegalArgumentException - if any of the specified parameters are invalid.
See Also:
setTag(), setDesc(), SINGLE_VALUED, MULTI_VALUED, HIDDEN, PUBLIC

IntParam

public IntParam(java.lang.String tag,
                java.lang.String desc,
                int min,
                int max)
constructor - creates a single-valued, optional, public, parameter that will accept an integer between the specifed minimum and maximum values.

Parameters:
tag - a unique identifier for this parameter
desc - a description of the parameter, suitable for display in a usage statement
min - the minimum acceptable value
max - the maximum acceptable value
Throws:
java.lang.IllegalArgumentException - if any parameter is invalid.
See Also:
setTag(), setDesc(), setMin(), setMax()

IntParam

public IntParam(java.lang.String tag,
                java.lang.String desc,
                int min,
                int max,
                boolean optional)
constructor - creates a single-valued, public parameter that will accept an integer between the specifed minimum and maximum values, and which is required or optional, as specified.

Parameters:
tag - a unique identifier for this parameter
desc - a description of the parameter, suitable for display in a usage statement
min - the minimum acceptable value
max - the maximum acceptable value
optional - OPTIONAL if optional, REQUIRED if required
Throws:
java.lang.IllegalArgumentException - if any parameter is invalid.
See Also:
setTag(), setDesc(), setMin(), setMax(), OPTIONAL, REQUIRED

IntParam

public IntParam(java.lang.String tag,
                java.lang.String desc,
                int min,
                int max,
                boolean optional,
                boolean multiValued)
constructor - creates a public parameter that will accept an integer between the specifed minimum and maximum values, and which is required or optional and/or multi-valued, as specified.

Parameters:
tag - a unique identifier for this parameter
desc - a description of the parameter, suitable for display in a usage statement
min - the minimum acceptable value
max - the maximum acceptable value
optional - OPTIONAL if optional, REQUIRED if required
multiValued - MULTI_VALUED if the parameter can accept multiple values, SINGLE_VALUED if the parameter can contain only a single value
Throws:
java.lang.IllegalArgumentException - if any parameter is invalid.
See Also:
setTag(), setDesc(), setMin(), setMax(), OPTIONAL, REQUIRED, SINGLE_VALUED, MULTI_VALUED

IntParam

public IntParam(java.lang.String tag,
                java.lang.String desc,
                int min,
                int max,
                boolean optional,
                boolean multiValued,
                boolean hidden)
constructor - creates a parameter that will accept an integer between the specifed minimum and maximum values, and for which all other options are specified.

Parameters:
tag - a unique identifier for this parameter
desc - a description of the parameter, suitable for display in a usage statement
min - the minimum acceptable value
max - the maximum acceptable value
optional - OPTIONAL if optional, REQUIRED if required
multiValued - MULTI_VALUED if the parameter can accept multiple values, SINGLE_VALUED if the parameter can contain only a single value
hidden - HIDDEN if parameter is not to be listed in the usage, PUBLIC otherwise.
Throws:
java.lang.IllegalArgumentException - if any parameter is invalid.
See Also:
setTag(), setDesc(), setMin(), setMax(), OPTIONAL, REQUIRED, SINGLE_VALUED, MULTI_VALUED, HIDDEN, PUBLIC

IntParam

public IntParam(java.lang.String tag,
                java.lang.String desc,
                java.lang.Integer[] acceptableValues)
constructor - creates a single-valued, optional, public, number parameter whose value must be one of the specified values.

Parameters:
tag - the tag associated with this parameter
desc - a description of the parameter, suitable for display in a usage statement
acceptableValues - the acceptable values for the parameter
Throws:
java.lang.IllegalArgumentException - if any parameter is invalid.
See Also:
setTag(), setDesc(), setAcceptableValues()

IntParam

public IntParam(java.lang.String tag,
                java.lang.String desc,
                java.lang.Integer[] acceptableValues,
                boolean optional)
constructor - creates a single-valued, public, number parameter whose value must be one of the specified values, and which is required or optional, as specified.

Parameters:
tag - the tag associated with this parameter
desc - a description of the parameter, suitable for display in a usage statement
acceptableValues - the acceptable values for the parameter
optional - OPTIONAL if optional, REQUIRED if required
Throws:
java.lang.IllegalArgumentException - if any parameter is invalid.
See Also:
setTag(), setDesc(), setAcceptableValues(), OPTIONAL, REQUIRED

IntParam

public IntParam(java.lang.String tag,
                java.lang.String desc,
                java.lang.Integer[] acceptableValues,
                boolean optional,
                boolean multiValued)
constructor - creates a public number parameter whose value must be one of the specified values, and which is required or optional and/or multi-valued, as specified.

Parameters:
tag - the tag associated with this parameter
desc - a description of the parameter, suitable for display in a usage statement
acceptableValues - the acceptable values for the parameter
optional - OPTIONAL if optional, REQUIRED if required
multiValued - MULTI_VALUED if the parameter can accept multiple values, SINGLE_VALUED if the parameter can contain only a single value
Throws:
java.lang.IllegalArgumentException - if any parameter is invalid.
See Also:
setTag(), setDesc(), setAcceptableValues(), OPTIONAL, REQUIRED, SINGLE_VALUED, MULTI_VALUED

IntParam

public IntParam(java.lang.String tag,
                java.lang.String desc,
                java.lang.Integer[] acceptableValues,
                boolean optional,
                boolean multiValued,
                boolean hidden)
constructor - creates a number parameter whose value must be one of the specified values, and all of whose other options are specified.

Parameters:
tag - the tag associated with this parameter
desc - a description of the parameter, suitable for display in a usage statement
acceptableValues - the acceptable values for the parameter
optional - OPTIONAL if optional, REQUIRED if required
multiValued - MULTI_VALUED if the parameter can accept multiple values, SINGLE_VALUED if the parameter can contain only a single value
hidden - HIDDEN if parameter is not to be listed in the usage, PUBLIC otherwise.
Throws:
java.lang.IllegalArgumentException - if any parameter is invalid.
See Also:
setTag(), setDesc(), setAcceptableValues(), OPTIONAL, REQUIRED, SINGLE_VALUED, MULTI_VALUED, HIDDEN, PUBLIC
Method Detail

convertValue

public java.lang.Integer convertValue(java.lang.String strVal)
                               throws CmdLineException
Description copied from class: AbstractParameter
Converts a String value to the type associated with the Parameter. All non-abstract subclasses must implement this method.

Specified by:
convertValue in class AbstractParameter<java.lang.Integer>
Parameters:
strVal - the String value of the Parameter
Returns:
the parameter value converted to the Object type with which the Parameter is associated
Throws:
CmdLineException - if the conversion cannot be made
See Also:
AbstractParameter.convertValue(java.lang.String)

getMax

public int getMax()
gets the maximum acceptable value for the parameter

Returns:
the maximum acceptable value

getMin

public int getMin()
gets minimum acceptable value for the parameter's value

Returns:
the minimum acceptable value

setMax

public void setMax(int max)
Sets the maximum acceptable value for the parameter.

If both acceptableValues and/or a minimum or maximum limit for the parameter value are specified, a valid value must satisfy all of the constraints.

Parameters:
max - the maximum acceptable value
Throws:
java.lang.IllegalArgumentException - if min is greater than max

setMin

public void setMin(int min)
Sets the minimum acceptable value for the parameter's value.

If both acceptableValues and/or a minimum or maximum limit for the parameter value are specified, a valid value must satisfy all of the constraints.

Parameters:
min - the minimum acceptable value
Throws:
java.lang.IllegalArgumentException - if min is greater than max

validateValue

public void validateValue(java.lang.Integer val)
                   throws CmdLineException
Validates a prospective value with regards to the minimum and maximum values and the acceptableValues called by add/setValue(s)().

Overrides:
validateValue in class AbstractParameter<java.lang.Integer>
Parameters:
val - the prospective value to validate
Throws:
CmdLineException - if value is not valid with regard to # the minimum and maximum values, and the acceptableValues.