java.lang.Object
org.jhotdraw8.collection.util.ListHelper
Provides static methods for lists that are based on arrays.
- Author:
- Werner Randelshofer
-
Method Summary
Modifier and TypeMethodDescriptionstatic <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[]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.
-
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 arrayindex- an indexvalues- 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 arrayindex- an indexnumComponents- 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 arrayindex- an indexnumComponents- 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 arrayindex- an indexvalue- a value- Returns:
- a new array
-
grow
Grows an items array.- Parameters:
targetCapacity- >= 0itemSize- number of array elements that an item occupiesitems- 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- >= 0itemSize- number of array elements that an item occupiesitems- 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- >= 0itemSize- number of array elements that an item occupiesitems- 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- >= 0itemSize- number of array elements that an item occupiesitems- 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- >= 0itemSize- number of array elements that an item occupiesitems- 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- >= 0itemSize- number of array elements that an item occupiesitems- 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- >= 0itemSize- number of array elements that an item occupiesitems- the items array- Returns:
- a new item array of larger size or the same if no resizing is necessary
-
trimToSize
Resizes an array to fit the number of items.- Parameters:
size- the size to fititemSize- number of array elements that an item occupiesitems- 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 fititemSize- number of array elements that an item occupiesitems- 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 fititemSize- number of array elements that an item occupiesitems- 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 fititemSize- number of array elements that an item occupiesitems- 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 fititemSize- number of array elements that an item occupiesitems- the items array- Returns:
- a new item array of smaller size or the same if no resizing is necessary
-