public class NumberValidator extends Object implements Validator
NumberValidator
validates the string argument
values are numbers. If the value is a number, the string value in
the List
of values is replaced with the
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);
Constructor and Description |
---|
NumberValidator(NumberFormat format)
Creates a new NumberValidator based on the specified NumberFormat
|
Modifier and Type | Method and Description |
---|---|
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.
|
public NumberValidator(NumberFormat format)
format
- the format of numbers to acceptpublic static NumberValidator getCurrencyInstance()
NumberValidator
for a currency format
for the current default locale.NumberValidator
for a currency format
for the current default locale.public static NumberValidator getIntegerInstance()
NumberValidator
for an integer number format
for the current default locale.NumberValidator
for an integer number format
for the current default locale.public static NumberValidator getPercentInstance()
NumberValidator
for a percentage format
for the current default locale.NumberValidator
for a percentage format
for the current default locale.public static NumberValidator getNumberInstance()
NumberValidator
for a general-purpose
number format for the current default locale.NumberValidator
for a general-purpose
number format for the current default locale.public void validate(List values) throws InvalidArgumentException
values
List
with the Number
instance.validate
in interface Validator
values
- The values to validate.InvalidArgumentException
- If any of the
specified values are not valid.Validator.validate(java.util.List)
public NumberFormat getFormat()
protected void setFormat(NumberFormat format)
format
- the format being used to validate argument values against.public Number getMaximum()
public void setMaximum(Number maximum)
maximum
- the maximum value allowed for an argument value.public Number getMinimum()
public void setMinimum(Number minimum)
minimum
- the minimum value allowed for an argument value.Copyright © 2002-2013 The Apache Software Foundation. All Rights Reserved.