liquibase.util
public abstract class NumberUtils extends java.lang.Object
Constructor and Description |
---|
NumberUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Number |
convertNumberToTargetClass(java.lang.Number number,
java.lang.Class targetClass)
Convert the given number into an instance of the given target class.
|
static java.lang.Number |
parseNumber(java.lang.String text,
java.lang.Class targetClass)
Parse the given text into a number instance of the given target class,
using the corresponding default
decode methods. |
static java.lang.Number |
parseNumber(java.lang.String text,
java.lang.Class targetClass,
java.text.NumberFormat numberFormat)
Parse the given text into a number instance of the given target class,
using the given NumberFormat.
|
static java.lang.Integer |
readInteger(java.lang.String value)
Convenience method for converting a string to an Integer object
|
public static java.lang.Number convertNumberToTargetClass(java.lang.Number number, java.lang.Class targetClass) throws java.lang.IllegalArgumentException
number
- the number to converttargetClass
- the target class to convert tojava.lang.IllegalArgumentException
- if the target class is not supported
(i.e. not a standard Number subclass as included in the JDK)Byte
,
Short
,
Integer
,
Long
,
BigInteger
,
Float
,
Double
,
BigDecimal
public static java.lang.Number parseNumber(java.lang.String text, java.lang.Class targetClass)
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).text
- the text to converttargetClass
- the target class to parse intojava.lang.IllegalArgumentException
- if the target class is not supported
(i.e. not a standard Number subclass as included in the JDK)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)
public static java.lang.Number parseNumber(java.lang.String text, java.lang.Class targetClass, java.text.NumberFormat numberFormat)
String
before attempting to parse the number.text
- the text to converttargetClass
- the target class to parse intonumberFormat
- the NumberFormat to use for parsing (if null
,
this method falls back to parseNumber(String, Class)
)java.lang.IllegalArgumentException
- if the target class is not supported
(i.e. not a standard Number subclass as included in the JDK)NumberFormat.parse(java.lang.String, java.text.ParsePosition)
,
convertNumberToTargetClass(java.lang.Number, java.lang.Class)
,
parseNumber(String,Class)
public static java.lang.Integer readInteger(java.lang.String value)
value
- string value