compare
public 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.
- It returns
-1
if the first value is less than the second.
- It returns
+1
if the first value is greater than the second.
- It returns
0
if the values are equal.
The ordering is as follows, largest to smallest:
- NaN
- Positive infinity
- Maximum double
- Normal positive numbers
- +0.0
- -0.0
- Normal negative numbers
- Minimum double (-Double.MAX_VALUE)
- Negative infinity
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 rhs
compare
public 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.
- It returns
-1
if the first value is less than the second.
- It returns
+1
if the first value is greater than the second.
- It returns
0
if the values are equal.
The ordering is as follows, largest to smallest:
- NaN
- Positive infinity
- Maximum float
- Normal positive numbers
- +0.0
- -0.0
- Normal negative numbers
- Minimum float (-Float.MAX_VALUE)
- Negative infinity
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 rhs
createBigDecimal
public static BigDecimal createBigDecimal(String val)
Convert a String
to a BigDecimal
.
val
- a String
to convert
createBigInteger
public static BigInteger createBigInteger(String val)
Convert a String
to a BigInteger
.
val
- a String
to convert
createDouble
public static Double createDouble(String val)
Convert a String
to a Double
.
val
- a String
to convert
createFloat
public static Float createFloat(String val)
Convert a String
to a Float
.
val
- a String
to convert
createInteger
public static Integer createInteger(String val)
Convert a String
to a Integer
, handling
hex and octal notations.
val
- a String
to convert
createLong
public static Long createLong(String val)
Convert a String
to a Long
.
val
- a String
to convert
createNumber
public static Number createNumber(String val)
throws 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 number
- Number created from the string
isDigits
public static boolean isDigits(String str)
Checks whether the
String
contains only
digit characters.
Null
and empty String will return
false
.
str
- the String
to check
true
if str contains only unicode numeric
isNumber
public static boolean isNumber(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 check
true
if the string is a correctly formatted number
maximum
public static int maximum(int a,
int b,
int c)
Gets the maximum of three int
values.
a
- value 1b
- value 2c
- value 3
- the largest of the values
maximum
public static long maximum(long a,
long b,
long c)
Gets the maximum of three long
values.
a
- value 1b
- value 2c
- value 3
- the largest of the values
minimum
public static int minimum(int a,
int b,
int c)
Gets the minimum of three int
values.
a
- value 1b
- value 2c
- value 3
- the smallest of the values
minimum
public static long minimum(long a,
long b,
long c)
Gets the minimum of three long
values.
a
- value 1b
- value 2c
- value 3
- the smallest of the values
stringToInt
public static int stringToInt(String str)
Convert a String
to an int
, returning
zero
if the conversion fails.
str
- the string to convert
- the int represented by the string, or
zero
if
conversion fails
stringToInt
public static int stringToInt(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 value
- the int represented by the string, or the default if conversion fails