Package icyllis.modernui.util
Class GrowingArrayUtils
java.lang.Object
icyllis.modernui.util.GrowingArrayUtils
A helper class that aims to provide comparable growth performance to ArrayList, but on primitive
arrays. Common array operations are implemented for efficient use in dynamic containers.
All methods in this class assume that the length of an array is equivalent to its capacity and NOT the number of elements in the array. The current size of the array is always passed in as a parameter.
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean[]
append
(boolean[] array, int currentSize, boolean element) Primitive boolean version ofappend(Object[], int, Object)
.static int[]
append
(int[] array, int currentSize, int element) Primitive int version ofappend(Object[], int, Object)
.static long[]
append
(long[] array, int currentSize, long element) Primitive long version ofappend(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 boolean[]
insert
(boolean[] array, int currentSize, int index, boolean element) Primitive boolean version ofinsert(Object[], int, int, Object)
.static int[]
insert
(int[] array, int currentSize, int index, int element) Primitive int version ofinsert(Object[], int, int, Object)
.static long[]
insert
(long[] array, int currentSize, int index, long element) Primitive long version ofinsert(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.
-
Method Details
-
growSize
public static int growSize(int currentSize) Given the current size of an array, returns an ideal size to which the array should grow. -
append
@Nonnull public static <T> T[] append(@Nonnull 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.
-
append
@Nonnull public static int[] append(@Nonnull int[] array, int currentSize, int element) Primitive int version ofappend(Object[], int, Object)
. -
append
@Nonnull public static long[] append(@Nonnull long[] array, int currentSize, long element) Primitive long version ofappend(Object[], int, Object)
. -
append
@Nonnull public static boolean[] append(@Nonnull boolean[] array, int currentSize, boolean element) Primitive boolean version ofappend(Object[], int, Object)
. -
insert
@Nonnull public static <T> T[] insert(@Nonnull 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.
-
insert
@Nonnull public static int[] insert(@Nonnull int[] array, int currentSize, int index, int element) Primitive int version ofinsert(Object[], int, int, Object)
. -
insert
@Nonnull public static long[] insert(@Nonnull long[] array, int currentSize, int index, long element) Primitive long version ofinsert(Object[], int, int, Object)
. -
insert
@Nonnull public static boolean[] insert(@Nonnull boolean[] array, int currentSize, int index, boolean element) Primitive boolean version ofinsert(Object[], int, int, Object)
.
-