1 | protected class EIterator<E1> implements Iterator<E1>↵ | | 1 | protected class EIterator<E1> implements Iterator<E1>↵
|
2 | {↵ | | 2 | {↵
|
3 | /**↵ | | 3 | /**↵
|
4 | * The current position of the iterator.↵ | | 4 | * The current position of the iterator.↵
|
5 | */↵ | | 5 | */↵
|
6 | protected int cursor = 0;↵ | | 6 | protected int cursor = 0;↵
|
|
7 | /**↵ | | 7 | /**↵
|
8 | * The previous position of the iterator.↵ | | 8 | * The previous position of the iterator.↵
|
9 | */↵ | | 9 | */↵
|
10 | protected int lastCursor = -1;↵ | | 10 | protected int lastCursor = -1;↵
|
|
11 | /**↵ | | 11 | /**↵
|
12 | * The modification count of the containing list.↵ | | 12 | * The modification count of the containing list.↵
|
13 | */↵ | | 13 | */↵
|
14 | protected int expectedModCount = modCount;↵ | | 14 | protected int expectedModCount = modCount;↵
|
|
15 | /**↵ | | 15 | /**↵
|
16 | * Returns whether there are more objects.↵ | | 16 | * Returns whether there are more objects.↵
|
17 | * @return whether there are more objects.↵ | | 17 | * @return whether there are more objects.↵
|
18 | */↵ | | 18 | */↵
|
19 | public boolean hasNext() ↵ | | 19 | public boolean hasNext() ↵
|
20 | {↵ | | 20 | {↵
|
21 | return cursor != size();↵ | | 21 | return cursor != size();↵
|
22 | }↵ | | 22 | }↵
|
|
23 | /**↵ | | 23 | /**↵
|
24 | * Returns the next object and advances the iterator.↵ | | 24 | * Returns the next object and advances the iterator.↵
|
25 | * This implementation delegates to {@link #doNext doNext}.↵ | | 25 | * This implementation delegates to {@link #doNext doNext}.↵
|
26 | * @return the next object.↵ | | 26 | * @return the next object.↵
|
27 | * @exception NoSuchElementException if the iterator is done.↵ | | 27 | * @exception NoSuchElementException if the iterator is done.↵
|
28 | */↵ | | 28 | */↵
|
29 | @SuppressWarnings("unchecked")↵ | | 29 | @SuppressWarnings("unchecked")↵
|
30 | public E1 next() ↵ | | 30 | public E1 next() ↵
|
31 | {↵ | | 31 | {↵
|
32 | return (E1)doNext();↵ | | 32 | return (E1)doNext();↵
|
33 | }↵ | | 33 | }↵
|
|
34 | /**↵ | | 34 | /**↵
|
35 | * Returns the next object and advances the iterator.↵ | | 35 | * Returns the next object and advances the iterator.↵
|
36 | * This implementation delegates to {@link BasicEList#get get}.↵ | | 36 | * This implementation delegates to {@link DelegatingEList#get get}.↵
|
37 | * @return the next object.↵ | | 37 | * @return the next object.↵
|
38 | * @exception NoSuchElementException if the iterator is done.↵ | | 38 | * @exception NoSuchElementException if the iterator is done.↵
|
39 | */↵ | | 39 | */↵
|
40 | protected E doNext() ↵ | | 40 | protected E doNext() ↵
|
41 | {↵ | | 41 | {↵
|
42 | try ↵ | | 42 | try ↵
|
43 | {↵ | | 43 | {↵
|
44 | E next = BasicEList.this.get(cursor);↵ | | 44 | E next = DelegatingEList.this.get(cursor);↵
|
45 | checkModCount();↵ | | 45 | checkModCount();↵
|
46 | lastCursor = cursor++;↵ | | 46 | lastCursor = cursor++;↵
|
47 | return next;↵ | | 47 | return next;↵
|
48 | } ↵ | | 48 | } ↵
|
49 | catch (IndexOutOfBoundsException exception) ↵ | | 49 | catch (IndexOutOfBoundsException exception) ↵
|
50 | {↵ | | 50 | {↵
|
51 | checkModCount();↵ | | 51 | checkModCount();↵
|
52 | throw new NoSuchElementException();↵ | | 52 | throw new NoSuchElementException();↵
|
53 | }↵ | | 53 | }↵
|
54 | }↵ | | 54 | }↵
|
|
55 | /**↵ | | 55 | /**↵
|
56 | * Removes the last object returned by {@link #next()} from the list,↵ | | 56 | * Removes the last object returned by {@link #next()} from the list,↵
|
57 | * it's an optional operation.↵ | | 57 | * it's an optional operation.↵
|
58 | * This implementation can also function in a list iterator ↵ | | 58 | * This implementation can also function in a list iterator ↵
|
59 | * to act upon on the object returned by calling <code>previous</code>.↵ | | 59 | * to act upon on the object returned by calling <code>previous</code>.↵
|
60 | * @exception IllegalStateException↵ | | 60 | * @exception IllegalStateException↵
|
61 | * if <code>next</code> has not yet been called,↵ | | 61 | * if <code>next</code> has not yet been called,↵
|
62 | * or <code>remove</code> has already been called after the last call to <code>next</code>.↵ | | 62 | * or <code>remove</code> has already been called after the last call to <code>next</code>.↵
|
63 | */↵ | | 63 | */↵
|
64 | public void remove() ↵ | | 64 | public void remove() ↵
|
65 | {↵ | | 65 | {↵
|
66 | if (lastCursor == -1)↵ | | 66 | if (lastCursor == -1)↵
|
67 | {↵ | | 67 | {↵
|
68 | throw new IllegalStateException();↵ | | 68 | throw new IllegalStateException();↵
|
69 | }↵ | | 69 | }↵
|
70 | checkModCount();↵ | | 70 | checkModCount();↵
|
|
71 | try ↵ | | 71 | try ↵
|
72 | {↵ | | 72 | {↵
|
73 | BasicEList.this.remove(lastCursor);↵ | | 73 | DelegatingEList.this.remove(lastCursor);↵
|
74 | expectedModCount = modCount;↵ | | 74 | expectedModCount = modCount;↵
|
75 | if (lastCursor < cursor)↵ | | 75 | if (lastCursor < cursor)↵
|
76 | {↵ | | 76 | {↵
|
77 | --cursor;↵ | | 77 | --cursor;↵
|
78 | }↵ | | 78 | }↵
|
79 | lastCursor = -1;↵ | | 79 | lastCursor = -1;↵
|
80 | } ↵ | | 80 | } ↵
|
81 | catch (IndexOutOfBoundsException exception) ↵ | | 81 | catch (IndexOutOfBoundsException exception) ↵
|
82 | {↵ | | 82 | {↵
|
83 | throw new ConcurrentModificationException();↵ | | 83 | throw new ConcurrentModificationException();↵
|
84 | }↵ | | 84 | }↵
|
85 | }↵ | | 85 | }↵
|
|
86 | /**↵ | | 86 | /**↵
|
87 | * Checks that the modification count is as expected.↵ | | 87 | * Checks that the modification count is as expected.↵
|
88 | * @exception ConcurrentModificationException if the modification count is not as expected.↵ | | 88 | * @exception ConcurrentModificationException if the modification count is not as expected.↵
|
89 | */↵ | | 89 | */↵
|
90 | protected void checkModCount() ↵ | | 90 | protected void checkModCount() ↵
|
91 | {↵ | | 91 | {↵
|
92 | if (modCount != expectedModCount)↵ | | 92 | if (modCount != expectedModCount)↵
|
93 | {↵ | | 93 | {↵
|
94 | throw new ConcurrentModificationException();↵ | | 94 | throw new ConcurrentModificationException();↵
|
95 | }↵ | | 95 | }↵
|
96 | }↵ | | 96 | }↵
|
97 | }↵ | | 97 | }↵
|
|
98 | /**↵ | | 98 | /**↵
|
99 | * Returns a read-only iterator that does not {@link #resolve resolve} objects.↵ | | 99 | * Returns a read-only iterator that does not {@link #resolve resolve} objects.↵
|
100 | * This implementation allocates a {@link NonResolvingEIterator}.↵ | | 100 | * This implementation allocates a {@link NonResolvingEIterator}.↵
|
101 | * @return a read-only iterator that does not resolve objects.↵ | | 101 | * @return a read-only iterator that does not resolve objects.↵
|
102 | */↵ | | 102 | */↵
|
103 | protected Iterator<E> basicIterator()↵ | | 103 | protected Iterator<E> basicIterator()↵
|
104 | {↵ | | 104 | {↵
|
105 | return new NonResolvingEIterator<E>(); | | 105 | return new NonResolvingEIterator<E>();
|