public class Convert
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static byte |
BYTE_MINUS |
private static byte |
BYTE_NINE |
private static byte |
BYTE_PLUS |
private static byte |
BYTE_ZERO |
private static byte[][] |
i2b_65535 |
static int |
INT_N_65535 |
static int |
INT_P_65535 |
private static int |
MAX_POSITIVE_32_BIT_DIGITS |
private static int |
MAX_POSITIVE_64_BIT_DIGITS |
| Constructor and Description |
|---|
Convert() |
| Modifier and Type | Method and Description |
|---|---|
private static byte[] |
getNegativeNumberBytes(byte[] unsigned) |
static byte[] |
toBytes(double dnum) |
static byte[] |
toBytes(int i)
return the bytes of the string representation of the integer.
|
static byte[] |
toBytes(long lnum)
Will delegate to
Convert#getBytes(int) if the 'long' number is actually
within the range of our int cache, otherwise it will return the bytes using std
JDK mechanisms. |
static double |
toDouble(byte[] stringRepOfDoublePrecisionBytes)
TODO: optimize.
|
static int |
toInt(byte[] potentiallySignedBytes) |
static int |
toInt(byte[] potentiallySignedAsciiBytes,
int offsetin,
int len)
Converts the byte[]s of the ASCII representation of a decimal number to an int.
|
static long |
toLong(byte[] potentiallySignedBytes) |
static long |
toLong(byte[] potentiallySignedAsciiBytes,
int offsetin,
int len)
Its just like (really! :)
toInt(byte[], int, int) but for Long values. |
public static final int INT_P_65535
public static final int INT_N_65535
private static final byte[][] i2b_65535
private static final byte BYTE_MINUS
private static final byte BYTE_PLUS
private static final byte BYTE_ZERO
private static final byte BYTE_NINE
private static final int MAX_POSITIVE_32_BIT_DIGITS
private static final int MAX_POSITIVE_64_BIT_DIGITS
public static final byte[] toBytes(int i)
toBytes(int) which is
using JDK libs for the same.
The whole point here is to be faster since we need to convert numbers to the byte array
of their string representation a lot in JRedis for the protocol and to cut out the
unnecessary step of creating a new string simply because there apparently isn't any other
way in JDK to go from a number to the bytes of its textual representation. (!)i - signed - public static final byte[] toBytes(long lnum)
Convert#getBytes(int) if the 'long' number is actually
within the range of our int cache, otherwise it will return the bytes using std
JDK mechanisms.lnum - public static final byte[] toBytes(double dnum)
public static final int toInt(byte[] potentiallySignedAsciiBytes,
int offsetin,
int len)
throws java.lang.IllegalArgumentException
Expects a byte array of no more than MAX_POSITIVE_32_BIT_DIGITS bytes in length
after accounting for potential leading byte indicating the sign of the number representation.
9 bytes (for a positive integer).
potentiallySignedAsciiBytes, - for example {49, 49, 52} ("114")java.lang.IllegalArgumentExceptionpublic static final long toLong(byte[] potentiallySignedAsciiBytes,
int offsetin,
int len)
throws java.lang.IllegalArgumentException
toInt(byte[], int, int) but for Long values. Max number of digits
is now MAX_POSITIVE_64_BIT_DIGITS.potentiallySignedAsciiBytes - offset - len - java.lang.IllegalArgumentExceptionpublic static final int toInt(byte[] potentiallySignedBytes)
throws java.lang.IllegalArgumentException
potentiallySignedBytes - java.lang.IllegalArgumentExceptionpublic static final long toLong(byte[] potentiallySignedBytes)
throws java.lang.IllegalArgumentException
potentiallySignedBytes - java.lang.IllegalArgumentExceptionpublic static final double toDouble(byte[] stringRepOfDoublePrecisionBytes)
throws java.lang.IllegalArgumentException
potentiallySignedBytes - java.lang.IllegalArgumentExceptionprivate static final byte[] getNegativeNumberBytes(byte[] unsigned)
unsigned -