|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.lang.NumberUtils
Provides extra functionality for java Number classes.
Constructor Summary | |
NumberUtils()
|
Method Summary | |
static java.math.BigDecimal |
createBigDecimal(java.lang.String val)
Convert a String to a BigDecimal |
static java.math.BigInteger |
createBigInteger(java.lang.String val)
Convert a String to a BigInteger |
static java.lang.Double |
createDouble(java.lang.String val)
Convert a String to a Double |
static java.lang.Float |
createFloat(java.lang.String val)
Convert a String to a Float |
static java.lang.Integer |
createInteger(java.lang.String val)
Convert a String to a Integer, handling hex and octal notations. |
static java.lang.Long |
createLong(java.lang.String val)
Convert a String to a Long |
static java.lang.Number |
createNumber(java.lang.String val)
Turns a string value into a java.lang.Number. |
private static boolean |
isAllZeros(java.lang.String s)
Utility method for createNumber. |
static boolean |
isDigits(java.lang.String str)
Checks whether the String contains only digit characters. |
static boolean |
isNumber(java.lang.String str)
Checks whether the String a valid Java number. |
static int |
maximum(int a,
int b,
int c)
Get the maximum of three values. |
static int |
minimum(int a,
int b,
int c)
Get the minimum of three values. |
static int |
stringToInt(java.lang.String str)
Convert a String to an int, returning zero if the conversion fails |
static int |
stringToInt(java.lang.String str,
int defaultValue)
Convert a String to an int, returning a default value if the conversion fails. |
Methods inherited from class java.lang.Object |
|
Constructor Detail |
public NumberUtils()
Method Detail |
public static int stringToInt(java.lang.String str)
str
- the string to convertpublic static int stringToInt(java.lang.String str, int defaultValue)
str
- the string to convertdefaultValue
- the default valuepublic static java.lang.Number createNumber(java.lang.String val) throws java.lang.NumberFormatException
Turns a string value into a java.lang.Number.
First, the value is examined for a type qualifier on the end
('f','F','d','D','l','L'
). If it is found, it starts
trying to create succissively larger types from the type specified
until one is found that can hold the value.
If a type specifier is not found, it will check for a decimal point and then try successively larger types from Integer to BigInteger and from Float to BigDecimal.
If the string starts with "0x" or "-0x", it will be interpreted as a hexadecimal integer. Values with leading 0's will not be interpreted as octal.
val
- String containing a numberjava.lang.NumberFormatException
- if the value cannot be convertedprivate static boolean isAllZeros(java.lang.String s)
s
- the String to checkpublic static java.lang.Float createFloat(java.lang.String val)
val
- a String to convertjava.lang.NumberFormatException
- if the value cannot be convertedpublic static java.lang.Double createDouble(java.lang.String val)
val
- a String to convertjava.lang.NumberFormatException
- if the value cannot be convertedpublic static java.lang.Integer createInteger(java.lang.String val)
val
- a String to convertjava.lang.NumberFormatException
- if the value cannot be convertedpublic static java.lang.Long createLong(java.lang.String val)
val
- a String to convertjava.lang.NumberFormatException
- if the value cannot be convertedpublic static java.math.BigInteger createBigInteger(java.lang.String val)
val
- a String to convertjava.lang.NumberFormatException
- if the value cannot be convertedpublic static java.math.BigDecimal createBigDecimal(java.lang.String val)
val
- a String to convertjava.lang.NumberFormatException
- if the value cannot be convertedpublic static int minimum(int a, int b, int c)
public static int maximum(int a, int b, int c)
public static boolean isDigits(java.lang.String str)
str
- the string to checkpublic static boolean isNumber(java.lang.String str)
Checks whether the String a valid Java number. Valid numbers include hexadecimal marked with the "0x" qualifier, scientific notation and numbers marked with a type qualifier (e.g. 123L).
Null and blank string will return false.
str
- the string to check
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |