org.springframework.ui.format.number
Class AbstractNumberFormatter

java.lang.Object
  extended by org.springframework.ui.format.number.AbstractNumberFormatter
All Implemented Interfaces:
Formatter<Number>
Direct Known Subclasses:
CurrencyFormatter, DecimalFormatter, IntegerFormatter, PercentFormatter

public abstract class AbstractNumberFormatter
extends Object
implements Formatter<Number>

Abstract formatter for Numbers, providing a getNumberFormat(java.util.Locale) template method.

Since:
3.0
Author:
Juergen Hoeller, Keith Donald

Constructor Summary
AbstractNumberFormatter()
           
 
Method Summary
 String format(Number integer, Locale locale)
          Format the object of type T for display.
protected abstract  NumberFormat getNumberFormat(Locale locale)
          Obtain a concrete NumberFormat for the specified locale.
 Number parse(String formatted, Locale locale)
          Parse an object from its formatted representation.
 void setLenient(boolean lenient)
          Specify whether or not parsing is to be lenient.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractNumberFormatter

public AbstractNumberFormatter()
Method Detail

setLenient

public void setLenient(boolean lenient)
Specify whether or not parsing is to be lenient. Default is false.

With lenient parsing, the parser may allow inputs that do not precisely match the format. With strict parsing, inputs must match the format exactly.


format

public String format(Number integer,
                     Locale locale)
Description copied from interface: Formatter
Format the object of type T for display.

Specified by:
format in interface Formatter<Number>
Parameters:
integer - the object to format
locale - the user's locale
Returns:
the formatted display string

parse

public Number parse(String formatted,
                    Locale locale)
             throws ParseException
Description copied from interface: Formatter
Parse an object from its formatted representation.

Specified by:
parse in interface Formatter<Number>
Parameters:
formatted - a formatted representation
locale - the user's locale
Returns:
the parsed object
Throws:
ParseException - when a parse exception occurs

getNumberFormat

protected abstract NumberFormat getNumberFormat(Locale locale)
Obtain a concrete NumberFormat for the specified locale.

Parameters:
locale - the current locale
Returns:
the NumberFormat instance (never null)