net.sourceforge.stripes.validation
Class BigDecimalTypeConverter

java.lang.Object
  extended by net.sourceforge.stripes.validation.NumberTypeConverterSupport
      extended by net.sourceforge.stripes.validation.BigDecimalTypeConverter
All Implemented Interfaces:
TypeConverter<BigDecimal>

public class BigDecimalTypeConverter
extends NumberTypeConverterSupport
implements TypeConverter<BigDecimal>

Type converter for converting localized strings into BigDecimal numbers without any loss of magnitude or precision. Relies on NumberFormat.getInstance() returning a decimal format, and will warn if that is not the case, as it will likely lead to loss of information.

Since:
Stripes 1.1.2
Author:
Tim Fennell

Constructor Summary
BigDecimalTypeConverter()
           
 
Method Summary
 BigDecimal convert(String input, Class<? extends BigDecimal> targetType, Collection<ValidationError> errors)
          Implemented to parse a BigDecimal using the parse() support method.
protected  NumberFormat[] getNumberFormats()
          Uses the parent implementation to fetch number formats, but then downcasts it to a decimal format and ensures that a BigDecimal is parsed instead of a Long or Double.
 
Methods inherited from class net.sourceforge.stripes.validation.NumberTypeConverterSupport
getLocale, parse, preprocess, setLocale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.stripes.validation.TypeConverter
setLocale
 

Constructor Detail

BigDecimalTypeConverter

public BigDecimalTypeConverter()
Method Detail

getNumberFormats

protected NumberFormat[] getNumberFormats()
Uses the parent implementation to fetch number formats, but then downcasts it to a decimal format and ensures that a BigDecimal is parsed instead of a Long or Double.

Overrides:
getNumberFormats in class NumberTypeConverterSupport
Returns:
one or more NumberFormats to use in parsing numbers

convert

public BigDecimal convert(String input,
                          Class<? extends BigDecimal> targetType,
                          Collection<ValidationError> errors)
Implemented to parse a BigDecimal using the parse() support method.

Specified by:
convert in interface TypeConverter<BigDecimal>
Parameters:
input - the String being converted
targetType - the Class representing the type of the property to which the return value of the conversion will be assigned. In many cases this can be ignored as converters will return a single type more often than not.
errors - an empty collection of validation errors that should be populated by the converter for any errors that occur during validation that are user input related.
Returns:
T an instance of the converted type, or null if the input cannot be converted


? Copyright 2005-2006, Stripes Development Team.