pivotIndex = pivotType.calculate(buffer.length); start = pivotIndex; end = start;
pivotIndex = pivotType.calculate(buffer.length); start = pivotIndex; end = start;
pivotIndex = start + pivotType.calculate(size);
/** * Normalizes list by moving the content into ideal position * balanced over pivot. It is called to prevent growth * of the buffer when there is enough empty space. */ protected void normalize() { int newPivotIndex = pivotType.calculate(buffer.length); int newStart = newPivotIndex - pivotType.calculate(size); int newEnd = newStart + size; System.arraycopy(buffer, start, buffer, newStart, size); if (newStart > start) { for (int i = start; i < newStart; i++) { buffer[i] = null; } } else { for (int i = Math.max(start, newEnd); i < end; i++) { buffer[i] = null; } } start = newStart; end = newEnd; pivotIndex = newPivotIndex; }
/** * Removes from this list all of the elements whose index is between * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive. * Shifts any succeeding elements to the left (reduces their index). */ @Override protected void removeRange(int fromIndex, int toIndex) { modCount++; int numMoved = size - toIndex; System.arraycopy(buffer, start + toIndex, buffer, start + fromIndex, numMoved); // clear to let GC do its work int newSize = size - (toIndex - fromIndex); for (int i = start + newSize; i < start + size; i++) { buffer[i] = null; } size = newSize; end = start + size; pivotIndex = start + pivotType.calculate(size); }
/** * Trims the capacity of this <code>ArrayList</code> instance to be the * list's current size. An application can use this operation to minimize * the storage of an <code>ArrayList</code> instance. */ public void trimToSize() { modCount++; if (size < buffer.length) { Object[] newBuffer = new Object[size]; System.arraycopy(buffer, start, newBuffer, 0, size); buffer = newBuffer; start = 0; size = buffer.length; end = size; pivotIndex = pivotType.calculate(size); } }
/** * Constructs a list containing the elements of the specified * collection, in the order they are returned by the collection's * iterator. */ public JoddArrayList(Collection<? extends E> collection) { buffer = collection.toArray(); size = buffer.length; // c.toArray might (incorrectly) not return Object[] (see 6260652) if (buffer.getClass() != Object[].class) { Object[] copy = new Object[size]; System.arraycopy(buffer, 0, copy, 0, size); buffer = copy; } start = 0; end = size; pivotIndex = pivotType.calculate(size); }
/** * Removes all of the elements from this list. The list will * be empty after this call returns. */ @Override public void clear() { modCount++; // clear to let GC do its work for (int i = start; i < end; i++) { buffer[i] = null; } pivotIndex = pivotType.calculate(buffer.length); start = pivotIndex; end = start; size = 0; }
/** * Constructs a list containing the elements of provided array. */ public JoddArrayList(E... array) { buffer = array.clone(); size = buffer.length; start = 0; end = size; pivotIndex = pivotType.calculate(size); }
pivotIndex = start + pivotType.calculate(size);
/** * Normalizes list by moving the content into ideal position * balanced over pivot. It is called to prevent growth * of the buffer when there is enough empty space. */ protected void normalize() { int newPivotIndex = pivotType.calculate(buffer.length); int newStart = newPivotIndex - pivotType.calculate(size); int newEnd = newStart + size; System.arraycopy(buffer, start, buffer, newStart, size); if (newStart > start) { for (int i = start; i < newStart; i++) { buffer[i] = null; } } else { for (int i = Math.max(start, newEnd); i < end; i++) { buffer[i] = null; } } start = newStart; end = newEnd; pivotIndex = newPivotIndex; }
/** * Removes from this list all of the elements whose index is between * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive. * Shifts any succeeding elements to the left (reduces their index). */ @Override protected void removeRange(int fromIndex, int toIndex) { modCount++; int numMoved = size - toIndex; System.arraycopy(buffer, start + toIndex, buffer, start + fromIndex, numMoved); // clear to let GC do its work int newSize = size - (toIndex - fromIndex); for (int i = start + newSize; i < start + size; i++) { buffer[i] = null; } size = newSize; end = start + size; pivotIndex = start + pivotType.calculate(size); }
/** * Constructs a list containing the elements of the specified * collection, in the order they are returned by the collection's * iterator. */ public JoddArrayList(Collection<? extends E> collection) { buffer = collection.toArray(); size = buffer.length; // c.toArray might (incorrectly) not return Object[] (see 6260652) if (buffer.getClass() != Object[].class) { Object[] copy = new Object[size]; System.arraycopy(buffer, 0, copy, 0, size); buffer = copy; } start = 0; end = size; pivotIndex = pivotType.calculate(size); }
/** * Removes all of the elements from this list. The list will * be empty after this call returns. */ @Override public void clear() { modCount++; // clear to let GC do its work for (int i = start; i < end; i++) { buffer[i] = null; } pivotIndex = pivotType.calculate(buffer.length); start = pivotIndex; end = start; size = 0; }
/** * Trims the capacity of this <code>ArrayList</code> instance to be the * list's current size. An application can use this operation to minimize * the storage of an <code>ArrayList</code> instance. */ public void trimToSize() { modCount++; if (size < buffer.length) { Object[] newBuffer = new Object[size]; System.arraycopy(buffer, start, newBuffer, 0, size); buffer = newBuffer; start = 0; size = buffer.length; end = size; pivotIndex = pivotType.calculate(size); } }
/** * Constructs a list containing the elements of provided array. */ public JoddArrayList(E... array) { buffer = array.clone(); size = buffer.length; start = 0; end = size; pivotIndex = pivotType.calculate(size); }