857 }
858 }
859
860 @Override
861 @SuppressWarnings("unchecked")
862 public void forEachRemaining(Consumer<? super E> consumer) {
863 Objects.requireNonNull(consumer);
864 final int size = ArrayList.this.size;
865 int i = cursor;
866 if (i >= size) {
867 return;
868 }
869 final Object[] elementData = ArrayList.this.elementData;
870 if (i >= elementData.length) {
871 throw new ConcurrentModificationException();
872 }
873 while (i != size && modCount == expectedModCount) {
874 consumer.accept((E) elementData[i++]);
875 }
876 // update once at end of iteration to reduce heap write traffic
877 lastRet = cursor = i;
878 checkForComodification();
879 }
880
881 final void checkForComodification() {
882 if (modCount != expectedModCount)
883 throw new ConcurrentModificationException();
884 }
885 }
886
887 /**
888 * An optimized version of AbstractList.ListItr
889 */
890 private class ListItr extends Itr implements ListIterator<E> {
891 ListItr(int index) {
892 super();
893 cursor = index;
894 }
895
896 public boolean hasPrevious() {
897 return cursor != 0;
|
857 }
858 }
859
860 @Override
861 @SuppressWarnings("unchecked")
862 public void forEachRemaining(Consumer<? super E> consumer) {
863 Objects.requireNonNull(consumer);
864 final int size = ArrayList.this.size;
865 int i = cursor;
866 if (i >= size) {
867 return;
868 }
869 final Object[] elementData = ArrayList.this.elementData;
870 if (i >= elementData.length) {
871 throw new ConcurrentModificationException();
872 }
873 while (i != size && modCount == expectedModCount) {
874 consumer.accept((E) elementData[i++]);
875 }
876 // update once at end of iteration to reduce heap write traffic
877 cursor = i;
878 lastRet = i - 1;
879 checkForComodification();
880 }
881
882 final void checkForComodification() {
883 if (modCount != expectedModCount)
884 throw new ConcurrentModificationException();
885 }
886 }
887
888 /**
889 * An optimized version of AbstractList.ListItr
890 */
891 private class ListItr extends Itr implements ListIterator<E> {
892 ListItr(int index) {
893 super();
894 cursor = index;
895 }
896
897 public boolean hasPrevious() {
898 return cursor != 0;
|