站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.1.0 API 文档英文版

NumberUtils (Spring Framework API 2.1) - Spring Framework 2.1.0 API 文档英文版


The Spring Framework

org.springframework.util
Class NumberUtils

java.lang.Object
  extended by org.springframework.util.NumberUtils

public abstract class NumberUtils
extends Object

Miscellaneous utility methods 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, Rob Harrop

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 decode 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:
Byte, 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 decode methods. Trims the input String before attempting to parse the number. Supports numbers in hex format (with leading 0x) and in octal format (with leading 0).

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:
Byte.decode(java.lang.String), Short.decode(java.lang.String), Integer.decode(java.lang.String), Long.decode(java.lang.String), decodeBigInteger(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. Trims the input String before attempting to parse the number.

Parameters:
text - the text to convert
targetClass - the target class to parse into
numberFormat - the NumberFormat to use for parsing (if null, this method falls back to parseNumber(String, Class))
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, java.text.ParsePosition), convertNumberToTargetClass(java.lang.Number, java.lang.Class), parseNumber(String, Class)

The Spring Framework

Copyright © 2002-2007 The Spring Framework.