859
860 /**
861 * Returns an iterator over the elements in this list in proper sequence.
862 *
863 * <p>The returned iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
864 *
865 * @return an iterator over the elements in this list in proper sequence
866 */
867 public Iterator<E> iterator() {
868 return new Itr();
869 }
870
871 /**
872 * An optimized version of AbstractList.Itr
873 */
874 private class Itr implements Iterator<E> {
875 int cursor; // index of next element to return
876 int lastRet = -1; // index of last element returned; -1 if no such
877 int expectedModCount = modCount;
878
879 Itr() {}
880
881 public boolean hasNext() {
882 return cursor != size;
883 }
884
885 @SuppressWarnings("unchecked")
886 public E next() {
887 checkForComodification();
888 int i = cursor;
889 if (i >= size)
890 throw new NoSuchElementException();
891 Object[] elementData = ArrayList.this.elementData;
892 if (i >= elementData.length)
893 throw new ConcurrentModificationException();
894 cursor = i + 1;
895 return (E) elementData[lastRet = i];
896 }
897
898 public void remove() {
|
859
860 /**
861 * Returns an iterator over the elements in this list in proper sequence.
862 *
863 * <p>The returned iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
864 *
865 * @return an iterator over the elements in this list in proper sequence
866 */
867 public Iterator<E> iterator() {
868 return new Itr();
869 }
870
871 /**
872 * An optimized version of AbstractList.Itr
873 */
874 private class Itr implements Iterator<E> {
875 int cursor; // index of next element to return
876 int lastRet = -1; // index of last element returned; -1 if no such
877 int expectedModCount = modCount;
878
879 // prevent generation of synthetic class required for access to private
880 // constructor
881 Itr() {}
882
883 public boolean hasNext() {
884 return cursor != size;
885 }
886
887 @SuppressWarnings("unchecked")
888 public E next() {
889 checkForComodification();
890 int i = cursor;
891 if (i >= size)
892 throw new NoSuchElementException();
893 Object[] elementData = ArrayList.this.elementData;
894 if (i >= elementData.length)
895 throw new ConcurrentModificationException();
896 cursor = i + 1;
897 return (E) elementData[lastRet = i];
898 }
899
900 public void remove() {
|