Package com.chemaxon.descriptors.common
Class BinaryVectors
java.lang.Object
com.chemaxon.descriptors.common.BinaryVectors
Utility methods related to bit string descriptors.
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Order of components in packed representations. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Number of bytes in an int.static final int
Number of bytes in a long.static final int
Log2 ofBYTES_IN_INT
.static final int
Log2 ofBYTES_IN_LONG
. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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[]
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.
-
Field Details
-
BYTES_IN_LONG
public static final int BYTES_IN_LONGNumber of bytes in a long.- See Also:
-
LOG2_BYTES_IN_LONG
public static final int LOG2_BYTES_IN_LONGLog2 ofBYTES_IN_LONG
.- See Also:
-
BYTES_IN_INT
public static final int BYTES_IN_INTNumber of bytes in an int.- See Also:
-
LOG2_BYTES_IN_INT
public static final int LOG2_BYTES_IN_INTLog2 ofBYTES_IN_INT
.- See Also:
-
-
Method Details
-
unpackBytesFromLongs
Unpack array of longs into an array of bytes.- Parameters:
longs
- Array of longsendianness
- Endianness of unpacking- Returns:
- array of bytes
-
unpackBytesFromInts
Unpack array of ints into an array of bytes.- Parameters:
ints
- Array of intsendianness
- Endianness of unpacking- Returns:
- array of bytes
-
unpackIntsFromLongs
Unpack array of longs into an array of ints.- Parameters:
longs
- Array of longsendianness
- Endianness of unpacking- Returns:
- array of ints
-
packBytesToInts
Pack array of bytes into an array of ints.- Parameters:
bytes
- Bytes to packendianness
- Endianness of packing- Returns:
- Packed ints
- Throws:
IllegalArgumentException
- when padding would be required
-
packBytesToLongs
Pack array of bytes into an array of longs.- Parameters:
bytes
- Bytes to packendianness
- Endianness of packing- Returns:
- Packed longs
- Throws:
IllegalArgumentException
- when padding would be required
-
packIntsToLongs
Pack array of ints into an array of longs.- Parameters:
ints
- Ints to packendianness
- Endianness of packing- Returns:
- Packed longs
- Throws:
IllegalArgumentException
- when padding would be required
-
parseInts
Parse an String containing integer values.- Parameters:
input
- String to parsecount
- Number of integers expecteddelim
- Delimiters for tokenization, passed toStringTokenizer(java.lang.String, java.lang.String)
- Returns:
- Array of parsed integers
- Throws:
IllegalArgumentException
- When count is zero or negative; when recognized token count (integers) in input differs from count; when parse error occurs
-
parseLongs
Parse an String containing long values.- Parameters:
input
- String to parsecount
- Number of long expecteddelim
- Delimiters for tokenization, passed toStringTokenizer(java.lang.String, java.lang.String)
- Returns:
- Array of parsed integers
- Throws:
IllegalArgumentException
- When count is zero or negative; when recognized token count (longs) in input differs from count; when parse error occurs
-
intsToString
Convert array of integers to a String.- Parameters:
in
- Array of integersdelim
- Delimiter between integers- Returns:
- Converted String
- Throws:
IllegalArgumentException
- when in or delim is empty
-
longsToString
Convert array of longs to a String.- Parameters:
in
- Array of longsdelim
- Delimiter between integers- Returns:
- Converted String
- Throws:
IllegalArgumentException
- when in or delim is empty
-
parseBinaryStringAsLongs
public static long[] parseBinaryStringAsLongs(String input, int bitCount, BinaryVectors.Endianness endianness) Parse a binary string of '0' and '1' characters into a packed long array.- Parameters:
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 array- Returns:
- Array of packed longs
- Throws:
IllegalArgumentException
- when bit count is not multiply of 64; its non positive; if input size mismatch or input contains characters other than '0' or '1'
-
longsToBinaryString
Convert array of longs to a binary String.- Parameters:
in
- Array of longsendianness
- Order of returned bits- Returns:
- Converted String; first 64 characters correspond to the first long; order is determined by endianness
- Throws:
IllegalArgumentException
- when in is empty
-