| java.lang.Object org.apache.commons.beanutils.converters.AbstractConverter org.apache.commons.beanutils.converters.NumberConverter
All known Subclasses: org.apache.commons.beanutils.converters.FloatConverter, org.apache.commons.beanutils.converters.ByteConverter, org.apache.commons.beanutils.converters.BigDecimalConverter, org.apache.commons.beanutils.converters.DoubleConverter, org.apache.commons.beanutils.converters.LongConverter, org.apache.commons.beanutils.converters.ShortConverter, org.apache.commons.beanutils.converters.IntegerConverter, org.apache.commons.beanutils.converters.BigIntegerConverter,
NumberConverter | public class NumberConverter extends AbstractConverter (Code) | | org.apache.commons.beanutils.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.Byte
java.lang.Short
java.lang.Integer
java.lang.Long
java.lang.Float
java.lang.Double
java.math.BigDecimal
java.math.BigInteger
String Conversions (to and from)
This class provides a number of ways in which number
conversions to/from Strings can be achieved:
- Using the default format for the default Locale, configure using:
- Using the default format for a specified Locale, configure using:
- Using a specified pattern for the default Locale, configure using:
- Using a specified pattern for a specified Locale, configure using:
setPattern(String)
setLocale(Locale)
- If none of the above are configured the
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 .
version: $Revision: 555845 $ $Date: 2007-07-13 03:52:05 +0100 (Fri, 13 Jul 2007) $ since: 1.8.0 |
Constructor Summary | |
public | NumberConverter(Class defaultType, boolean allowDecimals) Construct a java.lang.Number Converter
that throws a ConversionException if a error occurs. | public | NumberConverter(Class defaultType, boolean allowDecimals, Object defaultValue) Construct a java.lang.Number Converter that returns
a default value if an error occurs. |
Method Summary | |
protected String | convertToString(Object value) Convert an input Number object into a String. | protected Object | convertToType(Class targetType, Object value) Convert the input object into a Number object of the
specified type.
Parameters: targetType - Data type to which this value should be converted. Parameters: value - The input value to be converted. | public Locale | getLocale() Return the Locale for the Converter
(or null if none specified). | public String | getPattern() Return the number format pattern used to convert
Numbers to/from a java.lang.String
(or null if none specified). | public boolean | isAllowDecimals() Return whether decimals are allowed in the number. | public void | setLocale(Locale locale) Set the Locale for the Converter. | public void | setPattern(String pattern) Set a number format pattern to use to convert
Numbers to/from a java.lang.String . | public void | setUseLocaleFormat(boolean useLocaleFormat) Set whether a format should be used to convert
the Number. | public String | toString() Provide a String representation of this number converter. |
NumberConverter | public NumberConverter(Class defaultType, boolean allowDecimals)(Code) | | Construct a java.lang.Number Converter
that throws a ConversionException if a error occurs.
Parameters: defaultType - The default type this Converter handles Parameters: allowDecimals - Indicates whether decimals are allowed |
NumberConverter | public NumberConverter(Class defaultType, boolean allowDecimals, Object defaultValue)(Code) | | Construct a java.lang.Number Converter that returns
a default value if an error occurs.
Parameters: defaultType - The default type this Converter handles Parameters: allowDecimals - Indicates whether decimals are allowed Parameters: defaultValue - The default value to be returned |
convertToString | protected String convertToString(Object value) throws Throwable(Code) | | Convert an input Number object into a String.
Parameters: value - The input value to be converted the converted String value. throws: Throwable - if an error occurs converting to a String |
convertToType | protected Object convertToType(Class targetType, Object value) throws Throwable(Code) | | Convert the input object into a Number object of the
specified type.
Parameters: targetType - Data type to which this value should be converted. Parameters: value - The input value to be converted. The converted value. throws: Throwable - if an error occurs converting to the specified type |
getLocale | public Locale getLocale()(Code) | | Return the Locale for the Converter
(or null if none specified).
The locale to use for conversion |
getPattern | public String getPattern()(Code) | | Return the number format pattern used to convert
Numbers to/from a java.lang.String
(or null if none specified).
See java.text.SimpleDateFormat for details
of how to specify the pattern.
The format pattern. |
isAllowDecimals | public boolean isAllowDecimals()(Code) | | Return whether decimals are allowed in the number.
Whether decimals are allowed in the number |
setLocale | public void setLocale(Locale locale)(Code) | | Set the Locale for the Converter.
Parameters: locale - The locale to use for conversion |
setPattern | public void setPattern(String pattern)(Code) | | Set a number format pattern to use to convert
Numbers to/from a java.lang.String .
See java.text.SimpleDateFormat for details
of how to specify the pattern.
Parameters: pattern - The format pattern. |
setUseLocaleFormat | public void setUseLocaleFormat(boolean useLocaleFormat)(Code) | | Set whether a format should be used to convert
the Number.
Parameters: useLocaleFormat - true if a number formatshould be used. |
toString | public String toString()(Code) | | Provide a String representation of this number converter.
A String representation of this number converter |
|
|