org.springframework.binding.format.support
Class NumberFormatter

java.lang.Object
  extended by org.springframework.binding.format.support.AbstractFormatter
      extended by org.springframework.binding.format.support.NumberFormatter
All Implemented Interfaces:
Formatter

public class NumberFormatter
extends AbstractFormatter

Converts from various Number specializations to String and back.

Author:
Keith Donald

Constructor Summary
NumberFormatter()
          Default constructor.
NumberFormatter(java.text.NumberFormat numberFormat)
          Create a new number formatter.
NumberFormatter(java.text.NumberFormat numberFormat, boolean allowEmpty)
          Create a new number formatter.
 
Method Summary
protected  java.lang.String doFormatValue(java.lang.Object number)
          Template method subclasses should override to encapsulate formatting logic.
protected  java.lang.Object doParseValue(java.lang.String text, java.lang.Class targetClass)
          Template method subclasses should override to encapsulate parsing logic.
 java.math.BigDecimal parseBigDecimal(java.lang.String formattedString)
           
 java.math.BigInteger parseBigInteger(java.lang.String formattedString)
           
 java.lang.Byte parseByte(java.lang.String formattedString)
           
 java.lang.Double parseDouble(java.lang.String formattedString)
           
 java.lang.Float parseFloat(java.lang.String formattedString)
           
 java.lang.Integer parseInteger(java.lang.String formattedString)
           
 java.lang.Long parseLong(java.lang.String formattedString)
           
 java.lang.Short parseShort(java.lang.String formattedString)
           
 
Methods inherited from class org.springframework.binding.format.support.AbstractFormatter
formatValue, getEmptyFormattedValue, getEmptyValue, getExpectedFormat, isAllowEmpty, isEmpty, parseValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberFormatter

public NumberFormatter()
Default constructor. The formatter will use "toString" when formatting a value and "valueOf" when parsing a value.


NumberFormatter

public NumberFormatter(java.text.NumberFormat numberFormat)
Create a new number formatter.

Parameters:
numberFormat - the number format to use

NumberFormatter

public NumberFormatter(java.text.NumberFormat numberFormat,
                       boolean allowEmpty)
Create a new number formatter.

Parameters:
numberFormat - the number format to use
allowEmpty - should this formatter allow empty input arguments?
Method Detail

doFormatValue

protected java.lang.String doFormatValue(java.lang.Object number)
Description copied from class: AbstractFormatter
Template method subclasses should override to encapsulate formatting logic.

Specified by:
doFormatValue in class AbstractFormatter
Parameters:
number - the value to format
Returns:
the formatted string representation

doParseValue

protected java.lang.Object doParseValue(java.lang.String text,
                                        java.lang.Class targetClass)
                                 throws java.lang.IllegalArgumentException
Description copied from class: AbstractFormatter
Template method subclasses should override to encapsulate parsing logic.

Specified by:
doParseValue in class AbstractFormatter
Parameters:
text - the formatted string to parse
Returns:
the parsed value
Throws:
java.lang.IllegalArgumentException

parseByte

public java.lang.Byte parseByte(java.lang.String formattedString)
                         throws InvalidFormatException
Throws:
InvalidFormatException

parseShort

public java.lang.Short parseShort(java.lang.String formattedString)
                           throws InvalidFormatException
Throws:
InvalidFormatException

parseInteger

public java.lang.Integer parseInteger(java.lang.String formattedString)
                               throws InvalidFormatException
Throws:
InvalidFormatException

parseLong

public java.lang.Long parseLong(java.lang.String formattedString)
                         throws InvalidFormatException
Throws:
InvalidFormatException

parseFloat

public java.lang.Float parseFloat(java.lang.String formattedString)
                           throws InvalidFormatException
Throws:
InvalidFormatException

parseDouble

public java.lang.Double parseDouble(java.lang.String formattedString)
                             throws InvalidFormatException
Throws:
InvalidFormatException

parseBigInteger

public java.math.BigInteger parseBigInteger(java.lang.String formattedString)
                                     throws InvalidFormatException
Throws:
InvalidFormatException

parseBigDecimal

public java.math.BigDecimal parseBigDecimal(java.lang.String formattedString)
                                     throws InvalidFormatException
Throws:
InvalidFormatException


Copyright � 2004-2007. All Rights Reserved.