org.springframework.util
Class NumberUtils

java.lang.Object
  extended byorg.springframework.util.NumberUtils

public abstract class NumberUtils
extends Object

Miscellaneous utility methos for number conversion and parsing. Mainly for internal use within the framework; consider Jakarta's Commons Lang for a more comprehensive suite of string utilities.

Since:
1.1.2
Author:
Juergen Hoeller

Constructor Summary
NumberUtils()
           
 
Method Summary
static Number convertNumberToTargetClass(Number number, Class targetClass)
          Convert the given number into an instance of the given target class.
static Number parseNumber(String text, Class targetClass)
          Parse the given text into a number instance of the given target class, using the corresponding default valueOf methods.
static Number parseNumber(String text, Class targetClass, NumberFormat numberFormat)
          Parse the given text into a number instance of the given target class, using the given NumberFormat.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberUtils

public NumberUtils()
Method Detail

convertNumberToTargetClass

public static Number convertNumberToTargetClass(Number number,
                                                Class targetClass)
                                         throws IllegalArgumentException
Convert the given number into an instance of the given target class.

Parameters:
number - the number to convert
targetClass - the target class to convert to
Returns:
the converted number
Throws:
IllegalArgumentException - if the target class is not supported (i.e. not a standard Number subclass as included in the JDK)
See Also:
Short, Integer, Long, BigInteger, Float, Double, BigDecimal

parseNumber

public static Number parseNumber(String text,
                                 Class targetClass)
Parse the given text into a number instance of the given target class, using the corresponding default valueOf methods.

Parameters:
text - the text to convert
targetClass - the target class to parse into
Returns:
the parsed number
Throws:
IllegalArgumentException - if the target class is not supported (i.e. not a standard Number subclass as included in the JDK)
See Also:
Short.valueOf(java.lang.String), Integer.valueOf(java.lang.String), Long.valueOf(java.lang.String), BigInteger.BigInteger(String), Float.valueOf(java.lang.String), Double.valueOf(java.lang.String), BigDecimal.BigDecimal(String)

parseNumber

public static Number parseNumber(String text,
                                 Class targetClass,
                                 NumberFormat numberFormat)
Parse the given text into a number instance of the given target class, using the given NumberFormat.

Parameters:
text - the text to convert
targetClass - the target class to parse into
numberFormat - the NumberFormat to use for parsing
Returns:
the parsed number
Throws:
IllegalArgumentException - if the target class is not supported (i.e. not a standard Number subclass as included in the JDK)
See Also:
NumberFormat.parse(java.lang.String), convertNumberToTargetClass(java.lang.Number, java.lang.Class)


Copyright (C) 2003-2004 The Spring Framework Project.