public final class NumericUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static int |
bytesToInt(byte[] bytes) |
static long |
bytesToLong(byte[] bytes) |
static byte[] |
byteToSortableBytes(byte value) |
static int |
compareNumber(Object first,
Number second)
Compare object with a number, the object should be a number,
or it can be converted to a BigDecimal
|
static Number |
convertToNumber(Object value) |
static long |
doubleToSortableLong(double value)
Converts a
double value to a sortable signed
long. |
static int |
floatToSortableInt(float value)
Converts a
float value to a sortable signed
int. |
static byte[] |
intToBytes(int value) |
static byte[] |
intToSortableBytes(int value) |
static boolean |
isNumber(Class<?> clazz) |
static boolean |
isNumber(Object value) |
static byte[] |
longToBytes(long value) |
static byte[] |
longToSortableBytes(long value) |
static Number |
maxValueOf(Class<?> clazz) |
static Number |
minValueOf(Class<?> clazz) |
static byte[] |
numberToSortableBytes(Number number) |
static long |
numberToSortableLong(Number number) |
static byte |
sortableBytesToByte(byte[] bytes) |
static int |
sortableBytesToInt(byte[] bytes) |
static long |
sortableBytesToLong(byte[] bytes) |
static Number |
sortableBytesToNumber(byte[] bytes,
Class<?> clazz) |
static long |
sortableDoubleBits(long bits)
Converts IEEE 754 representation of a double to sortable order (or back
to the original)
|
static int |
sortableFloatBits(int bits)
Converts IEEE 754 representation of a float to sortable order (or back to
the original)
|
static float |
sortableIntToFloat(int value)
Converts a sortable
int back to a float. |
static double |
sortableLongToDouble(long value)
Converts a sortable
long back to a double. |
static Number |
sortableLongToNumber(long value,
Class<?> clazz) |
public static long doubleToSortableLong(double value)
double value to a sortable signed
long. The value is converted by getting their IEEE 754
floating-point "double format" bit layout and then some bits
are swapped, to be able to compare the result as long. By this the
precision is not reduced, but the value can easily used as a long. The
sort order (including Double.NaN) is defined by
Double.compareTo(java.lang.Double); NaN is greater than positive infinity.value - input double valuesortableLongToDouble(long)public static double sortableLongToDouble(long value)
long back to a double.value - input double valuedoubleToSortableLong(double)public static int floatToSortableInt(float value)
float value to a sortable signed
int. The value is converted by getting their IEEE 754
floating-point "float format" bit layout and then some bits are
swapped, to be able to compare the result as int. By this the precision
is not reduced, but the value can easily used as an int. The sort order
(including Float.NaN) is defined by Float.compareTo(java.lang.Float);
NaN is greater than positive infinity.value - input float valuesortableIntToFloat(int)public static float sortableIntToFloat(int value)
int back to a float.value - input int valuefloatToSortableInt(float)public static long sortableDoubleBits(long bits)
bits - The long format of a double valuepublic static int sortableFloatBits(int bits)
bits - The int format of an float valuepublic static long numberToSortableLong(Number number)
public static byte[] numberToSortableBytes(Number number)
public static byte[] longToSortableBytes(long value)
public static long sortableBytesToLong(byte[] bytes)
public static byte[] intToSortableBytes(int value)
public static int sortableBytesToInt(byte[] bytes)
public static byte[] byteToSortableBytes(byte value)
public static byte sortableBytesToByte(byte[] bytes)
public static byte[] longToBytes(long value)
public static long bytesToLong(byte[] bytes)
public static byte[] intToBytes(int value)
public static int bytesToInt(byte[] bytes)
public static boolean isNumber(Object value)
public static boolean isNumber(Class<?> clazz)
public static int compareNumber(Object first, Number second)
first - might be number or stringsecond - must be numberCopyright © 2021. All rights reserved.