public class OrderedBytes extends Object
Bytes instead.
For example:
Consider integer values 100 and -100, their binary forms are :
100 -> 0x0000 0064
-100 -> 0xFFFF FF9C
Apparently -100 is 'greater than' 100 by directly comparing to -100 in binary(similar to memcmp() in C).
In order to get it right we have to flip the signed bit in this scenario:
100 -> 0x0000 0064 -> 0x8000 0064
-100 -> 0xFFFF FF9C -> 0x7FFF FF9C
By flipping the signed bit, negative values will be sorted before the positives.
Note that this utility class has two parts:
1) Basic functions to handle ordered bytes conversion, this is enough for most of the cases.
2) Support user-defined sort order
for each data type, there are 4 methods in each part, consider INT:
1) convert int to byte[]
toBytes(int)
putInt(byte[], int, int)
2) convert byte[] to int
toInt(byte[])
toInt(byte[], int)| 构造器和说明 |
|---|
OrderedBytes() |
| 限定符和类型 | 方法和说明 |
|---|---|
static int |
putBigDecimal(byte[] output,
int offset,
BigDecimal val)
Put a BigDecimal value into the specified byte array position, using its binary-comparable form.
|
static int |
putBigDecimal(byte[] output,
int offset,
BigDecimal val,
AliHBaseColumn.SortOrder order)
Put a BigDecimal value into the specified byte array position, using its binary-comparable form with explicit sort order.
|
static int |
putByte(byte[] output,
int offset,
byte val)
Put a byte value into the specified byte array position, using its binary-comparable form.
|
static int |
putByte(byte[] output,
int offset,
byte val,
AliHBaseColumn.SortOrder order)
Put a byte value into the specified byte array position, using its binary-comparable form with explicit sort order.
|
static int |
putDouble(byte[] output,
int offset,
double val)
Put a double value into the specified byte array position, using its binary-comparable form.
|
static int |
putDouble(byte[] output,
int offset,
double val,
AliHBaseColumn.SortOrder order)
Put a double value into the specified byte array position, using its binary-comparable form with explicit sort order.
|
static int |
putFloat(byte[] output,
int offset,
float val)
Put a float value into the specified byte array position, using its binary-comparable form.
|
static int |
putFloat(byte[] output,
int offset,
float val,
AliHBaseColumn.SortOrder order)
Put a float value into the specified byte array position, using its binary-comparable form with explicit sort order.
|
static int |
putInt(byte[] output,
int offset,
int val)
Put an integer value into the specified byte array position, using its binary-comparable form.
|
static int |
putInt(byte[] output,
int offset,
int val,
AliHBaseColumn.SortOrder order)
Put an integer value into the specified byte array position, using its binary-comparable form with explicit sort order.
|
static int |
putLong(byte[] output,
int offset,
long val)
Put a long value into the specified byte array position, using its binary-comparable form.
|
static int |
putLong(byte[] output,
int offset,
long val,
AliHBaseColumn.SortOrder order)
Put a long value into the specified byte array position, using its binary-comparable form with explicit sort order.
|
static int |
putShort(byte[] output,
int offset,
short val)
Put a short value into the specified byte array position, using its binary-comparable form.
|
static int |
putShort(byte[] output,
int offset,
short val,
AliHBaseColumn.SortOrder order)
Put a short value into the specified byte array position, using its binary-comparable form with explicit sort order.
|
static BigDecimal |
toBigDecimal(byte[] bytes)
Deserialize a BigDecimal value from its binary-comparable byte array.
|
static BigDecimal |
toBigDecimal(byte[] bytes,
AliHBaseColumn.SortOrder order)
Deserialize a BigDecimal value from its binary-comparable byte array with explicit sort order.
|
static BigDecimal |
toBigDecimal(byte[] bytes,
int offset,
int length)
Deserialize a BigDecimal value from its binary-comparable byte array.
|
static BigDecimal |
toBigDecimal(byte[] bytes,
int offset,
int length,
AliHBaseColumn.SortOrder order)
Deserialize a BigDecimal value from its binary-comparable byte array with explicit sort order.
|
static byte |
toByte(byte[] bytes)
Deserialize a byte value from its binary-comparable byte array.
|
static byte |
toByte(byte[] bytes,
AliHBaseColumn.SortOrder order)
Deserialize a byte value from its binary-comparable byte array with explicit sort order.
|
static byte |
toByte(byte[] bytes,
int offset)
Deserialize a byte value from its binary-comparable byte array.
|
static byte |
toByte(byte[] bytes,
int offset,
AliHBaseColumn.SortOrder order)
Deserialize a byte value from its binary-comparable byte array with explicit sort order.
|
static byte[] |
toBytes(BigDecimal val)
Serialize a BigDecimal value into its binary-comparable byte array.
|
static byte[] |
toBytes(BigDecimal val,
AliHBaseColumn.SortOrder order)
Serialize a BigDecimal value into its binary-comparable byte array with explicit sort order.
|
static byte[] |
toBytes(byte val)
Serialize a byte value into its binary-comparable byte array.
|
static byte[] |
toBytes(byte val,
AliHBaseColumn.SortOrder order)
Serialize a byte value into its binary-comparable byte array with explicit sort order.
|
static byte[] |
toBytes(double val)
Serialize a double value into its binary-comparable byte array.
|
static byte[] |
toBytes(double val,
AliHBaseColumn.SortOrder order)
Serialize a double value into its binary-comparable byte array with explicit sort order.
|
static byte[] |
toBytes(float val)
Serialize a float value into its binary-comparable byte array.
|
static byte[] |
toBytes(float val,
AliHBaseColumn.SortOrder order)
Serialize a float value into its binary-comparable byte array with explicit sort order.
|
static byte[] |
toBytes(int val)
Serialize an integer value into its binary-comparable byte array.
|
static byte[] |
toBytes(int val,
AliHBaseColumn.SortOrder order)
Serialize an integer value into its binary-comparable byte array with explicit sort order.
|
static byte[] |
toBytes(long val)
Serialize a long value into its binary-comparable byte array.
|
static byte[] |
toBytes(long val,
AliHBaseColumn.SortOrder order)
Serialize a long value into its binary-comparable byte array with explicit sort order.
|
static byte[] |
toBytes(short val)
Serialize a short value into its binary-comparable byte array.
|
static byte[] |
toBytes(short val,
AliHBaseColumn.SortOrder order)
Serialize a short value into its binary-comparable byte array with explicit sort order.
|
static double |
toDouble(byte[] bytes)
Deserialize a double value from its binary-comparable byte array.
|
static double |
toDouble(byte[] bytes,
AliHBaseColumn.SortOrder order)
Deserialize a double value from its binary-comparable byte array with explicit sort order.
|
static double |
toDouble(byte[] bytes,
int offset)
Deserialize a double value from its binary-comparable byte array.
|
static double |
toDouble(byte[] bytes,
int offset,
AliHBaseColumn.SortOrder order)
Deserialize a double value from its binary-comparable byte array with explicit sort order.
|
static float |
toFloat(byte[] bytes)
Deserialize a float value from its binary-comparable byte array.
|
static float |
toFloat(byte[] bytes,
AliHBaseColumn.SortOrder order)
Deserialize a float value from its binary-comparable byte array with explicit sort order.
|
static float |
toFloat(byte[] bytes,
int offset)
Deserialize a float value from its binary-comparable byte array.
|
static float |
toFloat(byte[] bytes,
int offset,
AliHBaseColumn.SortOrder order)
Deserialize a float value from its binary-comparable byte array with explicit sort order.
|
static int |
toInt(byte[] bytes)
Deserialize an integer value from its binary-comparable byte array.
|
static int |
toInt(byte[] bytes,
AliHBaseColumn.SortOrder order)
Deserialize an integer value from its binary-comparable byte array with explicit sort order.
|
static int |
toInt(byte[] bytes,
int offset)
Deserialize an integer value from its binary-comparable byte array.
|
static int |
toInt(byte[] bytes,
int offset,
AliHBaseColumn.SortOrder order)
Deserialize an integer value from its binary-comparable byte array with explicit sort order.
|
static long |
toLong(byte[] bytes)
Deserialize a long value from its binary-comparable byte array.
|
static long |
toLong(byte[] bytes,
AliHBaseColumn.SortOrder order)
Deserialize a long value from its binary-comparable byte array with explicit sort order.
|
static long |
toLong(byte[] bytes,
int offset)
Deserialize a long value from its binary-comparable byte array.
|
static long |
toLong(byte[] bytes,
int offset,
AliHBaseColumn.SortOrder order)
Deserialize a long value from its binary-comparable byte array with explicit sort order.
|
static short |
toShort(byte[] bytes)
Deserialize a short value from its binary-comparable byte array.
|
static short |
toShort(byte[] bytes,
AliHBaseColumn.SortOrder order)
Deserialize a short value from its binary-comparable byte array with explicit sort order.
|
static short |
toShort(byte[] bytes,
int offset)
Deserialize a short value from its binary-comparable byte array.
|
static short |
toShort(byte[] bytes,
int offset,
AliHBaseColumn.SortOrder order)
Deserialize a short value from its binary-comparable byte array with explicit sort order.
|
public static byte[] toBytes(byte val)
val - value to be serialized.public static int putByte(byte[] output,
int offset,
byte val)
output - the output byte arrayoffset - position in the arrayval - byte value to write toIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static byte toByte(byte[] bytes)
bytes - binary-comparable byte array of a byte valuepublic static byte toByte(byte[] bytes,
int offset)
bytes - binary-comparable byte array of a byte valueoffset - start positionpublic static byte[] toBytes(short val)
val - value to be serialized.public static int putShort(byte[] output,
int offset,
short val)
output - the output byte arrayoffset - position in the arrayval - short value to write toIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static short toShort(byte[] bytes)
bytes - binary-comparable byte array of a short valuepublic static short toShort(byte[] bytes,
int offset)
bytes - binary-comparable byte array of a short valueoffset - start positionpublic static byte[] toBytes(int val)
val - value to be serialized.public static int putInt(byte[] output,
int offset,
int val)
output - the output byte arrayoffset - position in the arrayval - integer value to write toIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static int toInt(byte[] bytes)
bytes - binary-comparable byte array of an integer valuepublic static int toInt(byte[] bytes,
int offset)
bytes - binary-comparable byte array of an integer valueoffset - start positionpublic static byte[] toBytes(long val)
val - value to be serialized.public static int putLong(byte[] output,
int offset,
long val)
output - the output byte arrayoffset - position in the arrayval - long value to write toIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static long toLong(byte[] bytes)
bytes - binary-comparable byte array of a long valuepublic static long toLong(byte[] bytes,
int offset)
bytes - binary-comparable byte array of a long valueoffset - start positionpublic static byte[] toBytes(float val)
val - value to be serialized.public static int putFloat(byte[] output,
int offset,
float val)
output - the output byte arrayoffset - position in the arrayval - float value to write toIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static float toFloat(byte[] bytes)
bytes - binary-comparable byte array of a float valuepublic static float toFloat(byte[] bytes,
int offset)
bytes - binary-comparable byte array of a float valueoffset - start positionpublic static byte[] toBytes(double val)
val - value to be serialized.public static int putDouble(byte[] output,
int offset,
double val)
output - the output byte arrayoffset - position in the arrayval - double value to write toIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static double toDouble(byte[] bytes)
bytes - binary-comparable byte array of a double valuepublic static double toDouble(byte[] bytes,
int offset)
bytes - binary-comparable byte array of a double valueoffset - start positionpublic static byte[] toBytes(BigDecimal val)
val - value to be serialized.public static int putBigDecimal(byte[] output,
int offset,
BigDecimal val)
output - the output byte arrayoffset - position in the arrayval - BigDecimal value to write toIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static BigDecimal toBigDecimal(byte[] bytes)
bytes - binary-comparable byte array of a BigDecimal valuepublic static BigDecimal toBigDecimal(byte[] bytes, int offset, int length)
bytes - binary-comparable byte array of a BigDecimal valueoffset - start positionlength - number of bytes that represents this BigDecimal valuepublic static byte[] toBytes(byte val,
AliHBaseColumn.SortOrder order)
val - value to be serialized.order - sort order of this valuepublic static int putByte(byte[] output,
int offset,
byte val,
AliHBaseColumn.SortOrder order)
output - the output byte arrayoffset - position in the arrayval - byte value to write toorder - sort order of this valueIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static byte toByte(byte[] bytes,
AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of a byte valueorder - sort order of this valuepublic static byte toByte(byte[] bytes,
int offset,
AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of a byte valueoffset - start positionorder - sort order of this valuepublic static byte[] toBytes(short val,
AliHBaseColumn.SortOrder order)
val - value to be serialized.order - sort order of this valuepublic static int putShort(byte[] output,
int offset,
short val,
AliHBaseColumn.SortOrder order)
output - the output byte arrayoffset - position in the arrayval - short value to write toorder - sort order of this valueIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static short toShort(byte[] bytes,
AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of a short valueorder - sort order of this valuepublic static short toShort(byte[] bytes,
int offset,
AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of a short valueoffset - start positionorder - sort order of this valuepublic static byte[] toBytes(int val,
AliHBaseColumn.SortOrder order)
val - value to be serialized.order - sort order of this valuepublic static int putInt(byte[] output,
int offset,
int val,
AliHBaseColumn.SortOrder order)
output - the output byte arrayoffset - position in the arrayval - integer value to write toorder - sort order of this valueIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static int toInt(byte[] bytes,
AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of an integer valueorder - sort order of this valuepublic static int toInt(byte[] bytes,
int offset,
AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of an integer valueoffset - start positionorder - sort order of this valuepublic static byte[] toBytes(long val,
AliHBaseColumn.SortOrder order)
val - value to be serialized.order - sort order of this valuepublic static int putLong(byte[] output,
int offset,
long val,
AliHBaseColumn.SortOrder order)
output - the output byte arrayoffset - position in the arrayval - long value to write toorder - sort order of this valueIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static long toLong(byte[] bytes,
AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of a long valueorder - sort order of this valuepublic static long toLong(byte[] bytes,
int offset,
AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of a long valueoffset - start positionorder - sort order of this valuepublic static byte[] toBytes(float val,
AliHBaseColumn.SortOrder order)
val - value to be serialized.order - sort order of this valuepublic static int putFloat(byte[] output,
int offset,
float val,
AliHBaseColumn.SortOrder order)
output - the output byte arrayoffset - position in the arrayval - float value to write toorder - sort order of this valueIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static float toFloat(byte[] bytes,
AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of a float valueorder - sort order of this valuepublic static float toFloat(byte[] bytes,
int offset,
AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of a float valueoffset - start positionorder - sort order of this valuepublic static byte[] toBytes(double val,
AliHBaseColumn.SortOrder order)
val - value to be serialized.order - sort order of this valuepublic static int putDouble(byte[] output,
int offset,
double val,
AliHBaseColumn.SortOrder order)
output - the output byte arrayoffset - position in the arrayval - double value to write toorder - sort order of this valueIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static double toDouble(byte[] bytes,
AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of a double valueorder - sort order of this valuepublic static double toDouble(byte[] bytes,
int offset,
AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of a double valueoffset - start positionorder - sort order of this valuepublic static byte[] toBytes(BigDecimal val, AliHBaseColumn.SortOrder order)
val - value to be serialized.order - sort order of this valuepublic static int putBigDecimal(byte[] output,
int offset,
BigDecimal val,
AliHBaseColumn.SortOrder order)
output - the output byte arrayoffset - position in the arrayval - BigDecimal value to write toorder - sort order of this valueIllegalArgumentException - if the specified byte array doesn't have enough room to hold this valuepublic static BigDecimal toBigDecimal(byte[] bytes, AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of a BigDecimal valueorder - sort order of this valuepublic static BigDecimal toBigDecimal(byte[] bytes, int offset, int length, AliHBaseColumn.SortOrder order)
bytes - binary-comparable byte array of a BigDecimal valueoffset - start positionlength - number of bytes that represents this BigDecimal valueorder - sort order of this valueCopyright © 2019. All rights reserved.