/** * Ensures that an array can contain the given number of entries, preserving * just a part of the array. * * @param array * an array. * @param length * the new minimum length for this array. * @param preserve * the number of elements of the array that must be preserved in case * a new allocation is necessary. * @return {@code array}, if it can contain {@code length} entries or more; * otherwise, an array with {@code length} entries whose first * {@code preserve} entries are the same as those of {@code array}. */ public static <K> K[] ensureCapacity(final K[] array, final int length, final int preserve) { return length > array.length ? forceCapacity(array, length, preserve) : array; } /**
@Override public void size(final int size) { if (size > a.length) a = ObjectArrays.forceCapacity(a, size, this.size); if (size > this.size) Arrays.fill(a, this.size, size, (null)); else Arrays.fill(a, size, this.size, (null)); this.size = size; } @Override
@Override public void size(final int size) { if (size > a.length) a = ObjectArrays.forceCapacity(a, size, this.size); if (size > this.size) Arrays.fill(a, this.size, size, (null)); else Arrays.fill(a, size, this.size, (null)); this.size = size; } @Override
/** * Grows this array list, ensuring that it can contain the given number of * entries without resizing, and in case increasing the current capacity at * least by a factor of 50%. * * @param capacity * the new minimum capacity for this array list. */ @SuppressWarnings("unchecked") private void grow(int capacity) { if (capacity <= a.length) return; if (a != ObjectArrays.DEFAULT_EMPTY_ARRAY) capacity = (int) Math.max( Math.min((long) a.length + (a.length >> 1), it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE), capacity); else if (capacity < DEFAULT_INITIAL_CAPACITY) capacity = DEFAULT_INITIAL_CAPACITY; if (wrapped) a = ObjectArrays.forceCapacity(a, capacity, size); else { final Object t[] = new Object[capacity]; System.arraycopy(a, 0, t, 0, size); a = (K[]) t; } assert size <= a.length; } @Override
/** * Grows this array list, ensuring that it can contain the given number of * entries without resizing, and in case increasing the current capacity at * least by a factor of 50%. * * @param capacity * the new minimum capacity for this array list. */ @SuppressWarnings("unchecked") private void grow(int capacity) { if (capacity <= a.length) return; if (a != ObjectArrays.DEFAULT_EMPTY_ARRAY) capacity = (int) Math.max( Math.min((long) a.length + (a.length >> 1), it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE), capacity); else if (capacity < DEFAULT_INITIAL_CAPACITY) capacity = DEFAULT_INITIAL_CAPACITY; if (wrapped) a = ObjectArrays.forceCapacity(a, capacity, size); else { final Object t[] = new Object[capacity]; System.arraycopy(a, 0, t, 0, size); a = (K[]) t; } assert size <= a.length; } @Override