Class BinaryVectors


  • @Beta
    @PublicAPI
    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.

    • 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(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(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

        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