com.fdsapi
Class ConverterNumToString

java.lang.Object
  |
  +--com.fdsapi.ConverterBase
        |
        +--com.fdsapi.ConverterNumToString
All Implemented Interfaces:
Converter

public class ConverterNumToString
extends ConverterBase

This class takes any Object the inherits from the Number class (BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, and Short) and converts it to a formatted string based on the NumberFormat that is passed to the constructor or if the no arg constructor is used based on the default NumberFormatter returned by NumberFormat.getInstance(). The following give examples on how to construct this object.

Note due to its use of the nonthread safe class NumberFormat this class is NOT thread safe. It could be wrapped in a ThreadSafe object if this is important.

Sample call:

  Converter converter=new ConverterNumToString();// default NumberFormat
  converter=new ConverterNumToString(NumberFormat.getInstance());// same as default
  converter=new ConverterNumToString(NumberFormat.getNumberInstance());// default NumberFormat
  converter=new ConverterNumToString(NumberFormat.getCurrencyInstance());
  converter=new ConverterNumToString(NumberFormat.getIntegerInstance());
  converter=new ConverterNumToString(NumberFormat.getPercentInstance());
  Object obj=converter.convert(new Long(10000));// obj will have the String 10,000
 
  



View Code


Constructor Summary
ConverterNumToString()
          Creates a new instance of ConverterNumToString
ConverterNumToString(Converter nextConverter)
          Constructor that takes the next Converter in the decorator chain
ConverterNumToString(java.text.NumberFormat numberFormat)
          Constructor that takes the NumberFormat that will be used to format the Number object passed to the convert method.
ConverterNumToString(java.text.NumberFormat numberFormat, Converter nextConverter)
          Constructor that takes the formatter that will be used by convert to format the number as well as the next Converter in the decorator chain.
 
Method Summary
 java.lang.Object convert(java.lang.Object inputObj)
           
protected  Converter createInstance(Converter nextConverter)
          Called by the parent class when a createInstance() is called to make a copy of this Object
 
Methods inherited from class com.fdsapi.ConverterBase
createInstance, decoratorConvert
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConverterNumToString

public ConverterNumToString()
Creates a new instance of ConverterNumToString


ConverterNumToString

public ConverterNumToString(java.text.NumberFormat numberFormat)
Constructor that takes the NumberFormat that will be used to format the Number object passed to the convert method.


ConverterNumToString

public ConverterNumToString(Converter nextConverter)
Constructor that takes the next Converter in the decorator chain


ConverterNumToString

public ConverterNumToString(java.text.NumberFormat numberFormat,
                            Converter nextConverter)
Constructor that takes the formatter that will be used by convert to format the number as well as the next Converter in the decorator chain.

Method Detail

convert

public java.lang.Object convert(java.lang.Object inputObj)

createInstance

protected Converter createInstance(Converter nextConverter)
Called by the parent class when a createInstance() is called to make a copy of this Object

Specified by:
createInstance in class ConverterBase