Package acdp.misc

Class Utils

java.lang.Object
acdp.misc.Utils

public class Utils extends Object
Defines some useful constants and methods that are heavily used inside ACDP but may be useful to custom database designers as well.
Author:
Beat Hörmann
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int[]
    The value of bnd4[x] for 0 ≤ x < 4 is equal to 256x - 1 and the value of bnd4[4] is equal to the value of the Integer.MAX_VALUE constant.
    static final long[]
    The value of bnd8[x] for 0 ≤ x < 8 is equal to 256x - 1 and the value of bnd8[8] is equal to the value of the Long.MAX_VALUE constant.
    static final int
    One mebibyte has 1024 * 1024 = 1048576 bytes.
    static final byte[][]
    The value of zeros[x] for 0 ≤ x ≤ 8 is equal to a byte array of length x filled with zeros.
  • Method Summary

    Modifier and Type
    Method
    Description
    static final int
    bitCount(byte[] bytes, int offset, int len)
    Returns the number of one-bits in the specified subarray of bytes.
    static final int
    bmLength(int n)
    Returns the number of bytes of a bitmap with n bits represented as an array of bytes.
    static final Path
    buildPath(String pathStr, Path dirPath)
    Builds a path from the specified path string and the optional directory path.
    static final boolean
    equals(byte[] arr1, byte[] arr2, int offset, int n)
    Finds out if arr1[k] == arr2[k] for offsetk < offset + n.
    static final boolean
    hasNull(Object[] arr)
    Finds out if at least one element of the specified array is equal to null.
    static final boolean
    isZero(byte[] bytes, int offset, int len)
    Finds out if all the bytes of the specified subarray of bytes are zero.
    static final int
    lor(long x)
    Computes ⌊log256(x)⌋ + 1 for x ≥ 1.
    static final long
    unsFromBytes(byte[] bytes, int len)
    Converts the specified byte array of the specified length to an unsigned integer value.
    static final long
    unsFromBytes(byte[] bytes, int offset, int len)
    Converts the specified byte subarray to an unsigned integer value.
    static final byte[]
    unsToBytes(long val, int len)
    Converts the specified unsigned integer value of the specified length to a byte array of the same length.
    static final void
    unsToBytes(long val, int len, byte[] bytes)
    Converts the specified unsigned integer value of the specified length to a byte array and stores it into the specified byte array.
    static final void
    unsToBytes(long val, int len, byte[] bytes, int offset)
    Converts the specified unsigned integer value of the specified length to a byte array and stores it into the specified byte array starting at the specified offset.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • oneMiB

      public static final int oneMiB
      One mebibyte has 1024 * 1024 = 1048576 bytes.
      See Also:
    • bnd8

      public static final long[] bnd8
      The value of bnd8[x] for 0 ≤ x < 8 is equal to 256x - 1 and the value of bnd8[8] is equal to the value of the Long.MAX_VALUE constant.

      The value of bnd8[x] is equal to the largest unsigned integer with a width (or precision) equal to x bytes using the binary numeral system. The value of bnd8[8] is equal to Java's largest positive built-in integer number.

      Treat this array as if it were immutable: Don't change any of its elements. (This variable is not used inside ACDP.)

    • bnd4

      public static final int[] bnd4
      The value of bnd4[x] for 0 ≤ x < 4 is equal to 256x - 1 and the value of bnd4[4] is equal to the value of the Integer.MAX_VALUE constant.

      Treat this array as if it were immutable: Don't change any of its elements. (This variable is not used inside ACDP.)

    • zeros

      public static final byte[][] zeros
      The value of zeros[x] for 0 ≤ x ≤ 8 is equal to a byte array of length x filled with zeros. Note that zeros[0] returns an empty byte array.

      Treat this array as if it were immutable: Don't change any of its elements. (This variable is not used inside ACDP.)

  • Method Details

    • lor

      public static final int lor(long x)
      Computes ⌊log256(x)⌋ + 1 for x ≥ 1.

      The result of this method is equal to the minimum number of bytes necessary to represent the argument as an unsigend integer using the binary numeral system.

      Note that lor(bnd8[x]) equals x for 1 ≤ x ≤ 8.

      Parameters:
      x - The argument.
      Returns:
      The value of the described function or 1 if x < 1.
    • bmLength

      public static final int bmLength(int n)
      Returns the number of bytes of a bitmap with n bits represented as an array of bytes.
      Parameters:
      n - The number of bits of the bitmap.
      Returns:
      The length of the bitmap or 0 if n is less than 1.
    • buildPath

      public static final Path buildPath(String pathStr, Path dirPath) throws NullPointerException, IllegalArgumentException, InvalidPathException
      Builds a path from the specified path string and the optional directory path. If the specified path string turns out to denote a relative path then it is resolved against the specified directory path.
      Parameters:
      pathStr - The path string, not allowed to be null or an empty string.
      dirPath - The directory path. This value is allowed to be null if and only if pathStr denotes an absolute path.
      Returns:
      The resulting path.
      Throws:
      NullPointerException - If the path string denotes a relative path and the directory path is null.
      IllegalArgumentException - If the path string is null or an empty string.
      InvalidPathException - If the path string is invalid.
    • isZero

      public static final boolean isZero(byte[] bytes, int offset, int len) throws NullPointerException, IndexOutOfBoundsException
      Finds out if all the bytes of the specified subarray of bytes are zero.
      Parameters:
      bytes - The byte array to test, not allowed to be null. The length of the array must be greater than or equal to the value of offset + len. This method reads the elements with indices offset, offset + 1, ..., offset + len - 1 of the array. The other elements of the array remain untouched.
      offset - The index within bytes where to start testing the bytes. The value must be greater than or equal to zero.
      len - The number of bytes to test. The value must be greater than or equal to zero.
      Returns:
      The boolean value true if the byte array has at least one byte and all bytes are equal 0, false otherwise.
      Throws:
      NullPointerException - If bytes is null.
      IndexOutOfBoundsException - If the condition described in the bytes parameter description is not met.
    • bitCount

      public static final int bitCount(byte[] bytes, int offset, int len) throws NullPointerException, IndexOutOfBoundsException
      Returns the number of one-bits in the specified subarray of bytes.
      Parameters:
      bytes - The byte array, not allowed to be null. The length of the array must be greater than or equal to the value of offset + len. This method reads the elements with indices offset, offset + 1, ..., offset + len - 1 of the array. The other elements of the array remain untouched.
      offset - The index within bytes where to start counting the one-bits. The value must be greater than or equal to zero.
      len - The number of bytes. The value must be greater than or equal to zero.
      Returns:
      The number of one-bits in the specified subarray of bytes.
      Throws:
      NullPointerException - If bytes is null.
      IndexOutOfBoundsException - If the condition described in the bytes parameter description is not met.
    • hasNull

      public static final boolean hasNull(Object[] arr) throws NullPointerException
      Finds out if at least one element of the specified array is equal to null.
      Parameters:
      arr - The array to test, not allowed to be null.
      Returns:
      The boolean value true if at least one element of the specified array is equal to null, false otherwise.
      Throws:
      NullPointerException - If arr is null.
    • equals

      public static final boolean equals(byte[] arr1, byte[] arr2, int offset, int n) throws NullPointerException, IndexOutOfBoundsException
      Finds out if arr1[k] == arr2[k] for offsetk < offset + n.
      Parameters:
      arr1 - The first byte array, not allowed to be null. The array must contain at least offset + n bytes.
      arr2 - The second byte array, not allowed to be null. The array must contain at least offset + n bytes.
      offset - The index where to start the comparison.
      n - The number of bytes to compare. Must be greater than or equal to zero.
      Returns:
      The boolean value true if the specified arrays have equal byte values for all indices in the specified range, false otherwise.
      Throws:
      NullPointerException - If arr1 or arr2 is null.
      IndexOutOfBoundsException - If the condition described in the arr1 or arr2 parameter description is not met.
    • unsToBytes

      public static final byte[] unsToBytes(long val, int len)
      Converts the specified unsigned integer value of the specified length to a byte array of the same length.
      Parameters:
      val - The value of the unsigned integer. The value must be greater than or equal to zero.
      len - The length of the unsigned integer value in bytes. The value must be greater than 0 and less than or equal to 8.
      Returns:
      The byte array of length len housing the converted unsigned integer.
      Throws:
      IndexOutOfBoundsException - If the condition described in the len parameter description is not met.
    • unsToBytes

      public static final void unsToBytes(long val, int len, byte[] bytes) throws NullPointerException, IndexOutOfBoundsException
      Converts the specified unsigned integer value of the specified length to a byte array and stores it into the specified byte array.

      Internally this method just calls the unsToBytes(long, int, byte[], int) method with the last parameter set to zero.

      Parameters:
      val - The value of the unsigned integer. The value must be greater than or equal to zero.
      len - The length of the unsigned integer value in bytes. The value must be greater than 0 and less than or equal to 8.
      bytes - The byte array which houses the byte representation of the unsigned integer, not allowed to be null. The length of the array must be greater than or equal to the value of len. This method sets the first len elements of the array. The other elements of the array remain untouched.
      Throws:
      NullPointerException - If bytes is null.
      IndexOutOfBoundsException - If the condition described in the bytes parameter description is not met.
    • unsToBytes

      public static final void unsToBytes(long val, int len, byte[] bytes, int offset) throws NullPointerException, IndexOutOfBoundsException
      Converts the specified unsigned integer value of the specified length to a byte array and stores it into the specified byte array starting at the specified offset.
      Parameters:
      val - The value of the unsigned integer. The value must be greater than or equal to zero.
      len - The length of the unsigned integer value in bytes. The value must be greater than 0 and less than or equal to 8.
      bytes - The byte array which houses the byte representation of the unsigned integer, not allowed to be null. The length of the array must be greater than or equal to the value of offset + len. This method sets the elements with indices offset, offset + 1, ..., offset + len - 1 of the array. The other elements of the array remain untouched.
      offset - The index within bytes where to start saving the result. The value must be greater than or equal to zero.
      Throws:
      NullPointerException - If bytes is null.
      IndexOutOfBoundsException - If the condition described in the bytes parameter description is not met.
    • unsFromBytes

      public static final long unsFromBytes(byte[] bytes, int len) throws NullPointerException, IndexOutOfBoundsException
      Converts the specified byte array of the specified length to an unsigned integer value.

      Internally this method just calls the unsFromBytes(byte[], int, int) method with the second parameter set to zero.

      Parameters:
      bytes - The byte array representing the unsigned integer value, not allowed to be null. The length of the array must be greater than or equal to the value of len. This method reads the first len elements of the array. The other elements of the array remain untouched.
      len - The length of the unsigned integer in bytes. The value must be greater than 0 and less than or equal to 8.
      Returns:
      The unsigned integer value.
      Throws:
      NullPointerException - If bytes is null.
      IndexOutOfBoundsException - If the condition described in the bytes parameter description is not met.
    • unsFromBytes

      public static final long unsFromBytes(byte[] bytes, int offset, int len) throws NullPointerException, IndexOutOfBoundsException
      Converts the specified byte subarray to an unsigned integer value.
      Parameters:
      bytes - The byte array representing the unsigned integer value, not allowed to be null. The length of the array must be greater than or equal to the value of offset + len. This method reads the elements with indices offset, offset + 1, ..., offset + len - 1 of the array. The other elements of the array remain untouched.
      offset - The index within bytes where to start reading the bytes of the unsigned integer. The value must be greater than or equal to zero.
      len - The length of the unsigned integer in bytes. The value must be greater than 0 and less than or equal to 8.
      Returns:
      The unsigned integer value.
      Throws:
      NullPointerException - If bytes is null.
      IndexOutOfBoundsException - If the condition described in the bytes parameter description is not met.