jcmdline
Class LongParam

java.lang.Object
  extended by jcmdline.AbstractParameter
      extended by jcmdline.LongParam
All Implemented Interfaces:
Parameter

public class LongParam
extends AbstractParameter

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

Author:
a.vacondio

Field Summary
static java.lang.String DEFAULT_OPTION_LABEL
          the default label that will represent option values for this Parameter when displaying usage.
protected  long max
          the maximum acceptable number - defaults to Long.MAX_VALUE
protected  long min
          the minimum acceptable number - defaults to Long.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
LongParam(java.lang.String tag, java.lang.String desc)
          constructor - creates single-valued, optional, public parameter which will accept an long between Long.MIN_VALUE and Long.MAX_VALUE.
LongParam(java.lang.String tag, java.lang.String desc, boolean optional)
          constructor - creates single-valued, public parameter which will accept an long between Long.MIN_VALUE and Long.MAX_VALUE, and will be either optional or required, as specified.
LongParam(java.lang.String tag, java.lang.String desc, boolean optional, boolean multiValued)
          constructor - creates a public parameter which will accept an long between Long.MIN_VALUE and Long.MAX_VALUE, and will be either optional or required, and/or multi-valued, as specified.
LongParam(java.lang.String tag, java.lang.String desc, boolean optional, boolean multiValued, boolean hidden)
          constructor - creates a parameter which will accept an long between Long.MIN_VALUE and Long.MAX_VALUE, and will be either optional or required, and/or multi-valued, as specified.
LongParam(java.lang.String tag, java.lang.String desc, long[] acceptableValues)
          constructor - creates a single-valued, optional, public, number parameter whose value must be one of the specified values.
LongParam(java.lang.String tag, java.lang.String desc, long[] 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.
LongParam(java.lang.String tag, java.lang.String desc, long[] 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.
LongParam(java.lang.String tag, java.lang.String desc, long[] 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.
LongParam(java.lang.String tag, java.lang.String desc, long min, long max)
          constructor - creates a single-valued, optional, public, parameter that will accept an long between the specifed minimum and maximum values.
LongParam(java.lang.String tag, java.lang.String desc, long min, long max, boolean optional)
          constructor - creates a single-valued, public parameter that will accept an long between the specifed minimum and maximum values, and which is required or optional, as specified.
LongParam(java.lang.String tag, java.lang.String desc, long min, long max, boolean optional, boolean multiValued)
          constructor - creates a public parameter that will accept an long between the specifed minimum and maximum values, and which is required or optional and/or multi-valued, as specified.
LongParam(java.lang.String tag, java.lang.String desc, long min, long max, boolean optional, boolean multiValued, boolean hidden)
          constructor - creates a parameter that will accept an long between the specifed minimum and maximum values, and for which all other options are specified.
 
Method Summary
 long[] getAcceptableLongValues()
          gets the acceptable values for this parameter
 long getMax()
          gets the maximum acceptable value for the parameter
 long getMin()
          gets minimum acceptable value for the parameter's value
 long longValue()
          Gets the value of the LongParam as in int.
 long[] longValues()
          Gets the values of the LongParam as an int array.
 void setAcceptablesLongValues(long[] longValues)
          Sets the acceptable values for this parameter.
 void setMax(long max)
          Sets the maximum acceptable value for the parameter.
 void setMin(long min)
          Sets the minimum acceptable value for the parameter's 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

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 LongParam option, where the option label is '<n>':
    count <n>  Specifies the maximum number of files to be
               produced by this program.
 

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

max

protected long max
the maximum acceptable number - defaults to Long.MAX_VALUE


min

protected long min
the minimum acceptable number - defaults to Long.MIN_VALUE

Constructor Detail

LongParam

public LongParam(java.lang.String tag,
                 java.lang.String desc)
constructor - creates single-valued, optional, public parameter which will accept an long between Long.MIN_VALUE and Long.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()

LongParam

public LongParam(java.lang.String tag,
                 java.lang.String desc,
                 boolean optional)
constructor - creates single-valued, public parameter which will accept an long between Long.MIN_VALUE and Long.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()

LongParam

public LongParam(java.lang.String tag,
                 java.lang.String desc,
                 boolean optional,
                 boolean multiValued)
constructor - creates a public parameter which will accept an long between Long.MIN_VALUE and Long.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

LongParam

public LongParam(java.lang.String tag,
                 java.lang.String desc,
                 boolean optional,
                 boolean multiValued,
                 boolean hidden)
constructor - creates a parameter which will accept an long between Long.MIN_VALUE and Long.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

LongParam

public LongParam(java.lang.String tag,
                 java.lang.String desc,
                 long min,
                 long max)
constructor - creates a single-valued, optional, public, parameter that will accept an long 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()

LongParam

public LongParam(java.lang.String tag,
                 java.lang.String desc,
                 long min,
                 long max,
                 boolean optional)
constructor - creates a single-valued, public parameter that will accept an long 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

LongParam

public LongParam(java.lang.String tag,
                 java.lang.String desc,
                 long min,
                 long max,
                 boolean optional,
                 boolean multiValued)
constructor - creates a public parameter that will accept an long 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

LongParam

public LongParam(java.lang.String tag,
                 java.lang.String desc,
                 long min,
                 long max,
                 boolean optional,
                 boolean multiValued,
                 boolean hidden)
constructor - creates a parameter that will accept an long 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

LongParam

public LongParam(java.lang.String tag,
                 java.lang.String desc,
                 long[] 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(), setAcceptableIntValues()

LongParam

public LongParam(java.lang.String tag,
                 java.lang.String desc,
                 long[] 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(), setAcceptableIntValues(), OPTIONAL, REQUIRED

LongParam

public LongParam(java.lang.String tag,
                 java.lang.String desc,
                 long[] 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(), setAcceptableIntValues(), OPTIONAL, REQUIRED, SINGLE_VALUED, MULTI_VALUED

LongParam

public LongParam(java.lang.String tag,
                 java.lang.String desc,
                 long[] 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(), setAcceptableIntValues(), OPTIONAL, REQUIRED, SINGLE_VALUED, MULTI_VALUED, HIDDEN, PUBLIC
Method Detail

setMin

public void setMin(long 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

longValue

public long longValue()
Gets the value of the LongParam as in int. If the LongParam is multi-valued, only the first value is returned.

Returns:
the value as an int
Throws:
java.lang.RuntimeException - if the value of the LongParam has not been set.
See Also:
Parameter.isSet()

longValues

public long[] longValues()
Gets the values of the LongParam as an int array. Note that if the LongParam has no values, an empty array is returned.

Returns:
an array of int values
See Also:
Parameter.isSet()

getMin

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

Returns:
the minimum acceptable value

setMax

public void setMax(long 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

getMax

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

Returns:
the maximum acceptable value

setAcceptablesLongValues

public void setAcceptablesLongValues(long[] longValues)
Sets the acceptable values for this 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:
acceptableValues - An array of acceptable long values that the parameter's values must match. If null, the parameter's values can be any long.

getAcceptableLongValues

public long[] getAcceptableLongValues()
gets the acceptable values for this parameter

Returns:
The acceptable values for this parameter. If no acceptable values have been specified, this method returns null.

validateValue

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

Specified by:
validateValue in interface Parameter
Overrides:
validateValue in class AbstractParameter
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.