Java org.apache.commons.lang.math NumberUtils fields, constructors, methods, implement or subclass

Example usage for Java org.apache.commons.lang.math NumberUtils fields, constructors, methods, implement or subclass

Introduction

In this page you can find the methods, fields and constructors for org.apache.commons.lang.math NumberUtils.

The text is from its open source code.

Subclass

org.apache.commons.lang.math.NumberUtils has subclasses.
Click this link to see all its subclasses.

Field

LongLONG_ZERO
Reusable Long constant for zero.
LongLONG_ONE
Reusable Long constant for one.
IntegerINTEGER_ZERO
Reusable Integer constant for zero.
IntegerINTEGER_ONE
Reusable Integer constant for one.
IntegerINTEGER_MINUS_ONE
Reusable Integer constant for minus one.
ShortSHORT_ZERO
Reusable Short constant for zero.
DoubleDOUBLE_ZERO
Reusable Double constant for zero.
FloatFLOAT_ZERO
Reusable Float constant for zero.

Constructor

NumberUtils()

NumberUtils instances should NOT be constructed in standard programming.

Method

intcompare(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.

intcompare(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.
BigDecimalcreateBigDecimal(String str)

Convert a String to a BigDecimal.

Returns null if the string is null.

BigIntegercreateBigInteger(String str)

Convert a String to a BigInteger.

Returns null if the string is null.

DoublecreateDouble(String str)

Convert a String to a Double.

Returns null if the string is null.

FloatcreateFloat(String str)

Convert a String to a Float.

Returns null if the string is null.

IntegercreateInteger(String str)

Convert a String to a Integer, handling hex and octal notations.

Returns null if the string is null.

LongcreateLong(String str)

Convert a String to a Long.

Returns null if the string is null.

NumbercreateNumber(String str)

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').

booleanisDigits(String str)

Checks whether the String contains only digit characters.

Null and empty String will return false.

booleanisNumber(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.

longmax(long[] array)

Returns the maximum value in an array.

intmax(int[] array)

Returns the maximum value in an array.

shortmax(short[] array)

Returns the maximum value in an array.

bytemax(byte[] array)

Returns the maximum value in an array.

doublemax(double[] array)

Returns the maximum value in an array.

floatmax(float[] array)

Returns the maximum value in an array.

longmax(long a, long b, long c)

Gets the maximum of three long values.

intmax(int a, int b, int c)

Gets the maximum of three int values.

shortmax(short a, short b, short c)

Gets the maximum of three short values.

bytemax(byte a, byte b, byte c)

Gets the maximum of three byte values.

doublemax(double a, double b, double c)

Gets the maximum of three double values.

If any value is NaN, NaN is returned.

floatmax(float a, float b, float c)

Gets the maximum of three float values.

If any value is NaN, NaN is returned.

longmin(long[] array)

Returns the minimum value in an array.

intmin(int[] array)

Returns the minimum value in an array.

shortmin(short[] array)

Returns the minimum value in an array.

bytemin(byte[] array)

Returns the minimum value in an array.

doublemin(double[] array)

Returns the minimum value in an array.

floatmin(float[] array)

Returns the minimum value in an array.

longmin(long a, long b, long c)

Gets the minimum of three long values.

intmin(int a, int b, int c)

Gets the minimum of three int values.

shortmin(short a, short b, short c)

Gets the minimum of three short values.

bytemin(byte a, byte b, byte c)

Gets the minimum of three byte values.

doublemin(double a, double b, double c)

Gets the minimum of three double values.

If any value is NaN, NaN is returned.

floatmin(float a, float b, float c)

Gets the minimum of three float values.

If any value is NaN, NaN is returned.

intstringToInt(String str)

Convert a String to an int, returning zero if the conversion fails.

If the string is null, zero is returned.

 NumberUtils.stringToInt(null) = 0 NumberUtils.stringToInt("")   = 0 NumberUtils.stringToInt("1")  = 1 
intstringToInt(String str, int defaultValue)

Convert a String to an int, returning a default value if the conversion fails.

If the string is null, the default value is returned.

 NumberUtils.stringToInt(null, 1) = 1 NumberUtils.stringToInt("", 1)   = 1 NumberUtils.stringToInt("1", 0)  = 1 
doubletoDouble(String str, double defaultValue)

Convert a String to a double, returning a default value if the conversion fails.

If the string str is null, 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 
doubletoDouble(String str)

Convert a String to a double, returning 0.0d if the conversion fails.

If the string str is null, 0.0d is returned.

 NumberUtils.toDouble(null)   = 0.0d NumberUtils.toDouble("")     = 0.0d NumberUtils.toDouble("1.5")  = 1.5d 
floattoFloat(String str)

Convert a String to a float, returning 0.0f if the conversion fails.

If the string str is null, 0.0f is returned.

 NumberUtils.toFloat(null)   = 0.0f NumberUtils.toFloat("")     = 0.0f NumberUtils.toFloat("1.5")  = 1.5f 
floattoFloat(String str, float defaultValue)

Convert a String to a float, returning a default value if the conversion fails.

If the string str is null, 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 
inttoInt(String str, int defaultValue)

Convert a String to an int, 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 
inttoInt(String str)

Convert a String to an int, returning zero if the conversion fails.

If the string is null, zero is returned.

 NumberUtils.toInt(null) = 0 NumberUtils.toInt("")   = 0 NumberUtils.toInt("1")  = 1 
longtoLong(String str)

Convert a String to a long, returning zero if the conversion fails.

If the string is null, zero is returned.

 NumberUtils.toLong(null) = 0L NumberUtils.toLong("")   = 0L NumberUtils.toLong("1")  = 1L 
longtoLong(String str, long defaultValue)

Convert a String to a long, 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