Class CurrencyValidator
- All Implemented Interfaces:
Serializable
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 presence of the currency symbol
- It converts the currency to a
java.math.BigDecimal
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charDecimalFormat's currency symbolstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intdetermineScale(NumberFormat format) Returns the multiplier of theNumberFormat.getExcelPattern(Locale locale) Returns aStringrepresenting the Excel pattern for this currency.Returns aNumberFormatfor the specified Locale.static CurrencyValidatorReturn a singleton instance of this validator.protected Numberparse(String value, DecimalFormat formatter) Parse the value with the specifiedFormat.protected ObjectParse the value using the specified pattern.protected BigDecimalprocessParsedValue(Number value, DecimalFormat formatter) Convert the parsed value to aBigDecimal.validate(String value, DecimalFormat format) Validate/convert aBigDecimalusing the specifiedDecimalFormat.Validate/convert aBigDecimalusing the specifiedLocale.
-
Field Details
-
CURRENCY_SYMBOL
public static final char CURRENCY_SYMBOLDecimalFormat's currency symbol- See Also:
-
CURRENCY_SYMBOL_STR
-
-
Constructor Details
-
CurrencyValidator
public CurrencyValidator()
-
-
Method Details
-
getInstance
Return a singleton instance of this validator.- Returns:
- A singleton instance of the CurrencyValidator.
-
validate
Validate/convert a
BigDecimalusing the specifiedLocale.- Parameters:
value- The value validation is being performed on.locale- The locale to use for the number format, system default if null.- Returns:
- The parsed
BigDecimalif valid ornullif invalid.
-
getExcelPattern
Returns a
Stringrepresenting the Excel pattern for this currency.- Parameters:
locale- The locale aNumberFormatis required for, system default if null.- Returns:
- The
Stringpattern for using in Excel format.
-
parse
Parse the value using the specified pattern.
- Parameters:
value- The value validation is being performed on.locale- The locale to use for the date format, system default if null.- Returns:
- The parsed value if valid or
nullif invalid.
-
getFormat
Returns a
NumberFormatfor the specified Locale.- Parameters:
locale- The locale aNumberFormatis required for, system default if null.- Returns:
- The
NumberFormatto created.
-
parse
Parse the value with the specified
Format.This implementation is lenient whether the currency symbol is present or not. The default
NumberFormatbehavior 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.formatter- The Format to parse the value with.- Returns:
- The parsed value if valid or
nullif invalid.
-
validate
Validate/convert a
BigDecimalusing the specifiedDecimalFormat.- Parameters:
value- The value validation is being performed on.format- The format used to validate the value against.- Returns:
- The parsed
BigDecimalif valid ornullif invalid.
-
processParsedValue
Convert the parsed value to aBigDecimal.- Parameters:
value- The parsedNumberobject created.formatter- The Format used to parse the value with.- Returns:
- The parsed
Numberconverted to aBigDecimal.
-
determineScale
Returns the multiplier of the
NumberFormat.- Parameters:
format- TheNumberFormatto determine the multiplier of.- Returns:
- The multiplying factor for the format.
-