public final class AsciiEncoding extends Object
| Modifier and Type | Field and Description |
|---|---|
static byte[] |
ASCII_DIGITS
Lookup table used for encoding ints/longs as ASCII characters.
|
static int |
INT_MAX_DIGITS
Maximum number of digits in a US-ASCII-encoded int.
|
static int[] |
INT_POW_10
Power of ten for int values.
|
static long |
INTEGER_ABSOLUTE_MIN_VALUE
An absolute value of the
Integer.MIN_VALUE as long. |
static int |
LONG_MAX_DIGITS
Maximum number of digits in a US-ASCII-encoded long.
|
static int[] |
LONG_MAX_VALUE_DIGITS
Long.MAX_VALUE split into components by 8 digits max. |
static int[] |
LONG_MIN_VALUE_DIGITS
Long.MIN_VALUE split into components by 8 digits max. |
static long[] |
LONG_POW_10
Power of ten for long values.
|
static byte[] |
MAX_INTEGER_VALUE
US-ASCII-encoded byte representation of the
Integer.MAX_VALUE. |
static byte[] |
MAX_LONG_VALUE
US-ASCII-encoded byte representation of the
Long.MAX_VALUE. |
static byte[] |
MIN_INTEGER_VALUE
US-ASCII-encoded byte representation of the
Integer.MIN_VALUE. |
static byte[] |
MIN_LONG_VALUE
US-ASCII-encoded byte representation of the
Long.MIN_VALUE. |
static byte |
MINUS_SIGN
Byte value of the minus sign ('
-'). |
static byte |
ZERO
Byte value of zero character ('
0'). |
| Modifier and Type | Method and Description |
|---|---|
static int |
digitCount(int value)
Count number of digits in a positive
int value. |
static int |
digitCount(long value)
Count number of digits in a positive
long value. |
static int |
endOffset(int value)
Deprecated.
Use
digitCount(int) instead. |
static int |
endOffset(long value)
Deprecated.
Use
digitCount(long) instead. |
static int |
getDigit(int index,
byte value)
Get the digit value of an ASCII encoded
byte. |
static int |
getDigit(int index,
char value)
Get the digit value of an ASCII encoded
char. |
static boolean |
isDigit(byte value)
Check if the
value is an ASCII-encoded digit. |
static boolean |
isEightDigitAsciiEncodedNumber(long value)
Checks if the provided
value represents an ASCII-encoded number which contains exactly eight digits. |
static boolean |
isFourDigitsAsciiEncodedNumber(int value)
Checks if the provided
value represents an ASCII-encoded number which contains exactly four digits. |
static int |
parseEightDigitsLittleEndian(long bytes)
Parses an eight-digit number out of an ASCII-encoded value assuming little-endian byte order.
|
static int |
parseFourDigitsLittleEndian(int bytes)
Parses a four-digit number out of an ASCII-encoded value assuming little-endian byte order.
|
static int |
parseIntAscii(CharSequence cs,
int index,
int length)
Parse an ASCII encoded int from a
CharSequence. |
static long |
parseLongAscii(CharSequence cs,
int index,
int length)
Parse an ASCII encoded long from a
CharSequence. |
public static final int INT_MAX_DIGITS
public static final int LONG_MAX_DIGITS
public static final long INTEGER_ABSOLUTE_MIN_VALUE
Integer.MIN_VALUE as long.public static final byte[] MIN_INTEGER_VALUE
Integer.MIN_VALUE.public static final byte[] MAX_INTEGER_VALUE
Integer.MAX_VALUE.public static final byte[] MIN_LONG_VALUE
Long.MIN_VALUE.public static final byte[] MAX_LONG_VALUE
Long.MAX_VALUE.public static final byte MINUS_SIGN
-').public static final byte ZERO
0').public static final byte[] ASCII_DIGITS
public static final int[] LONG_MAX_VALUE_DIGITS
Long.MAX_VALUE split into components by 8 digits max.public static final int[] LONG_MIN_VALUE_DIGITS
Long.MIN_VALUE split into components by 8 digits max.public static final int[] INT_POW_10
public static final long[] LONG_POW_10
@Deprecated public static int endOffset(int value)
digitCount(int) instead.
digitCount(value) - 1
value - to find the end encoded character offset.digitCount(int)@Deprecated public static int endOffset(long value)
digitCount(long) instead.
digitCount(value) - 1
value - to find the end encoded character offset.digitCount(long)public static int digitCount(int value)
int value.
Implementation is based on the Kendall Willets' idea as presented in the Computing the number of digits of an integer even faster blog post.
Use org.agrona.AsciiEncodingTest#printDigitCountIntTable() to regenerate lookup table.
value - to count number of digits int.123 then the result will be 3.public static int digitCount(long value)
long value.
Implementation is based on the Kendall Willets' idea as presented in the Computing the number of digits of an integer even faster blog post.
Use org.agrona.AsciiEncodingTest#printDigitCountLongTable() to regenerate lookup table.
value - to count number of digits int.12345678909876 then the result will be
14.public static boolean isDigit(byte value)
value is an ASCII-encoded digit.value - ti be checked.true if the value is an ASCII-encoded digit.public static int getDigit(int index,
byte value)
byte.index - within the string the value is encoded.value - of the encoding in ASCII.AsciiNumberFormatException - if the value is not a digit.public static int getDigit(int index,
char value)
char.index - within the string the value is encoded.value - of the encoding in ASCII.AsciiNumberFormatException - if the value is not a digit.public static int parseIntAscii(CharSequence cs, int index, int length)
CharSequence.cs - to parse.index - at which the number begins.length - of the encoded number in characters.AsciiNumberFormatException - if length <= 0 or cs is not an int valuepublic static long parseLongAscii(CharSequence cs, int index, int length)
CharSequence.cs - to parse.index - at which the number begins.length - of the encoded number in characters.AsciiNumberFormatException - if length <= 0 or cs is not a long valuepublic static boolean isFourDigitsAsciiEncodedNumber(int value)
value represents an ASCII-encoded number which contains exactly four digits.value - four ASCII-encoded bytes to check.true if the value is an ASCII-encoded number with four digits in it.public static int parseFourDigitsLittleEndian(int bytes)
bytes - ASCII-encoded value in little-endian byte order.int value with four digits.public static boolean isEightDigitAsciiEncodedNumber(long value)
value represents an ASCII-encoded number which contains exactly eight digits.value - eoght ASCII-encoded bytes to check.true if the value is an ASCII-encoded number with eight digits in it.public static int parseEightDigitsLittleEndian(long bytes)
bytes - ASCII-encoded value in little-endian byte order.int value with eight digits.Copyright © 2014-2022 Real Logic Limited. All Rights Reserved.