org.jopendocument.util
Class NumberUtils

java.lang.Object
  extended by org.jopendocument.util.NumberUtils

public class NumberUtils
extends Object


Constructor Summary
NumberUtils()
           
 
Method Summary
static
<N extends Number>
boolean
areEqual(N n1, N n2)
          Test class and numerical equality.
static boolean areNumericallyEqual(Number n1, Number n2)
          Test numerical equality (but ignore class).
static int compare(Number n1, Number n2)
          Compare two arbitrary numbers.
static Number divide(Number n, double d)
          High precision divide.
static Class<? extends Number> getWiderClass(Number n1, Number n2)
          Return a class wide enough for both numbers.
static boolean hasFractionalPart(Number n)
          Whether n has a non-zero fractional part.
static int intDigits(long l)
           
static int intDigits(Number n)
          The number of digits of the integer part in decimal representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberUtils

public NumberUtils()
Method Detail

areEqual

public static final <N extends Number> boolean areEqual(N n1,
                                                        N n2)
Test class and numerical equality. E.g. BigDecimal.equals(Object) also tests the scale.

Type Parameters:
N - type of number.
Parameters:
n1 - first number, can be null.
n2 - second number, can be null.
Returns:
true if n1 and n2 have the same class and are numerically equal.
See Also:
areNumericallyEqual(Number, Number)

areNumericallyEqual

public static final boolean areNumericallyEqual(Number n1,
                                                Number n2)
Test numerical equality (but ignore class).

Parameters:
n1 - first number, can be null.
n2 - second number, can be null.
Returns:
true if n1 and n2 are numerically equal.
See Also:
compare(Number, Number)

compare

public static final int compare(Number n1,
                                Number n2)
Compare two arbitrary numbers.

Parameters:
n1 - first number, not null.
n2 - second number, not null.
Returns:
a negative integer, zero, or a positive integer as n1 is less than, equal to, or greater than n2.
See Also:
Comparable.compareTo(Object)

getWiderClass

public static final Class<? extends Number> getWiderClass(Number n1,
                                                          Number n2)
Return a class wide enough for both numbers. E.g. for Integer and Short, Integer ; for BigInteger and Float, BigDecimal.

Parameters:
n1 - first number, not null.
n2 - second number, not null.
Returns:
a class wide enough for both numbers.
See Also:
NumberConvertor.convertExact(Number, Class)

hasFractionalPart

public static final boolean hasFractionalPart(Number n)
Whether n has a non-zero fractional part.

Parameters:
n - a number.
Returns:
true if there is a non-zero fractional part, e.g. true for 1.3d and false for new BigDecimal("1.00").

intDigits

public static final int intDigits(long l)

intDigits

public static final int intDigits(Number n)
The number of digits of the integer part in decimal representation.

Parameters:
n - a number, e.g. 123.45.
Returns:
the number of digits of the integer part, e.g. 3.

divide

public static Number divide(Number n,
                            double d)
High precision divide.

Parameters:
n - the dividend.
d - the divisor.
Returns:
n / d.
See Also:
DecimalUtils.HIGH_PRECISION


Copyright © 2010 jOpenDocument All Rights Reserved.