|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.dpml.cli.validation.NumberValidator
public class NumberValidator
The 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 Summary | |
---|---|
NumberValidator(NumberFormat format)
Creates a new NumberValidator based on the specified NumberFormat |
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NumberValidator(NumberFormat format)
format
- the format of numbers to acceptMethod Detail |
---|
public 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 list of values to validate
InvalidArgumentException
- if a value is invalidValidator.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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |