com.twelvemonkeys.util.convert
Class NumberConverter

java.lang.Object
  extended by com.twelvemonkeys.util.convert.NumberConverter
All Implemented Interfaces:
PropertyConverter
Direct Known Subclasses:
DateConverter, TimeConverter

public class NumberConverter
extends Object
implements PropertyConverter

Converts strings to numbers and back.

This class has a static cache of NumberFormats, to avoid creation and parsing of number formats every time one is used.

Version:
$Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/util/convert/NumberConverter.java#2 $
Author:
Harald Kuhr, last modified by $Author: haku $

Constructor Summary
NumberConverter()
           
 
Method Summary
protected  Format getFormat(Class pFormatterClass, Object... pFormat)
           
 Object toObject(String pString, Class pType, String pFormat)
          Converts the string to a number, using the given format for parsing.
 String toString(Object pObject, String pFormat)
          Converts the object to a string, using the given format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberConverter

public NumberConverter()
Method Detail

toObject

public Object toObject(String pString,
                       Class pType,
                       String pFormat)
                throws ConversionException
Converts the string to a number, using the given format for parsing.

Specified by:
toObject in interface PropertyConverter
Parameters:
pString - the string to convert.
pType - the type to convert to. PropertyConverter implementations may choose to ignore this parameter.
pFormat - the format used for parsing. PropertyConverter implementations may choose to ignore this parameter. Also, implementations that require a parser format, should provide a default format, and allow null as the format argument.
Returns:
the object created from the given string. May safely be typecast to java.lang.Number or the class of the type parameter.
Throws:
ConversionException
See Also:
Number, NumberFormat

toString

public String toString(Object pObject,
                       String pFormat)
                throws ConversionException
Converts the object to a string, using the given format

Specified by:
toString in interface PropertyConverter
Parameters:
pObject - the object to convert.
pFormat - the format used for parsing. PropertyConverter implementations may choose to ignore this parameter. Also, implementations that require a parser format, should provide a default format, and allow null as the format argument.
Returns:
the string representation of the object, on the correct format.
Throws:
ConversionException - if the object is not a subclass of Number

getFormat

protected final Format getFormat(Class pFormatterClass,
                                 Object... pFormat)


Copyright © 2015. All Rights Reserved.