ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/Vector.java
(Generate patch)

Comparing jsr166/src/main/java/util/Vector.java (file contents):
Revision 1.2 by jsr166, Sat Nov 26 03:12:10 2005 UTC vs.
Revision 1.17 by jsr166, Mon Jun 26 00:17:48 2006 UTC

# Line 1 | Line 1
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
# Line 41 | Line 36 | import java.util.*; // for javadoc (till
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
# Line 66 | Line 63 | public class Vector<E>
63      /**
64       * The array buffer into which the components of the vector are
65       * stored. The capacity of the vector is the length of this array buffer,
66 <     * and is at least large enough to contain all the vector's elements.<p>
66 >     * and is at least large enough to contain all the vector's elements.
67       *
68 <     * Any array elements following the last element in the Vector are null.
68 >     * <p>Any array elements following the last element in the Vector are null.
69       *
70       * @serial
71       */
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       */
# Line 103 | Line 100 | public class Vector<E>
100       * @param   initialCapacity     the initial capacity of the vector
101       * @param   capacityIncrement   the amount by which the capacity is
102       *                              increased when the vector overflows
103 <     * @exception IllegalArgumentException if the specified initial capacity
104 <     *               is negative
103 >     * @throws IllegalArgumentException if the specified initial capacity
104 >     *         is negative
105       */
106      public Vector(int initialCapacity, int capacityIncrement) {
107          super();
# Line 120 | Line 117 | public class Vector<E>
117       * with its capacity increment equal to zero.
118       *
119       * @param   initialCapacity   the initial capacity of the vector
120 <     * @exception IllegalArgumentException if the specified initial capacity
121 <     *               is negative
120 >     * @throws IllegalArgumentException if the specified initial capacity
121 >     *         is negative
122       */
123      public Vector(int initialCapacity) {
124          this(initialCapacity, 0);
# Line 129 | Line 126 | public class Vector<E>
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() {
# Line 147 | Line 144 | public class Vector<E>
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
# Line 177 | Line 172 | public class Vector<E>
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       */
# Line 195 | Line 190 | public class Vector<E>
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       */
# Line 217 | Line 212 | public class Vector<E>
212       * method for ensuring capacity without incurring the cost of an
213       * extra synchronization.
214       *
215 <     * @see java.util.Vector#ensureCapacity(int)
215 >     * @see #ensureCapacity(int)
216       */
217      private void ensureCapacityHelper(int minCapacity) {
218          int oldCapacity = elementData.length;
# Line 234 | Line 229 | public class Vector<E>
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
236 >     * @param  newSize   the new size of this vector
237 >     * @throws ArrayIndexOutOfBoundsException if the new size is negative
238       */
239      public synchronized void setSize(int newSize) {
240          modCount++;
# Line 257 | Line 252 | public class Vector<E>
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() {
# Line 276 | Line 271 | public class Vector<E>
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;
# Line 286 | Line 281 | public class Vector<E>
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
294     * @see     Enumeration
289       * @see     Iterator
290       */
291      public Enumeration<E> elements() {
# Line 314 | Line 308 | public class Vector<E>
308      }
309  
310      /**
311 <     * Returns <tt>true</tt> if this vector contains the specified element.
312 <     * More formally, returns <tt>true</tt> if and only if this vector
313 <     * contains at least one element <tt>e</tt> such that
311 >     * Returns {@code true} if this vector contains the specified element.
312 >     * More formally, returns {@code true} if and only if this vector
313 >     * contains at least one element {@code e} such that
314       * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
315       *
316       * @param o element whose presence in this vector is to be tested
317 <     * @return <tt>true</tt> if this vector contains the specified element
317 >     * @return {@code true} if this vector contains the specified element
318       */
319      public boolean contains(Object o) {
320          return indexOf(o, 0) >= 0;
# Line 329 | Line 323 | public class Vector<E>
323      /**
324       * Returns the index of the first occurrence of the specified element
325       * in this vector, or -1 if this vector does not contain the element.
326 <     * More formally, returns the lowest index <tt>i</tt> such that
326 >     * More formally, returns the lowest index {@code i} such that
327       * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
328       * or -1 if there is no such index.
329       *
# Line 343 | Line 337 | public class Vector<E>
337  
338      /**
339       * Returns the index of the first occurrence of the specified element in
340 <     * this vector, searching forwards from <tt>index</tt>, or returns -1 if
340 >     * this vector, searching forwards from {@code index}, or returns -1 if
341       * the element is not found.
342 <     * More formally, returns the lowest index <tt>i</tt> such that
342 >     * More formally, returns the lowest index {@code i} such that
343       * <tt>(i&nbsp;&gt;=&nbsp;index&nbsp;&amp;&amp;&nbsp;(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i))))</tt>,
344       * or -1 if there is no such index.
345       *
346       * @param o element to search for
347       * @param index index to start searching from
348       * @return the index of the first occurrence of the element in
349 <     *         this vector at position <tt>index</tt> or later in the vector;
350 <     *         <tt>-1</tt> if the element is not found.
349 >     *         this vector at position {@code index} or later in the vector;
350 >     *         {@code -1} if the element is not found.
351       * @throws IndexOutOfBoundsException if the specified index is negative
352       * @see     Object#equals(Object)
353       */
# Line 373 | Line 367 | public class Vector<E>
367      /**
368       * Returns the index of the last occurrence of the specified element
369       * in this vector, or -1 if this vector does not contain the element.
370 <     * More formally, returns the highest index <tt>i</tt> such that
370 >     * More formally, returns the highest index {@code i} such that
371       * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
372       * or -1 if there is no such index.
373       *
# Line 387 | Line 381 | public class Vector<E>
381  
382      /**
383       * Returns the index of the last occurrence of the specified element in
384 <     * this vector, searching backwards from <tt>index</tt>, or returns -1 if
384 >     * this vector, searching backwards from {@code index}, or returns -1 if
385       * the element is not found.
386 <     * More formally, returns the highest index <tt>i</tt> such that
386 >     * More formally, returns the highest index {@code i} such that
387       * <tt>(i&nbsp;&lt;=&nbsp;index&nbsp;&amp;&amp;&nbsp;(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i))))</tt>,
388       * or -1 if there is no such index.
389       *
390       * @param o element to search for
391       * @param index index to start searching backwards from
392       * @return the index of the last occurrence of the element at position
393 <     *         less than or equal to <tt>index</tt> in this vector;
393 >     *         less than or equal to {@code index} in this vector;
394       *         -1 if the element is not found.
395       * @throws IndexOutOfBoundsException if the specified index is greater
396       *         than or equal to the current size of this vector
# Line 418 | Line 412 | public class Vector<E>
412      }
413  
414      /**
415 <     * Returns the component at the specified index.<p>
415 >     * Returns the component at the specified index.
416       *
417 <     * This method is identical in functionality to the get method
418 <     * (which is part of the List interface).
417 >     * <p>This method is identical in functionality to the {@link #get(int)}
418 >     * method (which is part of the {@link List} interface).
419       *
420       * @param      index   an index into this vector
421       * @return     the component at the specified index
422 <     * @exception  ArrayIndexOutOfBoundsException  if the <tt>index</tt>
423 <     *             is negative or not less than the current size of this
430 <     *             <tt>Vector</tt> object.
431 <     * @see        #get(int)
432 <     * @see        List
422 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
423 >     *         ({@code index < 0 || index >= size()})
424       */
425      public synchronized E elementAt(int index) {
426          if (index >= elementCount) {
# Line 440 | Line 431 | public class Vector<E>
431      }
432  
433      /**
434 <     * Returns the first component (the item at index <tt>0</tt>) of
434 >     * Returns the first component (the item at index {@code 0}) of
435       * this vector.
436       *
437       * @return     the first component of this vector
438 <     * @exception  NoSuchElementException  if this vector has no components
438 >     * @throws NoSuchElementException if this vector has no components
439       */
440      public synchronized E firstElement() {
441          if (elementCount == 0) {
# Line 458 | Line 449 | public class Vector<E>
449       *
450       * @return  the last component of the vector, i.e., the component at index
451       *          <code>size()&nbsp;-&nbsp;1</code>.
452 <     * @exception  NoSuchElementException  if this vector is empty
452 >     * @throws NoSuchElementException if this vector is empty
453       */
454      public synchronized E lastElement() {
455          if (elementCount == 0) {
# Line 468 | Line 459 | public class Vector<E>
459      }
460  
461      /**
462 <     * Sets the component at the specified <code>index</code> of this
462 >     * Sets the component at the specified {@code index} of this
463       * vector to be the specified object. The previous component at that
464 <     * position is discarded.<p>
464 >     * position is discarded.
465       *
466 <     * The index must be a value greater than or equal to <code>0</code>
467 <     * and less than the current size of the vector. <p>
466 >     * <p>The index must be a value greater than or equal to {@code 0}
467 >     * and less than the current size of the vector.
468       *
469 <     * This method is identical in functionality to the set method
470 <     * (which is part of the List interface). Note that the set method reverses
471 <     * the order of the parameters, to more closely match array usage.  Note
472 <     * also that the set method returns the old value that was stored at the
473 <     * specified position.
469 >     * <p>This method is identical in functionality to the
470 >     * {@link #set(int, Object) set(int, E)}
471 >     * method (which is part of the {@link List} interface). Note that the
472 >     * {@code set} method reverses the order of the parameters, to more closely
473 >     * match array usage.  Note also that the {@code set} method returns the
474 >     * old value that was stored at the specified position.
475       *
476       * @param      obj     what the component is to be set to
477       * @param      index   the specified index
478 <     * @exception  ArrayIndexOutOfBoundsException  if the index was invalid
479 <     * @see        #size()
488 <     * @see        List
489 <     * @see        #set(int, java.lang.Object)
478 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
479 >     *         ({@code index < 0 || index >= size()})
480       */
481      public synchronized void setElementAt(E obj, int index) {
482          if (index >= elementCount) {
# Line 499 | Line 489 | public class Vector<E>
489      /**
490       * Deletes the component at the specified index. Each component in
491       * this vector with an index greater or equal to the specified
492 <     * <code>index</code> is shifted downward to have an index one
492 >     * {@code index} is shifted downward to have an index one
493       * smaller than the value it had previously. The size of this vector
494 <     * is decreased by <tt>1</tt>.<p>
494 >     * is decreased by {@code 1}.
495       *
496 <     * The index must be a value greater than or equal to <code>0</code>
497 <     * and less than the current size of the vector. <p>
496 >     * <p>The index must be a value greater than or equal to {@code 0}
497 >     * and less than the current size of the vector.
498       *
499 <     * This method is identical in functionality to the remove method
500 <     * (which is part of the List interface).  Note that the remove method
501 <     * returns the old value that was stored at the specified position.
499 >     * <p>This method is identical in functionality to the {@link #remove(int)}
500 >     * method (which is part of the {@link List} interface).  Note that the
501 >     * {@code remove} method returns the old value that was stored at the
502 >     * specified position.
503       *
504       * @param      index   the index of the object to remove
505 <     * @exception  ArrayIndexOutOfBoundsException  if the index was invalid
506 <     * @see        #size()
516 <     * @see        #remove(int)
517 <     * @see        List
505 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
506 >     *         ({@code index < 0 || index >= size()})
507       */
508      public synchronized void removeElementAt(int index) {
509          modCount++;
# Line 535 | Line 524 | public class Vector<E>
524  
525      /**
526       * Inserts the specified object as a component in this vector at the
527 <     * specified <code>index</code>. Each component in this vector with
528 <     * an index greater or equal to the specified <code>index</code> is
527 >     * specified {@code index}. Each component in this vector with
528 >     * an index greater or equal to the specified {@code index} is
529       * shifted upward to have an index one greater than the value it had
530 <     * previously. <p>
530 >     * previously.
531       *
532 <     * The index must be a value greater than or equal to <code>0</code>
532 >     * <p>The index must be a value greater than or equal to {@code 0}
533       * and less than or equal to the current size of the vector. (If the
534       * index is equal to the current size of the vector, the new element
535 <     * is appended to the Vector.)<p>
535 >     * is appended to the Vector.)
536       *
537 <     * This method is identical in functionality to the add(Object, int) method
538 <     * (which is part of the List interface). Note that the add method reverses
539 <     * the order of the parameters, to more closely match array usage.
537 >     * <p>This method is identical in functionality to the
538 >     * {@link #add(int, Object) add(int, E)}
539 >     * method (which is part of the {@link List} interface).  Note that the
540 >     * {@code add} method reverses the order of the parameters, to more closely
541 >     * match array usage.
542       *
543       * @param      obj     the component to insert
544       * @param      index   where to insert the new component
545 <     * @exception  ArrayIndexOutOfBoundsException  if the index was invalid
546 <     * @see        #size()
556 <     * @see        #add(int, Object)
557 <     * @see        List
545 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
546 >     *         ({@code index < 0 || index > size()})
547       */
548      public synchronized void insertElementAt(E obj, int index) {
549          modCount++;
# Line 571 | Line 560 | public class Vector<E>
560      /**
561       * Adds the specified component to the end of this vector,
562       * increasing its size by one. The capacity of this vector is
563 <     * increased if its size becomes greater than its capacity. <p>
563 >     * increased if its size becomes greater than its capacity.
564       *
565 <     * This method is identical in functionality to the add(Object) method
566 <     * (which is part of the List interface).
565 >     * <p>This method is identical in functionality to the
566 >     * {@link #remove(Object)} method (which is part of the
567 >     * {@link List} interface).
568       *
569       * @param   obj   the component to be added
580     * @see        #add(Object)
581     * @see        List
570       */
571      public synchronized void addElement(E obj) {
572          modCount++;
# Line 591 | Line 579 | public class Vector<E>
579       * from this vector. If the object is found in this vector, each
580       * component in the vector with an index greater or equal to the
581       * object's index is shifted downward to have an index one smaller
582 <     * than the value it had previously.<p>
582 >     * than the value it had previously.
583       *
584 <     * This method is identical in functionality to the remove(Object)
584 >     * <p>This method is identical in functionality to the remove(Object)
585       * method (which is part of the List interface).
586       *
587       * @param   obj   the component to be removed
588 <     * @return  <code>true</code> if the argument was a component of this
589 <     *          vector; <code>false</code> otherwise.
588 >     * @return  {@code true} if the argument was a component of this
589 >     *          vector; {@code false} otherwise.
590       * @see     List#remove(Object)
591       * @see     List
592       */
# Line 613 | Line 601 | public class Vector<E>
601      }
602  
603      /**
604 <     * Removes all components from this vector and sets its size to zero.<p>
604 >     * Removes all components from this vector and sets its size to zero.
605       *
606 <     * This method is identical in functionality to the clear method
607 <     * (which is part of the List interface).
620 <     *
621 <     * @see     #clear
622 <     * @see     List
606 >     * <p>This method is identical in functionality to the {@link #clear}
607 >     * method (which is part of the {@link List} interface).
608       */
609      public synchronized void removeAllElements() {
610          modCount++;
# Line 633 | Line 618 | public class Vector<E>
618      /**
619       * Returns a clone of this vector. The copy will contain a
620       * reference to a clone of the internal data array, not a reference
621 <     * to the original internal data array of this <tt>Vector</tt> object.
621 >     * to the original internal data array of this {@code Vector} object.
622       *
623       * @return  a clone of this vector
624       */
# Line 664 | Line 649 | public class Vector<E>
649       * correct order; the runtime type of the returned array is that of the
650       * specified array.  If the Vector fits in the specified array, it is
651       * returned therein.  Otherwise, a new array is allocated with the runtime
652 <     * type of the specified array and the size of this Vector.<p>
652 >     * type of the specified array and the size of this Vector.
653       *
654 <     * If the Vector fits in the specified array with room to spare
654 >     * <p>If the Vector fits in the specified array with room to spare
655       * (i.e., the array has more elements than the Vector),
656       * the element in the array immediately following the end of the
657       * Vector is set to null.  (This is useful in determining the length
# Line 677 | Line 662 | public class Vector<E>
662       *          be stored, if it is big enough; otherwise, a new array of the
663       *          same runtime type is allocated for this purpose.
664       * @return an array containing the elements of the Vector
665 <     * @exception ArrayStoreException the runtime type of a is not a supertype
665 >     * @throws ArrayStoreException if the runtime type of a is not a supertype
666       * of the runtime type of every element in this Vector
667       * @throws NullPointerException if the given array is null
668       * @since 1.2
# Line 701 | Line 686 | public class Vector<E>
686       *
687       * @param index index of the element to return
688       * @return object at the specified index
689 <     * @exception ArrayIndexOutOfBoundsException index is out of range (index
690 <     *            &lt; 0 || index &gt;= size())
689 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
690 >     *            ({@code index < 0 || index >= size()})
691       * @since 1.2
692       */
693      public synchronized E get(int index) {
# Line 719 | Line 704 | public class Vector<E>
704       * @param index index of the element to replace
705       * @param element element to be stored at the specified position
706       * @return the element previously at the specified position
707 <     * @exception ArrayIndexOutOfBoundsException index out of range
708 <     *            (index &lt; 0 || index &gt;= size())
707 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
708 >     *         ({@code index < 0 || index >= size()})
709       * @since 1.2
710       */
711      public synchronized E set(int index, E element) {
# Line 736 | Line 721 | public class Vector<E>
721       * Appends the specified element to the end of this Vector.
722       *
723       * @param e element to be appended to this Vector
724 <     * @return <tt>true</tt> (as specified by {@link Collection#add})
724 >     * @return {@code true} (as specified by {@link Collection#add})
725       * @since 1.2
726       */
727      public synchronized boolean add(E e) {
# Line 750 | Line 735 | public class Vector<E>
735       * Removes the first occurrence of the specified element in this Vector
736       * If the Vector does not contain the element, it is unchanged.  More
737       * formally, removes the element with the lowest index i such that
738 <     * <code>(o==null ? get(i)==null : o.equals(get(i)))</code> (if such
738 >     * {@code (o==null ? get(i)==null : o.equals(get(i)))} (if such
739       * an element exists).
740       *
741       * @param o element to be removed from this Vector, if present
# Line 768 | Line 753 | public class Vector<E>
753       *
754       * @param index index at which the specified element is to be inserted
755       * @param element element to be inserted
756 <     * @exception ArrayIndexOutOfBoundsException index is out of range
757 <     *            (index &lt; 0 || index &gt; size())
756 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
757 >     *         ({@code index < 0 || index > size()})
758       * @since 1.2
759       */
760      public void add(int index, E element) {
# Line 837 | Line 822 | public class Vector<E>
822       * specified Collection is this Vector, and this Vector is nonempty.)
823       *
824       * @param c elements to be inserted into this Vector
825 <     * @return <tt>true</tt> if this Vector changed as a result of the call
825 >     * @return {@code true} if this Vector changed as a result of the call
826       * @throws NullPointerException if the specified collection is null
827       * @since 1.2
828       */
# Line 900 | Line 885 | public class Vector<E>
885       * @param index index at which to insert the first element from the
886       *              specified collection
887       * @param c elements to be inserted into this Vector
888 <     * @return <tt>true</tt> if this Vector changed as a result of the call
888 >     * @return {@code true} if this Vector changed as a result of the call
889       * @exception ArrayIndexOutOfBoundsException index out of range (index
890       *            &lt; 0 || index &gt; size())
891       * @throws NullPointerException if the specified collection is null
# Line 929 | Line 914 | public class Vector<E>
914       * Compares the specified Object with this Vector for equality.  Returns
915       * true if and only if the specified Object is also a List, both Lists
916       * have the same size, and all corresponding pairs of elements in the two
917 <     * Lists are <em>equal</em>.  (Two elements <code>e1</code> and
918 <     * <code>e2</code> are <em>equal</em> if <code>(e1==null ? e2==null :
919 <     * e1.equals(e2))</code>.)  In other words, two Lists are defined to be
917 >     * Lists are <em>equal</em>.  (Two elements {@code e1} and
918 >     * {@code e2} are <em>equal</em> if {@code (e1==null ? e2==null :
919 >     * e1.equals(e2))}.)  In other words, two Lists are defined to be
920       * equal if they contain the same elements in the same order.
921       *
922       * @param o the Object to be compared for equality with this Vector
# Line 957 | Line 942 | public class Vector<E>
942      }
943  
944      /**
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 &lt; 0 || toIndex &gt; size)</code>
990     * @throws IllegalArgumentException endpoint indices out of order
991     *         <code>(fromIndex &gt; 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    /**
945       * Removes from this List all of the elements whose index is between
946       * fromIndex, inclusive and toIndex, exclusive.  Shifts any succeeding
947       * elements to the left (reduces their index).
948 <     * This call shortens the ArrayList by (toIndex - fromIndex) elements.  (If
948 >     * This call shortens the Vector by (toIndex - fromIndex) elements.  (If
949       * toIndex==fromIndex, this operation has no effect.)
950       *
951       * @param fromIndex index of first element to be removed
# Line 1018 | Line 964 | public class Vector<E>
964      }
965  
966      /**
967 <     * Save the state of the <tt>Vector</tt> instance to a stream (that
967 >     * Save the state of the {@code Vector} instance to a stream (that
968       * is, serialize it).  This method is present merely for synchronization.
969       * It just calls the default writeObject method.
970       */
# Line 1031 | Line 977 | public class Vector<E>
977      /**
978       * Returns a list-iterator of the elements in this list (in proper
979       * sequence), starting at the specified position in the list.
980 <     * Obeys the general contract of <tt>List.listIterator(int)</tt>.<p>
980 >     * Obeys the general contract of {@link List#listIterator(int)}.
981       *
982 <     * The list-iterator is <i>fail-fast</i>: if the list is structurally
982 >     * <p>The list-iterator is <i>fail-fast</i>: if the list is structurally
983       * modified at any time after the Iterator is created, in any way except
984 <     * through the list-iterator's own <tt>remove</tt> or <tt>add</tt>
984 >     * through the list-iterator's own {@code remove} or {@code add}
985       * methods, the list-iterator will throw a
986 <     * <tt>ConcurrentModificationException</tt>.  Thus, in the face of
986 >     * {@code ConcurrentModificationException}.  Thus, in the face of
987       * concurrent modification, the iterator fails quickly and cleanly, rather
988       * than risking arbitrary, non-deterministic behavior at an undetermined
989       * time in the future.
990       *
991       * @param index index of the first element to be returned from the
992 <     *              list-iterator (by a call to <tt>next</tt>)
993 <     * @return a ListIterator of the elements in this list (in proper
992 >     *        list-iterator (by a call to {@link ListIterator#next})
993 >     * @return a list-iterator of the elements in this list (in proper
994       *         sequence), starting at the specified position in the list
995       * @throws IndexOutOfBoundsException {@inheritDoc}
1050     * @see List#listIterator(int)
996       */
997      public synchronized ListIterator<E> listIterator(int index) {
998          if (index < 0 || index > elementCount)
999              throw new IndexOutOfBoundsException("Index: "+index);
1000 <        return new VectorIterator(index);
1000 >        return new VectorIterator(index, elementCount);
1001 >    }
1002 >
1003 >    /**
1004 >     * {@inheritDoc}
1005 >     */
1006 >    public synchronized ListIterator<E> listIterator() {
1007 >        return new VectorIterator(0, elementCount);
1008      }
1009  
1010      /**
# Line 1061 | Line 1013 | public class Vector<E>
1013       * @return an iterator over the elements in this list in proper sequence
1014       */
1015      public synchronized Iterator<E> iterator() {
1016 <        return new VectorIterator(0);
1016 >        return new VectorIterator(0, elementCount);
1017      }
1018  
1019      /**
1020 <     * A streamlined version of AbstractList.Itr.
1020 >     * Helper method to access array elements under synchronization by
1021 >     * iterators. The caller performs index check with respect to
1022 >     * expected bounds, so errors accessing the element are reported
1023 >     * as ConcurrentModificationExceptions.
1024       */
1025 <    final class VectorIterator implements ListIterator<E> {
1026 <        int cursor;           // index of next element to return;
1027 <        int lastRet;          // index of last element, or -1 if no such
1028 <        int expectedModCount; // to check for CME
1025 >    final synchronized Object iteratorGet(int index, int expectedModCount) {
1026 >        if (modCount == expectedModCount) {
1027 >            try {
1028 >                return elementData[index];
1029 >            } catch(IndexOutOfBoundsException fallThrough) {
1030 >            }
1031 >        }
1032 >        throw new ConcurrentModificationException();
1033 >    }
1034 >
1035 >    /**
1036 >     * Streamlined specialization of AbstractList version of iterator.
1037 >     * Locally perfroms bounds checks, but relies on outer Vector
1038 >     * to access elements under synchronization.
1039 >     */
1040 >    private final class VectorIterator implements ListIterator<E> {
1041 >        int cursor;              // Index of next element to return;
1042 >        int fence;               // Upper bound on cursor (cache of size())
1043 >        int lastRet;             // Index of last element, or -1 if no such
1044 >        int expectedModCount;    // To check for CME
1045  
1046 <        VectorIterator(int index) {
1047 <            cursor = index;
1048 <            lastRet = -1;
1049 <            expectedModCount = modCount;
1046 >        VectorIterator(int index, int fence) {
1047 >            this.cursor = index;
1048 >            this.fence = fence;
1049 >            this.lastRet = -1;
1050 >            this.expectedModCount = Vector.this.modCount;
1051          }
1052  
1053          public boolean hasNext() {
1054 <            // Racy but within spec and backwards-compatible
1083 <            return cursor < elementCount;
1054 >            return cursor < fence;
1055          }
1056  
1057          public boolean hasPrevious() {
# Line 1096 | Line 1067 | public class Vector<E>
1067          }
1068  
1069          public E next() {
1070 <            synchronized(Vector.this) {
1071 <                if (expectedModCount == modCount) {
1072 <                    int i = cursor;
1073 <                    if (i < elementCount) {
1074 <                        try {
1075 <                            E e = (E)elementData[i];
1076 <                            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 <            }
1070 >            int i = cursor;
1071 >            if (i >= fence)
1072 >                throw new NoSuchElementException();
1073 >            Object next = Vector.this.iteratorGet(i, expectedModCount);
1074 >            lastRet = i;
1075 >            cursor = i + 1;
1076 >            return (E)next;
1077          }
1078  
1079          public E previous() {
1080 <            synchronized(Vector.this) {
1081 <                if (expectedModCount == modCount) {
1082 <                    int i = cursor - 1;
1083 <                    if (i < elementCount) {
1084 <                        try {
1085 <                            E e = (E)elementData[i];
1086 <                            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 <            }
1080 >            int i = cursor - 1;
1081 >            if (i < 0)
1082 >                throw new NoSuchElementException();
1083 >            Object prev = Vector.this.iteratorGet(i, expectedModCount);
1084 >            lastRet = i;
1085 >            cursor = i;
1086 >            return (E)prev;
1087          }
1088  
1089 <        public void remove() {
1089 >        public void set(E e) {
1090              if (lastRet < 0)
1091                  throw new IllegalStateException();
1092 <            synchronized(Vector.this) {
1093 <                if (modCount != expectedModCount)
1094 <                    throw new ConcurrentModificationException();
1095 <                Vector.this.remove(lastRet);
1096 <                if (lastRet < cursor)
1097 <                    cursor--;
1098 <                lastRet = -1;
1099 <                expectedModCount = modCount;
1150 <            }
1092 >            if (Vector.this.modCount != expectedModCount)
1093 >                throw new ConcurrentModificationException();
1094 >            try {
1095 >                Vector.this.set(lastRet, e);
1096 >                expectedModCount = Vector.this.modCount;
1097 >            } catch (IndexOutOfBoundsException ex) {
1098 >                throw new ConcurrentModificationException();
1099 >            }
1100          }
1101  
1102 <        public void set(E e) {
1103 <            if (lastRet < 0)
1102 >        public void remove() {
1103 >            int i = lastRet;
1104 >            if (i < 0)
1105                  throw new IllegalStateException();
1106 <            synchronized(Vector.this) {
1107 <                if (modCount != expectedModCount)
1108 <                    throw new ConcurrentModificationException();
1109 <                Vector.this.set(lastRet, e);
1110 <                expectedModCount = modCount;
1111 <            }
1106 >            if (Vector.this.modCount != expectedModCount)
1107 >                throw new ConcurrentModificationException();
1108 >            try {
1109 >                Vector.this.remove(i);
1110 >                if (i < cursor)
1111 >                    cursor--;
1112 >                lastRet = -1;
1113 >                fence = Vector.this.size();
1114 >                expectedModCount = Vector.this.modCount;
1115 >            } catch (IndexOutOfBoundsException ex) {
1116 >                throw new ConcurrentModificationException();
1117 >            }
1118          }
1119  
1120          public void add(E e) {
1121 <            synchronized(Vector.this) {
1122 <                if (modCount != expectedModCount)
1123 <                    throw new ConcurrentModificationException();
1124 <                Vector.this.add(cursor++, e);
1121 >            if (Vector.this.modCount != expectedModCount)
1122 >                throw new ConcurrentModificationException();
1123 >            try {
1124 >                int i = cursor;
1125 >                Vector.this.add(i, e);
1126 >                cursor = i + 1;
1127                  lastRet = -1;
1128 <                expectedModCount = modCount;
1129 <            }
1128 >                fence = Vector.this.size();
1129 >                expectedModCount = Vector.this.modCount;
1130 >            } catch (IndexOutOfBoundsException ex) {
1131 >                throw new ConcurrentModificationException();
1132 >            }
1133          }
1134      }
1135  
1136 +    /**
1137 +     * Returns a view of the portion of this List between fromIndex,
1138 +     * inclusive, and toIndex, exclusive.  (If fromIndex and toIndex are
1139 +     * equal, the returned List is empty.)  The returned List is backed by this
1140 +     * List, so changes in the returned List are reflected in this List, and
1141 +     * vice-versa.  The returned List supports all of the optional List
1142 +     * operations supported by this List.
1143 +     *
1144 +     * <p>This method eliminates the need for explicit range operations (of
1145 +     * the sort that commonly exist for arrays).   Any operation that expects
1146 +     * a List can be used as a range operation by operating on a subList view
1147 +     * instead of a whole List.  For example, the following idiom
1148 +     * removes a range of elements from a List:
1149 +     * <pre>
1150 +     *      list.subList(from, to).clear();
1151 +     * </pre>
1152 +     * Similar idioms may be constructed for indexOf and lastIndexOf,
1153 +     * and all of the algorithms in the Collections class can be applied to
1154 +     * a subList.
1155 +     *
1156 +     * <p>The semantics of the List returned by this method become undefined if
1157 +     * the backing list (i.e., this List) is <i>structurally modified</i> in
1158 +     * any way other than via the returned List.  (Structural modifications are
1159 +     * those that change the size of the List, or otherwise perturb it in such
1160 +     * a fashion that iterations in progress may yield incorrect results.)
1161 +     *
1162 +     * @param fromIndex low endpoint (inclusive) of the subList
1163 +     * @param toIndex high endpoint (exclusive) of the subList
1164 +     * @return a view of the specified range within this List
1165 +     * @throws IndexOutOfBoundsException endpoint index value out of range
1166 +     *         <code>(fromIndex &lt; 0 || toIndex &gt; size)</code>
1167 +     * @throws IllegalArgumentException endpoint indices out of order
1168 +     *         <code>(fromIndex &gt; toIndex)</code>
1169 +     */
1170 +    public synchronized List<E> subList(int fromIndex, int toIndex) {
1171 +        return new VectorSubList(this, this, fromIndex, fromIndex, toIndex);
1172 +    }
1173 +
1174 +    /**
1175 +     * This class specializes the AbstractList version of SubList to
1176 +     * avoid the double-indirection penalty that would arise using a
1177 +     * synchronized wrapper, as well as to avoid some unnecessary
1178 +     * checks in sublist iterators.
1179 +     */
1180 +    private static final class VectorSubList<E> extends AbstractList<E> implements RandomAccess {
1181 +        final Vector<E> base;             // base list
1182 +        final AbstractList<E> parent;     // Creating list
1183 +        final int baseOffset;             // index wrt Vector
1184 +        final int parentOffset;           // index wrt parent
1185 +        int length;                       // length of sublist
1186 +
1187 +        VectorSubList(Vector<E> base, AbstractList<E> parent, int baseOffset,
1188 +                     int fromIndex, int toIndex) {
1189 +            if (fromIndex < 0)
1190 +                throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
1191 +            if (toIndex > parent.size())
1192 +                throw new IndexOutOfBoundsException("toIndex = " + toIndex);
1193 +            if (fromIndex > toIndex)
1194 +                throw new IllegalArgumentException("fromIndex(" + fromIndex +
1195 +                                                   ") > toIndex(" + toIndex + ")");
1196 +
1197 +            this.base = base;
1198 +            this.parent = parent;
1199 +            this.baseOffset = baseOffset;
1200 +            this.parentOffset = fromIndex;
1201 +            this.length = toIndex - fromIndex;
1202 +            modCount = base.modCount;
1203 +        }
1204 +
1205 +        /**
1206 +         * Returns an IndexOutOfBoundsException with nicer message
1207 +         */
1208 +        private IndexOutOfBoundsException indexError(int index) {
1209 +            return new IndexOutOfBoundsException("Index: " + index +
1210 +                                                 ", Size: " + length);
1211 +        }
1212 +
1213 +        public E set(int index, E element) {
1214 +            synchronized(base) {
1215 +                if (index < 0 || index >= length)
1216 +                    throw indexError(index);
1217 +                if (base.modCount != modCount)
1218 +                    throw new ConcurrentModificationException();
1219 +                return base.set(index + baseOffset, element);
1220 +            }
1221 +        }
1222 +
1223 +        public E get(int index) {
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.get(index + baseOffset);
1230 +            }
1231 +        }
1232 +
1233 +        public int size() {
1234 +            synchronized(base) {
1235 +                if (base.modCount != modCount)
1236 +                    throw new ConcurrentModificationException();
1237 +                return length;
1238 +            }
1239 +        }
1240 +
1241 +        public void add(int index, E element) {
1242 +            synchronized(base) {
1243 +                if (index < 0 || index > length)
1244 +                    throw indexError(index);
1245 +                if (base.modCount != modCount)
1246 +                    throw new ConcurrentModificationException();
1247 +                parent.add(index + parentOffset, element);
1248 +                length++;
1249 +                modCount = base.modCount;
1250 +            }
1251 +        }
1252 +
1253 +        public E remove(int index) {
1254 +            synchronized(base) {
1255 +                if (index < 0 || index >= length)
1256 +                    throw indexError(index);
1257 +                if (base.modCount != modCount)
1258 +                    throw new ConcurrentModificationException();
1259 +                E result = parent.remove(index + parentOffset);
1260 +                length--;
1261 +                modCount = base.modCount;
1262 +                return result;
1263 +            }
1264 +        }
1265 +
1266 +        protected void removeRange(int fromIndex, int toIndex) {
1267 +            synchronized(base) {
1268 +                if (base.modCount != modCount)
1269 +                    throw new ConcurrentModificationException();
1270 +                parent.removeRange(fromIndex + parentOffset,
1271 +                                   toIndex + parentOffset);
1272 +                length -= (toIndex-fromIndex);
1273 +                modCount = base.modCount;
1274 +            }
1275 +        }
1276 +
1277 +        public boolean addAll(Collection<? extends E> c) {
1278 +            return addAll(length, c);
1279 +        }
1280 +
1281 +        public boolean addAll(int index, Collection<? extends E> c) {
1282 +            synchronized(base) {
1283 +                if (index < 0 || index > length)
1284 +                    throw indexError(index);
1285 +                int cSize = c.size();
1286 +                if (cSize==0)
1287 +                    return false;
1288 +
1289 +                if (base.modCount != modCount)
1290 +                    throw new ConcurrentModificationException();
1291 +                parent.addAll(parentOffset + index, c);
1292 +                modCount = base.modCount;
1293 +                length += cSize;
1294 +                return true;
1295 +            }
1296 +        }
1297 +
1298 +        public boolean equals(Object o) {
1299 +            synchronized(base) {return super.equals(o);}
1300 +        }
1301 +
1302 +        public int hashCode() {
1303 +            synchronized(base) {return super.hashCode();}
1304 +        }
1305 +
1306 +        public int indexOf(Object o) {
1307 +            synchronized(base) {return super.indexOf(o);}
1308 +        }
1309 +
1310 +        public int lastIndexOf(Object o) {
1311 +            synchronized(base) {return super.lastIndexOf(o);}
1312 +        }
1313 +
1314 +        public List<E> subList(int fromIndex, int toIndex) {
1315 +            return new VectorSubList(base, this, fromIndex + baseOffset,
1316 +                                     fromIndex, toIndex);
1317 +        }
1318 +
1319 +        public Iterator<E> iterator() {
1320 +            synchronized(base) {
1321 +                return new VectorSubListIterator(this, 0);
1322 +            }
1323 +        }
1324 +
1325 +        public synchronized ListIterator<E> listIterator() {
1326 +            synchronized(base) {
1327 +                return new VectorSubListIterator(this, 0);
1328 +            }
1329 +        }
1330 +
1331 +        public ListIterator<E> listIterator(int index) {
1332 +            synchronized(base) {
1333 +                if (index < 0 || index > length)
1334 +                    throw indexError(index);
1335 +                return new VectorSubListIterator(this, index);
1336 +            }
1337 +        }
1338 +
1339 +        /**
1340 +         * Same idea as VectorIterator, except routing structural
1341 +         * change operations through the sublist.
1342 +         */
1343 +        private static final class VectorSubListIterator<E> implements ListIterator<E> {
1344 +            final Vector<E> base;         // base list
1345 +            final VectorSubList<E> outer; // Sublist creating this iteraor
1346 +            final int offset;             // cursor offset wrt base
1347 +            int cursor;                   // Current index
1348 +            int fence;                    // Upper bound on cursor
1349 +            int lastRet;                  // Index of returned element, or -1
1350 +            int expectedModCount;         // Expected modCount of base Vector
1351 +
1352 +            VectorSubListIterator(VectorSubList<E> list, int index) {
1353 +                this.lastRet = -1;
1354 +                this.cursor = index;
1355 +                this.outer = list;
1356 +                this.offset = list.baseOffset;
1357 +                this.fence = list.length;
1358 +                this.base = list.base;
1359 +                this.expectedModCount = base.modCount;
1360 +            }
1361 +
1362 +            public boolean hasNext() {
1363 +                return cursor < fence;
1364 +            }
1365 +
1366 +            public boolean hasPrevious() {
1367 +                return cursor > 0;
1368 +            }
1369 +
1370 +            public int nextIndex() {
1371 +                return cursor;
1372 +            }
1373 +
1374 +            public int previousIndex() {
1375 +                return cursor - 1;
1376 +            }
1377 +
1378 +            public E next() {
1379 +                int i = cursor;
1380 +                if (cursor >= fence)
1381 +                    throw new NoSuchElementException();
1382 +                Object next = base.iteratorGet(i + offset, expectedModCount);
1383 +                lastRet = i;
1384 +                cursor = i + 1;
1385 +                return (E)next;
1386 +            }
1387 +
1388 +            public E previous() {
1389 +                int i = cursor - 1;
1390 +                if (i < 0)
1391 +                    throw new NoSuchElementException();
1392 +                Object prev = base.iteratorGet(i + offset, expectedModCount);
1393 +                lastRet = i;
1394 +                cursor = i;
1395 +                return (E)prev;
1396 +            }
1397 +
1398 +            public void set(E e) {
1399 +                if (lastRet < 0)
1400 +                    throw new IllegalStateException();
1401 +                if (base.modCount != expectedModCount)
1402 +                    throw new ConcurrentModificationException();
1403 +                try {
1404 +                    outer.set(lastRet, e);
1405 +                    expectedModCount = base.modCount;
1406 +                } catch (IndexOutOfBoundsException ex) {
1407 +                    throw new ConcurrentModificationException();
1408 +                }
1409 +            }
1410 +
1411 +            public void remove() {
1412 +                int i = lastRet;
1413 +                if (i < 0)
1414 +                    throw new IllegalStateException();
1415 +                if (base.modCount != expectedModCount)
1416 +                    throw new ConcurrentModificationException();
1417 +                try {
1418 +                    outer.remove(i);
1419 +                    if (i < cursor)
1420 +                        cursor--;
1421 +                    lastRet = -1;
1422 +                    fence = outer.length;
1423 +                    expectedModCount = base.modCount;
1424 +                } catch (IndexOutOfBoundsException ex) {
1425 +                    throw new ConcurrentModificationException();
1426 +                }
1427 +            }
1428 +
1429 +            public void add(E e) {
1430 +                if (base.modCount != expectedModCount)
1431 +                    throw new ConcurrentModificationException();
1432 +                try {
1433 +                    int i = cursor;
1434 +                    outer.add(i, e);
1435 +                    cursor = i + 1;
1436 +                    lastRet = -1;
1437 +                    fence = outer.length;
1438 +                    expectedModCount = base.modCount;
1439 +                } catch (IndexOutOfBoundsException ex) {
1440 +                    throw new ConcurrentModificationException();
1441 +                }
1442 +            }
1443 +        }
1444 +    }
1445   }
1446 +
1447 +
1448 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines