1 |
|
/* |
2 |
|
* %W% %E% |
3 |
|
* |
4 |
< |
* Copyright 2005 Sun Microsystems, Inc. All rights reserved. |
4 |
> |
* Copyright 2006 Sun Microsystems, Inc. All rights reserved. |
5 |
|
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. |
6 |
|
*/ |
7 |
|
|
8 |
|
package java.util; |
9 |
– |
import java.util.*; // for javadoc (till 6280605 is fixed) |
9 |
|
|
10 |
|
/** |
11 |
< |
* The <code>Vector</code> class implements a growable array of |
11 |
> |
* The {@code Vector} class implements a growable array of |
12 |
|
* objects. Like an array, it contains components that can be |
13 |
|
* accessed using an integer index. However, the size of a |
14 |
< |
* <code>Vector</code> can grow or shrink as needed to accommodate |
15 |
< |
* adding and removing items after the <code>Vector</code> has been created.<p> |
14 |
> |
* {@code Vector} can grow or shrink as needed to accommodate |
15 |
> |
* adding and removing items after the {@code Vector} has been created. |
16 |
|
* |
17 |
< |
* Each vector tries to optimize storage management by maintaining a |
18 |
< |
* <code>capacity</code> and a <code>capacityIncrement</code>. The |
19 |
< |
* <code>capacity</code> is always at least as large as the vector |
17 |
> |
* <p>Each vector tries to optimize storage management by maintaining a |
18 |
> |
* {@code capacity} and a {@code capacityIncrement}. The |
19 |
> |
* {@code capacity} is always at least as large as the vector |
20 |
|
* size; it is usually larger because as components are added to the |
21 |
|
* vector, the vector's storage increases in chunks the size of |
22 |
< |
* <code>capacityIncrement</code>. An application can increase the |
22 |
> |
* {@code capacityIncrement}. An application can increase the |
23 |
|
* capacity of a vector before inserting a large number of |
24 |
< |
* components; this reduces the amount of incremental reallocation. <p> |
24 |
> |
* components; this reduces the amount of incremental reallocation. |
25 |
|
* |
26 |
< |
* As of the Java 2 platform v1.2, this class has been retrofitted to |
28 |
< |
* implement List, so that it becomes a part of Java's collection framework. |
29 |
< |
* Unlike the new collection implementations, Vector is synchronized.<p> |
30 |
< |
* |
31 |
< |
* The Iterators returned by Vector's iterator and listIterator |
26 |
> |
* <p>The Iterators returned by Vector's iterator and listIterator |
27 |
|
* methods are <em>fail-fast</em>: if the Vector is structurally modified |
28 |
|
* at any time after the Iterator is created, in any way except through the |
29 |
|
* Iterator's own remove or add methods, the Iterator will throw a |
36 |
|
* <p>Note that the fail-fast behavior of an iterator cannot be guaranteed |
37 |
|
* as it is, generally speaking, impossible to make any hard guarantees in the |
38 |
|
* presence of unsynchronized concurrent modification. Fail-fast iterators |
39 |
< |
* throw <tt>ConcurrentModificationException</tt> on a best-effort basis. |
39 |
> |
* throw {@code ConcurrentModificationException} on a best-effort basis. |
40 |
|
* Therefore, it would be wrong to write a program that depended on this |
41 |
|
* exception for its correctness: <i>the fail-fast behavior of iterators |
42 |
< |
* should be used only to detect bugs.</i><p> |
42 |
> |
* should be used only to detect bugs.</i> |
43 |
|
* |
44 |
< |
* This class is a member of the |
45 |
< |
* <a href="{@docRoot}/../guide/collections/index.html"> |
46 |
< |
* Java Collections Framework</a>. |
44 |
> |
* <p>As of the Java 2 platform v1.2, this class was retrofitted to |
45 |
> |
* implement the {@link List} interface, making it a member of the |
46 |
> |
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> Java |
47 |
> |
* Collections Framework</a>. Unlike the new collection |
48 |
> |
* implementations, {@code Vector} is synchronized. |
49 |
|
* |
50 |
|
* @author Lee Boynton |
51 |
|
* @author Jonathan Payne |
72 |
|
protected Object[] elementData; |
73 |
|
|
74 |
|
/** |
75 |
< |
* The number of valid components in this <tt>Vector</tt> object. |
76 |
< |
* Components <tt>elementData[0]</tt> through |
77 |
< |
* <tt>elementData[elementCount-1]</tt> are the actual items. |
75 |
> |
* The number of valid components in this {@code Vector} object. |
76 |
> |
* Components {@code elementData[0]} through |
77 |
> |
* {@code elementData[elementCount-1]} are the actual items. |
78 |
|
* |
79 |
|
* @serial |
80 |
|
*/ |
126 |
|
|
127 |
|
/** |
128 |
|
* Constructs an empty vector so that its internal data array |
129 |
< |
* has size <tt>10</tt> and its standard capacity increment is |
129 |
> |
* has size {@code 10} and its standard capacity increment is |
130 |
|
* zero. |
131 |
|
*/ |
132 |
|
public Vector() { |
144 |
|
* @since 1.2 |
145 |
|
*/ |
146 |
|
public Vector(Collection<? extends E> c) { |
147 |
< |
Object[] a = c.toArray(); |
148 |
< |
elementCount = a.length; |
149 |
< |
// If c.toArray incorrectly doesn't return Object[], copy it. |
150 |
< |
if (a.getClass() == Object[].class) |
151 |
< |
elementData = a; |
155 |
< |
else |
156 |
< |
elementData = Arrays.copyOf(a, a.length, Object[].class); |
147 |
> |
elementData = c.toArray(); |
148 |
> |
elementCount = elementData.length; |
149 |
> |
// c.toArray might (incorrectly) not return Object[] (see 6260652) |
150 |
> |
if (elementData.getClass() != Object[].class) |
151 |
> |
elementData = Arrays.copyOf(elementData, elementCount, Object[].class); |
152 |
|
} |
153 |
|
|
154 |
|
/** |
155 |
|
* Copies the components of this vector into the specified array. |
156 |
< |
* The item at index <tt>k</tt> in this vector is copied into |
157 |
< |
* component <tt>k</tt> of <tt>anArray</tt>. |
156 |
> |
* The item at index {@code k} in this vector is copied into |
157 |
> |
* component {@code k} of {@code anArray}. |
158 |
|
* |
159 |
|
* @param anArray the array into which the components get copied |
160 |
|
* @throws NullPointerException if the given array is null |
172 |
|
* Trims the capacity of this vector to be the vector's current |
173 |
|
* size. If the capacity of this vector is larger than its current |
174 |
|
* size, then the capacity is changed to equal the size by replacing |
175 |
< |
* its internal data array, kept in the field <tt>elementData</tt>, |
175 |
> |
* its internal data array, kept in the field {@code elementData}, |
176 |
|
* with a smaller one. An application can use this operation to |
177 |
|
* minimize the storage of a vector. |
178 |
|
*/ |
190 |
|
* the minimum capacity argument. |
191 |
|
* |
192 |
|
* <p>If the current capacity of this vector is less than |
193 |
< |
* <tt>minCapacity</tt>, then its capacity is increased by replacing its |
194 |
< |
* internal data array, kept in the field <tt>elementData</tt>, with a |
193 |
> |
* {@code minCapacity}, then its capacity is increased by replacing its |
194 |
> |
* internal data array, kept in the field {@code elementData}, with a |
195 |
|
* larger one. The size of the new data array will be the old size plus |
196 |
< |
* <tt>capacityIncrement</tt>, unless the value of |
197 |
< |
* <tt>capacityIncrement</tt> is less than or equal to zero, in which case |
196 |
> |
* {@code capacityIncrement}, unless the value of |
197 |
> |
* {@code capacityIncrement} is less than or equal to zero, in which case |
198 |
|
* the new capacity will be twice the old capacity; but if this new size |
199 |
< |
* is still smaller than <tt>minCapacity</tt>, then the new capacity will |
200 |
< |
* be <tt>minCapacity</tt>. |
199 |
> |
* is still smaller than {@code minCapacity}, then the new capacity will |
200 |
> |
* be {@code minCapacity}. |
201 |
|
* |
202 |
|
* @param minCapacity the desired minimum capacity |
203 |
|
*/ |
229 |
|
|
230 |
|
/** |
231 |
|
* Sets the size of this vector. If the new size is greater than the |
232 |
< |
* current size, new <code>null</code> items are added to the end of |
232 |
> |
* current size, new {@code null} items are added to the end of |
233 |
|
* the vector. If the new size is less than the current size, all |
234 |
< |
* components at index <code>newSize</code> and greater are discarded. |
234 |
> |
* components at index {@code newSize} and greater are discarded. |
235 |
|
* |
236 |
|
* @param newSize the new size of this vector |
237 |
|
* @throws ArrayIndexOutOfBoundsException if new size is negative |
252 |
|
* Returns the current capacity of this vector. |
253 |
|
* |
254 |
|
* @return the current capacity (the length of its internal |
255 |
< |
* data array, kept in the field <tt>elementData</tt> |
255 |
> |
* data array, kept in the field {@code elementData} |
256 |
|
* of this vector) |
257 |
|
*/ |
258 |
|
public synchronized int capacity() { |
271 |
|
/** |
272 |
|
* Tests if this vector has no components. |
273 |
|
* |
274 |
< |
* @return <code>true</code> if and only if this vector has |
274 |
> |
* @return {@code true} if and only if this vector has |
275 |
|
* no components, that is, its size is zero; |
276 |
< |
* <code>false</code> otherwise. |
276 |
> |
* {@code false} otherwise. |
277 |
|
*/ |
278 |
|
public synchronized boolean isEmpty() { |
279 |
|
return elementCount == 0; |
281 |
|
|
282 |
|
/** |
283 |
|
* Returns an enumeration of the components of this vector. The |
284 |
< |
* returned <tt>Enumeration</tt> object will generate all items in |
285 |
< |
* this vector. The first item generated is the item at index <tt>0</tt>, |
286 |
< |
* then the item at index <tt>1</tt>, and so on. |
284 |
> |
* returned {@code Enumeration} object will generate all items in |
285 |
> |
* this vector. The first item generated is the item at index {@code 0}, |
286 |
> |
* then the item at index {@code 1}, and so on. |
287 |
|
* |
288 |
|
* @return an enumeration of the components of this vector |
289 |
|
* @see Enumeration |
309 |
|
} |
310 |
|
|
311 |
|
/** |
312 |
< |
* Returns <tt>true</tt> if this vector contains the specified element. |
313 |
< |
* More formally, returns <tt>true</tt> if and only if this vector |
314 |
< |
* contains at least one element <tt>e</tt> such that |
312 |
> |
* Returns {@code true} if this vector contains the specified element. |
313 |
> |
* More formally, returns {@code true} if and only if this vector |
314 |
> |
* contains at least one element {@code e} such that |
315 |
|
* <tt>(o==null ? e==null : o.equals(e))</tt>. |
316 |
|
* |
317 |
|
* @param o element whose presence in this vector is to be tested |
318 |
< |
* @return <tt>true</tt> if this vector contains the specified element |
318 |
> |
* @return {@code true} if this vector contains the specified element |
319 |
|
*/ |
320 |
|
public boolean contains(Object o) { |
321 |
|
return indexOf(o, 0) >= 0; |
324 |
|
/** |
325 |
|
* Returns the index of the first occurrence of the specified element |
326 |
|
* in this vector, or -1 if this vector does not contain the element. |
327 |
< |
* More formally, returns the lowest index <tt>i</tt> such that |
327 |
> |
* More formally, returns the lowest index {@code i} such that |
328 |
|
* <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>, |
329 |
|
* or -1 if there is no such index. |
330 |
|
* |
338 |
|
|
339 |
|
/** |
340 |
|
* Returns the index of the first occurrence of the specified element in |
341 |
< |
* this vector, searching forwards from <tt>index</tt>, or returns -1 if |
341 |
> |
* this vector, searching forwards from {@code index}, or returns -1 if |
342 |
|
* the element is not found. |
343 |
< |
* More formally, returns the lowest index <tt>i</tt> such that |
343 |
> |
* More formally, returns the lowest index {@code i} such that |
344 |
|
* <tt>(i >= index && (o==null ? get(i)==null : o.equals(get(i))))</tt>, |
345 |
|
* or -1 if there is no such index. |
346 |
|
* |
347 |
|
* @param o element to search for |
348 |
|
* @param index index to start searching from |
349 |
|
* @return the index of the first occurrence of the element in |
350 |
< |
* this vector at position <tt>index</tt> or later in the vector; |
351 |
< |
* <tt>-1</tt> if the element is not found. |
350 |
> |
* this vector at position {@code index} or later in the vector; |
351 |
> |
* {@code -1} if the element is not found. |
352 |
|
* @throws IndexOutOfBoundsException if the specified index is negative |
353 |
|
* @see Object#equals(Object) |
354 |
|
*/ |
368 |
|
/** |
369 |
|
* Returns the index of the last occurrence of the specified element |
370 |
|
* in this vector, or -1 if this vector does not contain the element. |
371 |
< |
* More formally, returns the highest index <tt>i</tt> such that |
371 |
> |
* More formally, returns the highest index {@code i} such that |
372 |
|
* <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>, |
373 |
|
* or -1 if there is no such index. |
374 |
|
* |
382 |
|
|
383 |
|
/** |
384 |
|
* Returns the index of the last occurrence of the specified element in |
385 |
< |
* this vector, searching backwards from <tt>index</tt>, or returns -1 if |
385 |
> |
* this vector, searching backwards from {@code index}, or returns -1 if |
386 |
|
* the element is not found. |
387 |
< |
* More formally, returns the highest index <tt>i</tt> such that |
387 |
> |
* More formally, returns the highest index {@code i} such that |
388 |
|
* <tt>(i <= index && (o==null ? get(i)==null : o.equals(get(i))))</tt>, |
389 |
|
* or -1 if there is no such index. |
390 |
|
* |
391 |
|
* @param o element to search for |
392 |
|
* @param index index to start searching backwards from |
393 |
|
* @return the index of the last occurrence of the element at position |
394 |
< |
* less than or equal to <tt>index</tt> in this vector; |
394 |
> |
* less than or equal to {@code index} in this vector; |
395 |
|
* -1 if the element is not found. |
396 |
|
* @throws IndexOutOfBoundsException if the specified index is greater |
397 |
|
* than or equal to the current size of this vector |
420 |
|
* |
421 |
|
* @param index an index into this vector |
422 |
|
* @return the component at the specified index |
423 |
< |
* @exception ArrayIndexOutOfBoundsException if the <tt>index</tt> |
423 |
> |
* @exception ArrayIndexOutOfBoundsException if the {@code index} |
424 |
|
* is negative or not less than the current size of this |
425 |
< |
* <tt>Vector</tt> object. |
425 |
> |
* {@code Vector} object. |
426 |
|
* @see #get(int) |
427 |
|
* @see List |
428 |
|
*/ |
435 |
|
} |
436 |
|
|
437 |
|
/** |
438 |
< |
* Returns the first component (the item at index <tt>0</tt>) of |
438 |
> |
* Returns the first component (the item at index {@code 0}) of |
439 |
|
* this vector. |
440 |
|
* |
441 |
|
* @return the first component of this vector |
463 |
|
} |
464 |
|
|
465 |
|
/** |
466 |
< |
* Sets the component at the specified <code>index</code> of this |
466 |
> |
* Sets the component at the specified {@code index} of this |
467 |
|
* vector to be the specified object. The previous component at that |
468 |
|
* position is discarded.<p> |
469 |
|
* |
470 |
< |
* The index must be a value greater than or equal to <code>0</code> |
470 |
> |
* The index must be a value greater than or equal to {@code 0} |
471 |
|
* and less than the current size of the vector. <p> |
472 |
|
* |
473 |
|
* This method is identical in functionality to the set method |
494 |
|
/** |
495 |
|
* Deletes the component at the specified index. Each component in |
496 |
|
* this vector with an index greater or equal to the specified |
497 |
< |
* <code>index</code> is shifted downward to have an index one |
497 |
> |
* {@code index} is shifted downward to have an index one |
498 |
|
* smaller than the value it had previously. The size of this vector |
499 |
< |
* is decreased by <tt>1</tt>.<p> |
499 |
> |
* is decreased by {@code 1}.<p> |
500 |
|
* |
501 |
< |
* The index must be a value greater than or equal to <code>0</code> |
501 |
> |
* The index must be a value greater than or equal to {@code 0} |
502 |
|
* and less than the current size of the vector. <p> |
503 |
|
* |
504 |
|
* This method is identical in functionality to the remove method |
530 |
|
|
531 |
|
/** |
532 |
|
* Inserts the specified object as a component in this vector at the |
533 |
< |
* specified <code>index</code>. Each component in this vector with |
534 |
< |
* an index greater or equal to the specified <code>index</code> is |
533 |
> |
* specified {@code index}. Each component in this vector with |
534 |
> |
* an index greater or equal to the specified {@code index} is |
535 |
|
* shifted upward to have an index one greater than the value it had |
536 |
|
* previously. <p> |
537 |
|
* |
538 |
< |
* The index must be a value greater than or equal to <code>0</code> |
538 |
> |
* The index must be a value greater than or equal to {@code 0} |
539 |
|
* and less than or equal to the current size of the vector. (If the |
540 |
|
* index is equal to the current size of the vector, the new element |
541 |
|
* is appended to the Vector.)<p> |
592 |
|
* method (which is part of the List interface). |
593 |
|
* |
594 |
|
* @param obj the component to be removed |
595 |
< |
* @return <code>true</code> if the argument was a component of this |
596 |
< |
* vector; <code>false</code> otherwise. |
595 |
> |
* @return {@code true} if the argument was a component of this |
596 |
> |
* vector; {@code false} otherwise. |
597 |
|
* @see List#remove(Object) |
598 |
|
* @see List |
599 |
|
*/ |
628 |
|
/** |
629 |
|
* Returns a clone of this vector. The copy will contain a |
630 |
|
* reference to a clone of the internal data array, not a reference |
631 |
< |
* to the original internal data array of this <tt>Vector</tt> object. |
631 |
> |
* to the original internal data array of this {@code Vector} object. |
632 |
|
* |
633 |
|
* @return a clone of this vector |
634 |
|
*/ |
731 |
|
* Appends the specified element to the end of this Vector. |
732 |
|
* |
733 |
|
* @param e element to be appended to this Vector |
734 |
< |
* @return <tt>true</tt> (as specified by {@link Collection#add}) |
734 |
> |
* @return {@code true} (as specified by {@link Collection#add}) |
735 |
|
* @since 1.2 |
736 |
|
*/ |
737 |
|
public synchronized boolean add(E e) { |
745 |
|
* Removes the first occurrence of the specified element in this Vector |
746 |
|
* If the Vector does not contain the element, it is unchanged. More |
747 |
|
* formally, removes the element with the lowest index i such that |
748 |
< |
* <code>(o==null ? get(i)==null : o.equals(get(i)))</code> (if such |
748 |
> |
* {@code (o==null ? get(i)==null : o.equals(get(i)))} (if such |
749 |
|
* an element exists). |
750 |
|
* |
751 |
|
* @param o element to be removed from this Vector, if present |
832 |
|
* specified Collection is this Vector, and this Vector is nonempty.) |
833 |
|
* |
834 |
|
* @param c elements to be inserted into this Vector |
835 |
< |
* @return <tt>true</tt> if this Vector changed as a result of the call |
835 |
> |
* @return {@code true} if this Vector changed as a result of the call |
836 |
|
* @throws NullPointerException if the specified collection is null |
837 |
|
* @since 1.2 |
838 |
|
*/ |
895 |
|
* @param index index at which to insert the first element from the |
896 |
|
* specified collection |
897 |
|
* @param c elements to be inserted into this Vector |
898 |
< |
* @return <tt>true</tt> if this Vector changed as a result of the call |
898 |
> |
* @return {@code true} if this Vector changed as a result of the call |
899 |
|
* @exception ArrayIndexOutOfBoundsException index out of range (index |
900 |
|
* < 0 || index > size()) |
901 |
|
* @throws NullPointerException if the specified collection is null |
924 |
|
* Compares the specified Object with this Vector for equality. Returns |
925 |
|
* true if and only if the specified Object is also a List, both Lists |
926 |
|
* have the same size, and all corresponding pairs of elements in the two |
927 |
< |
* Lists are <em>equal</em>. (Two elements <code>e1</code> and |
928 |
< |
* <code>e2</code> are <em>equal</em> if <code>(e1==null ? e2==null : |
929 |
< |
* e1.equals(e2))</code>.) In other words, two Lists are defined to be |
927 |
> |
* Lists are <em>equal</em>. (Two elements {@code e1} and |
928 |
> |
* {@code e2} are <em>equal</em> if {@code (e1==null ? e2==null : |
929 |
> |
* e1.equals(e2))}.) In other words, two Lists are defined to be |
930 |
|
* equal if they contain the same elements in the same order. |
931 |
|
* |
932 |
|
* @param o the Object to be compared for equality with this Vector |
952 |
|
} |
953 |
|
|
954 |
|
/** |
960 |
– |
* Returns a view of the portion of this List between fromIndex, |
961 |
– |
* inclusive, and toIndex, exclusive. (If fromIndex and toIndex are |
962 |
– |
* equal, the returned List is empty.) The returned List is backed by this |
963 |
– |
* List, so changes in the returned List are reflected in this List, and |
964 |
– |
* vice-versa. The returned List supports all of the optional List |
965 |
– |
* operations supported by this List.<p> |
966 |
– |
* |
967 |
– |
* This method eliminates the need for explicit range operations (of |
968 |
– |
* the sort that commonly exist for arrays). Any operation that expects |
969 |
– |
* a List can be used as a range operation by operating on a subList view |
970 |
– |
* instead of a whole List. For example, the following idiom |
971 |
– |
* removes a range of elements from a List: |
972 |
– |
* <pre> |
973 |
– |
* list.subList(from, to).clear(); |
974 |
– |
* </pre> |
975 |
– |
* Similar idioms may be constructed for indexOf and lastIndexOf, |
976 |
– |
* and all of the algorithms in the Collections class can be applied to |
977 |
– |
* a subList.<p> |
978 |
– |
* |
979 |
– |
* The semantics of the List returned by this method become undefined if |
980 |
– |
* the backing list (i.e., this List) is <i>structurally modified</i> in |
981 |
– |
* any way other than via the returned List. (Structural modifications are |
982 |
– |
* those that change the size of the List, or otherwise perturb it in such |
983 |
– |
* a fashion that iterations in progress may yield incorrect results.) |
984 |
– |
* |
985 |
– |
* @param fromIndex low endpoint (inclusive) of the subList |
986 |
– |
* @param toIndex high endpoint (exclusive) of the subList |
987 |
– |
* @return a view of the specified range within this List |
988 |
– |
* @throws IndexOutOfBoundsException endpoint index value out of range |
989 |
– |
* <code>(fromIndex < 0 || toIndex > size)</code> |
990 |
– |
* @throws IllegalArgumentException endpoint indices out of order |
991 |
– |
* <code>(fromIndex > toIndex)</code> |
992 |
– |
*/ |
993 |
– |
public synchronized List<E> subList(int fromIndex, int toIndex) { |
994 |
– |
return Collections.synchronizedList(super.subList(fromIndex, toIndex), |
995 |
– |
this); |
996 |
– |
} |
997 |
– |
|
998 |
– |
/** |
955 |
|
* Removes from this List all of the elements whose index is between |
956 |
|
* fromIndex, inclusive and toIndex, exclusive. Shifts any succeeding |
957 |
|
* elements to the left (reduces their index). |
958 |
< |
* This call shortens the ArrayList by (toIndex - fromIndex) elements. (If |
958 |
> |
* This call shortens the Vector by (toIndex - fromIndex) elements. (If |
959 |
|
* toIndex==fromIndex, this operation has no effect.) |
960 |
|
* |
961 |
|
* @param fromIndex index of first element to be removed |
974 |
|
} |
975 |
|
|
976 |
|
/** |
977 |
< |
* Save the state of the <tt>Vector</tt> instance to a stream (that |
977 |
> |
* Save the state of the {@code Vector} instance to a stream (that |
978 |
|
* is, serialize it). This method is present merely for synchronization. |
979 |
|
* It just calls the default writeObject method. |
980 |
|
*/ |
987 |
|
/** |
988 |
|
* Returns a list-iterator of the elements in this list (in proper |
989 |
|
* sequence), starting at the specified position in the list. |
990 |
< |
* Obeys the general contract of <tt>List.listIterator(int)</tt>.<p> |
990 |
> |
* Obeys the general contract of {@link List#listIterator(int)}. |
991 |
|
* |
992 |
< |
* The list-iterator is <i>fail-fast</i>: if the list is structurally |
992 |
> |
* <p>The list-iterator is <i>fail-fast</i>: if the list is structurally |
993 |
|
* modified at any time after the Iterator is created, in any way except |
994 |
< |
* through the list-iterator's own <tt>remove</tt> or <tt>add</tt> |
994 |
> |
* through the list-iterator's own {@code remove} or {@code add} |
995 |
|
* methods, the list-iterator will throw a |
996 |
< |
* <tt>ConcurrentModificationException</tt>. Thus, in the face of |
996 |
> |
* {@code ConcurrentModificationException}. Thus, in the face of |
997 |
|
* concurrent modification, the iterator fails quickly and cleanly, rather |
998 |
|
* than risking arbitrary, non-deterministic behavior at an undetermined |
999 |
|
* time in the future. |
1000 |
|
* |
1001 |
|
* @param index index of the first element to be returned from the |
1002 |
< |
* list-iterator (by a call to <tt>next</tt>) |
1003 |
< |
* @return a ListIterator of the elements in this list (in proper |
1002 |
> |
* list-iterator (by a call to {@link ListIterator#next}) |
1003 |
> |
* @return a list-iterator of the elements in this list (in proper |
1004 |
|
* sequence), starting at the specified position in the list |
1005 |
|
* @throws IndexOutOfBoundsException {@inheritDoc} |
1050 |
– |
* @see List#listIterator(int) |
1006 |
|
*/ |
1007 |
|
public synchronized ListIterator<E> listIterator(int index) { |
1008 |
|
if (index < 0 || index > elementCount) |
1009 |
|
throw new IndexOutOfBoundsException("Index: "+index); |
1010 |
< |
return new VectorIterator(index); |
1010 |
> |
return new VectorIterator(index, elementCount); |
1011 |
> |
} |
1012 |
> |
|
1013 |
> |
/** |
1014 |
> |
* {@inheritDoc} |
1015 |
> |
*/ |
1016 |
> |
public synchronized ListIterator<E> listIterator() { |
1017 |
> |
return new VectorIterator(0, elementCount); |
1018 |
|
} |
1019 |
< |
|
1019 |
> |
|
1020 |
|
/** |
1021 |
|
* Returns an iterator over the elements in this list in proper sequence. |
1022 |
|
* |
1023 |
|
* @return an iterator over the elements in this list in proper sequence |
1024 |
|
*/ |
1025 |
|
public synchronized Iterator<E> iterator() { |
1026 |
< |
return new VectorIterator(0); |
1026 |
> |
return new VectorIterator(0, elementCount); |
1027 |
|
} |
1028 |
|
|
1029 |
|
/** |
1030 |
< |
* A streamlined version of AbstractList.Itr. |
1030 |
> |
* Helper method to access array elements under synchronization by |
1031 |
> |
* iterators. The caller performs index check with respect to |
1032 |
> |
* expected bounds, so errors accessing the element are reported |
1033 |
> |
* as ConcurrentModificationExceptions. |
1034 |
|
*/ |
1035 |
< |
final class VectorIterator implements ListIterator<E> { |
1036 |
< |
int cursor; // index of next element to return; |
1037 |
< |
int lastRet; // index of last element, or -1 if no such |
1038 |
< |
int expectedModCount; // to check for CME |
1035 |
> |
final synchronized Object iteratorGet(int index, int expectedModCount) { |
1036 |
> |
if (modCount == expectedModCount) { |
1037 |
> |
try { |
1038 |
> |
return elementData[index]; |
1039 |
> |
} catch(IndexOutOfBoundsException fallThrough) { |
1040 |
> |
} |
1041 |
> |
} |
1042 |
> |
throw new ConcurrentModificationException(); |
1043 |
> |
} |
1044 |
|
|
1045 |
< |
VectorIterator(int index) { |
1046 |
< |
cursor = index; |
1047 |
< |
lastRet = -1; |
1048 |
< |
expectedModCount = modCount; |
1045 |
> |
/** |
1046 |
> |
* Streamlined specialization of AbstractList version of iterator. |
1047 |
> |
* Locally perfroms bounds checks, but relies on outer Vector |
1048 |
> |
* to access elements under synchronization. |
1049 |
> |
*/ |
1050 |
> |
private final class VectorIterator implements ListIterator<E> { |
1051 |
> |
int cursor; // Index of next element to return; |
1052 |
> |
int fence; // Upper bound on cursor (cache of size()) |
1053 |
> |
int lastRet; // Index of last element, or -1 if no such |
1054 |
> |
int expectedModCount; // To check for CME |
1055 |
> |
|
1056 |
> |
VectorIterator(int index, int fence) { |
1057 |
> |
this.cursor = index; |
1058 |
> |
this.fence = fence; |
1059 |
> |
this.lastRet = -1; |
1060 |
> |
this.expectedModCount = Vector.this.modCount; |
1061 |
|
} |
1062 |
|
|
1063 |
|
public boolean hasNext() { |
1064 |
< |
// Racy but within spec and backwards-compatible |
1083 |
< |
return cursor < elementCount; |
1064 |
> |
return cursor < fence; |
1065 |
|
} |
1066 |
|
|
1067 |
|
public boolean hasPrevious() { |
1077 |
|
} |
1078 |
|
|
1079 |
|
public E next() { |
1080 |
< |
synchronized(Vector.this) { |
1081 |
< |
if (expectedModCount == modCount) { |
1082 |
< |
int i = cursor; |
1083 |
< |
if (i < elementCount) { |
1084 |
< |
try { |
1085 |
< |
E e = (E)elementData[i]; |
1086 |
< |
lastRet = i; |
1106 |
< |
cursor = i + 1; |
1107 |
< |
return e; |
1108 |
< |
} catch (IndexOutOfBoundsException fallthrough) { |
1109 |
< |
} |
1110 |
< |
} |
1111 |
< |
} |
1112 |
< |
// Prefer reporting CME if applicable on failures |
1113 |
< |
if (expectedModCount == modCount) |
1114 |
< |
throw new NoSuchElementException(); |
1115 |
< |
throw new ConcurrentModificationException(); |
1116 |
< |
} |
1080 |
> |
int i = cursor; |
1081 |
> |
if (i >= fence) |
1082 |
> |
throw new NoSuchElementException(); |
1083 |
> |
Object next = Vector.this.iteratorGet(i, expectedModCount); |
1084 |
> |
lastRet = i; |
1085 |
> |
cursor = i + 1; |
1086 |
> |
return (E)next; |
1087 |
|
} |
1088 |
|
|
1089 |
|
public E previous() { |
1090 |
< |
synchronized(Vector.this) { |
1091 |
< |
if (expectedModCount == modCount) { |
1092 |
< |
int i = cursor - 1; |
1093 |
< |
if (i < elementCount) { |
1094 |
< |
try { |
1095 |
< |
E e = (E)elementData[i]; |
1096 |
< |
lastRet = i; |
1127 |
< |
cursor = i; |
1128 |
< |
return e; |
1129 |
< |
} catch (IndexOutOfBoundsException fallthrough) { |
1130 |
< |
} |
1131 |
< |
} |
1132 |
< |
} |
1133 |
< |
if (expectedModCount == modCount) |
1134 |
< |
throw new NoSuchElementException(); |
1135 |
< |
throw new ConcurrentModificationException(); |
1136 |
< |
} |
1090 |
> |
int i = cursor - 1; |
1091 |
> |
if (i < 0) |
1092 |
> |
throw new NoSuchElementException(); |
1093 |
> |
Object prev = Vector.this.iteratorGet(i, expectedModCount); |
1094 |
> |
lastRet = i; |
1095 |
> |
cursor = i; |
1096 |
> |
return (E)prev; |
1097 |
|
} |
1098 |
|
|
1099 |
< |
public void remove() { |
1099 |
> |
public void set(E e) { |
1100 |
|
if (lastRet < 0) |
1101 |
|
throw new IllegalStateException(); |
1102 |
< |
synchronized(Vector.this) { |
1103 |
< |
if (modCount != expectedModCount) |
1104 |
< |
throw new ConcurrentModificationException(); |
1105 |
< |
Vector.this.remove(lastRet); |
1106 |
< |
if (lastRet < cursor) |
1107 |
< |
cursor--; |
1108 |
< |
lastRet = -1; |
1109 |
< |
expectedModCount = modCount; |
1150 |
< |
} |
1102 |
> |
if (Vector.this.modCount != expectedModCount) |
1103 |
> |
throw new ConcurrentModificationException(); |
1104 |
> |
try { |
1105 |
> |
Vector.this.set(lastRet, e); |
1106 |
> |
expectedModCount = Vector.this.modCount; |
1107 |
> |
} catch (IndexOutOfBoundsException ex) { |
1108 |
> |
throw new ConcurrentModificationException(); |
1109 |
> |
} |
1110 |
|
} |
1111 |
|
|
1112 |
< |
public void set(E e) { |
1113 |
< |
if (lastRet < 0) |
1112 |
> |
public void remove() { |
1113 |
> |
int i = lastRet; |
1114 |
> |
if (i < 0) |
1115 |
|
throw new IllegalStateException(); |
1116 |
< |
synchronized(Vector.this) { |
1117 |
< |
if (modCount != expectedModCount) |
1118 |
< |
throw new ConcurrentModificationException(); |
1119 |
< |
Vector.this.set(lastRet, e); |
1120 |
< |
expectedModCount = modCount; |
1121 |
< |
} |
1116 |
> |
if (Vector.this.modCount != expectedModCount) |
1117 |
> |
throw new ConcurrentModificationException(); |
1118 |
> |
try { |
1119 |
> |
Vector.this.remove(i); |
1120 |
> |
if (i < cursor) |
1121 |
> |
cursor--; |
1122 |
> |
lastRet = -1; |
1123 |
> |
fence = Vector.this.size(); |
1124 |
> |
expectedModCount = Vector.this.modCount; |
1125 |
> |
} catch (IndexOutOfBoundsException ex) { |
1126 |
> |
throw new ConcurrentModificationException(); |
1127 |
> |
} |
1128 |
|
} |
1129 |
|
|
1130 |
|
public void add(E e) { |
1131 |
< |
synchronized(Vector.this) { |
1132 |
< |
if (modCount != expectedModCount) |
1133 |
< |
throw new ConcurrentModificationException(); |
1134 |
< |
Vector.this.add(cursor++, e); |
1131 |
> |
if (Vector.this.modCount != expectedModCount) |
1132 |
> |
throw new ConcurrentModificationException(); |
1133 |
> |
try { |
1134 |
> |
int i = cursor; |
1135 |
> |
Vector.this.add(i, e); |
1136 |
> |
cursor = i + 1; |
1137 |
|
lastRet = -1; |
1138 |
< |
expectedModCount = modCount; |
1139 |
< |
} |
1138 |
> |
fence = Vector.this.size(); |
1139 |
> |
expectedModCount = Vector.this.modCount; |
1140 |
> |
} catch (IndexOutOfBoundsException ex) { |
1141 |
> |
throw new ConcurrentModificationException(); |
1142 |
> |
} |
1143 |
|
} |
1144 |
|
} |
1145 |
|
|
1146 |
+ |
/** |
1147 |
+ |
* Returns a view of the portion of this List between fromIndex, |
1148 |
+ |
* inclusive, and toIndex, exclusive. (If fromIndex and toIndex are |
1149 |
+ |
* equal, the returned List is empty.) The returned List is backed by this |
1150 |
+ |
* List, so changes in the returned List are reflected in this List, and |
1151 |
+ |
* vice-versa. The returned List supports all of the optional List |
1152 |
+ |
* operations supported by this List.<p> |
1153 |
+ |
* |
1154 |
+ |
* This method eliminates the need for explicit range operations (of |
1155 |
+ |
* the sort that commonly exist for arrays). Any operation that expects |
1156 |
+ |
* a List can be used as a range operation by operating on a subList view |
1157 |
+ |
* instead of a whole List. For example, the following idiom |
1158 |
+ |
* removes a range of elements from a List: |
1159 |
+ |
* <pre> |
1160 |
+ |
* list.subList(from, to).clear(); |
1161 |
+ |
* </pre> |
1162 |
+ |
* Similar idioms may be constructed for indexOf and lastIndexOf, |
1163 |
+ |
* and all of the algorithms in the Collections class can be applied to |
1164 |
+ |
* a subList.<p> |
1165 |
+ |
* |
1166 |
+ |
* The semantics of the List returned by this method become undefined if |
1167 |
+ |
* the backing list (i.e., this List) is <i>structurally modified</i> in |
1168 |
+ |
* any way other than via the returned List. (Structural modifications are |
1169 |
+ |
* those that change the size of the List, or otherwise perturb it in such |
1170 |
+ |
* a fashion that iterations in progress may yield incorrect results.) |
1171 |
+ |
* |
1172 |
+ |
* @param fromIndex low endpoint (inclusive) of the subList |
1173 |
+ |
* @param toIndex high endpoint (exclusive) of the subList |
1174 |
+ |
* @return a view of the specified range within this List |
1175 |
+ |
* @throws IndexOutOfBoundsException endpoint index value out of range |
1176 |
+ |
* <code>(fromIndex < 0 || toIndex > size)</code> |
1177 |
+ |
* @throws IllegalArgumentException endpoint indices out of order |
1178 |
+ |
* <code>(fromIndex > toIndex)</code> |
1179 |
+ |
*/ |
1180 |
+ |
public synchronized List<E> subList(int fromIndex, int toIndex) { |
1181 |
+ |
return new VectorSubList(this, this, fromIndex, fromIndex, toIndex); |
1182 |
+ |
} |
1183 |
+ |
|
1184 |
+ |
/** |
1185 |
+ |
* This class specializes the AbstractList version of SubList to |
1186 |
+ |
* avoid the double-indirection penalty that would arise using a |
1187 |
+ |
* synchronized wrapper, as well as to avoid some unnecessary |
1188 |
+ |
* checks in sublist iterators. |
1189 |
+ |
*/ |
1190 |
+ |
private static final class VectorSubList<E> extends AbstractList<E> implements RandomAccess { |
1191 |
+ |
final Vector<E> base; // base list |
1192 |
+ |
final AbstractList<E> parent; // Creating list |
1193 |
+ |
final int baseOffset; // index wrt Vector |
1194 |
+ |
final int parentOffset; // index wrt parent |
1195 |
+ |
int length; // length of sublist |
1196 |
+ |
|
1197 |
+ |
VectorSubList(Vector<E> base, AbstractList<E> parent, int baseOffset, |
1198 |
+ |
int fromIndex, int toIndex) { |
1199 |
+ |
if (fromIndex < 0) |
1200 |
+ |
throw new IndexOutOfBoundsException("fromIndex = " + fromIndex); |
1201 |
+ |
if (toIndex > parent.size()) |
1202 |
+ |
throw new IndexOutOfBoundsException("toIndex = " + toIndex); |
1203 |
+ |
if (fromIndex > toIndex) |
1204 |
+ |
throw new IllegalArgumentException("fromIndex(" + fromIndex + |
1205 |
+ |
") > toIndex(" + toIndex + ")"); |
1206 |
+ |
|
1207 |
+ |
this.base = base; |
1208 |
+ |
this.parent = parent; |
1209 |
+ |
this.baseOffset = baseOffset; |
1210 |
+ |
this.parentOffset = fromIndex; |
1211 |
+ |
this.length = toIndex - fromIndex; |
1212 |
+ |
modCount = base.modCount; |
1213 |
+ |
} |
1214 |
+ |
|
1215 |
+ |
/** |
1216 |
+ |
* Returns an IndexOutOfBoundsException with nicer message |
1217 |
+ |
*/ |
1218 |
+ |
private IndexOutOfBoundsException indexError(int index) { |
1219 |
+ |
return new IndexOutOfBoundsException("Index: " + index + |
1220 |
+ |
", Size: " + length); |
1221 |
+ |
} |
1222 |
+ |
|
1223 |
+ |
public E set(int index, E element) { |
1224 |
+ |
synchronized(base) { |
1225 |
+ |
if (index < 0 || index >= length) |
1226 |
+ |
throw indexError(index); |
1227 |
+ |
if (base.modCount != modCount) |
1228 |
+ |
throw new ConcurrentModificationException(); |
1229 |
+ |
return base.set(index + baseOffset, element); |
1230 |
+ |
} |
1231 |
+ |
} |
1232 |
+ |
|
1233 |
+ |
public E get(int index) { |
1234 |
+ |
synchronized(base) { |
1235 |
+ |
if (index < 0 || index >= length) |
1236 |
+ |
throw indexError(index); |
1237 |
+ |
if (base.modCount != modCount) |
1238 |
+ |
throw new ConcurrentModificationException(); |
1239 |
+ |
return base.get(index + baseOffset); |
1240 |
+ |
} |
1241 |
+ |
} |
1242 |
+ |
|
1243 |
+ |
public int size() { |
1244 |
+ |
synchronized(base) { |
1245 |
+ |
if (base.modCount != modCount) |
1246 |
+ |
throw new ConcurrentModificationException(); |
1247 |
+ |
return length; |
1248 |
+ |
} |
1249 |
+ |
} |
1250 |
+ |
|
1251 |
+ |
public void add(int index, E element) { |
1252 |
+ |
synchronized(base) { |
1253 |
+ |
if (index < 0 || index > length) |
1254 |
+ |
throw indexError(index); |
1255 |
+ |
if (base.modCount != modCount) |
1256 |
+ |
throw new ConcurrentModificationException(); |
1257 |
+ |
parent.add(index + parentOffset, element); |
1258 |
+ |
length++; |
1259 |
+ |
modCount = base.modCount; |
1260 |
+ |
} |
1261 |
+ |
} |
1262 |
+ |
|
1263 |
+ |
public E remove(int index) { |
1264 |
+ |
synchronized(base) { |
1265 |
+ |
if (index < 0 || index >= length) |
1266 |
+ |
throw indexError(index); |
1267 |
+ |
if (base.modCount != modCount) |
1268 |
+ |
throw new ConcurrentModificationException(); |
1269 |
+ |
E result = parent.remove(index + parentOffset); |
1270 |
+ |
length--; |
1271 |
+ |
modCount = base.modCount; |
1272 |
+ |
return result; |
1273 |
+ |
} |
1274 |
+ |
} |
1275 |
+ |
|
1276 |
+ |
protected void removeRange(int fromIndex, int toIndex) { |
1277 |
+ |
synchronized(base) { |
1278 |
+ |
if (base.modCount != modCount) |
1279 |
+ |
throw new ConcurrentModificationException(); |
1280 |
+ |
parent.removeRange(fromIndex + parentOffset, |
1281 |
+ |
toIndex + parentOffset); |
1282 |
+ |
length -= (toIndex-fromIndex); |
1283 |
+ |
modCount = base.modCount; |
1284 |
+ |
} |
1285 |
+ |
} |
1286 |
+ |
|
1287 |
+ |
public boolean addAll(Collection<? extends E> c) { |
1288 |
+ |
return addAll(length, c); |
1289 |
+ |
} |
1290 |
+ |
|
1291 |
+ |
public boolean addAll(int index, Collection<? extends E> c) { |
1292 |
+ |
synchronized(base) { |
1293 |
+ |
if (index < 0 || index > length) |
1294 |
+ |
throw indexError(index); |
1295 |
+ |
int cSize = c.size(); |
1296 |
+ |
if (cSize==0) |
1297 |
+ |
return false; |
1298 |
+ |
|
1299 |
+ |
if (base.modCount != modCount) |
1300 |
+ |
throw new ConcurrentModificationException(); |
1301 |
+ |
parent.addAll(parentOffset + index, c); |
1302 |
+ |
modCount = base.modCount; |
1303 |
+ |
length += cSize; |
1304 |
+ |
return true; |
1305 |
+ |
} |
1306 |
+ |
} |
1307 |
+ |
|
1308 |
+ |
public boolean equals(Object o) { |
1309 |
+ |
synchronized(base) {return super.equals(o);} |
1310 |
+ |
} |
1311 |
+ |
|
1312 |
+ |
public int hashCode() { |
1313 |
+ |
synchronized(base) {return super.hashCode();} |
1314 |
+ |
} |
1315 |
+ |
|
1316 |
+ |
public int indexOf(Object o) { |
1317 |
+ |
synchronized(base) {return super.indexOf(o);} |
1318 |
+ |
} |
1319 |
+ |
|
1320 |
+ |
public int lastIndexOf(Object o) { |
1321 |
+ |
synchronized(base) {return super.lastIndexOf(o);} |
1322 |
+ |
} |
1323 |
+ |
|
1324 |
+ |
public List<E> subList(int fromIndex, int toIndex) { |
1325 |
+ |
return new VectorSubList(base, this, fromIndex + baseOffset, |
1326 |
+ |
fromIndex, toIndex); |
1327 |
+ |
} |
1328 |
+ |
|
1329 |
+ |
public Iterator<E> iterator() { |
1330 |
+ |
synchronized(base) { |
1331 |
+ |
return new VectorSubListIterator(this, 0); |
1332 |
+ |
} |
1333 |
+ |
} |
1334 |
+ |
|
1335 |
+ |
public synchronized ListIterator<E> listIterator() { |
1336 |
+ |
synchronized(base) { |
1337 |
+ |
return new VectorSubListIterator(this, 0); |
1338 |
+ |
} |
1339 |
+ |
} |
1340 |
+ |
|
1341 |
+ |
public ListIterator<E> listIterator(int index) { |
1342 |
+ |
synchronized(base) { |
1343 |
+ |
if (index < 0 || index > length) |
1344 |
+ |
throw indexError(index); |
1345 |
+ |
return new VectorSubListIterator(this, index); |
1346 |
+ |
} |
1347 |
+ |
} |
1348 |
+ |
|
1349 |
+ |
/** |
1350 |
+ |
* Same idea as VectorIterator, except routing structural |
1351 |
+ |
* change operations through the sublist. |
1352 |
+ |
*/ |
1353 |
+ |
private static final class VectorSubListIterator<E> implements ListIterator<E> { |
1354 |
+ |
final Vector<E> base; // base list |
1355 |
+ |
final VectorSubList<E> outer; // Sublist creating this iteraor |
1356 |
+ |
final int offset; // cursor offset wrt base |
1357 |
+ |
int cursor; // Current index |
1358 |
+ |
int fence; // Upper bound on cursor |
1359 |
+ |
int lastRet; // Index of returned element, or -1 |
1360 |
+ |
int expectedModCount; // Expected modCount of base Vector |
1361 |
+ |
|
1362 |
+ |
VectorSubListIterator(VectorSubList<E> list, int index) { |
1363 |
+ |
this.lastRet = -1; |
1364 |
+ |
this.cursor = index; |
1365 |
+ |
this.outer = list; |
1366 |
+ |
this.offset = list.baseOffset; |
1367 |
+ |
this.fence = list.length; |
1368 |
+ |
this.base = list.base; |
1369 |
+ |
this.expectedModCount = base.modCount; |
1370 |
+ |
} |
1371 |
+ |
|
1372 |
+ |
public boolean hasNext() { |
1373 |
+ |
return cursor < fence; |
1374 |
+ |
} |
1375 |
+ |
|
1376 |
+ |
public boolean hasPrevious() { |
1377 |
+ |
return cursor > 0; |
1378 |
+ |
} |
1379 |
+ |
|
1380 |
+ |
public int nextIndex() { |
1381 |
+ |
return cursor; |
1382 |
+ |
} |
1383 |
+ |
|
1384 |
+ |
public int previousIndex() { |
1385 |
+ |
return cursor - 1; |
1386 |
+ |
} |
1387 |
+ |
|
1388 |
+ |
public E next() { |
1389 |
+ |
int i = cursor; |
1390 |
+ |
if (cursor >= fence) |
1391 |
+ |
throw new NoSuchElementException(); |
1392 |
+ |
Object next = base.iteratorGet(i + offset, expectedModCount); |
1393 |
+ |
lastRet = i; |
1394 |
+ |
cursor = i + 1; |
1395 |
+ |
return (E)next; |
1396 |
+ |
} |
1397 |
+ |
|
1398 |
+ |
public E previous() { |
1399 |
+ |
int i = cursor - 1; |
1400 |
+ |
if (i < 0) |
1401 |
+ |
throw new NoSuchElementException(); |
1402 |
+ |
Object prev = base.iteratorGet(i + offset, expectedModCount); |
1403 |
+ |
lastRet = i; |
1404 |
+ |
cursor = i; |
1405 |
+ |
return (E)prev; |
1406 |
+ |
} |
1407 |
+ |
|
1408 |
+ |
public void set(E e) { |
1409 |
+ |
if (lastRet < 0) |
1410 |
+ |
throw new IllegalStateException(); |
1411 |
+ |
if (base.modCount != expectedModCount) |
1412 |
+ |
throw new ConcurrentModificationException(); |
1413 |
+ |
try { |
1414 |
+ |
outer.set(lastRet, e); |
1415 |
+ |
expectedModCount = base.modCount; |
1416 |
+ |
} catch (IndexOutOfBoundsException ex) { |
1417 |
+ |
throw new ConcurrentModificationException(); |
1418 |
+ |
} |
1419 |
+ |
} |
1420 |
+ |
|
1421 |
+ |
public void remove() { |
1422 |
+ |
int i = lastRet; |
1423 |
+ |
if (i < 0) |
1424 |
+ |
throw new IllegalStateException(); |
1425 |
+ |
if (base.modCount != expectedModCount) |
1426 |
+ |
throw new ConcurrentModificationException(); |
1427 |
+ |
try { |
1428 |
+ |
outer.remove(i); |
1429 |
+ |
if (i < cursor) |
1430 |
+ |
cursor--; |
1431 |
+ |
lastRet = -1; |
1432 |
+ |
fence = outer.length; |
1433 |
+ |
expectedModCount = base.modCount; |
1434 |
+ |
} catch (IndexOutOfBoundsException ex) { |
1435 |
+ |
throw new ConcurrentModificationException(); |
1436 |
+ |
} |
1437 |
+ |
} |
1438 |
+ |
|
1439 |
+ |
public void add(E e) { |
1440 |
+ |
if (base.modCount != expectedModCount) |
1441 |
+ |
throw new ConcurrentModificationException(); |
1442 |
+ |
try { |
1443 |
+ |
int i = cursor; |
1444 |
+ |
outer.add(i, e); |
1445 |
+ |
cursor = i + 1; |
1446 |
+ |
lastRet = -1; |
1447 |
+ |
fence = outer.length; |
1448 |
+ |
expectedModCount = base.modCount; |
1449 |
+ |
} catch (IndexOutOfBoundsException ex) { |
1450 |
+ |
throw new ConcurrentModificationException(); |
1451 |
+ |
} |
1452 |
+ |
} |
1453 |
+ |
} |
1454 |
+ |
} |
1455 |
|
} |
1456 |
+ |
|
1457 |
+ |
|
1458 |
+ |
|