public class Convert extends Object
Modifier and Type | Field and Description |
---|---|
static int |
INT_N_65535 |
static int |
INT_P_65535 |
Constructor and Description |
---|
Convert() |
Modifier and Type | Method and Description |
---|---|
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
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 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")IllegalArgumentException
public static final long toLong(byte[] potentiallySignedAsciiBytes, int offsetin, int len) throws IllegalArgumentException
toInt(byte[], int, int)
but for Long
values. Max number of digits
is now MAX_POSITIVE_64_BIT_DIGITS
.potentiallySignedAsciiBytes
- offset
- len
- IllegalArgumentException
public static final int toInt(byte[] potentiallySignedBytes) throws IllegalArgumentException
potentiallySignedBytes
- IllegalArgumentException
public static final long toLong(byte[] potentiallySignedBytes) throws IllegalArgumentException
potentiallySignedBytes
- IllegalArgumentException
public static final double toDouble(byte[] stringRepOfDoublePrecisionBytes) throws IllegalArgumentException
potentiallySignedBytes
- IllegalArgumentException
Copyright © 2009–2018. All rights reserved.