net.i2p.router.crypto.ratchet

## Class GrowingArrayUtils

- java.lang.Object
- - net.i2p.router.crypto.ratchet.GrowingArrayUtils

-     final class GrowingArrayUtils
      extends Object

  Helper methods for efficient primitive array growth and insertion operations, treating array length as capacity rather than element count for optimal performance All methods in this class assume that the length of an array is equivalent to its capacity and NOT to number of elements in the array. The current size of the array is always passed in as a parameter.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static char[]` | `append(char[] array, int currentSize, char element)` Primitive char version of `append(Object[], int, Object)`.
    `static <T> T[]` | `append(T[] array, int currentSize, T element)` Appends an element to the end of the array, growing the array if there is no more room.
    `static int` | `growSize(int currentSize)` Given the current size of an array, returns an ideal size to which the array should grow.
    `static char[]` | `insert(char[] array, int currentSize, int index, char element)` Primitive char version of `insert(Object[], int, int, Object)`.
    `static <T> T[]` | `insert(T[] array, int currentSize, int index, T element)` Inserts an element into the array at the specified index, growing the array if there is no more room.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### append

          public static char[] append(char[] array,
                                      int currentSize,
                                      char element)

      Primitive char version of `append(Object[], int, Object)`.

    - #### append

          public static <T> T[] append(T[] array,
                                       int currentSize,
                                       T element)

      Appends an element to the end of the array, growing the array if there is no more room.
      Parameters:
        `array` - The array to which to append the element. This must NOT be null.
        `currentSize` - The number of elements in the array. Must be less than or equal to array.length.
        `element` - The element to append.
      Returns:
        the array to which the element was appended. This may be different than the given array.

    - #### growSize

          public static int growSize(int currentSize)

      Given the current size of an array, returns an ideal size to which the array should grow. This is typically double the given size, but should not be relied upon to do so in the future.

    - #### insert

          public static char[] insert(char[] array,
                                      int currentSize,
                                      int index,
                                      char element)

      Primitive char version of `insert(Object[], int, int, Object)`.

    - #### insert

          public static <T> T[] insert(T[] array,
                                       int currentSize,
                                       int index,
                                       T element)

      Inserts an element into the array at the specified index, growing the array if there is no more room.
      Parameters:
        `array` - The array to which to append the element. Must NOT be null.
        `currentSize` - The number of elements in the array. Must be less than or equal to array.length.
        `element` - The element to insert.
      Returns:
        the array to which the element was appended. This may be different than the given array.