| Modifier and Type | Method and Description |
|---|---|
static double |
asDoubleExactly(Number number)
Represents the given
Number exactly as a double value without any
magnitude and precision losses; if that's not possible, fails by throwing
an exception. |
static int |
asIntExactly(Number number)
Represents the given
Number exactly as an int value without any
magnitude and precision losses; if that's not possible, fails by throwing
an exception. |
static long |
asLongExactly(Number number)
Represents the given
Number exactly as a long value without any
magnitude and precision losses; if that's not possible, fails by throwing
an exception. |
static Comparable |
canonicalizeForHashLookup(Comparable value)
Canonicalizes the given
Number value for the purpose of a
hash-based lookup. |
static int |
compare(Comparable lhs,
Comparable rhs)
Compares the provided
Number instances. |
static int |
compareLongs(long lhs,
long rhs)
Compares two longs exactly as Java 7 Long.compare does.
|
static boolean |
equal(Number lhs,
Number rhs)
Checks the provided
Number instances for equality. |
static boolean |
equalDoubles(double lhs,
double rhs)
Checks the provided double values for equality exactly as
Double.equals(java.lang.Object) does it, avoiding the boxing-unboxing cycle. |
static boolean |
equalFloats(float lhs,
float rhs)
Checks the provided float values for equality exactly as
Float.equals(java.lang.Object) does it, avoiding the boxing-unboxing cycle. |
static boolean |
equalLongAndDouble(long l,
double d)
Checks the provided long and double values for equality.
|
static boolean |
isDoubleRepresentable(Class clazz) |
static boolean |
isLongRepresentable(Class clazz) |
public static int compare(Comparable lhs, Comparable rhs)
Number instances.
The method accepts Comparable instances because to compare
something it must be comparable, but Number is not comparable.
Special numeric comparison logic is used for Double, Long,
Float, Integer, Short and Byte:
comparison is performed by taking into account only the magnitudes and
signs of the passed numbers, disregarding the actual underlying types.
public static Comparable canonicalizeForHashLookup(Comparable value)
Number value for the purpose of a
hash-based lookup.
The method accepts a Comparable instance and returns one because
query engine acts on comparable values, but Number is not
comparable.
Special numeric canonicalization logic is used for Double,
Long, Float, Integer, Short and
Byte: all whole numbers in the [Long.MIN_VALUE,
Long.MAX_VALUE] range are represented as Long, all other
whole and non-whole numbers are presented as Double. That logic
allows to mix numeric types while performing hash-based lookups, e.g.
while using one of the standard Map implementations.
public static boolean equalDoubles(double lhs,
double rhs)
Double.equals(java.lang.Object) does it, avoiding the boxing-unboxing cycle.lhs - the left-hand side double value.rhs - the right-hand side double value.true if the given values are equal, false
otherwise.public static boolean equalFloats(float lhs,
float rhs)
Float.equals(java.lang.Object) does it, avoiding the boxing-unboxing cycle.lhs - the left-hand side float value.rhs - the right-hand side float value.true if the given values are equal, false
otherwise.public static double asDoubleExactly(Number number)
Number exactly as a double value without any
magnitude and precision losses; if that's not possible, fails by throwing
an exception.number - the number to represent as a double value.IllegalArgumentException - if no exact representation exists.public static long asLongExactly(Number number)
Number exactly as a long value without any
magnitude and precision losses; if that's not possible, fails by throwing
an exception.number - the number to represent as a long value.IllegalArgumentException - if no exact representation exists.public static int asIntExactly(Number number)
Number exactly as an int value without any
magnitude and precision losses; if that's not possible, fails by throwing
an exception.number - the number to represent as an int value.IllegalArgumentException - if no exact representation exists.public static boolean isDoubleRepresentable(Class clazz)
true if instances of the given class can be represented
as double values without any magnitude and precision losses, false
otherwise.public static boolean isLongRepresentable(Class clazz)
true if instances of the given class can be represented
as long values without any magnitude and precision losses, false
otherwise.public static boolean equalLongAndDouble(long l,
double d)
The method fully avoids magnitude and precision losses while performing
the equality check, e.g. (double) Long.MAX_VALUE is not equal to
Long.MAX_VALUE - 1.
l - the long value to check the equality of.d - the double value to check the equality of.true if the provided values are equal, false
otherwise.public static int compareLongs(long lhs,
long rhs)
Copyright © 2020 Hazelcast, Inc.. All Rights Reserved.