|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.molae.pipe.number.NumberComparator
public final class NumberComparator
This class provides a means to compare numbers of different types.
Field Summary | |
---|---|
static Double |
NAN_DOUBLE
Double.NaN as a Double . |
static Float |
NAN_FLOAT
Float.NaN as a Float . |
static Double |
NEGATIVE_INFINITY_DOUBLE
Double.NEGATIVE_INFINITY as a Double . |
static Float |
NEGATIVE_INFINITY_FLOAT
Float.NEGATIVE_INFINITY as a Float . |
static Double |
POSITIVE_INFINITY_DOUBLE
Double.POSITIVE_INFINITY as a Double . |
static Float |
POSITIVE_INFINITY_FLOAT
Float.POSITIVE_INFINITY as a Float . |
Method Summary | |
---|---|
int |
compare(Class<? extends Number> type,
Number n1,
Number n2)
Converts two numbers to the specified type and compares them. |
int |
compare(Number n1,
Number n2)
Compares two numbers regardless of their specific type. |
static Number |
convertTo(Class<? extends Number> type,
Number input)
Converts the specified number into an object of the specified class. |
static AtomicInteger |
convertToAtomicInteger(Number input)
Converts the specified number to a AtomicInteger |
static AtomicLong |
convertToAtomicLong(Number input)
Converts the specified number to a AtomicLong |
static BigDecimal |
convertToBigDecimal(Number input)
Converts the specified number to a BigDecimal |
static BigInteger |
convertToBigInteger(Number input)
Converts the specified number to a BigInteger |
static Byte |
convertToByte(Number input)
Converts the specified number to a Byte |
static Double |
convertToDouble(Number input)
Converts the specified number to a Double |
static Float |
convertToFloat(Number input)
Converts the specified number to a Float |
static Integer |
convertToInteger(Number input)
Converts the specified number to a Integer |
static Long |
convertToLong(Number input)
Converts the specified number to a Long |
static Short |
convertToShort(Number input)
Converts the specified number to a Short |
static NumberComparator |
getInstance()
Returns the singleton instance of this comparator. |
static boolean |
isInfinite(Number num)
Checks if the specified number is infinite (positive or negative). |
static boolean |
isMorePreciseThanOrEquals(Class<? extends Number> a,
Class<? extends Number> b)
Checks if the value set of the first parameter contains the value set of the second parameter. |
static boolean |
isNegativeInfinity(Number num)
Checks if the specified number is negative infinite. |
static boolean |
isNotANumber(Number num)
Checks if the specified number is a number. |
static boolean |
isPositiveInfinity(Number num)
Checks if the specified number is positive infinite. |
static Class<? extends Number> |
leastCommonType(Class<? extends Number> c1,
Class<? extends Number> c2)
Returns the least precise class lct so that
lct is more precise than each of the specified classes. |
static byte |
max(byte a,
byte b)
Returns the greater of two byte values. |
static Number |
max(Number n1,
Number n2)
Compares the two specified numbers and returns the greater one. |
static short |
max(short a,
short b)
Returns the greater of two short values. |
static byte |
min(byte a,
byte b)
Returns the smaller of two byte values. |
static Number |
min(Number n1,
Number n2)
Compares the two specified numbers and returns the smaller one. |
static short |
min(short a,
short b)
Returns the smaller of two short values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Comparator |
---|
equals |
Field Detail |
---|
public static final Float NEGATIVE_INFINITY_FLOAT
Float.NEGATIVE_INFINITY
as a Float
.
public static final Double NEGATIVE_INFINITY_DOUBLE
Double.NEGATIVE_INFINITY
as a Double
.
public static final Float POSITIVE_INFINITY_FLOAT
Float.POSITIVE_INFINITY
as a Float
.
public static final Double POSITIVE_INFINITY_DOUBLE
Double.POSITIVE_INFINITY
as a Double
.
public static final Double NAN_DOUBLE
Double.NaN
as a Double
.
public static final Float NAN_FLOAT
Float.NaN
as a Float
.
Method Detail |
---|
public static NumberComparator getInstance()
public static boolean isMorePreciseThanOrEquals(Class<? extends Number> a, Class<? extends Number> b)
Float
and Double
are not regarded.
Therefore Float and Double fit into BigDecimal
.
If one of the classes is an unkown Number
subclass
(not in java.lang or java.math), false
is returned.
The method follows the following rules:
BigDecimal > Double > Float V V V BigInteger > (Atomic)Long > (Atomic)Integer > Short > ByteIt should not be used with other classes.
a
- the first operand of the comparisonb
- the second operand of the comparison
true
, iff all values of class b are also
members of class a.
IllegalClassException
- if either parameter is not assignable to
Number
.public static Class<? extends Number> leastCommonType(Class<? extends Number> c1, Class<? extends Number> c2)
lct
so that
lct
is more precise than each of the specified classes.
For definition of "more precise than" see
isMorePreciseThanOrEquals(Class, Class)
.
Note that if either class is unknown (not in the java.lang or
java.math or java.util.concurrent.atomic package),
BigDecimal
is returned.
c1
- first class to comparec2
- second class to compare
lct
so that
lct
is more precise than each of the specified classes.
IllegalClassException
- if either parameter is not assignable to
Number
.public static boolean isNegativeInfinity(Number num)
num
- number to check
true
, iff the specified number is
Float.NEGATIVE_INFINITY
or
Double.NEGATIVE_INFINITY
.public static boolean isPositiveInfinity(Number num)
num
- number to check
true
, iff the specified number is
Float.POSITIVE_INFINITY
or
Double.POSITIVE_INFINITY
.public static boolean isInfinite(Number num)
num
- number to check
true
, iff the specified number is
negative infinite
or
positive infinite
.public static boolean isNotANumber(Number num)
num
- number to check
true
, iff the specified number is
Float.NaN
or
Double.NaN
.public static Byte convertToByte(Number input)
Byte
input
- the value the return value should have
Byte
public static Short convertToShort(Number input)
Short
input
- the value the return value should have
Short
public static Integer convertToInteger(Number input)
Integer
input
- the value the return value should have
Integer
public static Long convertToLong(Number input)
Long
input
- the value the return value should have
Long
public static Float convertToFloat(Number input)
Float
input
- the value the return value should have
Float
public static Double convertToDouble(Number input)
Double
input
- the value the return value should have
Double
public static BigInteger convertToBigInteger(Number input)
BigInteger
input
- the value the return value should have
BigInteger
public static BigDecimal convertToBigDecimal(Number input)
BigDecimal
input
- the value the return value should have
BigDecimal
public static AtomicInteger convertToAtomicInteger(Number input)
AtomicInteger
input
- the value the return value should have
AtomicInteger
public static AtomicLong convertToAtomicLong(Number input)
AtomicLong
input
- the value the return value should have
AtomicLong
public static Number convertTo(Class<? extends Number> type, Number input)
type
- the desired class of the return valueinput
- the value the return value should have
IllegalClassException
- if the specified class is null,
not a number or not known.public int compare(Class<? extends Number> type, Number n1, Number n2)
n1
- the first operand of the comparisonn2
- the second operand of the comparison
IllegalClassException
- if the specified class does not implement
the Comparable
interface
or is not implemented.public int compare(Number n1, Number n2)
compare
in interface Comparator<Number>
n1
- the first operand of the comparisonn2
- the second operand of the comparison
ClassCastException
- if the first number does not implement
the Comparable
interface.public static short max(short a, short b)
short
values. That is, the
result is the argument closer to the value of
Short.MAX_VALUE
. If the arguments have the same value,
the result is that same value.
a
- a short
value.b
- a short
value.
a
and b
.public static byte max(byte a, byte b)
byte
values. That is, the
result is the argument closer to the value of
Byte.MAX_VALUE
. If the arguments have the same value,
the result is that same value.
a
- a byte
value.b
- a byte
value.
a
and b
.public static short min(short a, short b)
short
values. That is, the
result is the argument closer to the value of
Short.MIN_VALUE
. If the arguments have the same value,
the result is that same value.
a
- a short
value.b
- a short
value.
a
and b
.public static byte min(byte a, byte b)
byte
values. That is, the
result is the argument closer to the value of
Byte.MIN_VALUE
. If the arguments have the same value,
the result is that same value.
a
- a byte
value.b
- a byte
value.
a
and b
.public static Number max(Number n1, Number n2)
n1
- first number to comparen2
- second number to compare
n1
and n2
.
If both are equal, n1
is returned.
ClassCastException
- if the first number does not implement
the Comparable
interface.public static Number min(Number n1, Number n2)
n1
- first number to comparen2
- second number to compare
n1
and n2
.
If both are equal, n1
is returned.
ClassCastException
- if the first number does not implement
the Comparable
interface.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |