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.10 by dl, Wed Apr 19 15:07:14 2006 UTC vs.
Revision 1.21 by jsr166, Sun May 20 07:54:01 2007 UTC

# Line 1 | Line 1
1   /*
2 < * @(#)Vector.java      1.103 05/12/06
2 > * Copyright 1994-2006 Sun Microsystems, Inc.  All Rights Reserved.
3 > * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4   *
5 < * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
6 < * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
5 > * This code is free software; you can redistribute it and/or modify it
6 > * under the terms of the GNU General Public License version 2 only, as
7 > * published by the Free Software Foundation.  Sun designates this
8 > * particular file as subject to the "Classpath" exception as provided
9 > * by Sun in the LICENSE file that accompanied this code.
10 > *
11 > * This code is distributed in the hope that it will be useful, but WITHOUT
12 > * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 > * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 > * version 2 for more details (a copy is included in the LICENSE file that
15 > * accompanied this code).
16 > *
17 > * You should have received a copy of the GNU General Public License version
18 > * 2 along with this work; if not, write to the Free Software Foundation,
19 > * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 > *
21 > * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 > * CA 95054 USA or visit www.sun.com if you need additional information or
23 > * have any questions.
24   */
25  
26   package java.util;
27  
28   /**
29 < * The <code>Vector</code> class implements a growable array of
29 > * The {@code Vector} class implements a growable array of
30   * objects. Like an array, it contains components that can be
31   * accessed using an integer index. However, the size of a
32 < * <code>Vector</code> can grow or shrink as needed to accommodate
33 < * adding and removing items after the <code>Vector</code> has been created.
32 > * {@code Vector} can grow or shrink as needed to accommodate
33 > * adding and removing items after the {@code Vector} has been created.
34   *
35   * <p>Each vector tries to optimize storage management by maintaining a
36 < * <code>capacity</code> and a <code>capacityIncrement</code>. The
37 < * <code>capacity</code> is always at least as large as the vector
36 > * {@code capacity} and a {@code capacityIncrement}. The
37 > * {@code capacity} is always at least as large as the vector
38   * size; it is usually larger because as components are added to the
39   * vector, the vector's storage increases in chunks the size of
40 < * <code>capacityIncrement</code>. An application can increase the
40 > * {@code capacityIncrement}. An application can increase the
41   * capacity of a vector before inserting a large number of
42   * components; this reduces the amount of incremental reallocation.
43   *
# Line 36 | Line 54 | package java.util;
54   * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
55   * as it is, generally speaking, impossible to make any hard guarantees in the
56   * presence of unsynchronized concurrent modification.  Fail-fast iterators
57 < * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
57 > * throw {@code ConcurrentModificationException} on a best-effort basis.
58   * Therefore, it would be wrong to write a program that depended on this
59   * exception for its correctness:  <i>the fail-fast behavior of iterators
60   * should be used only to detect bugs.</i>
61   *
62   * <p>As of the Java 2 platform v1.2, this class was retrofitted to
63   * implement the {@link List} interface, making it a member of the
64 < * <a href="{@docRoot}/../guide/collections/index.html"> Java
64 > * <a href="{@docRoot}/../technotes/guides/collections/index.html"> Java
65   * Collections Framework</a>.  Unlike the new collection
66   * implementations, {@code Vector} is synchronized.
67   *
68   * @author  Lee Boynton
69   * @author  Jonathan Payne
70 < * @version 1.103, 12/06/05
70 > * @version %I%, %G%
71   * @see Collection
72   * @see List
73   * @see ArrayList
# Line 63 | Line 81 | public class Vector<E>
81      /**
82       * The array buffer into which the components of the vector are
83       * stored. The capacity of the vector is the length of this array buffer,
84 <     * and is at least large enough to contain all the vector's elements.<p>
84 >     * and is at least large enough to contain all the vector's elements.
85       *
86 <     * Any array elements following the last element in the Vector are null.
86 >     * <p>Any array elements following the last element in the Vector are null.
87       *
88       * @serial
89       */
90      protected Object[] elementData;
91  
92      /**
93 <     * The number of valid components in this <tt>Vector</tt> object.
94 <     * Components <tt>elementData[0]</tt> through
95 <     * <tt>elementData[elementCount-1]</tt> are the actual items.
93 >     * The number of valid components in this {@code Vector} object.
94 >     * Components {@code elementData[0]} through
95 >     * {@code elementData[elementCount-1]} are the actual items.
96       *
97       * @serial
98       */
# Line 100 | Line 118 | public class Vector<E>
118       * @param   initialCapacity     the initial capacity of the vector
119       * @param   capacityIncrement   the amount by which the capacity is
120       *                              increased when the vector overflows
121 <     * @exception IllegalArgumentException if the specified initial capacity
122 <     *               is negative
121 >     * @throws IllegalArgumentException if the specified initial capacity
122 >     *         is negative
123       */
124      public Vector(int initialCapacity, int capacityIncrement) {
125          super();
# Line 117 | Line 135 | public class Vector<E>
135       * with its capacity increment equal to zero.
136       *
137       * @param   initialCapacity   the initial capacity of the vector
138 <     * @exception IllegalArgumentException if the specified initial capacity
139 <     *               is negative
138 >     * @throws IllegalArgumentException if the specified initial capacity
139 >     *         is negative
140       */
141      public Vector(int initialCapacity) {
142          this(initialCapacity, 0);
# Line 126 | Line 144 | public class Vector<E>
144  
145      /**
146       * Constructs an empty vector so that its internal data array
147 <     * has size <tt>10</tt> and its standard capacity increment is
147 >     * has size {@code 10} and its standard capacity increment is
148       * zero.
149       */
150      public Vector() {
# Line 153 | Line 171 | public class Vector<E>
171  
172      /**
173       * Copies the components of this vector into the specified array.
174 <     * The item at index <tt>k</tt> in this vector is copied into
175 <     * component <tt>k</tt> of <tt>anArray</tt>.
174 >     * The item at index {@code k} in this vector is copied into
175 >     * component {@code k} of {@code anArray}.
176       *
177       * @param  anArray the array into which the components get copied
178       * @throws NullPointerException if the given array is null
# Line 172 | Line 190 | public class Vector<E>
190       * Trims the capacity of this vector to be the vector's current
191       * size. If the capacity of this vector is larger than its current
192       * size, then the capacity is changed to equal the size by replacing
193 <     * its internal data array, kept in the field <tt>elementData</tt>,
193 >     * its internal data array, kept in the field {@code elementData},
194       * with a smaller one. An application can use this operation to
195       * minimize the storage of a vector.
196       */
# Line 190 | Line 208 | public class Vector<E>
208       * the minimum capacity argument.
209       *
210       * <p>If the current capacity of this vector is less than
211 <     * <tt>minCapacity</tt>, then its capacity is increased by replacing its
212 <     * internal data array, kept in the field <tt>elementData</tt>, with a
211 >     * {@code minCapacity}, then its capacity is increased by replacing its
212 >     * internal data array, kept in the field {@code elementData}, with a
213       * larger one.  The size of the new data array will be the old size plus
214 <     * <tt>capacityIncrement</tt>, unless the value of
215 <     * <tt>capacityIncrement</tt> is less than or equal to zero, in which case
214 >     * {@code capacityIncrement}, unless the value of
215 >     * {@code capacityIncrement} is less than or equal to zero, in which case
216       * the new capacity will be twice the old capacity; but if this new size
217 <     * is still smaller than <tt>minCapacity</tt>, then the new capacity will
218 <     * be <tt>minCapacity</tt>.
217 >     * is still smaller than {@code minCapacity}, then the new capacity will
218 >     * be {@code minCapacity}.
219       *
220       * @param minCapacity the desired minimum capacity
221       */
# Line 212 | Line 230 | public class Vector<E>
230       * method for ensuring capacity without incurring the cost of an
231       * extra synchronization.
232       *
233 <     * @see java.util.Vector#ensureCapacity(int)
233 >     * @see #ensureCapacity(int)
234       */
235      private void ensureCapacityHelper(int minCapacity) {
236          int oldCapacity = elementData.length;
# Line 229 | Line 247 | public class Vector<E>
247  
248      /**
249       * Sets the size of this vector. If the new size is greater than the
250 <     * current size, new <code>null</code> items are added to the end of
250 >     * current size, new {@code null} items are added to the end of
251       * the vector. If the new size is less than the current size, all
252 <     * components at index <code>newSize</code> and greater are discarded.
252 >     * components at index {@code newSize} and greater are discarded.
253       *
254 <     * @param   newSize   the new size of this vector
255 <     * @throws  ArrayIndexOutOfBoundsException if new size is negative
254 >     * @param  newSize   the new size of this vector
255 >     * @throws ArrayIndexOutOfBoundsException if the new size is negative
256       */
257      public synchronized void setSize(int newSize) {
258          modCount++;
# Line 252 | Line 270 | public class Vector<E>
270       * Returns the current capacity of this vector.
271       *
272       * @return  the current capacity (the length of its internal
273 <     *          data array, kept in the field <tt>elementData</tt>
273 >     *          data array, kept in the field {@code elementData}
274       *          of this vector)
275       */
276      public synchronized int capacity() {
# Line 271 | Line 289 | public class Vector<E>
289      /**
290       * Tests if this vector has no components.
291       *
292 <     * @return  <code>true</code> if and only if this vector has
292 >     * @return  {@code true} if and only if this vector has
293       *          no components, that is, its size is zero;
294 <     *          <code>false</code> otherwise.
294 >     *          {@code false} otherwise.
295       */
296      public synchronized boolean isEmpty() {
297          return elementCount == 0;
# Line 281 | Line 299 | public class Vector<E>
299  
300      /**
301       * Returns an enumeration of the components of this vector. The
302 <     * returned <tt>Enumeration</tt> object will generate all items in
303 <     * this vector. The first item generated is the item at index <tt>0</tt>,
304 <     * then the item at index <tt>1</tt>, and so on.
302 >     * returned {@code Enumeration} object will generate all items in
303 >     * this vector. The first item generated is the item at index {@code 0},
304 >     * then the item at index {@code 1}, and so on.
305       *
306       * @return  an enumeration of the components of this vector
289     * @see     Enumeration
307       * @see     Iterator
308       */
309      public Enumeration<E> elements() {
# Line 309 | Line 326 | public class Vector<E>
326      }
327  
328      /**
329 <     * Returns <tt>true</tt> if this vector contains the specified element.
330 <     * More formally, returns <tt>true</tt> if and only if this vector
331 <     * contains at least one element <tt>e</tt> such that
329 >     * Returns {@code true} if this vector contains the specified element.
330 >     * More formally, returns {@code true} if and only if this vector
331 >     * contains at least one element {@code e} such that
332       * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
333       *
334       * @param o element whose presence in this vector is to be tested
335 <     * @return <tt>true</tt> if this vector contains the specified element
335 >     * @return {@code true} if this vector contains the specified element
336       */
337      public boolean contains(Object o) {
338          return indexOf(o, 0) >= 0;
# Line 324 | Line 341 | public class Vector<E>
341      /**
342       * Returns the index of the first occurrence of the specified element
343       * in this vector, or -1 if this vector does not contain the element.
344 <     * More formally, returns the lowest index <tt>i</tt> such that
344 >     * More formally, returns the lowest index {@code i} such that
345       * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
346       * or -1 if there is no such index.
347       *
# Line 338 | Line 355 | public class Vector<E>
355  
356      /**
357       * Returns the index of the first occurrence of the specified element in
358 <     * this vector, searching forwards from <tt>index</tt>, or returns -1 if
358 >     * this vector, searching forwards from {@code index}, or returns -1 if
359       * the element is not found.
360 <     * More formally, returns the lowest index <tt>i</tt> such that
360 >     * More formally, returns the lowest index {@code i} such that
361       * <tt>(i&nbsp;&gt;=&nbsp;index&nbsp;&amp;&amp;&nbsp;(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i))))</tt>,
362       * or -1 if there is no such index.
363       *
364       * @param o element to search for
365       * @param index index to start searching from
366       * @return the index of the first occurrence of the element in
367 <     *         this vector at position <tt>index</tt> or later in the vector;
368 <     *         <tt>-1</tt> if the element is not found.
367 >     *         this vector at position {@code index} or later in the vector;
368 >     *         {@code -1} if the element is not found.
369       * @throws IndexOutOfBoundsException if the specified index is negative
370       * @see     Object#equals(Object)
371       */
# Line 368 | Line 385 | public class Vector<E>
385      /**
386       * Returns the index of the last occurrence of the specified element
387       * in this vector, or -1 if this vector does not contain the element.
388 <     * More formally, returns the highest index <tt>i</tt> such that
388 >     * More formally, returns the highest index {@code i} such that
389       * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
390       * or -1 if there is no such index.
391       *
# Line 382 | Line 399 | public class Vector<E>
399  
400      /**
401       * Returns the index of the last occurrence of the specified element in
402 <     * this vector, searching backwards from <tt>index</tt>, or returns -1 if
402 >     * this vector, searching backwards from {@code index}, or returns -1 if
403       * the element is not found.
404 <     * More formally, returns the highest index <tt>i</tt> such that
404 >     * More formally, returns the highest index {@code i} such that
405       * <tt>(i&nbsp;&lt;=&nbsp;index&nbsp;&amp;&amp;&nbsp;(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i))))</tt>,
406       * or -1 if there is no such index.
407       *
408       * @param o element to search for
409       * @param index index to start searching backwards from
410       * @return the index of the last occurrence of the element at position
411 <     *         less than or equal to <tt>index</tt> in this vector;
411 >     *         less than or equal to {@code index} in this vector;
412       *         -1 if the element is not found.
413       * @throws IndexOutOfBoundsException if the specified index is greater
414       *         than or equal to the current size of this vector
# Line 413 | Line 430 | public class Vector<E>
430      }
431  
432      /**
433 <     * Returns the component at the specified index.<p>
433 >     * Returns the component at the specified index.
434       *
435 <     * This method is identical in functionality to the get method
436 <     * (which is part of the List interface).
435 >     * <p>This method is identical in functionality to the {@link #get(int)}
436 >     * method (which is part of the {@link List} interface).
437       *
438       * @param      index   an index into this vector
439       * @return     the component at the specified index
440 <     * @exception  ArrayIndexOutOfBoundsException  if the <tt>index</tt>
441 <     *             is negative or not less than the current size of this
425 <     *             <tt>Vector</tt> object.
426 <     * @see        #get(int)
427 <     * @see        List
440 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
441 >     *         ({@code index < 0 || index >= size()})
442       */
443      public synchronized E elementAt(int index) {
444          if (index >= elementCount) {
# Line 435 | Line 449 | public class Vector<E>
449      }
450  
451      /**
452 <     * Returns the first component (the item at index <tt>0</tt>) of
452 >     * Returns the first component (the item at index {@code 0}) of
453       * this vector.
454       *
455       * @return     the first component of this vector
456 <     * @exception  NoSuchElementException  if this vector has no components
456 >     * @throws NoSuchElementException if this vector has no components
457       */
458      public synchronized E firstElement() {
459          if (elementCount == 0) {
# Line 453 | Line 467 | public class Vector<E>
467       *
468       * @return  the last component of the vector, i.e., the component at index
469       *          <code>size()&nbsp;-&nbsp;1</code>.
470 <     * @exception  NoSuchElementException  if this vector is empty
470 >     * @throws NoSuchElementException if this vector is empty
471       */
472      public synchronized E lastElement() {
473          if (elementCount == 0) {
# Line 463 | Line 477 | public class Vector<E>
477      }
478  
479      /**
480 <     * Sets the component at the specified <code>index</code> of this
480 >     * Sets the component at the specified {@code index} of this
481       * vector to be the specified object. The previous component at that
482 <     * position is discarded.<p>
482 >     * position is discarded.
483       *
484 <     * The index must be a value greater than or equal to <code>0</code>
485 <     * and less than the current size of the vector. <p>
484 >     * <p>The index must be a value greater than or equal to {@code 0}
485 >     * and less than the current size of the vector.
486       *
487 <     * This method is identical in functionality to the set method
488 <     * (which is part of the List interface). Note that the set method reverses
489 <     * the order of the parameters, to more closely match array usage.  Note
490 <     * also that the set method returns the old value that was stored at the
491 <     * specified position.
487 >     * <p>This method is identical in functionality to the
488 >     * {@link #set(int, Object) set(int, E)}
489 >     * method (which is part of the {@link List} interface). Note that the
490 >     * {@code set} method reverses the order of the parameters, to more closely
491 >     * match array usage.  Note also that the {@code set} method returns the
492 >     * old value that was stored at the specified position.
493       *
494       * @param      obj     what the component is to be set to
495       * @param      index   the specified index
496 <     * @exception  ArrayIndexOutOfBoundsException  if the index was invalid
497 <     * @see        #size()
483 <     * @see        List
484 <     * @see        #set(int, java.lang.Object)
496 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
497 >     *         ({@code index < 0 || index >= size()})
498       */
499      public synchronized void setElementAt(E obj, int index) {
500          if (index >= elementCount) {
# Line 494 | Line 507 | public class Vector<E>
507      /**
508       * Deletes the component at the specified index. Each component in
509       * this vector with an index greater or equal to the specified
510 <     * <code>index</code> is shifted downward to have an index one
510 >     * {@code index} is shifted downward to have an index one
511       * smaller than the value it had previously. The size of this vector
512 <     * is decreased by <tt>1</tt>.<p>
512 >     * is decreased by {@code 1}.
513       *
514 <     * The index must be a value greater than or equal to <code>0</code>
515 <     * and less than the current size of the vector. <p>
514 >     * <p>The index must be a value greater than or equal to {@code 0}
515 >     * and less than the current size of the vector.
516       *
517 <     * This method is identical in functionality to the remove method
518 <     * (which is part of the List interface).  Note that the remove method
519 <     * returns the old value that was stored at the specified position.
517 >     * <p>This method is identical in functionality to the {@link #remove(int)}
518 >     * method (which is part of the {@link List} interface).  Note that the
519 >     * {@code remove} method returns the old value that was stored at the
520 >     * specified position.
521       *
522       * @param      index   the index of the object to remove
523 <     * @exception  ArrayIndexOutOfBoundsException  if the index was invalid
524 <     * @see        #size()
511 <     * @see        #remove(int)
512 <     * @see        List
523 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
524 >     *         ({@code index < 0 || index >= size()})
525       */
526      public synchronized void removeElementAt(int index) {
527          modCount++;
# Line 530 | Line 542 | public class Vector<E>
542  
543      /**
544       * Inserts the specified object as a component in this vector at the
545 <     * specified <code>index</code>. Each component in this vector with
546 <     * an index greater or equal to the specified <code>index</code> is
545 >     * specified {@code index}. Each component in this vector with
546 >     * an index greater or equal to the specified {@code index} is
547       * shifted upward to have an index one greater than the value it had
548 <     * previously. <p>
548 >     * previously.
549       *
550 <     * The index must be a value greater than or equal to <code>0</code>
550 >     * <p>The index must be a value greater than or equal to {@code 0}
551       * and less than or equal to the current size of the vector. (If the
552       * index is equal to the current size of the vector, the new element
553 <     * is appended to the Vector.)<p>
553 >     * is appended to the Vector.)
554       *
555 <     * This method is identical in functionality to the add(Object, int) method
556 <     * (which is part of the List interface). Note that the add method reverses
557 <     * the order of the parameters, to more closely match array usage.
555 >     * <p>This method is identical in functionality to the
556 >     * {@link #add(int, Object) add(int, E)}
557 >     * method (which is part of the {@link List} interface).  Note that the
558 >     * {@code add} method reverses the order of the parameters, to more closely
559 >     * match array usage.
560       *
561       * @param      obj     the component to insert
562       * @param      index   where to insert the new component
563 <     * @exception  ArrayIndexOutOfBoundsException  if the index was invalid
564 <     * @see        #size()
551 <     * @see        #add(int, Object)
552 <     * @see        List
563 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
564 >     *         ({@code index < 0 || index > size()})
565       */
566      public synchronized void insertElementAt(E obj, int index) {
567          modCount++;
# Line 566 | Line 578 | public class Vector<E>
578      /**
579       * Adds the specified component to the end of this vector,
580       * increasing its size by one. The capacity of this vector is
581 <     * increased if its size becomes greater than its capacity. <p>
581 >     * increased if its size becomes greater than its capacity.
582       *
583 <     * This method is identical in functionality to the add(Object) method
584 <     * (which is part of the List interface).
583 >     * <p>This method is identical in functionality to the
584 >     * {@link #add(Object) add(E)}
585 >     * method (which is part of the {@link List} interface).
586       *
587       * @param   obj   the component to be added
575     * @see        #add(Object)
576     * @see        List
588       */
589      public synchronized void addElement(E obj) {
590          modCount++;
# Line 586 | Line 597 | public class Vector<E>
597       * from this vector. If the object is found in this vector, each
598       * component in the vector with an index greater or equal to the
599       * object's index is shifted downward to have an index one smaller
600 <     * than the value it had previously.<p>
600 >     * than the value it had previously.
601       *
602 <     * This method is identical in functionality to the remove(Object)
603 <     * method (which is part of the List interface).
602 >     * <p>This method is identical in functionality to the
603 >     * {@link #remove(Object)} method (which is part of the
604 >     * {@link List} interface).
605       *
606       * @param   obj   the component to be removed
607 <     * @return  <code>true</code> if the argument was a component of this
608 <     *          vector; <code>false</code> otherwise.
597 <     * @see     List#remove(Object)
598 <     * @see     List
607 >     * @return  {@code true} if the argument was a component of this
608 >     *          vector; {@code false} otherwise.
609       */
610      public synchronized boolean removeElement(Object obj) {
611          modCount++;
# Line 608 | Line 618 | public class Vector<E>
618      }
619  
620      /**
621 <     * Removes all components from this vector and sets its size to zero.<p>
621 >     * Removes all components from this vector and sets its size to zero.
622       *
623 <     * This method is identical in functionality to the clear method
624 <     * (which is part of the List interface).
615 <     *
616 <     * @see     #clear
617 <     * @see     List
623 >     * <p>This method is identical in functionality to the {@link #clear}
624 >     * method (which is part of the {@link List} interface).
625       */
626      public synchronized void removeAllElements() {
627          modCount++;
# Line 628 | Line 635 | public class Vector<E>
635      /**
636       * Returns a clone of this vector. The copy will contain a
637       * reference to a clone of the internal data array, not a reference
638 <     * to the original internal data array of this <tt>Vector</tt> object.
638 >     * to the original internal data array of this {@code Vector} object.
639       *
640       * @return  a clone of this vector
641       */
# Line 659 | Line 666 | public class Vector<E>
666       * correct order; the runtime type of the returned array is that of the
667       * specified array.  If the Vector fits in the specified array, it is
668       * returned therein.  Otherwise, a new array is allocated with the runtime
669 <     * type of the specified array and the size of this Vector.<p>
669 >     * type of the specified array and the size of this Vector.
670       *
671 <     * If the Vector fits in the specified array with room to spare
671 >     * <p>If the Vector fits in the specified array with room to spare
672       * (i.e., the array has more elements than the Vector),
673       * the element in the array immediately following the end of the
674       * Vector is set to null.  (This is useful in determining the length
# Line 672 | Line 679 | public class Vector<E>
679       *          be stored, if it is big enough; otherwise, a new array of the
680       *          same runtime type is allocated for this purpose.
681       * @return an array containing the elements of the Vector
682 <     * @exception ArrayStoreException the runtime type of a is not a supertype
682 >     * @throws ArrayStoreException if the runtime type of a is not a supertype
683       * of the runtime type of every element in this Vector
684       * @throws NullPointerException if the given array is null
685       * @since 1.2
# Line 696 | Line 703 | public class Vector<E>
703       *
704       * @param index index of the element to return
705       * @return object at the specified index
706 <     * @exception ArrayIndexOutOfBoundsException index is out of range (index
707 <     *            &lt; 0 || index &gt;= size())
706 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
707 >     *            ({@code index < 0 || index >= size()})
708       * @since 1.2
709       */
710      public synchronized E get(int index) {
# Line 714 | Line 721 | public class Vector<E>
721       * @param index index of the element to replace
722       * @param element element to be stored at the specified position
723       * @return the element previously at the specified position
724 <     * @exception ArrayIndexOutOfBoundsException index out of range
725 <     *            (index &lt; 0 || index &gt;= size())
724 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
725 >     *         ({@code index < 0 || index >= size()})
726       * @since 1.2
727       */
728      public synchronized E set(int index, E element) {
# Line 731 | Line 738 | public class Vector<E>
738       * Appends the specified element to the end of this Vector.
739       *
740       * @param e element to be appended to this Vector
741 <     * @return <tt>true</tt> (as specified by {@link Collection#add})
741 >     * @return {@code true} (as specified by {@link Collection#add})
742       * @since 1.2
743       */
744      public synchronized boolean add(E e) {
# Line 745 | Line 752 | public class Vector<E>
752       * Removes the first occurrence of the specified element in this Vector
753       * If the Vector does not contain the element, it is unchanged.  More
754       * formally, removes the element with the lowest index i such that
755 <     * <code>(o==null ? get(i)==null : o.equals(get(i)))</code> (if such
755 >     * {@code (o==null ? get(i)==null : o.equals(get(i)))} (if such
756       * an element exists).
757       *
758       * @param o element to be removed from this Vector, if present
# Line 763 | Line 770 | public class Vector<E>
770       *
771       * @param index index at which the specified element is to be inserted
772       * @param element element to be inserted
773 <     * @exception ArrayIndexOutOfBoundsException index is out of range
774 <     *            (index &lt; 0 || index &gt; size())
773 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
774 >     *         ({@code index < 0 || index > size()})
775       * @since 1.2
776       */
777      public void add(int index, E element) {
# Line 776 | Line 783 | public class Vector<E>
783       * Shifts any subsequent elements to the left (subtracts one from their
784       * indices).  Returns the element that was removed from the Vector.
785       *
786 <     * @exception ArrayIndexOutOfBoundsException index out of range (index
787 <     *            &lt; 0 || index &gt;= size())
786 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
787 >     *         ({@code index < 0 || index >= size()})
788       * @param index the index of the element to be removed
789       * @return element that was removed
790       * @since 1.2
# Line 832 | Line 839 | public class Vector<E>
839       * specified Collection is this Vector, and this Vector is nonempty.)
840       *
841       * @param c elements to be inserted into this Vector
842 <     * @return <tt>true</tt> if this Vector changed as a result of the call
842 >     * @return {@code true} if this Vector changed as a result of the call
843       * @throws NullPointerException if the specified collection is null
844       * @since 1.2
845       */
# Line 895 | Line 902 | public class Vector<E>
902       * @param index index at which to insert the first element from the
903       *              specified collection
904       * @param c elements to be inserted into this Vector
905 <     * @return <tt>true</tt> if this Vector changed as a result of the call
906 <     * @exception ArrayIndexOutOfBoundsException index out of range (index
907 <     *            &lt; 0 || index &gt; size())
905 >     * @return {@code true} if this Vector changed as a result of the call
906 >     * @throws ArrayIndexOutOfBoundsException if the index is out of range
907 >     *         ({@code index < 0 || index > size()})
908       * @throws NullPointerException if the specified collection is null
909       * @since 1.2
910       */
# Line 924 | Line 931 | public class Vector<E>
931       * Compares the specified Object with this Vector for equality.  Returns
932       * true if and only if the specified Object is also a List, both Lists
933       * have the same size, and all corresponding pairs of elements in the two
934 <     * Lists are <em>equal</em>.  (Two elements <code>e1</code> and
935 <     * <code>e2</code> are <em>equal</em> if <code>(e1==null ? e2==null :
936 <     * e1.equals(e2))</code>.)  In other words, two Lists are defined to be
934 >     * Lists are <em>equal</em>.  (Two elements {@code e1} and
935 >     * {@code e2} are <em>equal</em> if {@code (e1==null ? e2==null :
936 >     * e1.equals(e2))}.)  In other words, two Lists are defined to be
937       * equal if they contain the same elements in the same order.
938       *
939       * @param o the Object to be compared for equality with this Vector
# Line 974 | Line 981 | public class Vector<E>
981      }
982  
983      /**
984 <     * Save the state of the <tt>Vector</tt> instance to a stream (that
984 >     * Save the state of the {@code Vector} instance to a stream (that
985       * is, serialize it).  This method is present merely for synchronization.
986       * It just calls the default writeObject method.
987       */
# Line 1044 | Line 1051 | public class Vector<E>
1051  
1052      /**
1053       * Streamlined specialization of AbstractList version of iterator.
1054 <     * Locally perfroms bounds checks, but relies on outer Vector
1054 >     * Locally performs bounds checks, but relies on outer Vector
1055       * to access elements under synchronization.
1056       */
1057      private final class VectorIterator implements ListIterator<E> {
# Line 1149 | Line 1156 | public class Vector<E>
1156       * equal, the returned List is empty.)  The returned List is backed by this
1157       * List, so changes in the returned List are reflected in this List, and
1158       * vice-versa.  The returned List supports all of the optional List
1159 <     * operations supported by this List.<p>
1159 >     * operations supported by this List.
1160       *
1161 <     * This method eliminates the need for explicit range operations (of
1161 >     * <p>This method eliminates the need for explicit range operations (of
1162       * the sort that commonly exist for arrays).   Any operation that expects
1163       * a List can be used as a range operation by operating on a subList view
1164       * instead of a whole List.  For example, the following idiom
# Line 1161 | Line 1168 | public class Vector<E>
1168       * </pre>
1169       * Similar idioms may be constructed for indexOf and lastIndexOf,
1170       * and all of the algorithms in the Collections class can be applied to
1171 <     * a subList.<p>
1171 >     * a subList.
1172       *
1173 <     * The semantics of the List returned by this method become undefined if
1173 >     * <p>The semantics of the List returned by this method become undefined if
1174       * the backing list (i.e., this List) is <i>structurally modified</i> in
1175       * any way other than via the returned List.  (Structural modifications are
1176       * those that change the size of the List, or otherwise perturb it in such
# Line 1172 | Line 1179 | public class Vector<E>
1179       * @param fromIndex low endpoint (inclusive) of the subList
1180       * @param toIndex high endpoint (exclusive) of the subList
1181       * @return a view of the specified range within this List
1182 <     * @throws IndexOutOfBoundsException endpoint index value out of range
1183 <     *         <code>(fromIndex &lt; 0 || toIndex &gt; size)</code>
1184 <     * @throws IllegalArgumentException endpoint indices out of order
1185 <     *         <code>(fromIndex &gt; toIndex)</code>
1182 >     * @throws IndexOutOfBoundsException if an endpoint index value is out of range
1183 >     *         {@code (fromIndex < 0 || toIndex > size)}
1184 >     * @throws IllegalArgumentException if the endpoint indices are out of order
1185 >     *         {@code (fromIndex > toIndex)}
1186       */
1187      public synchronized List<E> subList(int fromIndex, int toIndex) {
1188          return new VectorSubList(this, this, fromIndex, fromIndex, toIndex);
# Line 1194 | Line 1201 | public class Vector<E>
1201          final int parentOffset;           // index wrt parent
1202          int length;                       // length of sublist
1203  
1204 <        VectorSubList(Vector<E> base, AbstractList<E> parent, int baseOffset,
1204 >        VectorSubList(Vector<E> base, AbstractList<E> parent, int baseOffset,
1205                       int fromIndex, int toIndex) {
1206              if (fromIndex < 0)
1207                  throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
# Line 1216 | Line 1223 | public class Vector<E>
1223           * Returns an IndexOutOfBoundsException with nicer message
1224           */
1225          private IndexOutOfBoundsException indexError(int index) {
1226 <            return new IndexOutOfBoundsException("Index: " + index +
1226 >            return new IndexOutOfBoundsException("Index: " + index +
1227                                                   ", Size: " + length);
1228          }
1229  
# Line 1277 | Line 1284 | public class Vector<E>
1284              synchronized(base) {
1285                  if (base.modCount != modCount)
1286                      throw new ConcurrentModificationException();
1287 <                parent.removeRange(fromIndex + parentOffset,
1287 >                parent.removeRange(fromIndex + parentOffset,
1288                                     toIndex + parentOffset);
1289                  length -= (toIndex-fromIndex);
1290                  modCount = base.modCount;
# Line 1295 | Line 1302 | public class Vector<E>
1302                  int cSize = c.size();
1303                  if (cSize==0)
1304                      return false;
1305 <                
1305 >
1306                  if (base.modCount != modCount)
1307                      throw new ConcurrentModificationException();
1308                  parent.addAll(parentOffset + index, c);
# Line 1322 | Line 1329 | public class Vector<E>
1329          }
1330  
1331          public List<E> subList(int fromIndex, int toIndex) {
1332 <            return new VectorSubList(base, this, fromIndex + baseOffset,
1332 >            return new VectorSubList(base, this, fromIndex + baseOffset,
1333                                       fromIndex, toIndex);
1334          }
1335  
# Line 1331 | Line 1338 | public class Vector<E>
1338                  return new VectorSubListIterator(this, 0);
1339              }
1340          }
1341 <        
1341 >
1342          public synchronized ListIterator<E> listIterator() {
1343              synchronized(base) {
1344                  return new VectorSubListIterator(this, 0);
# Line 1358 | Line 1365 | public class Vector<E>
1365              int fence;                    // Upper bound on cursor
1366              int lastRet;                  // Index of returned element, or -1
1367              int expectedModCount;         // Expected modCount of base Vector
1368 <        
1368 >
1369              VectorSubListIterator(VectorSubList<E> list, int index) {
1370                  this.lastRet = -1;
1371                  this.cursor = index;
# Line 1368 | Line 1375 | public class Vector<E>
1375                  this.base = list.base;
1376                  this.expectedModCount = base.modCount;
1377              }
1378 <        
1378 >
1379              public boolean hasNext() {
1380                  return cursor < fence;
1381              }
1382 <        
1382 >
1383              public boolean hasPrevious() {
1384                  return cursor > 0;
1385              }
1386 <        
1386 >
1387              public int nextIndex() {
1388                  return cursor;
1389              }
1390 <        
1390 >
1391              public int previousIndex() {
1392                  return cursor - 1;
1393              }
1394 <        
1394 >
1395              public E next() {
1396                  int i = cursor;
1397                  if (cursor >= fence)
# Line 1394 | Line 1401 | public class Vector<E>
1401                  cursor = i + 1;
1402                  return (E)next;
1403              }
1404 <        
1404 >
1405              public E previous() {
1406                  int i = cursor - 1;
1407                  if (i < 0)
# Line 1404 | Line 1411 | public class Vector<E>
1411                  cursor = i;
1412                  return (E)prev;
1413              }
1414 <        
1414 >
1415              public void set(E e) {
1416                  if (lastRet < 0)
1417                      throw new IllegalStateException();
# Line 1417 | Line 1424 | public class Vector<E>
1424                      throw new ConcurrentModificationException();
1425                  }
1426              }
1427 <        
1427 >
1428              public void remove() {
1429                  int i = lastRet;
1430                  if (i < 0)
# Line 1435 | Line 1442 | public class Vector<E>
1442                      throw new ConcurrentModificationException();
1443                  }
1444              }
1445 <        
1445 >
1446              public void add(E e) {
1447                  if (base.modCount != expectedModCount)
1448                      throw new ConcurrentModificationException();
# Line 1455 | Line 1462 | public class Vector<E>
1462   }
1463  
1464  
1465 <    
1465 >

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines