net.dpml.cli.validation
Class NumberValidator
java.lang.Objectnet.dpml.cli.validation.NumberValidator
- Validator
The
NumberValidator validates the string argument
values are numbers. If the value is a number, the string value in
the
java.util.List of values is replaced with the
java.lang.Number instance.
A maximum and minimum value can also be specified using
the
setMaximum, and the
setMinimum methods.
The following example shows how to limit the valid values
for the age attribute to integers less than 100.
...
ArgumentBuilder builder = new ArgumentBuilder();
NumberValidator validator = NumberValidator.getIntegerInstance();
validator.setMaximum(new Integer(100));
Argument age =
builder.withName("age");
.withValidator(validator);
NumberValidator(NumberFormat format)- Creates a new NumberValidator based on the specified NumberFormat
|
static NumberValidator | getCurrencyInstance()- Returns a
NumberValidator for a currency format
for the current default locale.
|
NumberFormat | getFormat()- Return the format being used to validate argument values against.
|
static NumberValidator | getIntegerInstance()- Returns a
NumberValidator for an integer number format
for the current default locale.
|
Number | getMaximum()- Return the maximum value allowed for an argument value.
|
Number | getMinimum()- Return the minimum value allowed for an argument value.
|
static NumberValidator | getNumberInstance()- Returns a
NumberValidator for a general-purpose
number format for the current default locale.
|
static NumberValidator | getPercentInstance()- Returns a
NumberValidator for a percentage format
for the current default locale.
|
protected void | setFormat(NumberFormat format)- Specify the format being used to validate argument values against.
|
void | setMaximum(Number maximum)- Specify the maximum value allowed for an argument value.
|
void | setMinimum(Number minimum)- Specify the minimum value allowed for an argument value.
|
void | validate(List values)- Validate the list of values against the list of permitted values.
|
NumberValidator
public NumberValidator(NumberFormat format)
Creates a new NumberValidator based on the specified NumberFormat
format - the format of numbers to accept
getCurrencyInstance
public static NumberValidator getCurrencyInstance()
Returns a NumberValidator for a currency format
for the current default locale.
- a
NumberValidator for a currency format
for the current default locale.
getFormat
public NumberFormat getFormat()
Return the format being used to validate argument values against.
- the format being used to validate argument values against.
getIntegerInstance
public static NumberValidator getIntegerInstance()
Returns a NumberValidator for an integer number format
for the current default locale.
- a
NumberValidator for an integer number format
for the current default locale.
getMaximum
public Number getMaximum()
Return the maximum value allowed for an argument value.
- the maximum value allowed for an argument value.
getMinimum
public Number getMinimum()
Return the minimum value allowed for an argument value.
- the minimum value allowed for an argument value.
getNumberInstance
public static NumberValidator getNumberInstance()
Returns a NumberValidator for a general-purpose
number format for the current default locale.
- a
NumberValidator for a general-purpose
number format for the current default locale.
getPercentInstance
public static NumberValidator getPercentInstance()
Returns a NumberValidator for a percentage format
for the current default locale.
- a
NumberValidator for a percentage format
for the current default locale.
setFormat
protected void setFormat(NumberFormat format)
Specify the format being used to validate argument values against.
format - the format being used to validate argument values against.
setMaximum
public void setMaximum(Number maximum)
Specify the maximum value allowed for an argument value.
maximum - the maximum value allowed for an argument value.
setMinimum
public void setMinimum(Number minimum)
Specify the minimum value allowed for an argument value.
minimum - the minimum value allowed for an argument value.
validate
public void validate(List values)
throws InvalidArgumentException Validate the list of values against the list of permitted values.
If a value is valid, replace the string in the values
java.util.List with the java.lang.Number instance.
- validate in interface Validator
values - the list of values to validate
net.dpml.cli.validation.Validator.validate(java.util.List)