19 |
|
* best-effort in the presence of concurrent modifications, and do |
20 |
|
* <em>NOT</em> throw {@link ConcurrentModificationException}. An |
21 |
|
* iterator's {@code next()} method returns consecutive elements as |
22 |
< |
* they appear in the underlying array upon each access. |
22 |
> |
* they appear in the underlying array upon each access. Alternatvely, |
23 |
> |
* method {@link #snapshotIterator} may be used for deterministic |
24 |
> |
* traversals, at the expense of making a copy, and unavailability of |
25 |
> |
* method {@code Iterator.remove}. |
26 |
|
* |
27 |
|
* <p>Otherwise, this class supports all methods, under the same |
28 |
|
* documented specifications, as {@code Vector}. Consult {@link |
161 |
|
Object e = items[i]; |
162 |
|
if (lock.getSequence() != seq) |
163 |
|
break; |
164 |
< |
if (x == null? e == null : x.equals(e)) |
164 |
> |
if ((x == null) ? e == null : x.equals(e)) |
165 |
|
return i; |
166 |
|
} |
167 |
|
return -1; |
171 |
|
Object[] items = array; |
172 |
|
for (int i = index; i < fence; ++i) { |
173 |
|
Object e = items[i]; |
174 |
< |
if (x == null? e == null : x.equals(e)) |
174 |
> |
if ((x == null) ? e == null : x.equals(e)) |
175 |
|
return i; |
176 |
|
} |
177 |
|
return -1; |
183 |
|
Object e = items[i]; |
184 |
|
if (lock.getSequence() != seq) |
185 |
|
break; |
186 |
< |
if (x == null? e == null : x.equals(e)) |
186 |
> |
if ((x == null) ? e == null : x.equals(e)) |
187 |
|
return i; |
188 |
|
} |
189 |
|
return -1; |
193 |
|
Object[] items = array; |
194 |
|
for (int i = index; i >= origin; --i) { |
195 |
|
Object e = items[i]; |
196 |
< |
if (x == null? e == null : x.equals(e)) |
196 |
> |
if ((x == null) ? e == null : x.equals(e)) |
197 |
|
return i; |
198 |
|
} |
199 |
|
return -1; |
335 |
|
else { |
336 |
|
contained = true; |
337 |
|
for (Object e : c) { |
338 |
< |
int idx = (locked? |
338 |
> |
int idx = (locked ? |
339 |
|
rawIndexOf(e, origin, fence) : |
340 |
|
validatedIndexOf(e, items, origin, |
341 |
|
fence, seq)); |
667 |
|
for (int i = 0; i < n; ++i) { |
668 |
|
Object e = items[i]; |
669 |
|
if (lock.getSequence() == seq) { |
670 |
< |
if (o == null? e == null : o.equals(e)) |
670 |
> |
if ((o == null) ? e == null : o.equals(e)) |
671 |
|
return i; |
672 |
|
} |
673 |
|
else { |
853 |
|
return added; |
854 |
|
} |
855 |
|
|
856 |
+ |
/** |
857 |
+ |
* Returns an iterator operating over a snapshot copy of the |
858 |
+ |
* elements of this collection created upon construction of the |
859 |
+ |
* iterator. The iterator does <em>NOT</em> support the |
860 |
+ |
* <tt>remove</tt> method. |
861 |
+ |
* |
862 |
+ |
* @return an iterator over the elements in this list in proper sequence |
863 |
+ |
*/ |
864 |
+ |
public Iterator<E> snapshotIterator() { |
865 |
+ |
return new SnapshotIterator<E>(this); |
866 |
+ |
} |
867 |
+ |
|
868 |
+ |
static final class SnapshotIterator<E> implements Iterator<E> { |
869 |
+ |
final Object[] items; |
870 |
+ |
int cursor; |
871 |
+ |
SnapshotIterator(ReadMostlyVector<E> v) { items = v.toArray(); } |
872 |
+ |
public boolean hasNext() { return cursor < items.length; } |
873 |
+ |
public E next() { |
874 |
+ |
if (cursor < items.length) |
875 |
+ |
return (E) items[cursor++]; |
876 |
+ |
throw new NoSuchElementException(); |
877 |
+ |
} |
878 |
+ |
public void remove() { throw new UnsupportedOperationException() ; } |
879 |
+ |
} |
880 |
+ |
|
881 |
|
// Vector-only methods |
882 |
|
|
883 |
|
/** See {@link Vector#firstElement} */ |