com.abstractics.utils.converter
Class ConverterNumber
java.lang.Object
com.abstractics.utils.converter.ConverterNumber
- All Implemented Interfaces:
- ObjectConverter
- public class ConverterNumber
- extends java.lang.Object
- implements ObjectConverter
Converter that can handle converting an object into the
java.lang.Number
subclass specified in the constructor.
Conversion is handled by calling the toString()
method on the
object and then using that String to attempt to construct the
java.lang.Number
subclass specified in the constructor.
This converter currently supports the following Number subclasses:
BigDecimal, BigInteger, Double, Float, Integer, Long, Short, and Byte.
- Version:
- $Id: ConverterNumber.java,v 1.2 2006/03/15 05:37:30 andyman99 Exp $
- Author:
- Andrew Lawrence, Copyright 2006 Abstractics, L.L.C., Licensed under the Apache
License, Version 2.0
Method Summary |
java.lang.Object |
convert(java.lang.Object obj,
java.util.Locale locale)
Since all of the subclasses of java.lang.Number have a
constructor that takes a single String, we use that to do the conversion. |
java.lang.Class |
getClassToConvertTo()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ConverterNumber
public ConverterNumber(java.lang.Class numberSubclass)
- Parameters:
numberSubclass
- Expected subclass of Number. Only BigDecimal, BigInteger,
Double, Float, Integer, Long, Short, and Byte are supported
- Throws:
java.lang.IllegalArgumentException
- Thrown if numberClass is null or is not one of the listed
Number subclasses.
convert
public java.lang.Object convert(java.lang.Object obj,
java.util.Locale locale)
throws ObjectConverterException
- Since all of the subclasses of
java.lang.Number
have a
constructor that takes a single String, we use that to do the conversion.
- Specified by:
convert
in interface ObjectConverter
- Parameters:
obj
- Object to be converted. Guaranteed not to be null and not to
already be an instanceof the Class returned by
ObjectConverter.getClassToConvertTo()
. Those conditions are checked
before the converter is even called.locale
- The locale that is asking for the conversion. This may or may
not be necessary for the conversion.
- Returns:
- The converted object - should NEVER return anything that is not
an instanceof the class returned by
ObjectConverter.getClassToConvertTo()
- Throws:
ObjectConverterException
- Throw this exception if the string cannot be converted, for
whatever reason.- See Also:
com.abstractics.xmlpanel.utils.stringtoobject.ObjectConverter#convert(Object)
getClassToConvertTo
public java.lang.Class getClassToConvertTo()
- Specified by:
getClassToConvertTo
in interface ObjectConverter
- Returns:
- The class that this converter converts to