592 int numMoved = size - index;
593 if (numMoved > 0)
594 System.arraycopy(elementData, index, elementData, index + numNew,
595 numMoved);
596
597 System.arraycopy(a, 0, elementData, index, numNew);
598 size += numNew;
599 return numNew != 0;
600 }
601
602 /**
603 * Removes from this list all of the elements whose index is between
604 * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
605 * Shifts any succeeding elements to the left (reduces their index).
606 * This call shortens the list by {@code (toIndex - fromIndex)} elements.
607 * (If {@code toIndex==fromIndex}, this operation has no effect.)
608 *
609 * @throws IndexOutOfBoundsException if {@code fromIndex} or
610 * {@code toIndex} is out of range
611 * ({@code fromIndex < 0 ||
612 * fromIndex >= size() ||
613 * toIndex > size() ||
614 * toIndex < fromIndex})
615 */
616 protected void removeRange(int fromIndex, int toIndex) {
617 modCount++;
618 int numMoved = size - toIndex;
619 System.arraycopy(elementData, toIndex, elementData, fromIndex,
620 numMoved);
621
622 // clear to let GC do its work
623 int newSize = size - (toIndex-fromIndex);
624 for (int i = newSize; i < size; i++) {
625 elementData[i] = null;
626 }
627 size = newSize;
628 }
629
630 /**
631 * Checks if the given index is in range. If not, throws an appropriate
632 * runtime exception. This method does *not* check if the index is
633 * negative: It is always used immediately prior to an array access,
634 * which throws an ArrayIndexOutOfBoundsException if index is negative.
635 */
636 private void rangeCheck(int index) {
637 if (index >= size)
|
592 int numMoved = size - index;
593 if (numMoved > 0)
594 System.arraycopy(elementData, index, elementData, index + numNew,
595 numMoved);
596
597 System.arraycopy(a, 0, elementData, index, numNew);
598 size += numNew;
599 return numNew != 0;
600 }
601
602 /**
603 * Removes from this list all of the elements whose index is between
604 * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
605 * Shifts any succeeding elements to the left (reduces their index).
606 * This call shortens the list by {@code (toIndex - fromIndex)} elements.
607 * (If {@code toIndex==fromIndex}, this operation has no effect.)
608 *
609 * @throws IndexOutOfBoundsException if {@code fromIndex} or
610 * {@code toIndex} is out of range
611 * ({@code fromIndex < 0 ||
612 * toIndex > size() ||
613 * toIndex < fromIndex})
614 */
615 protected void removeRange(int fromIndex, int toIndex) {
616 modCount++;
617 if (fromIndex > toIndex)
618 throw new IndexOutOfBoundsException(
619 "From Index: " + fromIndex + " > To Index: " + toIndex);
620 int numMoved = size - toIndex;
621 System.arraycopy(elementData, toIndex, elementData, fromIndex,
622 numMoved);
623
624 // clear to let GC do its work
625 int newSize = size - (toIndex-fromIndex);
626 for (int i = newSize; i < size; i++) {
627 elementData[i] = null;
628 }
629 size = newSize;
630 }
631
632 /**
633 * Checks if the given index is in range. If not, throws an appropriate
634 * runtime exception. This method does *not* check if the index is
635 * negative: It is always used immediately prior to an array access,
636 * which throws an ArrayIndexOutOfBoundsException if index is negative.
637 */
638 private void rangeCheck(int index) {
639 if (index >= size)
|