Created
July 11, 2013 06:36
-
-
Save lichenbo/5973032 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private class ListItr extends Itr implements ListIterator<E> { | |
| ListItr(int index) { | |
| super(); | |
| cursor = index; | |
| } | |
| public boolean hasPrevious() { | |
| return cursor != 0; | |
| } | |
| public int nextIndex() { | |
| return cursor; | |
| } | |
| public int previousIndex() { | |
| return cursor - 1; | |
| } | |
| @SuppressWarnings("unchecked") | |
| public E previous() { | |
| checkForComodification(); | |
| int i = cursor - 1; | |
| if (i < 0) | |
| throw new NoSuchElementException(); | |
| Object[] elementData = ArrayList.this.elementData; | |
| if (i >= elementData.length) | |
| throw new ConcurrentModificationException(); | |
| cursor = i; | |
| return (E) elementData[lastRet = i]; | |
| } | |
| public void set(E e) { | |
| if (lastRet < 0) | |
| throw new IllegalStateException(); | |
| checkForComodification(); | |
| try { | |
| ArrayList.this.set(lastRet, e); | |
| } catch (IndexOutOfBoundsException ex) { | |
| throw new ConcurrentModificationException(); | |
| } | |
| } | |
| public void add(E e) { | |
| checkForComodification(); | |
| try { | |
| int i = cursor; | |
| ArrayList.this.add(i, e); | |
| cursor = i + 1; | |
| lastRet = -1; | |
| expectedModCount = modCount; | |
| } catch (IndexOutOfBoundsException ex) { | |
| throw new ConcurrentModificationException(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment