Class ListHelper

java.lang.Object
org.jhotdraw8.collection.util.ListHelper

public class ListHelper extends Object
Provides static methods for lists that are based on arrays.
Author:
Werner Randelshofer
  • Method Details

    • copyAddAll

      public static <T> @NonNull T @NonNull [] copyAddAll(@NonNull T @NonNull [] src, int index, @NonNull T @NonNull [] values)
      Copies 'src' and inserts 'values' at position 'index'.
      Type Parameters:
      T - the array type
      Parameters:
      src - an array
      index - an index
      values - the values
      Returns:
      a new array
    • copyComponentAdd

      public static <T> @NonNull T @NonNull [] copyComponentAdd(@NonNull T @NonNull [] src, int index, int numComponents)
      Copies 'src' and inserts 'numComponents' at position 'index'.

      The new components will have a null value.

      Type Parameters:
      T - the array type
      Parameters:
      src - an array
      index - an index
      numComponents - the number of array components to be added
      Returns:
      a new array
    • copyComponentRemove

      public static <T> @NonNull T @NonNull [] copyComponentRemove(@NonNull T @NonNull [] src, int index, int numComponents)
      Copies 'src' and removes 'numComponents' at position 'index'.
      Type Parameters:
      T - the array type
      Parameters:
      src - an array
      index - an index
      numComponents - the number of array components to be removed
      Returns:
      a new array
    • copySet

      public static <T> @NonNull T @NonNull [] copySet(@NonNull T @NonNull [] src, int index, T value)
      Copies 'src' and sets 'value' at position 'index'.
      Type Parameters:
      T - the array type
      Parameters:
      src - an array
      index - an index
      value - a value
      Returns:
      a new array
    • grow

      public static @NonNull Object @NonNull [] grow(int targetCapacity, int itemSize, @NonNull Object @NonNull [] items)
      Grows an items array.
      Parameters:
      targetCapacity - >= 0
      itemSize - number of array elements that an item occupies
      items - the items array
      Returns:
      a new item array of larger size or the same if no resizing is necessary
    • grow

      public static double @NonNull [] grow(int targetCapacity, int itemSize, double @NonNull [] items)
      Grows an items array.
      Parameters:
      targetCapacity - >= 0
      itemSize - number of array elements that an item occupies
      items - the items array
      Returns:
      a new item array of larger size or the same if no resizing is necessary
    • grow

      public static byte @NonNull [] grow(int targetCapacity, int itemSize, byte @NonNull [] items)
      Grows an items array.
      Parameters:
      targetCapacity - >= 0
      itemSize - number of array elements that an item occupies
      items - the items array
      Returns:
      a new item array of larger size or the same if no resizing is necessary
    • grow

      public static short @NonNull [] grow(int targetCapacity, int itemSize, short @NonNull [] items)
      Grows an items array.
      Parameters:
      targetCapacity - >= 0
      itemSize - number of array elements that an item occupies
      items - the items array
      Returns:
      a new item array of larger size or the same if no resizing is necessary
    • grow

      public static int @NonNull [] grow(int targetCapacity, int itemSize, int @NonNull [] items)
      Grows an items array.
      Parameters:
      targetCapacity - >= 0
      itemSize - number of array elements that an item occupies
      items - the items array
      Returns:
      a new item array of larger size or the same if no resizing is necessary
    • grow

      public static long @NonNull [] grow(int targetCapacity, int itemSize, long @NonNull [] items)
      Grows an items array.
      Parameters:
      targetCapacity - >= 0
      itemSize - number of array elements that an item occupies
      items - the items array
      Returns:
      a new item array of larger size or the same if no resizing is necessary
    • grow

      public static char @NonNull [] grow(int targetCapacity, int itemSize, char @NonNull [] items)
      Grows an items array.
      Parameters:
      targetCapacity - >= 0
      itemSize - number of array elements that an item occupies
      items - the items array
      Returns:
      a new item array of larger size or the same if no resizing is necessary
    • trimToSize

      public static @NonNull Object @NonNull [] trimToSize(int size, int itemSize, @NonNull Object @NonNull [] items)
      Resizes an array to fit the number of items.
      Parameters:
      size - the size to fit
      itemSize - number of array elements that an item occupies
      items - the items array
      Returns:
      a new item array of smaller size or the same if no resizing is necessary
    • trimToSize

      public static int @NonNull [] trimToSize(int size, int itemSize, int @NonNull [] items)
      Resizes an array to fit the number of items.
      Parameters:
      size - the size to fit
      itemSize - number of array elements that an item occupies
      items - the items array
      Returns:
      a new item array of smaller size or the same if no resizing is necessary
    • trimToSize

      public static long @NonNull [] trimToSize(int size, int itemSize, long @NonNull [] items)
      Resizes an array to fit the number of items.
      Parameters:
      size - the size to fit
      itemSize - number of array elements that an item occupies
      items - the items array
      Returns:
      a new item array of smaller size or the same if no resizing is necessary
    • trimToSize

      public static double @NonNull [] trimToSize(int size, int itemSize, double @NonNull [] items)
      Resizes an array to fit the number of items.
      Parameters:
      size - the size to fit
      itemSize - number of array elements that an item occupies
      items - the items array
      Returns:
      a new item array of smaller size or the same if no resizing is necessary
    • trimToSize

      public static byte @NonNull [] trimToSize(int size, int itemSize, byte @NonNull [] items)
      Resizes an array to fit the number of items.
      Parameters:
      size - the size to fit
      itemSize - number of array elements that an item occupies
      items - the items array
      Returns:
      a new item array of smaller size or the same if no resizing is necessary