|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jaitools.numeric.NumberOperations
public class NumberOperations
Provides static methods to work directly with Number objects
without having to cast them to narrower types.
| Nested Class Summary | |
|---|---|
static class |
NumberOperations.ClassInfo
Information about the Number classes supported including
their rank in terms of numeric precision. |
| Field Summary | |
|---|---|
static double |
DEFAULT_DOUBLE_TOL
Default tolerance for double comparisons |
static float |
DEFAULT_FLOAT_TOL
Default tolerance for float comparisons. |
| Constructor Summary | |
|---|---|
NumberOperations()
|
|
| Method Summary | |
|---|---|
static Number |
add(Number n1,
Number n2)
Adds two Number objects. |
static Number |
castNumber(Number number,
Class<? extends Number> clazz)
Cast the value from number to the class clazz |
static int |
compare(Number n1,
Number n2)
Compares value n1 to value n2. |
static Number |
copy(Number number)
Copies the given Number object. |
static Number |
divide(Number n1,
Number n2)
Calculates n2 / n1. |
static double |
doubleValue(Number number)
Safely convert the argument to a double value. |
static float |
floatValue(Number number)
Safely convert the argument to a float value. |
static double |
getDoubleTolerance()
Gets the current tolerance used for Double comparisons. |
static float |
getFloatTolerance()
Gets the current tolerance used for Float comparisons. |
static Class<? extends Number> |
highestClass(Number... numbers)
Determine the highest ranking class (in terms of numeric precision) among the arguments |
static int |
intValue(Number number)
Safely convert the argument to an int value. |
static long |
longValue(Number number)
Safely convert the argument to a long value. |
static Class<? extends Number> |
lowestClass(Number... numbers)
Determine the lowest ranking class (in terms of numeric precision) among the arguments |
static Number |
multiply(Number n1,
Number n2)
Calculates n2 * n1. |
static Number |
newInstance(Number number,
Class<? extends Number> clazz)
Return a new instance of class clazz taking its value from number |
static void |
setFloatTolerance(double tol)
Sets the tolerance used for Double comparisons. |
static void |
setFloatTolerance(float tol)
Sets the tolerance used for Float comparisons. |
static Number |
subtract(Number n1,
Number n2)
Calculates n2 - n1. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final float DEFAULT_FLOAT_TOL
public static final double DEFAULT_DOUBLE_TOL
| Constructor Detail |
|---|
public NumberOperations()
| Method Detail |
|---|
public static Number add(Number n1,
Number n2)
Number objects. The return value will be an instance
of the highest ranking class of the two arguments (e.g. Byte + Integer
will give an Integer result)
n1 - first valuen2 - second value
public static Number subtract(Number n1,
Number n2)
n2 - n1. The return value will be an instance
of the highest ranking class of the two arguments (e.g. Byte - Integer
will give an Integer result)
n1 - first valuen2 - second value
public static Number multiply(Number n1,
Number n2)
n2 * n1. The return value will be an instance
of the highest ranking class of the two arguments (e.g. Byte * Integer
will give an Integer result)
n1 - first valuen2 - second value
public static Number divide(Number n1,
Number n2)
n2 / n1. The return value will be an instance
of the highest ranking class of the two arguments (e.g. Byte / Integer
will give an Integer result)
n1 - first valuen2 - second value
public static int compare(Number n1,
Number n2)
n1 to value n2. If one or both of the values are
Float or Double the comparison is done within the currently set float or double
tolerance.
n1 - the first valuen2 - the second value
getFloatTolerance(),
setFloatTolerance(float)public static float getFloatTolerance()
public static void setFloatTolerance(float tol)
tol - a small positive valuepublic static double getDoubleTolerance()
public static void setFloatTolerance(double tol)
tol - a small positive valuepublic static int intValue(Number number)
int value. The following conventions apply:
number - the object to convert
intpublic static long longValue(Number number)
long value. The following conventions apply:
number - the object to convert
longpublic static float floatValue(Number number)
float value. The following conventions apply:
number - the object to convert
floatpublic static double doubleValue(Number number)
double value. The only difference
between this method and Number.doubleValue() is that Byte values
are handled as unsigned (e.g. range 0 - 255).
number - the object to convert
doublepublic static Number copy(Number number)
Number object. This is a short-cut for
NumberOperations.newInstance(number, number.getClass()).
Returns null if the input is null.
number - the number to copy
number;
or null
public static Number newInstance(Number number,
Class<? extends Number> clazz)
clazz taking its value from number
number - the number object whose value will be copiedclazz - the class of the new instance
number
public static Number castNumber(Number number,
Class<? extends Number> clazz)
number to the class clazz
number - the number object whose value will be copiedclazz - the class of the new instance
numberpublic static Class<? extends Number> highestClass(Number... numbers)
numbers - Number objects to compare
null if no arguments were suppliedpublic static Class<? extends Number> lowestClass(Number... numbers)
numbers - Number objects to compare
null if no arguments were supplied
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||