@Beta @PublicAPI public final class BinaryVectors extends Object
Please note that this utility class is marked with the Beta
annotation, so it can be subject of incompatible
changes or removal in later releases.
Modifier and Type | Class and Description |
---|---|
static class |
BinaryVectors.Endianness
Order of components in packed representations.
|
Modifier and Type | Field and Description |
---|---|
static int |
BYTES_IN_INT
Number of bytes in an int.
|
static int |
BYTES_IN_LONG
Number of bytes in a long.
|
static int |
LOG2_BYTES_IN_INT
Log2 of
BYTES_IN_INT . |
static int |
LOG2_BYTES_IN_LONG
Log2 of
BYTES_IN_LONG . |
Modifier and Type | Method and Description |
---|---|
static String |
intsToString(int[] in,
String delim)
Convert array of integers to a String.
|
static String |
longsToBinaryString(long[] in,
BinaryVectors.Endianness endianness)
Convert array of longs to a binary String.
|
static String |
longsToString(long[] in,
String delim)
Convert array of longs to a String.
|
static int[] |
packBytesToInts(byte[] bytes,
BinaryVectors.Endianness endianness)
Pack array of bytes into an array of ints.
|
static long[] |
packBytesToLongs(byte[] bytes,
BinaryVectors.Endianness endianness)
Pack array of bytes into an array of longs.
|
static long[] |
packIntsToLongs(int[] ints,
BinaryVectors.Endianness endianness)
Pack array of ints into an array of longs.
|
static long[] |
parseBinaryStringAsLongs(String input,
int bitCount,
BinaryVectors.Endianness endianness)
Parse a binary string of '0' and '1' characters into a packed long array.
|
static int[] |
parseInts(String input,
int count,
String delim)
Parse an String containing integer values.
|
static long[] |
parseLongs(String input,
int count,
String delim)
Parse an String containing long values.
|
static byte[] |
unpackBytesFromInts(int[] ints,
BinaryVectors.Endianness endianness)
Unpack array of ints into an array of bytes.
|
static byte[] |
unpackBytesFromLongs(long[] longs,
BinaryVectors.Endianness endianness)
Unpack array of longs into an array of bytes.
|
static int[] |
unpackIntsFromLongs(long[] longs,
BinaryVectors.Endianness endianness)
Unpack array of longs into an array of ints.
|
public static final int BYTES_IN_LONG
public static final int LOG2_BYTES_IN_LONG
BYTES_IN_LONG
.public static final int BYTES_IN_INT
public static final int LOG2_BYTES_IN_INT
BYTES_IN_INT
.public static byte[] unpackBytesFromLongs(long[] longs, BinaryVectors.Endianness endianness)
longs
- Array of longsendianness
- Endianness of unpackingpublic static byte[] unpackBytesFromInts(int[] ints, BinaryVectors.Endianness endianness)
ints
- Array of intsendianness
- Endianness of unpackingpublic static int[] unpackIntsFromLongs(long[] longs, BinaryVectors.Endianness endianness)
longs
- Array of longsendianness
- Endianness of unpackingpublic static int[] packBytesToInts(byte[] bytes, BinaryVectors.Endianness endianness)
bytes
- Bytes to packendianness
- Endianness of packingIllegalArgumentException
- when padding would be requiredpublic static long[] packBytesToLongs(byte[] bytes, BinaryVectors.Endianness endianness)
bytes
- Bytes to packendianness
- Endianness of packingIllegalArgumentException
- when padding would be requiredpublic static long[] packIntsToLongs(int[] ints, BinaryVectors.Endianness endianness)
ints
- Ints to packendianness
- Endianness of packingIllegalArgumentException
- when padding would be requiredpublic static int[] parseInts(String input, int count, String delim)
input
- String to parsecount
- Number of integers expecteddelim
- Delimiters for tokenization, passed to
StringTokenizer.StringTokenizer(java.lang.String, java.lang.String)
IllegalArgumentException
- When count is zero or negative; when recognized token count (integers) in input
differs from count; when parse error occurspublic static long[] parseLongs(String input, int count, String delim)
input
- String to parsecount
- Number of long expecteddelim
- Delimiters for tokenization, passed to
StringTokenizer.StringTokenizer(java.lang.String, java.lang.String)
IllegalArgumentException
- When count is zero or negative; when recognized token count (longs) in input
differs from count; when parse error occurspublic static String intsToString(int[] in, String delim)
in
- Array of integersdelim
- Delimiter between integersIllegalArgumentException
- when in or delim is emptypublic static String longsToString(long[] in, String delim)
in
- Array of longsdelim
- Delimiter between integersIllegalArgumentException
- when in or delim is emptypublic static long[] parseBinaryStringAsLongs(String input, int bitCount, BinaryVectors.Endianness endianness)
input
- Input String. First 64 characters are associated to the first long in the returned arraybitCount
- Expected bit count; must be multiply of 64endianness
- Order of bits mapping in the returned arrayIllegalArgumentException
- when bit count is not multiply of 64; its non positive; if input size mismatch
or input contains characters other than '0' or '1'public static String longsToBinaryString(long[] in, BinaryVectors.Endianness endianness)
in
- Array of longsendianness
- Order of returned bitsIllegalArgumentException
- when in is empty