public final class NumberUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static int |
BILLION |
private static byte |
BYTE_1 |
private static byte |
BYTE_2 |
private static byte |
BYTE_HYPHEN |
(package private) static char[] |
FULL_TRIPLETS |
(package private) static char[] |
LEADING_TRIPLETS |
static int |
MAX_DOUBLE_CLEN
Maximum number of characters in a serialized double is
26 (at least for Sun JDK; 19 digits for mantissa, 3 for exponent,
signs for mantissa and exponent, decimal point, 'E'):
but let's pad it up a little bit just to play it safe.
|
static int |
MAX_FLOAT_CLEN
JDK serializes floats same way as doubles, so let's
reserve as much space
|
private static long |
MAX_INT_AS_LONG |
static int |
MAX_INT_CLEN
Maximum number of characters in a serialized integer is
11; one for (minus) sign, and then up to 10 digits
|
static int |
MAX_LONG_CLEN
Maximum number of characters in a serialized long is
21; one for (minus) sign, and then up to 20 digits
|
private static int |
MILLION |
private static long |
MIN_INT_AS_LONG
Note: we'll increase value since Integer.MIN_VALUE can not
actually be output using simple int-serialization mechanism
(since its negation does not fit in 32-bit signed int range)
|
private static char |
NULL_CHAR |
private static long |
TEN_BILLION_L |
private static long |
THOUSAND_L |
Constructor and Description |
---|
NumberUtil() |
Modifier and Type | Method and Description |
---|---|
private static int |
calcLongStrLength(long posValue)
Pre-conditions: posValue is positive, and larger than
Integer.MAX_VALUE (about 2 billions).
|
private static int |
getAsciiBytes(java.lang.String str,
byte[] buffer,
int ptr) |
private static int |
getChars(java.lang.String str,
char[] buffer,
int ptr) |
static int |
writeDouble(double value,
byte[] buffer,
int offset) |
static int |
writeDouble(double value,
char[] buffer,
int offset) |
static int |
writeFloat(float value,
byte[] buffer,
int offset) |
static int |
writeFloat(float value,
char[] buffer,
int offset) |
private static int |
writeFullTriplet(int triplet,
byte[] buffer,
int offset) |
private static int |
writeFullTriplet(int triplet,
char[] buffer,
int offset) |
static int |
writeInt(int value,
byte[] buffer,
int offset) |
static int |
writeInt(int value,
char[] buffer,
int offset)
Note: caller must ensure that there is room for least 11 characters
(leading sign, and up to 10 digits) in buffer passed.
|
private static int |
writeLeadingTriplet(int triplet,
byte[] buffer,
int offset) |
private static int |
writeLeadingTriplet(int triplet,
char[] buffer,
int offset) |
static int |
writeLong(long value,
byte[] buffer,
int offset) |
static int |
writeLong(long value,
char[] buffer,
int offset)
Note: caller must ensure that there is room for least 21 characters
(leading sign, and up to 20 digits ) in buffer passed.
|
public static final int MAX_INT_CLEN
public static final int MAX_LONG_CLEN
public static final int MAX_DOUBLE_CLEN
public static final int MAX_FLOAT_CLEN
private static final char NULL_CHAR
private static final int MILLION
private static final int BILLION
private static final long TEN_BILLION_L
private static final long THOUSAND_L
private static final byte BYTE_HYPHEN
private static final byte BYTE_1
private static final byte BYTE_2
private static long MIN_INT_AS_LONG
Note: we'll increase value since Integer.MIN_VALUE can not actually be output using simple int-serialization mechanism (since its negation does not fit in 32-bit signed int range)
private static long MAX_INT_AS_LONG
static final char[] LEADING_TRIPLETS
static final char[] FULL_TRIPLETS
public static int writeInt(int value, char[] buffer, int offset)
Note: caller must ensure that there is room for least 11 characters (leading sign, and up to 10 digits) in buffer passed.
public static int writeInt(int value, byte[] buffer, int offset)
public static int writeLong(long value, char[] buffer, int offset)
Note: caller must ensure that there is room for least 21 characters (leading sign, and up to 20 digits ) in buffer passed.
public static int writeLong(long value, byte[] buffer, int offset)
public static int writeFloat(float value, char[] buffer, int offset)
public static int writeFloat(float value, byte[] buffer, int offset)
public static int writeDouble(double value, char[] buffer, int offset)
public static int writeDouble(double value, byte[] buffer, int offset)
private static int writeLeadingTriplet(int triplet, char[] buffer, int offset)
private static int writeLeadingTriplet(int triplet, byte[] buffer, int offset)
private static int writeFullTriplet(int triplet, char[] buffer, int offset)
private static int writeFullTriplet(int triplet, byte[] buffer, int offset)
private static int calcLongStrLength(long posValue)
Pre-conditions: posValue is positive, and larger than Integer.MAX_VALUE (about 2 billions).
private static int getChars(java.lang.String str, char[] buffer, int ptr)
private static int getAsciiBytes(java.lang.String str, byte[] buffer, int ptr)