Spring Framework

org.springframework.format.number
Class AbstractNumberFormatter

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

public abstract class AbstractNumberFormatter
extends java.lang.Object
implements Formatter<java.lang.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
protected abstract  java.text.NumberFormat getNumberFormat(java.util.Locale locale)
          Obtain a concrete NumberFormat for the specified locale.
 java.lang.Number parse(java.lang.String text, java.util.Locale locale)
          Parse a text String to produce a T.
 java.lang.String print(java.lang.Number number, java.util.Locale locale)
          Print the object of type T for display.
 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.


print

public java.lang.String print(java.lang.Number number,
                              java.util.Locale locale)
Description copied from interface: Printer
Print the object of type T for display.

Specified by:
print in interface Printer<java.lang.Number>
Parameters:
number - the instance to print
locale - the current user locale
Returns:
the printed text string

parse

public java.lang.Number parse(java.lang.String text,
                              java.util.Locale locale)
                       throws java.text.ParseException
Description copied from interface: Parser
Parse a text String to produce a T.

Specified by:
parse in interface Parser<java.lang.Number>
Parameters:
text - the text string
locale - the current user locale
Returns:
an instance of T
Throws:
java.text.ParseException - when a parse exception occurs in a java.text parsing library

getNumberFormat

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

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

Spring Framework