| java.lang.Object org.apache.commons.validator.routines.AbstractFormatValidator org.apache.commons.validator.routines.AbstractNumberValidator org.apache.commons.validator.routines.BigDecimalValidator org.apache.commons.validator.routines.CurrencyValidator
CurrencyValidator | public class CurrencyValidator extends BigDecimalValidator (Code) | | Currency Validation and Conversion routines (java.math.BigDecimal ).
This is one implementation of a currency validator that has the following features:
- It is lenient about the the presence of the currency symbol
- It converts the currency to a
java.math.BigDecimal
However any of the number validators can be used for currency validation.
For example, if you wanted a currency validator that converts to a
java.lang.Integer then you can simply instantiate an
IntegerValidator with the appropriate format type:
... = new IntegerValidator(false, IntegerValidator.CURRENCY_FORMAT);
Pick the appropriate validator, depending on the type (e.g Float, Double, Integer, Long etc)
you want the currency converted to. One thing to note - only the CurrencyValidator
implements lenient behaviour regarding the currency symbol.
version: $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $ since: Validator 1.3.0 |
Constructor Summary | |
public | CurrencyValidator() Construct a strict instance. | public | CurrencyValidator(boolean strict, boolean allowFractions) Construct an instance with the specified strict setting. |
Method Summary | |
public static BigDecimalValidator | getInstance() Return a singleton instance of this validator. | protected Object | parse(String value, Format formatter) Parse the value with the specified Format .
This implementation is lenient whether the currency symbol
is present or not. |
CurrencyValidator | public CurrencyValidator()(Code) | | Construct a strict instance.
|
CurrencyValidator | public CurrencyValidator(boolean strict, boolean allowFractions)(Code) | | Construct an instance with the specified strict setting.
Parameters: strict - true if strict Format parsing should be used. Parameters: allowFractions - true if fractions areallowed or false if integers only. |
getInstance | public static BigDecimalValidator getInstance()(Code) | | Return a singleton instance of this validator.
A singleton instance of the CurrencyValidator. |
parse | protected Object parse(String value, Format formatter)(Code) | | Parse the value with the specified Format .
This implementation is lenient whether the currency symbol
is present or not. The default NumberFormat
behaviour is for the parsing to "fail" if the currency
symbol is missing. This method re-parses with a format
without the currency symbol if it fails initially.
Parameters: value - The value to be parsed. Parameters: formatter - The Format to parse the value with. The parsed value if valid or null if invalid. |
Fields inherited from org.apache.commons.validator.routines.AbstractNumberValidator | final public static int CURRENCY_FORMAT(Code)(Java Doc) final public static int PERCENT_FORMAT(Code)(Java Doc) final public static int STANDARD_FORMAT(Code)(Java Doc)
|
Methods inherited from org.apache.commons.validator.routines.AbstractNumberValidator | protected int determineScale(NumberFormat format)(Code)(Java Doc) protected Format getFormat(String pattern, Locale locale)(Code)(Java Doc) protected Format getFormat(Locale locale)(Code)(Java Doc) public int getFormatType()(Code)(Java Doc) public boolean isAllowFractions()(Code)(Java Doc) public boolean isInRange(Number value, Number min, Number max)(Code)(Java Doc) public boolean isValid(String value, String pattern, Locale locale)(Code)(Java Doc) public boolean maxValue(Number value, Number max)(Code)(Java Doc) public boolean minValue(Number value, Number min)(Code)(Java Doc) protected Object parse(String value, String pattern, Locale locale)(Code)(Java Doc) abstract protected Object processParsedValue(Object value, Format formatter)(Code)(Java Doc)
|
Methods inherited from org.apache.commons.validator.routines.AbstractFormatValidator | public String format(Object value)(Code)(Java Doc) public String format(Object value, String pattern)(Code)(Java Doc) public String format(Object value, Locale locale)(Code)(Java Doc) public String format(Object value, String pattern, Locale locale)(Code)(Java Doc) protected String format(Object value, Format formatter)(Code)(Java Doc) abstract protected Format getFormat(String pattern, Locale locale)(Code)(Java Doc) public boolean isStrict()(Code)(Java Doc) public boolean isValid(String value)(Code)(Java Doc) public boolean isValid(String value, String pattern)(Code)(Java Doc) public boolean isValid(String value, Locale locale)(Code)(Java Doc) abstract public boolean isValid(String value, String pattern, Locale locale)(Code)(Java Doc) protected Object parse(String value, Format formatter)(Code)(Java Doc) abstract protected Object processParsedValue(Object value, Format formatter)(Code)(Java Doc)
|
|
|