jklustor-all-api-0.0.7-20140619012755 (ChemAxon)


com.chemaxon.descriptors.common
Class BinaryVectors

Object
  extended by com.chemaxon.descriptors.common.BinaryVectors

@Beta
public final class BinaryVectors
extends Object

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.

Author:
Gabor Imre

Nested Class Summary
static class BinaryVectors.Endianness
          Order of components in packed representations.
 
Field Summary
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.
 
Method Summary
(package private) static void ensureBinaryString(String input, int expectedBits)
          Ensure that a String contains a valid binary representation.
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.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTES_IN_LONG

public static final int BYTES_IN_LONG
Number of bytes in a long.

See Also:
Constant Field Values

LOG2_BYTES_IN_LONG

public static final int LOG2_BYTES_IN_LONG
Log2 of BYTES_IN_LONG.

See Also:
Constant Field Values

BYTES_IN_INT

public static final int BYTES_IN_INT
Number of bytes in an int.

See Also:
Constant Field Values

LOG2_BYTES_IN_INT

public static final int LOG2_BYTES_IN_INT
Log2 of BYTES_IN_INT.

See Also:
Constant Field Values
Method Detail

unpackBytesFromLongs

public static byte[] unpackBytesFromLongs(long[] longs,
                                          BinaryVectors.Endianness endianness)
Unpack array of longs into an array of bytes.

Parameters:
longs - Array of longs
endianness - Endianness of unpacking
Returns:
array of bytes

unpackBytesFromInts

public static byte[] unpackBytesFromInts(int[] ints,
                                         BinaryVectors.Endianness endianness)
Unpack array of ints into an array of bytes.

Parameters:
ints - Array of ints
endianness - Endianness of unpacking
Returns:
array of bytes

unpackIntsFromLongs

public static int[] unpackIntsFromLongs(long[] longs,
                                        BinaryVectors.Endianness endianness)
Unpack array of longs into an array of ints.

Parameters:
longs - Array of longs
endianness - Endianness of unpacking
Returns:
array of ints

packBytesToInts

public static int[] packBytesToInts(byte[] bytes,
                                    BinaryVectors.Endianness endianness)
Pack array of bytes into an array of ints.

Parameters:
bytes - Bytes to pack
endianness - Endianness of packing
Returns:
Packed ints
Throws:
IllegalArgumentException - when padding would be required

packBytesToLongs

public static long[] packBytesToLongs(byte[] bytes,
                                      BinaryVectors.Endianness endianness)
Pack array of bytes into an array of longs.

Parameters:
bytes - Bytes to pack
endianness - Endianness of packing
Returns:
Packed longs
Throws:
IllegalArgumentException - when padding would be required

packIntsToLongs

public static long[] packIntsToLongs(int[] ints,
                                     BinaryVectors.Endianness endianness)
Pack array of ints into an array of longs.

Parameters:
ints - Ints to pack
endianness - Endianness of packing
Returns:
Packed longs
Throws:
IllegalArgumentException - when padding would be required

parseInts

public static int[] parseInts(String input,
                              int count,
                              String delim)
Parse an String containing integer values.

Parameters:
input - String to parse
count - Number of integers expected
delim - Delimiters for tokenization, passed to StringTokenizer.StringTokenizer(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

public static long[] parseLongs(String input,
                                int count,
                                String delim)
Parse an String containing long values.

Parameters:
input - String to parse
count - Number of long expected
delim - Delimiters for tokenization, passed to StringTokenizer.StringTokenizer(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

ensureBinaryString

static void ensureBinaryString(String input,
                               int expectedBits)
Ensure that a String contains a valid binary representation.

Parameters:
input - Input string
expectedBits - Expected bit count
Throws:
IllegalArgumentException - when bit count does not match or the input contains other than '0' and '1' characters

intsToString

public static String intsToString(int[] in,
                                  String delim)
Convert array of integers to a String.

Parameters:
in - Array of integers
delim - Delimiter between integers
Returns:
Converted String
Throws:
IllegalArgumentException - when in or delim is empty

longsToString

public static String longsToString(long[] in,
                                   String delim)
Convert array of longs to a String.

Parameters:
in - Array of longs
delim - 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 array
bitCount - Expected bit count; must be multiply of 64
endianness - 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

public static String longsToBinaryString(long[] in,
                                         BinaryVectors.Endianness endianness)
Convert array of longs to a binary String.

Parameters:
in - Array of longs
endianness - 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

jklustor-all-api-0.0.7-20140619012755 (ChemAxon)