public final class NumberUtils
extends java.lang.Object
Provides extra functionality for Java Number classes.
Constructor and Description |
---|
NumberUtils()
Deprecated.
NumberUtils instances should NOT be constructed in standard programming. |
Modifier and Type | Method and Description |
---|---|
static int |
compare(double lhs,
double rhs)
Deprecated.
Compares two
doubles for order. |
static int |
compare(float lhs,
float rhs)
Deprecated.
Compares two floats for order.
|
static java.math.BigDecimal |
createBigDecimal(java.lang.String val)
Deprecated.
Convert a
String to a BigDecimal . |
static java.math.BigInteger |
createBigInteger(java.lang.String val)
Deprecated.
Convert a
String to a BigInteger . |
static java.lang.Double |
createDouble(java.lang.String val)
Deprecated.
Convert a
String to a Double . |
static java.lang.Float |
createFloat(java.lang.String val)
Deprecated.
Convert a
String to a Float . |
static java.lang.Integer |
createInteger(java.lang.String val)
Deprecated.
Convert a
String to a Integer , handling
hex and octal notations. |
static java.lang.Long |
createLong(java.lang.String val)
Deprecated.
Convert a
String to a Long . |
static java.lang.Number |
createNumber(java.lang.String val)
Deprecated.
Turns a string value into a java.lang.Number.
|
static boolean |
isDigits(java.lang.String str)
Deprecated.
Checks whether the
String contains only
digit characters. |
static boolean |
isNumber(java.lang.String str)
Deprecated.
Checks whether the String a valid Java number.
|
static int |
maximum(int a,
int b,
int c)
Deprecated.
Gets the maximum of three
int values. |
static long |
maximum(long a,
long b,
long c)
Deprecated.
Gets the maximum of three
long values. |
static int |
minimum(int a,
int b,
int c)
Deprecated.
Gets the minimum of three
int values. |
static long |
minimum(long a,
long b,
long c)
Deprecated.
Gets the minimum of three
long values. |
static int |
stringToInt(java.lang.String str)
Deprecated.
Convert a
String to an int , returning
zero if the conversion fails. |
static int |
stringToInt(java.lang.String str,
int defaultValue)
Deprecated.
Convert a
String to an int , returning a
default value if the conversion fails. |
public NumberUtils()
NumberUtils
instances should NOT be constructed in standard programming.
Instead, the class should be used as NumberUtils.stringToInt("6");
.
This constructor is public to permit tools that require a JavaBean instance to operate.
public static int stringToInt(java.lang.String str)
Convert a String
to an int
, returning
zero
if the conversion fails.
str
- the string to convertzero
if
conversion failspublic static int stringToInt(java.lang.String str, int defaultValue)
Convert a String
to an int
, returning a
default value if the conversion fails.
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 successively 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 convertedpublic static java.lang.Float createFloat(java.lang.String val)
Convert a String
to a Float
.
val
- a String
to convertFloat
java.lang.NumberFormatException
- if the value cannot be convertedpublic static java.lang.Double createDouble(java.lang.String val)
Convert a String
to a Double
.
val
- a String
to convertDouble
java.lang.NumberFormatException
- if the value cannot be convertedpublic static java.lang.Integer createInteger(java.lang.String val)
Convert a String
to a Integer
, handling
hex and octal notations.
val
- a String
to convertInteger
java.lang.NumberFormatException
- if the value cannot be convertedpublic static java.lang.Long createLong(java.lang.String val)
Convert a String
to a Long
.
val
- a String
to convertLong
java.lang.NumberFormatException
- if the value cannot be convertedpublic static java.math.BigInteger createBigInteger(java.lang.String val)
Convert a String
to a BigInteger
.
val
- a String
to convertBigInteger
java.lang.NumberFormatException
- if the value cannot be convertedpublic static java.math.BigDecimal createBigDecimal(java.lang.String val)
Convert a String
to a BigDecimal
.
val
- a String
to convertBigDecimal
java.lang.NumberFormatException
- if the value cannot be convertedpublic static long minimum(long a, long b, long c)
Gets the minimum of three long
values.
a
- value 1b
- value 2c
- value 3public static int minimum(int a, int b, int c)
Gets the minimum of three int
values.
a
- value 1b
- value 2c
- value 3public static long maximum(long a, long b, long c)
Gets the maximum of three long
values.
a
- value 1b
- value 2c
- value 3public static int maximum(int a, int b, int c)
Gets the maximum of three int
values.
a
- value 1b
- value 2c
- value 3public static int compare(double lhs, double rhs)
Compares two doubles
for order.
This method is more comprehensive than the standard Java greater than, less than and equals operators.
-1
if the first value is less than the second.
+1
if the first value is greater than the second.
0
if the values are equal.
The ordering is as follows, largest to smallest:
Comparing NaN
with NaN
will
return 0
.
lhs
- the first double
rhs
- the second double
-1
if lhs is less, +1
if greater,
0
if equal to rhspublic static int compare(float lhs, float rhs)
Compares two floats for order.
This method is more comprehensive than the standard Java greater than, less than and equals operators.
-1
if the first value is less than the second.
+1
if the first value is greater than the second.
0
if the values are equal.
The ordering is as follows, largest to smallest:
Comparing NaN
with NaN
will return
0
.
lhs
- the first float
rhs
- the second float
-1
if lhs is less, +1
if greater,
0
if equal to rhspublic static boolean isDigits(java.lang.String str)
Checks whether the String
contains only
digit characters.
Null
and empty String will return
false
.
str
- the String
to checktrue
if str contains only unicode numericpublic 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 empty String will return
false
.
str
- the String
to checktrue
if the string is a correctly formatted number"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"