Class NumberUtils
Provides extra functionality for Java Number classes.
- Since:
- 2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ByteReusable Byte constant for minus one.static final ByteReusable Byte constant for one.static final ByteReusable Byte constant for zero.static final DoubleReusable Double constant for minus one.static final DoubleReusable Double constant for one.static final DoubleReusable Double constant for zero.static final FloatReusable Float constant for minus one.static final FloatReusable Float constant for one.static final FloatReusable Float constant for zero.static final IntegerReusable Integer constant for minus one.static final IntegerReusable Integer constant for one.static final IntegerReusable Integer constant for twostatic final IntegerReusable Integer constant for zero.static final LongInteger.MAX_VALUEas aLong.static final LongInteger.MIN_VALUEas aLong.static final LongReusable Long constant for minus one.static final LongReusable Long constant for one.static final LongReusable Long constant for zero.static final ShortReusable Short constant for minus one.static final ShortReusable Short constant for one.static final ShortReusable Short constant for zero. -
Constructor Summary
ConstructorsConstructorDescriptionNumberUtilsinstances should NOT be constructed in standard programming. -
Method Summary
Modifier and TypeMethodDescriptionstatic intcompare(byte x, byte y) Compares twobytevalues numerically.static intcompare(int x, int y) Compares twointvalues numerically.static intcompare(long x, long y) Compares tolongvalues numerically.static intcompare(short x, short y) Compares toshortvalues numerically.static BigDecimalcreateBigDecimal(String str) Convert aStringto aBigDecimal.static BigIntegercreateBigInteger(String str) Convert aStringto aBigInteger; since 3.2 it handles hex (0x or #) and octal (0) notations.static DoublecreateDouble(String str) Convert aStringto aDouble.static FloatcreateFloat(String str) Convert aStringto aFloat.static IntegercreateInteger(String str) Convert aStringto aInteger, handling hex (0xhhhh) and octal (0dddd) notations.static LongcreateLong(String str) Convert aStringto aLong; since 3.1 it handles hex (0Xhhhh) and octal (0ddd) notations.static NumbercreateNumber(String str) Turns a string value into a java.lang.Number.private static StringgetMantissa(String str) Utility method forcreateNumber(java.lang.String).private static StringgetMantissa(String str, int stopPos) Utility method forcreateNumber(java.lang.String).private static booleanisAllZeros(String str) Utility method forcreateNumber(java.lang.String).static booleanisCreatable(String str) Checks whether the String a valid Java number.static booleanChecks whether theStringcontains only digit characters.static booleanDeprecated.static booleanisParsable(String str) Checks whether the given String is a parsable number.static bytemax(byte... array) Returns the maximum value in an array.static bytemax(byte a, byte b, byte c) Gets the maximum of threebytevalues.static doublemax(double... array) Returns the maximum value in an array.static doublemax(double a, double b, double c) Gets the maximum of threedoublevalues.static floatmax(float... array) Returns the maximum value in an array.static floatmax(float a, float b, float c) Gets the maximum of threefloatvalues.static intmax(int... array) Returns the maximum value in an array.static intmax(int a, int b, int c) Gets the maximum of threeintvalues.static longmax(long... array) Returns the maximum value in an array.static longmax(long a, long b, long c) Gets the maximum of threelongvalues.static shortmax(short... array) Returns the maximum value in an array.static shortmax(short a, short b, short c) Gets the maximum of threeshortvalues.static bytemin(byte... array) Returns the minimum value in an array.static bytemin(byte a, byte b, byte c) Gets the minimum of threebytevalues.static doublemin(double... array) Returns the minimum value in an array.static doublemin(double a, double b, double c) Gets the minimum of threedoublevalues.static floatmin(float... array) Returns the minimum value in an array.static floatmin(float a, float b, float c) Gets the minimum of threefloatvalues.static intmin(int... array) Returns the minimum value in an array.static intmin(int a, int b, int c) Gets the minimum of threeintvalues.static longmin(long... array) Returns the minimum value in an array.static longmin(long a, long b, long c) Gets the minimum of threelongvalues.static shortmin(short... array) Returns the minimum value in an array.static shortmin(short a, short b, short c) Gets the minimum of threeshortvalues.static byteConvert aStringto abyte, returningzeroif the conversion fails.static byteConvert aStringto abyte, returning a default value if the conversion fails.static doubleConvert aStringto adouble, returning0.0dif the conversion fails.static doubleConvert aStringto adouble, returning a default value if the conversion fails.static doubletoDouble(BigDecimal value) Convert aBigDecimalto adouble.static doubletoDouble(BigDecimal value, double defaultValue) Convert aBigDecimalto adouble.static floatConvert aStringto afloat, returning0.0fif the conversion fails.static floatConvert aStringto afloat, returning a default value if the conversion fails.static intConvert aStringto anint, returningzeroif the conversion fails.static intConvert aStringto anint, returning a default value if the conversion fails.static longConvert aStringto along, returningzeroif the conversion fails.static longConvert aStringto along, returning a default value if the conversion fails.static BigDecimaltoScaledBigDecimal(Double value) Convert aDoubleto aBigDecimalwith a scale of two that has been rounded usingRoundingMode.HALF_EVEN.static BigDecimaltoScaledBigDecimal(Double value, int scale, RoundingMode roundingMode) Convert aDoubleto aBigDecimalwhose scale is the specified value with aRoundingModeapplied.static BigDecimaltoScaledBigDecimal(Float value) Convert aFloatto aBigDecimalwith a scale of two that has been rounded usingRoundingMode.HALF_EVEN.static BigDecimaltoScaledBigDecimal(Float value, int scale, RoundingMode roundingMode) Convert aFloatto aBigDecimalwhose scale is the specified value with aRoundingModeapplied.static BigDecimaltoScaledBigDecimal(String value) Convert aStringto aBigDecimalwith a scale of two that has been rounded usingRoundingMode.HALF_EVEN.static BigDecimaltoScaledBigDecimal(String value, int scale, RoundingMode roundingMode) Convert aStringto aBigDecimalwhose scale is the specified value with aRoundingModeapplied.static BigDecimaltoScaledBigDecimal(BigDecimal value) Convert aBigDecimalto aBigDecimalwith a scale of two that has been rounded usingRoundingMode.HALF_EVEN.static BigDecimaltoScaledBigDecimal(BigDecimal value, int scale, RoundingMode roundingMode) Convert aBigDecimalto aBigDecimalwhose scale is the specified value with aRoundingModeapplied.static shortConvert aStringto ashort, returningzeroif the conversion fails.static shortConvert aStringto anshort, returning a default value if the conversion fails.private static voidvalidateArray(Object array) Checks if the specified array is neither null nor empty.private static booleanwithDecimalsParsing(String str, int beginIdx)
-
Field Details
-
LONG_ZERO
Reusable Long constant for zero. -
LONG_ONE
Reusable Long constant for one. -
LONG_MINUS_ONE
Reusable Long constant for minus one. -
INTEGER_ZERO
Reusable Integer constant for zero. -
INTEGER_ONE
Reusable Integer constant for one. -
INTEGER_TWO
Reusable Integer constant for two -
INTEGER_MINUS_ONE
Reusable Integer constant for minus one. -
SHORT_ZERO
Reusable Short constant for zero. -
SHORT_ONE
Reusable Short constant for one. -
SHORT_MINUS_ONE
Reusable Short constant for minus one. -
BYTE_ZERO
Reusable Byte constant for zero. -
BYTE_ONE
Reusable Byte constant for one. -
BYTE_MINUS_ONE
Reusable Byte constant for minus one. -
DOUBLE_ZERO
Reusable Double constant for zero. -
DOUBLE_ONE
Reusable Double constant for one. -
DOUBLE_MINUS_ONE
Reusable Double constant for minus one. -
FLOAT_ZERO
Reusable Float constant for zero. -
FLOAT_ONE
Reusable Float constant for one. -
FLOAT_MINUS_ONE
Reusable Float constant for minus one. -
LONG_INT_MAX_VALUE
Integer.MAX_VALUEas aLong.- Since:
- 3.12.0
-
LONG_INT_MIN_VALUE
Integer.MIN_VALUEas aLong.- Since:
- 3.12.0
-
-
Constructor Details
-
NumberUtils
public NumberUtils()NumberUtilsinstances should NOT be constructed in standard programming. Instead, the class should be used asNumberUtils.toInt("6");.This constructor is public to permit tools that require a JavaBean instance to operate.
-
-
Method Details
-
toInt
Convert a
Stringto anint, returningzeroif the conversion fails.If the string is
null,zerois returned.NumberUtils.toInt(null) = 0 NumberUtils.toInt("") = 0 NumberUtils.toInt("1") = 1- Parameters:
str- the string to convert, may be null- Returns:
- the int represented by the string, or
zeroif conversion fails - Since:
- 2.1
-
toInt
Convert a
Stringto anint, returning a default value if the conversion fails.If the string is
null, the default value is returned.NumberUtils.toInt(null, 1) = 1 NumberUtils.toInt("", 1) = 1 NumberUtils.toInt("1", 0) = 1- Parameters:
str- the string to convert, may be nulldefaultValue- the default value- Returns:
- the int represented by the string, or the default if conversion fails
- Since:
- 2.1
-
toLong
Convert a
Stringto along, returningzeroif the conversion fails.If the string is
null,zerois returned.NumberUtils.toLong(null) = 0L NumberUtils.toLong("") = 0L NumberUtils.toLong("1") = 1L- Parameters:
str- the string to convert, may be null- Returns:
- the long represented by the string, or
0if conversion fails - Since:
- 2.1
-
toLong
Convert a
Stringto along, returning a default value if the conversion fails.If the string is
null, the default value is returned.NumberUtils.toLong(null, 1L) = 1L NumberUtils.toLong("", 1L) = 1L NumberUtils.toLong("1", 0L) = 1L- Parameters:
str- the string to convert, may be nulldefaultValue- the default value- Returns:
- the long represented by the string, or the default if conversion fails
- Since:
- 2.1
-
toFloat
Convert a
Stringto afloat, returning0.0fif the conversion fails.If the string
strisnull,0.0fis returned.NumberUtils.toFloat(null) = 0.0f NumberUtils.toFloat("") = 0.0f NumberUtils.toFloat("1.5") = 1.5f- Parameters:
str- the string to convert, may benull- Returns:
- the float represented by the string, or
0.0fif conversion fails - Since:
- 2.1
-
toFloat
Convert a
Stringto afloat, returning a default value if the conversion fails.If the string
strisnull, the default value is returned.NumberUtils.toFloat(null, 1.1f) = 1.0f NumberUtils.toFloat("", 1.1f) = 1.1f NumberUtils.toFloat("1.5", 0.0f) = 1.5f- Parameters:
str- the string to convert, may benulldefaultValue- the default value- Returns:
- the float represented by the string, or defaultValue if conversion fails
- Since:
- 2.1
-
toDouble
Convert a
Stringto adouble, returning0.0dif the conversion fails.If the string
strisnull,0.0dis returned.NumberUtils.toDouble(null) = 0.0d NumberUtils.toDouble("") = 0.0d NumberUtils.toDouble("1.5") = 1.5d- Parameters:
str- the string to convert, may benull- Returns:
- the double represented by the string, or
0.0dif conversion fails - Since:
- 2.1
-
toDouble
Convert a
Stringto adouble, returning a default value if the conversion fails.If the string
strisnull, the default value is returned.NumberUtils.toDouble(null, 1.1d) = 1.1d NumberUtils.toDouble("", 1.1d) = 1.1d NumberUtils.toDouble("1.5", 0.0d) = 1.5d- Parameters:
str- the string to convert, may benulldefaultValue- the default value- Returns:
- the double represented by the string, or defaultValue if conversion fails
- Since:
- 2.1
-
toDouble
Convert a
BigDecimalto adouble.If the
BigDecimalvalueisnull, then the specified default value is returned.NumberUtils.toDouble(null) = 0.0d NumberUtils.toDouble(BigDecimal.valudOf(8.5d)) = 8.5d
- Parameters:
value- theBigDecimalto convert, may benull.- Returns:
- the double represented by the
BigDecimalor0.0dif theBigDecimalisnull. - Since:
- 3.8
-
toDouble
Convert a
BigDecimalto adouble.If the
BigDecimalvalueisnull, then the specified default value is returned.NumberUtils.toDouble(null, 1.1d) = 1.1d NumberUtils.toDouble(BigDecimal.valudOf(8.5d), 1.1d) = 8.5d
- Parameters:
value- theBigDecimalto convert, may benull.defaultValue- the default value- Returns:
- the double represented by the
BigDecimalor the defaultValue if theBigDecimalisnull. - Since:
- 3.8
-
toByte
Convert a
Stringto abyte, returningzeroif the conversion fails.If the string is
null,zerois returned.NumberUtils.toByte(null) = 0 NumberUtils.toByte("") = 0 NumberUtils.toByte("1") = 1- Parameters:
str- the string to convert, may be null- Returns:
- the byte represented by the string, or
zeroif conversion fails - Since:
- 2.5
-
toByte
Convert a
Stringto abyte, returning a default value if the conversion fails.If the string is
null, the default value is returned.NumberUtils.toByte(null, 1) = 1 NumberUtils.toByte("", 1) = 1 NumberUtils.toByte("1", 0) = 1- Parameters:
str- the string to convert, may be nulldefaultValue- the default value- Returns:
- the byte represented by the string, or the default if conversion fails
- Since:
- 2.5
-
toShort
Convert a
Stringto ashort, returningzeroif the conversion fails.If the string is
null,zerois returned.NumberUtils.toShort(null) = 0 NumberUtils.toShort("") = 0 NumberUtils.toShort("1") = 1- Parameters:
str- the string to convert, may be null- Returns:
- the short represented by the string, or
zeroif conversion fails - Since:
- 2.5
-
toShort
Convert a
Stringto anshort, returning a default value if the conversion fails.If the string is
null, the default value is returned.NumberUtils.toShort(null, 1) = 1 NumberUtils.toShort("", 1) = 1 NumberUtils.toShort("1", 0) = 1- Parameters:
str- the string to convert, may be nulldefaultValue- the default value- Returns:
- the short represented by the string, or the default if conversion fails
- Since:
- 2.5
-
toScaledBigDecimal
Convert aBigDecimalto aBigDecimalwith a scale of two that has been rounded usingRoundingMode.HALF_EVEN. If the suppliedvalueis null, thenBigDecimal.ZEROis returned.Note, the scale of a
BigDecimalis the number of digits to the right of the decimal point.- Parameters:
value- theBigDecimalto convert, may be null.- Returns:
- the scaled, with appropriate rounding,
BigDecimal. - Since:
- 3.8
-
toScaledBigDecimal
Convert aBigDecimalto aBigDecimalwhose scale is the specified value with aRoundingModeapplied. If the inputvalueisnull, we simply returnBigDecimal.ZERO.- Parameters:
value- theBigDecimalto convert, may be null.scale- the number of digits to the right of the decimal point.roundingMode- a rounding behavior for numerical operations capable of discarding precision.- Returns:
- the scaled, with appropriate rounding,
BigDecimal. - Since:
- 3.8
-
toScaledBigDecimal
Convert aFloatto aBigDecimalwith a scale of two that has been rounded usingRoundingMode.HALF_EVEN. If the suppliedvalueis null, thenBigDecimal.ZEROis returned.Note, the scale of a
BigDecimalis the number of digits to the right of the decimal point.- Parameters:
value- theFloatto convert, may be null.- Returns:
- the scaled, with appropriate rounding,
BigDecimal. - Since:
- 3.8
-
toScaledBigDecimal
Convert aFloatto aBigDecimalwhose scale is the specified value with aRoundingModeapplied. If the inputvalueisnull, we simply returnBigDecimal.ZERO.- Parameters:
value- theFloatto convert, may be null.scale- the number of digits to the right of the decimal point.roundingMode- a rounding behavior for numerical operations capable of discarding precision.- Returns:
- the scaled, with appropriate rounding,
BigDecimal. - Since:
- 3.8
-
toScaledBigDecimal
Convert aDoubleto aBigDecimalwith a scale of two that has been rounded usingRoundingMode.HALF_EVEN. If the suppliedvalueis null, thenBigDecimal.ZEROis returned.Note, the scale of a
BigDecimalis the number of digits to the right of the decimal point.- Parameters:
value- theDoubleto convert, may be null.- Returns:
- the scaled, with appropriate rounding,
BigDecimal. - Since:
- 3.8
-
toScaledBigDecimal
Convert aDoubleto aBigDecimalwhose scale is the specified value with aRoundingModeapplied. If the inputvalueisnull, we simply returnBigDecimal.ZERO.- Parameters:
value- theDoubleto convert, may be null.scale- the number of digits to the right of the decimal point.roundingMode- a rounding behavior for numerical operations capable of discarding precision.- Returns:
- the scaled, with appropriate rounding,
BigDecimal. - Since:
- 3.8
-
toScaledBigDecimal
Convert aStringto aBigDecimalwith a scale of two that has been rounded usingRoundingMode.HALF_EVEN. If the suppliedvalueis null, thenBigDecimal.ZEROis returned.Note, the scale of a
BigDecimalis the number of digits to the right of the decimal point.- Parameters:
value- theStringto convert, may be null.- Returns:
- the scaled, with appropriate rounding,
BigDecimal. - Since:
- 3.8
-
toScaledBigDecimal
Convert aStringto aBigDecimalwhose scale is the specified value with aRoundingModeapplied. If the inputvalueisnull, we simply returnBigDecimal.ZERO.- Parameters:
value- theStringto convert, may be null.scale- the number of digits to the right of the decimal point.roundingMode- a rounding behavior for numerical operations capable of discarding precision.- Returns:
- the scaled, with appropriate rounding,
BigDecimal. - Since:
- 3.8
-
createNumber
Turns a string value into a java.lang.Number.
If the string starts with
0xor-0x(lower or upper case) or#or-#, it will be interpreted as a hexadecimal Integer - or Long, if the number of digits after the prefix is more than 8 - or BigInteger if there are more than 16 digits.Then, the value is examined for a type qualifier on the end, i.e. one of
'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 represent the value.If a type specifier is not found, it will check for a decimal point and then try successively larger types from
IntegertoBigIntegerand fromFloattoBigDecimal.Integral values with a leading
0will be interpreted as octal; the returned number will be Integer, Long or BigDecimal as appropriate.Returns
nullif the string isnull.This method does not trim the input string, i.e., strings with leading or trailing spaces will generate NumberFormatExceptions.
- Parameters:
str- String containing a number, may be null- Returns:
- Number created from the string (or null if the input is null)
- Throws:
NumberFormatException- if the value cannot be converted
-
getMantissa
Utility method for
createNumber(java.lang.String).Returns mantissa of the given number.
- Parameters:
str- the string representation of the number- Returns:
- mantissa of the given number
-
getMantissa
Utility method for
createNumber(java.lang.String).Returns mantissa of the given number.
- Parameters:
str- the string representation of the numberstopPos- the position of the exponent or decimal point- Returns:
- mantissa of the given number
-
isAllZeros
Utility method for
createNumber(java.lang.String).Returns
trueif s isnull.- Parameters:
str- the String to check- Returns:
- if it is all zeros or
null
-
createFloat
Convert a
Stringto aFloat.Returns
nullif the string isnull.- Parameters:
str- aStringto convert, may be null- Returns:
- converted
Float(or null if the input is null) - Throws:
NumberFormatException- if the value cannot be converted
-
createDouble
Convert a
Stringto aDouble.Returns
nullif the string isnull.- Parameters:
str- aStringto convert, may be null- Returns:
- converted
Double(or null if the input is null) - Throws:
NumberFormatException- if the value cannot be converted
-
createInteger
Convert a
Stringto aInteger, handling hex (0xhhhh) and octal (0dddd) notations. N.B. a leading zero means octal; spaces are not trimmed.Returns
nullif the string isnull.- Parameters:
str- aStringto convert, may be null- Returns:
- converted
Integer(or null if the input is null) - Throws:
NumberFormatException- if the value cannot be converted
-
createLong
Convert a
Stringto aLong; since 3.1 it handles hex (0Xhhhh) and octal (0ddd) notations. N.B. a leading zero means octal; spaces are not trimmed.Returns
nullif the string isnull.- Parameters:
str- aStringto convert, may be null- Returns:
- converted
Long(or null if the input is null) - Throws:
NumberFormatException- if the value cannot be converted
-
createBigInteger
Convert a
Stringto aBigInteger; since 3.2 it handles hex (0x or #) and octal (0) notations.Returns
nullif the string isnull.- Parameters:
str- aStringto convert, may be null- Returns:
- converted
BigInteger(or null if the input is null) - Throws:
NumberFormatException- if the value cannot be converted
-
createBigDecimal
Convert a
Stringto aBigDecimal.Returns
nullif the string isnull.- Parameters:
str- aStringto convert, may be null- Returns:
- converted
BigDecimal(or null if the input is null) - Throws:
NumberFormatException- if the value cannot be converted
-
min
public static long min(long... array) Returns the minimum value in an array.
- Parameters:
array- an array, must not be null or empty- Returns:
- the minimum value in the array
- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty- Since:
- 3.4 Changed signature from min(long[]) to min(long...)
-
min
public static int min(int... array) Returns the minimum value in an array.
- Parameters:
array- an array, must not be null or empty- Returns:
- the minimum value in the array
- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty- Since:
- 3.4 Changed signature from min(int[]) to min(int...)
-
min
public static short min(short... array) Returns the minimum value in an array.
- Parameters:
array- an array, must not be null or empty- Returns:
- the minimum value in the array
- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty- Since:
- 3.4 Changed signature from min(short[]) to min(short...)
-
min
public static byte min(byte... array) Returns the minimum value in an array.
- Parameters:
array- an array, must not be null or empty- Returns:
- the minimum value in the array
- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty- Since:
- 3.4 Changed signature from min(byte[]) to min(byte...)
-
min
public static double min(double... array) Returns the minimum value in an array.
- Parameters:
array- an array, must not be null or empty- Returns:
- the minimum value in the array
- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty- Since:
- 3.4 Changed signature from min(double[]) to min(double...)
- See Also:
-
min
public static float min(float... array) Returns the minimum value in an array.
- Parameters:
array- an array, must not be null or empty- Returns:
- the minimum value in the array
- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty- Since:
- 3.4 Changed signature from min(float[]) to min(float...)
- See Also:
-
max
public static long max(long... array) Returns the maximum value in an array.
- Parameters:
array- an array, must not be null or empty- Returns:
- the maximum value in the array
- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty- Since:
- 3.4 Changed signature from max(long[]) to max(long...)
-
max
public static int max(int... array) Returns the maximum value in an array.
- Parameters:
array- an array, must not be null or empty- Returns:
- the maximum value in the array
- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty- Since:
- 3.4 Changed signature from max(int[]) to max(int...)
-
max
public static short max(short... array) Returns the maximum value in an array.
- Parameters:
array- an array, must not be null or empty- Returns:
- the maximum value in the array
- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty- Since:
- 3.4 Changed signature from max(short[]) to max(short...)
-
max
public static byte max(byte... array) Returns the maximum value in an array.
- Parameters:
array- an array, must not be null or empty- Returns:
- the maximum value in the array
- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty- Since:
- 3.4 Changed signature from max(byte[]) to max(byte...)
-
max
public static double max(double... array) Returns the maximum value in an array.
- Parameters:
array- an array, must not be null or empty- Returns:
- the maximum value in the array
- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty- Since:
- 3.4 Changed signature from max(double[]) to max(double...)
- See Also:
-
max
public static float max(float... array) Returns the maximum value in an array.
- Parameters:
array- an array, must not be null or empty- Returns:
- the maximum value in the array
- Throws:
IllegalArgumentException- ifarrayisnullIllegalArgumentException- ifarrayis empty- Since:
- 3.4 Changed signature from max(float[]) to max(float...)
- See Also:
-
validateArray
Checks if the specified array is neither null nor empty.- Parameters:
array- the array to check- Throws:
IllegalArgumentException- ifarrayis eithernullor empty
-
min
public static long min(long a, long b, long c) Gets the minimum of three
longvalues.- Parameters:
a- value 1b- value 2c- value 3- Returns:
- the smallest of the values
-
min
public static int min(int a, int b, int c) Gets the minimum of three
intvalues.- Parameters:
a- value 1b- value 2c- value 3- Returns:
- the smallest of the values
-
min
public static short min(short a, short b, short c) Gets the minimum of three
shortvalues.- Parameters:
a- value 1b- value 2c- value 3- Returns:
- the smallest of the values
-
min
public static byte min(byte a, byte b, byte c) Gets the minimum of three
bytevalues.- Parameters:
a- value 1b- value 2c- value 3- Returns:
- the smallest of the values
-
min
public static double min(double a, double b, double c) Gets the minimum of three
doublevalues.If any value is
NaN,NaNis returned. Infinity is handled.- Parameters:
a- value 1b- value 2c- value 3- Returns:
- the smallest of the values
- See Also:
-
min
public static float min(float a, float b, float c) Gets the minimum of three
floatvalues.If any value is
NaN,NaNis returned. Infinity is handled.- Parameters:
a- value 1b- value 2c- value 3- Returns:
- the smallest of the values
- See Also:
-
max
public static long max(long a, long b, long c) Gets the maximum of three
longvalues.- Parameters:
a- value 1b- value 2c- value 3- Returns:
- the largest of the values
-
max
public static int max(int a, int b, int c) Gets the maximum of three
intvalues.- Parameters:
a- value 1b- value 2c- value 3- Returns:
- the largest of the values
-
max
public static short max(short a, short b, short c) Gets the maximum of three
shortvalues.- Parameters:
a- value 1b- value 2c- value 3- Returns:
- the largest of the values
-
max
public static byte max(byte a, byte b, byte c) Gets the maximum of three
bytevalues.- Parameters:
a- value 1b- value 2c- value 3- Returns:
- the largest of the values
-
max
public static double max(double a, double b, double c) Gets the maximum of three
doublevalues.If any value is
NaN,NaNis returned. Infinity is handled.- Parameters:
a- value 1b- value 2c- value 3- Returns:
- the largest of the values
- See Also:
-
max
public static float max(float a, float b, float c) Gets the maximum of three
floatvalues.If any value is
NaN,NaNis returned. Infinity is handled.- Parameters:
a- value 1b- value 2c- value 3- Returns:
- the largest of the values
- See Also:
-
isDigits
Checks whether the
Stringcontains only digit characters.Nulland empty String will returnfalse.- Parameters:
str- theStringto check- Returns:
trueif str contains only Unicode numeric
-
isNumber
Deprecated.This feature will be removed in Lang 4.0, useisCreatable(String)insteadChecks whether the String a valid Java number.
Valid numbers include hexadecimal marked with the
0xor0Xqualifier, octal numbers, scientific notation and numbers marked with a type qualifier (e.g. 123L).Non-hexadecimal strings beginning with a leading zero are treated as octal values. Thus the string
09will returnfalse, since9is not a valid octal value. However, numbers beginning with0.are treated as decimal.nulland empty/blankStringwill returnfalse.Note,
createNumber(String)should return a number for every input resulting intrue.- Parameters:
str- theStringto check- Returns:
trueif the string is a correctly formatted number- Since:
- 3.3 the code supports hex
0Xhhhan octal0dddvalidation
-
isCreatable
Checks whether the String a valid Java number.
Valid numbers include hexadecimal marked with the
0xor0Xqualifier, octal numbers, scientific notation and numbers marked with a type qualifier (e.g. 123L).Non-hexadecimal strings beginning with a leading zero are treated as octal values. Thus the string
09will returnfalse, since9is not a valid octal value. However, numbers beginning with0.are treated as decimal.nulland empty/blankStringwill returnfalse.Note,
createNumber(String)should return a number for every input resulting intrue.- Parameters:
str- theStringto check- Returns:
trueif the string is a correctly formatted number- Since:
- 3.5
-
isParsable
Checks whether the given String is a parsable number.
Parsable numbers include those Strings understood by
Integer.parseInt(String),Long.parseLong(String),Float.parseFloat(String)orDouble.parseDouble(String). This method can be used instead of catchingParseExceptionwhen calling one of those methods.Hexadecimal and scientific notations are not considered parsable. See
isCreatable(String)on those cases.Nulland empty String will returnfalse.- Parameters:
str- the String to check.- Returns:
trueif the string is a parsable number.- Since:
- 3.4
-
withDecimalsParsing
-
compare
public static int compare(int x, int y) Compares two
intvalues numerically. This is the same functionality as provided in Java 7.- Parameters:
x- the firstintto comparey- the secondintto compare- Returns:
- the value
0ifx == y; a value less than0ifx < y; and a value greater than0ifx > y - Since:
- 3.4
-
compare
public static int compare(long x, long y) Compares to
longvalues numerically. This is the same functionality as provided in Java 7.- Parameters:
x- the firstlongto comparey- the secondlongto compare- Returns:
- the value
0ifx == y; a value less than0ifx < y; and a value greater than0ifx > y - Since:
- 3.4
-
compare
public static int compare(short x, short y) Compares to
shortvalues numerically. This is the same functionality as provided in Java 7.- Parameters:
x- the firstshortto comparey- the secondshortto compare- Returns:
- the value
0ifx == y; a value less than0ifx < y; and a value greater than0ifx > y - Since:
- 3.4
-
compare
public static int compare(byte x, byte y) Compares two
bytevalues numerically. This is the same functionality as provided in Java 7.- Parameters:
x- the firstbyteto comparey- the secondbyteto compare- Returns:
- the value
0ifx == y; a value less than0ifx < y; and a value greater than0ifx > y - Since:
- 3.4
-
isCreatable(String)instead