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 Summary

    Modifier and Type
    Method
    Description
    static <T> T[]
    copyAddAll(T[] src, int index, T[] values)
    Copies 'src' and inserts 'values' at position 'index'.
    static <T> T[]
    copyComponentAdd(T[] src, int index, int numComponents)
    Copies 'src' and inserts 'numComponents' at position 'index'.
    static <T> T[]
    copyComponentRemove(T[] src, int index, int numComponents)
    Copies 'src' and removes 'numComponents' at position 'index'.
    static <T> T[]
    copySet(T[] src, int index, T value)
    Copies 'src' and sets 'value' at position 'index'.
    static byte[]
    grow(int targetCapacity, int itemSize, byte[] items)
    Grows an items array.
    static char[]
    grow(int targetCapacity, int itemSize, char[] items)
    Grows an items array.
    static double[]
    grow(int targetCapacity, int itemSize, double[] items)
    Grows an items array.
    static int[]
    grow(int targetCapacity, int itemSize, int[] items)
    Grows an items array.
    static long[]
    grow(int targetCapacity, int itemSize, long[] items)
    Grows an items array.
    static short[]
    grow(int targetCapacity, int itemSize, short[] items)
    Grows an items array.
    static Object[]
    grow(int targetCapacity, int itemSize, Object[] items)
    Grows an items array.
    static byte[]
    trimToSize(int size, int itemSize, byte[] items)
    Resizes an array to fit the number of items.
    static double[]
    trimToSize(int size, int itemSize, double[] items)
    Resizes an array to fit the number of items.
    static int[]
    trimToSize(int size, int itemSize, int[] items)
    Resizes an array to fit the number of items.
    static long[]
    trimToSize(int size, int itemSize, long[] items)
    Resizes an array to fit the number of items.
    static Object[]
    trimToSize(int size, int itemSize, Object[] items)
    Resizes an array to fit the number of items.

    Methods inherited from class java.lang.Object

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

    • copyAddAll

      public static <T> T[] copyAddAll(T[] src, int index, T[] 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> T[] copyComponentAdd(T[] 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> T[] copyComponentRemove(T[] 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> T[] copySet(T[] 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 Object[] grow(int targetCapacity, int itemSize, Object[] 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[] grow(int targetCapacity, int itemSize, double[] 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[] grow(int targetCapacity, int itemSize, byte[] 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[] grow(int targetCapacity, int itemSize, short[] 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[] grow(int targetCapacity, int itemSize, int[] 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[] grow(int targetCapacity, int itemSize, long[] 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[] grow(int targetCapacity, int itemSize, char[] 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 Object[] trimToSize(int size, int itemSize, Object[] 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[] trimToSize(int size, int itemSize, int[] 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[] trimToSize(int size, int itemSize, long[] 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[] trimToSize(int size, int itemSize, double[] 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[] trimToSize(int size, int itemSize, byte[] 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