Lines Matching refs:array

21  * arrays. Common array operations are implemented for efficient use in dynamic containers.
23 * All methods in this class assume that the length of an array is equivalent to its capacity and
24 * NOT the number of elements in the array. The current size of the array is always passed in as a
32 * Appends an element to the end of the array, growing the array if there is no more room.
33 * @param array The array to which to append the element. This must NOT be null.
34 * @param currentSize The number of elements in the array. Must be less than or equal to
35 * array.length.
37 * @return the array to which the element was appended. This may be different than the given
38 * array.
40 public static <T> T[] append(T[] array, int currentSize, T element) {
41 assert currentSize <= array.length;
43 if (currentSize + 1 > array.length) {
46 (Class<T>) array.getClass().getComponentType(), growSize(currentSize));
47 System.arraycopy(array, 0, newArray, 0, currentSize);
48 array = newArray;
50 array[currentSize] = element;
51 return array;
57 public static int[] append(int[] array, int currentSize, int element) {
58 assert currentSize <= array.length;
60 if (currentSize + 1 > array.length) {
62 System.arraycopy(array, 0, newArray, 0, currentSize);
63 array = newArray;
65 array[currentSize] = element;
66 return array;
72 public static long[] append(long[] array, int currentSize, long element) {
73 assert currentSize <= array.length;
75 if (currentSize + 1 > array.length) {
77 System.arraycopy(array, 0, newArray, 0, currentSize);
78 array = newArray;
80 array[currentSize] = element;
81 return array;
87 public static boolean[] append(boolean[] array, int currentSize, boolean element) {
88 assert currentSize <= array.length;
90 if (currentSize + 1 > array.length) {
92 System.arraycopy(array, 0, newArray, 0, currentSize);
93 array = newArray;
95 array[currentSize] = element;
96 return array;
102 public static float[] append(float[] array, int currentSize, float element) {
103 assert currentSize <= array.length;
105 if (currentSize + 1 > array.length) {
107 System.arraycopy(array, 0, newArray, 0, currentSize);
108 array = newArray;
110 array[currentSize] = element;
111 return array;
115 * Inserts an element into the array at the specified index, growing the array if there is no
118 * @param array The array to which to append the element. Must NOT be null.
119 * @param currentSize The number of elements in the array. Must be less than or equal to
120 * array.length.
122 * @return the array to which the element was appended. This may be different than the given
123 * array.
125 public static <T> T[] insert(T[] array, int currentSize, int index, T element) {
126 assert currentSize <= array.length;
128 if (currentSize + 1 <= array.length) {
129 System.arraycopy(array, index, array, index + 1, currentSize - index);
130 array[index] = element;
131 return array;
135 T[] newArray = ArrayUtils.newUnpaddedArray((Class<T>)array.getClass().getComponentType(),
137 System.arraycopy(array, 0, newArray, 0, index);
139 System.arraycopy(array, index, newArray, index + 1, array.length - index);
146 public static int[] insert(int[] array, int currentSize, int index, int element) {
147 assert currentSize <= array.length;
149 if (currentSize + 1 <= array.length) {
150 System.arraycopy(array, index, array, index + 1, currentSize - index);
151 array[index] = element;
152 return array;
156 System.arraycopy(array, 0, newArray, 0, index);
158 System.arraycopy(array, index, newArray, index + 1, array.length - index);
165 public static long[] insert(long[] array, int currentSize, int index, long element) {
166 assert currentSize <= array.length;
168 if (currentSize + 1 <= array.length) {
169 System.arraycopy(array, index, array, index + 1, currentSize - index);
170 array[index] = element;
171 return array;
175 System.arraycopy(array, 0, newArray, 0, index);
177 System.arraycopy(array, index, newArray, index + 1, array.length - index);
184 public static boolean[] insert(boolean[] array, int currentSize, int index, boolean element) {
185 assert currentSize <= array.length;
187 if (currentSize + 1 <= array.length) {
188 System.arraycopy(array, index, array, index + 1, currentSize - index);
189 array[index] = element;
190 return array;
194 System.arraycopy(array, 0, newArray, 0, index);
196 System.arraycopy(array, index, newArray, index + 1, array.length - index);
201 * Given the current size of an array, returns an ideal size to which the array should grow.