Module hash4j

Class ArraySizeUtil

java.lang.Object
com.dynatrace.hash4j.internal.ArraySizeUtil

public final class ArraySizeUtil extends Object
Utility class for resizing arrays.
  • Method Details

    • increaseArraySize

      public static int increaseArraySize(int currentSize, int requiredIndex)
      Returns a new array size that is greater than the current array size and that supports the given required index.

      If possible, this function doubles the current array size.

      It is guaranteed that the return value is greater than the current size. If the current size is equal to Integer.MAX_VALUE, an OutOfMemoryError exception is thrown.

      This function takes care that the maximum allowed arrow size is not exceeded.

      Parameters:
      currentSize - current array size
      requiredIndex - the index that needs to be supported/covered with the new array size
      Returns:
      the new array size
      Throws:
      OutOfMemoryError - if the current size is equal to Integer.MAX_VALUE