|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.commons.beanutils.converters.AbstractConverter
org.apache.commons.beanutils.converters.NumberConverter
public abstract class NumberConverter
Converter implementaion that handles conversion
to and from java.lang.Number objects.
This implementation handles conversion for the following
java.lang.Number types.
java.lang.Bytejava.lang.Shortjava.lang.Integerjava.lang.Longjava.lang.Floatjava.lang.Doublejava.math.BigDecimaljava.math.BigIntegersetUseLocaleFormat(true)setLocale(Locale)setPattern(String)setPattern(String)setLocale(Locale)toNumber(String) method is used to convert
from String to Number and the Number's
toString() method used to convert from
Number to String.
N.B.Patterns can only be specified used the standard
pattern characters and NOT in localized form (see java.text.SimpleDateFormat).
For example to cater for number styles used in Germany such as 0.000,00 the pattern
is specified in the normal form 0,000.00 and the locale set to Locale.GERMANY.
| Field Summary | |
|---|---|
private boolean |
allowDecimals
|
private java.util.Locale |
locale
|
private static java.lang.Integer |
ONE
|
private java.lang.String |
pattern
|
private boolean |
useLocaleFormat
|
private static java.lang.Integer |
ZERO
|
| Constructor Summary | |
|---|---|
NumberConverter(boolean allowDecimals)
Construct a java.lang.Number Converter that throws a ConversionException if a error occurs. |
|
NumberConverter(boolean allowDecimals,
java.lang.Object defaultValue)
Construct a java.lang.Number Converter that returns
a default value if an error occurs. |
|
| Method Summary | |
|---|---|
protected java.lang.String |
convertToString(java.lang.Object value)
Convert an input Number object into a String. |
protected java.lang.Object |
convertToType(java.lang.Class targetType,
java.lang.Object value)
Convert the input object into a Number object of the specified type. |
private java.text.NumberFormat |
getFormat()
Return a NumberFormat to use for Conversion. |
java.util.Locale |
getLocale()
Return the Locale for the Converter (or null if none specified). |
java.lang.String |
getPattern()
Return the number format pattern used to convert Numbers to/from a java.lang.String
(or null if none specified). |
boolean |
isAllowDecimals()
Return whether decimals are allowed in the number. |
private java.lang.Number |
parse(java.lang.Class sourceType,
java.lang.Class targetType,
java.lang.String value,
java.text.NumberFormat format)
Convert a String into a Number object. |
void |
setLocale(java.util.Locale locale)
Set the Locale for the Converter. |
void |
setPattern(java.lang.String pattern)
Set a number format pattern to use to convert Numbers to/from a java.lang.String. |
void |
setUseLocaleFormat(boolean useLocaleFormat)
Set whether a format should be used to convert the Number. |
private java.lang.Number |
toNumber(java.lang.Class sourceType,
java.lang.Class targetType,
java.lang.Number value)
Convert any Number object to the specified type for this Converter. |
private java.lang.Number |
toNumber(java.lang.Class sourceType,
java.lang.Class targetType,
java.lang.String value)
Default String to Number conversion. |
java.lang.String |
toString()
Provide a String representation of this number converter. |
| Methods inherited from class org.apache.commons.beanutils.converters.AbstractConverter |
|---|
convert, convertArray, getDefault, getDefaultType, handleError, handleMissing, isUseDefault, log, primitive, setDefaultValue, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private static final java.lang.Integer ZERO
private static final java.lang.Integer ONE
private java.lang.String pattern
private boolean allowDecimals
private boolean useLocaleFormat
private java.util.Locale locale
| Constructor Detail |
|---|
public NumberConverter(boolean allowDecimals)
ConversionException if a error occurs.
allowDecimals - Indicates whether decimals are allowed
public NumberConverter(boolean allowDecimals,
java.lang.Object defaultValue)
java.lang.Number Converter that returns
a default value if an error occurs.
allowDecimals - Indicates whether decimals are alloweddefaultValue - The default value to be returned| Method Detail |
|---|
public boolean isAllowDecimals()
public void setUseLocaleFormat(boolean useLocaleFormat)
useLocaleFormat - true if a number format
should be used.public java.lang.String getPattern()
java.lang.String
(or null if none specified).
See java.text.SimpleDateFormat for details
of how to specify the pattern.
public void setPattern(java.lang.String pattern)
java.lang.String.
See java.text.SimpleDateFormat for details
of how to specify the pattern.
pattern - The format pattern.public java.util.Locale getLocale()
null if none specified).
public void setLocale(java.util.Locale locale)
locale - The locale to use for conversion
protected java.lang.String convertToString(java.lang.Object value)
throws java.lang.Throwable
convertToString in class AbstractConvertervalue - The input value to be converted
java.lang.Throwable - if an error occurs converting to a String
protected java.lang.Object convertToType(java.lang.Class targetType,
java.lang.Object value)
throws java.lang.Throwable
convertToType in class AbstractConvertertargetType - Data type to which this value should be converted.value - The input value to be converted.
java.lang.Throwable - if an error occurs converting to the specified type
private java.lang.Number toNumber(java.lang.Class sourceType,
java.lang.Class targetType,
java.lang.Number value)
This method handles conversion to the following types:
java.lang.Bytejava.lang.Shortjava.lang.Integerjava.lang.Longjava.lang.Floatjava.lang.Doublejava.math.BigDecimaljava.math.BigInteger
sourceType - The type being converted fromtargetType - The Number type to convert tovalue - The Number to convert.
private java.lang.Number toNumber(java.lang.Class sourceType,
java.lang.Class targetType,
java.lang.String value)
This method handles conversion from a String to the following types:
java.lang.Bytejava.lang.Shortjava.lang.Integerjava.lang.Longjava.lang.Floatjava.lang.Doublejava.math.BigDecimaljava.math.BigInteger
sourceType - The type being converted fromtargetType - The Number type to convert tovalue - The String value to convert.
public java.lang.String toString()
toString in class AbstractConverterprivate java.text.NumberFormat getFormat()
private java.lang.Number parse(java.lang.Class sourceType,
java.lang.Class targetType,
java.lang.String value,
java.text.NumberFormat format)
Number object.
sourceType - TODOtargetType - The type to convert the value tovalue - The String date value.format - The NumberFormat to parse the String value.
ConversionException - if the String cannot be converted.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||