|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.binding.convert.converters.StringToObject
org.springframework.binding.convert.converters.FormattedStringToNumber
public class FormattedStringToNumber
A converter for common number types such as integers and big decimals. Allows the configuration of an explicit number
pattern and locale.
Works with a general purpose DecimalFormat
instance returned by calling
NumberFormat.getInstance(Locale)
by default. This instance supports parsing any number type generally and
will not perform special type-specific logic such as rounding or truncation. Subclasses may override.
Will coerse parsed Numbers to the desired numberClass as necessary. If type-coersion results in an overflow
condition; for example, what can occur with a Long being coersed to a Short, an exception will be thrown.
NumberFormat
,
DecimalFormat
Constructor Summary | |
---|---|
FormattedStringToNumber()
|
|
FormattedStringToNumber(java.lang.Class numberClass)
|
Method Summary | |
---|---|
protected java.lang.Number |
convertToNumberClass(java.lang.Number number,
java.lang.Class numberClass)
Coerces the Number object returned by NumberFormat to the desired numberClass. |
boolean |
getLenient()
If this Converter is "lenient" in parsing number strings. |
void |
setLenient(boolean lenient)
Sets if this Converter should parse leniently. |
void |
setNumberFormatFactory(NumberFormatFactory numberFormatFactory)
Sets the factory that returns the NumberFormat instance that will format numbers handled by this
converter. |
protected java.lang.Object |
toObject(java.lang.String string,
java.lang.Class targetClass)
|
protected java.lang.String |
toString(java.lang.Object object)
|
Methods inherited from class org.springframework.binding.convert.converters.StringToObject |
---|
convertSourceToTargetClass, convertTargetToSourceClass, getSourceClass, getTargetClass |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FormattedStringToNumber()
public FormattedStringToNumber(java.lang.Class numberClass)
Method Detail |
---|
public void setNumberFormatFactory(NumberFormatFactory numberFormatFactory)
NumberFormat
instance that will format numbers handled by this
converter.
numberFormatFactory
- the number format factorypublic boolean getLenient()
public void setLenient(boolean lenient)
lenient
- the lenient flagprotected java.lang.Object toObject(java.lang.String string, java.lang.Class targetClass) throws java.lang.Exception
toObject
in class StringToObject
java.lang.Exception
protected java.lang.String toString(java.lang.Object object) throws java.lang.Exception
toString
in class StringToObject
java.lang.Exception
protected java.lang.Number convertToNumberClass(java.lang.Number number, java.lang.Class numberClass) throws java.lang.IllegalArgumentException
number
- the parsed number
java.lang.IllegalArgumentException
- when an overflow condition occurs during coersion
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |