net.dpml.cli.validation
Class NumberValidator

java.lang.Object
  extended by net.dpml.cli.validation.NumberValidator
All Implemented Interfaces:
Validator

public class NumberValidator
extends Object
implements Validator

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);
 

Version:
1.0.0
Author:
Digital Product Meta Library

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

NumberValidator

public NumberValidator(NumberFormat format)
Creates a new NumberValidator based on the specified NumberFormat

Parameters:
format - the format of numbers to accept
Method Detail

getCurrencyInstance

public static NumberValidator getCurrencyInstance()
Returns a NumberValidator for a currency format for the current default locale.

Returns:
a NumberValidator for a currency format for the current default locale.

getIntegerInstance

public static NumberValidator getIntegerInstance()
Returns a NumberValidator for an integer number format for the current default locale.

Returns:
a NumberValidator for an integer number format for the current default locale.

getPercentInstance

public static NumberValidator getPercentInstance()
Returns a NumberValidator for a percentage format for the current default locale.

Returns:
a NumberValidator for a percentage format for the current default locale.

getNumberInstance

public static NumberValidator getNumberInstance()
Returns a NumberValidator for a general-purpose number format for the current default locale.

Returns:
a NumberValidator for a general-purpose number format for the current default locale.

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 List with the Number instance.

Specified by:
validate in interface Validator
Parameters:
values - the list of values to validate
Throws:
InvalidArgumentException - if a value is invalid
See Also:
Validator.validate(java.util.List)

getFormat

public NumberFormat getFormat()
Return the format being used to validate argument values against.

Returns:
the format being used to validate argument values against.

setFormat

protected void setFormat(NumberFormat format)
Specify the format being used to validate argument values against.

Parameters:
format - the format being used to validate argument values against.

getMaximum

public Number getMaximum()
Return the maximum value allowed for an argument value.

Returns:
the maximum value allowed for an argument value.

setMaximum

public void setMaximum(Number maximum)
Specify the maximum value allowed for an argument value.

Parameters:
maximum - the maximum value allowed for an argument value.

getMinimum

public Number getMinimum()
Return the minimum value allowed for an argument value.

Returns:
the minimum value allowed for an argument value.

setMinimum

public void setMinimum(Number minimum)
Specify the minimum value allowed for an argument value.

Parameters:
minimum - the minimum value allowed for an argument value.