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.21 by jsr166, Sun May 20 07:54:01 2007 UTC vs.
Revision 1.23 by jsr166, Sun May 18 23:47:56 2008 UTC

# Line 1 | Line 1
1   /*
2 < * Copyright 1994-2006 Sun Microsystems, Inc.  All Rights Reserved.
2 > * Copyright 1994-2007 Sun Microsystems, Inc.  All Rights Reserved.
3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4   *
5   * This code is free software; you can redistribute it and/or modify it
# Line 41 | Line 41 | package java.util;
41   * capacity of a vector before inserting a large number of
42   * components; this reduces the amount of incremental reallocation.
43   *
44 < * <p>The Iterators returned by Vector's iterator and listIterator
45 < * methods are <em>fail-fast</em>: if the Vector is structurally modified
46 < * at any time after the Iterator is created, in any way except through the
47 < * Iterator's own remove or add methods, the Iterator will throw a
48 < * ConcurrentModificationException.  Thus, in the face of concurrent
49 < * modification, the Iterator fails quickly and cleanly, rather than risking
50 < * arbitrary, non-deterministic behavior at an undetermined time in the future.
51 < * The Enumerations returned by Vector's elements method are <em>not</em>
52 < * fail-fast.
44 > * <p><a name="fail-fast"/>
45 > * The iterators returned by this class's {@link #iterator() iterator} and
46 > * {@link #listIterator(int) listIterator} methods are <em>fail-fast</em>:
47 > * if the vector is structurally modified at any time after the iterator is
48 > * created, in any way except through the iterator's own
49 > * {@link ListIterator#remove() remove} or
50 > * {@link ListIterator#add(Object) add} methods, the iterator will throw a
51 > * {@link ConcurrentModificationException}.  Thus, in the face of
52 > * concurrent modification, the iterator fails quickly and cleanly, rather
53 > * than risking arbitrary, non-deterministic behavior at an undetermined
54 > * time in the future.  The {@link Enumeration Enumerations} returned by
55 > * the {@link #elements() elements} method are <em>not</em> fail-fast.
56   *
57   * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
58   * as it is, generally speaking, impossible to make any hard guarantees in the
# Line 122 | Line 125 | public class Vector<E>
125       *         is negative
126       */
127      public Vector(int initialCapacity, int capacityIncrement) {
128 <        super();
128 >        super();
129          if (initialCapacity < 0)
130              throw new IllegalArgumentException("Illegal Capacity: "+
131                                                 initialCapacity);
132 <        this.elementData = new Object[initialCapacity];
133 <        this.capacityIncrement = capacityIncrement;
132 >        this.elementData = new Object[initialCapacity];
133 >        this.capacityIncrement = capacityIncrement;
134      }
135  
136      /**
# Line 139 | Line 142 | public class Vector<E>
142       *         is negative
143       */
144      public Vector(int initialCapacity) {
145 <        this(initialCapacity, 0);
145 >        this(initialCapacity, 0);
146      }
147  
148      /**
# Line 148 | Line 151 | public class Vector<E>
151       * zero.
152       */
153      public Vector() {
154 <        this(10);
154 >        this(10);
155      }
156  
157      /**
# Line 162 | Line 165 | public class Vector<E>
165       * @since   1.2
166       */
167      public Vector(Collection<? extends E> c) {
168 <        elementData = c.toArray();
169 <        elementCount = elementData.length;
170 <        // c.toArray might (incorrectly) not return Object[] (see 6260652)
171 <        if (elementData.getClass() != Object[].class)
172 <            elementData = Arrays.copyOf(elementData, elementCount, Object[].class);
168 >        elementData = c.toArray();
169 >        elementCount = elementData.length;
170 >        // c.toArray might (incorrectly) not return Object[] (see 6260652)
171 >        if (elementData.getClass() != Object[].class)
172 >            elementData = Arrays.copyOf(elementData, elementCount, Object[].class);
173      }
174  
175      /**
# Line 183 | Line 186 | public class Vector<E>
186       * @see #toArray(Object[])
187       */
188      public synchronized void copyInto(Object[] anArray) {
189 <        System.arraycopy(elementData, 0, anArray, 0, elementCount);
189 >        System.arraycopy(elementData, 0, anArray, 0, elementCount);
190      }
191  
192      /**
# Line 195 | Line 198 | public class Vector<E>
198       * minimize the storage of a vector.
199       */
200      public synchronized void trimToSize() {
201 <        modCount++;
202 <        int oldCapacity = elementData.length;
203 <        if (elementCount < oldCapacity) {
201 >        modCount++;
202 >        int oldCapacity = elementData.length;
203 >        if (elementCount < oldCapacity) {
204              elementData = Arrays.copyOf(elementData, elementCount);
205 <        }
205 >        }
206      }
207  
208      /**
# Line 220 | Line 223 | public class Vector<E>
223       * @param minCapacity the desired minimum capacity
224       */
225      public synchronized void ensureCapacity(int minCapacity) {
226 <        modCount++;
227 <        ensureCapacityHelper(minCapacity);
226 >        modCount++;
227 >        ensureCapacityHelper(minCapacity);
228      }
229  
230      /**
# Line 233 | Line 236 | public class Vector<E>
236       * @see #ensureCapacity(int)
237       */
238      private void ensureCapacityHelper(int minCapacity) {
239 <        int oldCapacity = elementData.length;
240 <        if (minCapacity > oldCapacity) {
241 <            Object[] oldData = elementData;
242 <            int newCapacity = (capacityIncrement > 0) ?
243 <                (oldCapacity + capacityIncrement) : (oldCapacity * 2);
244 <            if (newCapacity < minCapacity) {
245 <                newCapacity = minCapacity;
246 <            }
239 >        int oldCapacity = elementData.length;
240 >        if (minCapacity > oldCapacity) {
241 >            Object[] oldData = elementData;
242 >            int newCapacity = (capacityIncrement > 0) ?
243 >                (oldCapacity + capacityIncrement) : (oldCapacity * 2);
244 >            if (newCapacity < minCapacity) {
245 >                newCapacity = minCapacity;
246 >            }
247              elementData = Arrays.copyOf(elementData, newCapacity);
248 <        }
248 >        }
249      }
250  
251      /**
# Line 255 | Line 258 | public class Vector<E>
258       * @throws ArrayIndexOutOfBoundsException if the new size is negative
259       */
260      public synchronized void setSize(int newSize) {
261 <        modCount++;
262 <        if (newSize > elementCount) {
263 <            ensureCapacityHelper(newSize);
264 <        } else {
265 <            for (int i = newSize ; i < elementCount ; i++) {
266 <                elementData[i] = null;
267 <            }
268 <        }
269 <        elementCount = newSize;
261 >        modCount++;
262 >        if (newSize > elementCount) {
263 >            ensureCapacityHelper(newSize);
264 >        } else {
265 >            for (int i = newSize ; i < elementCount ; i++) {
266 >                elementData[i] = null;
267 >            }
268 >        }
269 >        elementCount = newSize;
270      }
271  
272      /**
# Line 274 | Line 277 | public class Vector<E>
277       *          of this vector)
278       */
279      public synchronized int capacity() {
280 <        return elementData.length;
280 >        return elementData.length;
281      }
282  
283      /**
# Line 283 | Line 286 | public class Vector<E>
286       * @return  the number of components in this vector
287       */
288      public synchronized int size() {
289 <        return elementCount;
289 >        return elementCount;
290      }
291  
292      /**
# Line 294 | Line 297 | public class Vector<E>
297       *          {@code false} otherwise.
298       */
299      public synchronized boolean isEmpty() {
300 <        return elementCount == 0;
300 >        return elementCount == 0;
301      }
302  
303      /**
# Line 307 | Line 310 | public class Vector<E>
310       * @see     Iterator
311       */
312      public Enumeration<E> elements() {
313 <        return new Enumeration<E>() {
314 <            int count = 0;
313 >        return new Enumeration<E>() {
314 >            int count = 0;
315 >
316 >            public boolean hasMoreElements() {
317 >                return count < elementCount;
318 >            }
319  
320 <            public boolean hasMoreElements() {
321 <                return count < elementCount;
322 <            }
323 <
324 <            public E nextElement() {
325 <                synchronized (Vector.this) {
326 <                    if (count < elementCount) {
327 <                        return (E)elementData[count++];
328 <                    }
322 <                }
323 <                throw new NoSuchElementException("Vector Enumeration");
324 <            }
325 <        };
320 >            public E nextElement() {
321 >                synchronized (Vector.this) {
322 >                    if (count < elementCount) {
323 >                        return elementData(count++);
324 >                    }
325 >                }
326 >                throw new NoSuchElementException("Vector Enumeration");
327 >            }
328 >        };
329      }
330  
331      /**
# Line 335 | Line 338 | public class Vector<E>
338       * @return {@code true} if this vector contains the specified element
339       */
340      public boolean contains(Object o) {
341 <        return indexOf(o, 0) >= 0;
341 >        return indexOf(o, 0) >= 0;
342      }
343  
344      /**
# Line 350 | Line 353 | public class Vector<E>
353       *         this vector, or -1 if this vector does not contain the element
354       */
355      public int indexOf(Object o) {
356 <        return indexOf(o, 0);
356 >        return indexOf(o, 0);
357      }
358  
359      /**
# Line 370 | Line 373 | public class Vector<E>
373       * @see     Object#equals(Object)
374       */
375      public synchronized int indexOf(Object o, int index) {
376 <        if (o == null) {
377 <            for (int i = index ; i < elementCount ; i++)
378 <                if (elementData[i]==null)
379 <                    return i;
380 <        } else {
381 <            for (int i = index ; i < elementCount ; i++)
382 <                if (o.equals(elementData[i]))
383 <                    return i;
384 <        }
385 <        return -1;
376 >        if (o == null) {
377 >            for (int i = index ; i < elementCount ; i++)
378 >                if (elementData[i]==null)
379 >                    return i;
380 >        } else {
381 >            for (int i = index ; i < elementCount ; i++)
382 >                if (o.equals(elementData[i]))
383 >                    return i;
384 >        }
385 >        return -1;
386      }
387  
388      /**
# Line 394 | Line 397 | public class Vector<E>
397       *         this vector, or -1 if this vector does not contain the element
398       */
399      public synchronized int lastIndexOf(Object o) {
400 <        return lastIndexOf(o, elementCount-1);
400 >        return lastIndexOf(o, elementCount-1);
401      }
402  
403      /**
# Line 417 | Line 420 | public class Vector<E>
420          if (index >= elementCount)
421              throw new IndexOutOfBoundsException(index + " >= "+ elementCount);
422  
423 <        if (o == null) {
424 <            for (int i = index; i >= 0; i--)
425 <                if (elementData[i]==null)
426 <                    return i;
427 <        } else {
428 <            for (int i = index; i >= 0; i--)
429 <                if (o.equals(elementData[i]))
430 <                    return i;
431 <        }
432 <        return -1;
423 >        if (o == null) {
424 >            for (int i = index; i >= 0; i--)
425 >                if (elementData[i]==null)
426 >                    return i;
427 >        } else {
428 >            for (int i = index; i >= 0; i--)
429 >                if (o.equals(elementData[i]))
430 >                    return i;
431 >        }
432 >        return -1;
433      }
434  
435      /**
# Line 438 | Line 441 | public class Vector<E>
441       * @param      index   an index into this vector
442       * @return     the component at the specified index
443       * @throws ArrayIndexOutOfBoundsException if the index is out of range
444 <     *         ({@code index < 0 || index >= size()})
444 >     *         ({@code index < 0 || index >= size()})
445       */
446      public synchronized E elementAt(int index) {
447 <        if (index >= elementCount) {
448 <            throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
449 <        }
447 >        if (index >= elementCount) {
448 >            throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
449 >        }
450  
451 <        return (E)elementData[index];
451 >        return elementData(index);
452      }
453  
454      /**
# Line 456 | Line 459 | public class Vector<E>
459       * @throws NoSuchElementException if this vector has no components
460       */
461      public synchronized E firstElement() {
462 <        if (elementCount == 0) {
463 <            throw new NoSuchElementException();
464 <        }
465 <        return (E)elementData[0];
462 >        if (elementCount == 0) {
463 >            throw new NoSuchElementException();
464 >        }
465 >        return elementData(0);
466      }
467  
468      /**
# Line 470 | Line 473 | public class Vector<E>
473       * @throws NoSuchElementException if this vector is empty
474       */
475      public synchronized E lastElement() {
476 <        if (elementCount == 0) {
477 <            throw new NoSuchElementException();
478 <        }
479 <        return (E)elementData[elementCount - 1];
476 >        if (elementCount == 0) {
477 >            throw new NoSuchElementException();
478 >        }
479 >        return elementData(elementCount - 1);
480      }
481  
482      /**
# Line 494 | Line 497 | public class Vector<E>
497       * @param      obj     what the component is to be set to
498       * @param      index   the specified index
499       * @throws ArrayIndexOutOfBoundsException if the index is out of range
500 <     *         ({@code index < 0 || index >= size()})
500 >     *         ({@code index < 0 || index >= size()})
501       */
502      public synchronized void setElementAt(E obj, int index) {
503 <        if (index >= elementCount) {
504 <            throw new ArrayIndexOutOfBoundsException(index + " >= " +
505 <                                                     elementCount);
506 <        }
507 <        elementData[index] = obj;
503 >        if (index >= elementCount) {
504 >            throw new ArrayIndexOutOfBoundsException(index + " >= " +
505 >                                                     elementCount);
506 >        }
507 >        elementData[index] = obj;
508      }
509  
510      /**
# Line 521 | Line 524 | public class Vector<E>
524       *
525       * @param      index   the index of the object to remove
526       * @throws ArrayIndexOutOfBoundsException if the index is out of range
527 <     *         ({@code index < 0 || index >= size()})
527 >     *         ({@code index < 0 || index >= size()})
528       */
529      public synchronized void removeElementAt(int index) {
530 <        modCount++;
531 <        if (index >= elementCount) {
532 <            throw new ArrayIndexOutOfBoundsException(index + " >= " +
533 <                                                     elementCount);
534 <        }
535 <        else if (index < 0) {
536 <            throw new ArrayIndexOutOfBoundsException(index);
537 <        }
538 <        int j = elementCount - index - 1;
539 <        if (j > 0) {
540 <            System.arraycopy(elementData, index + 1, elementData, index, j);
541 <        }
542 <        elementCount--;
543 <        elementData[elementCount] = null; /* to let gc do its work */
530 >        modCount++;
531 >        if (index >= elementCount) {
532 >            throw new ArrayIndexOutOfBoundsException(index + " >= " +
533 >                                                     elementCount);
534 >        }
535 >        else if (index < 0) {
536 >            throw new ArrayIndexOutOfBoundsException(index);
537 >        }
538 >        int j = elementCount - index - 1;
539 >        if (j > 0) {
540 >            System.arraycopy(elementData, index + 1, elementData, index, j);
541 >        }
542 >        elementCount--;
543 >        elementData[elementCount] = null; /* to let gc do its work */
544      }
545  
546      /**
# Line 561 | Line 564 | public class Vector<E>
564       * @param      obj     the component to insert
565       * @param      index   where to insert the new component
566       * @throws ArrayIndexOutOfBoundsException if the index is out of range
567 <     *         ({@code index < 0 || index > size()})
567 >     *         ({@code index < 0 || index > size()})
568       */
569      public synchronized void insertElementAt(E obj, int index) {
570 <        modCount++;
571 <        if (index > elementCount) {
572 <            throw new ArrayIndexOutOfBoundsException(index
573 <                                                     + " > " + elementCount);
574 <        }
575 <        ensureCapacityHelper(elementCount + 1);
576 <        System.arraycopy(elementData, index, elementData, index + 1, elementCount - index);
577 <        elementData[index] = obj;
578 <        elementCount++;
570 >        modCount++;
571 >        if (index > elementCount) {
572 >            throw new ArrayIndexOutOfBoundsException(index
573 >                                                     + " > " + elementCount);
574 >        }
575 >        ensureCapacityHelper(elementCount + 1);
576 >        System.arraycopy(elementData, index, elementData, index + 1, elementCount - index);
577 >        elementData[index] = obj;
578 >        elementCount++;
579      }
580  
581      /**
# Line 587 | Line 590 | public class Vector<E>
590       * @param   obj   the component to be added
591       */
592      public synchronized void addElement(E obj) {
593 <        modCount++;
594 <        ensureCapacityHelper(elementCount + 1);
595 <        elementData[elementCount++] = obj;
593 >        modCount++;
594 >        ensureCapacityHelper(elementCount + 1);
595 >        elementData[elementCount++] = obj;
596      }
597  
598      /**
# Line 608 | Line 611 | public class Vector<E>
611       *          vector; {@code false} otherwise.
612       */
613      public synchronized boolean removeElement(Object obj) {
614 <        modCount++;
615 <        int i = indexOf(obj);
616 <        if (i >= 0) {
617 <            removeElementAt(i);
618 <            return true;
619 <        }
620 <        return false;
614 >        modCount++;
615 >        int i = indexOf(obj);
616 >        if (i >= 0) {
617 >            removeElementAt(i);
618 >            return true;
619 >        }
620 >        return false;
621      }
622  
623      /**
# Line 625 | Line 628 | public class Vector<E>
628       */
629      public synchronized void removeAllElements() {
630          modCount++;
631 <        // Let gc do its work
632 <        for (int i = 0; i < elementCount; i++)
633 <            elementData[i] = null;
631 >        // Let gc do its work
632 >        for (int i = 0; i < elementCount; i++)
633 >            elementData[i] = null;
634  
635 <        elementCount = 0;
635 >        elementCount = 0;
636      }
637  
638      /**
# Line 640 | Line 643 | public class Vector<E>
643       * @return  a clone of this vector
644       */
645      public synchronized Object clone() {
646 <        try {
647 <            Vector<E> v = (Vector<E>) super.clone();
648 <            v.elementData = Arrays.copyOf(elementData, elementCount);
649 <            v.modCount = 0;
650 <            return v;
651 <        } catch (CloneNotSupportedException e) {
652 <            // this shouldn't happen, since we are Cloneable
653 <            throw new InternalError();
654 <        }
646 >        try {
647 >            @SuppressWarnings("unchecked")
648 >                Vector<E> v = (Vector<E>) super.clone();
649 >            v.elementData = Arrays.copyOf(elementData, elementCount);
650 >            v.modCount = 0;
651 >            return v;
652 >        } catch (CloneNotSupportedException e) {
653 >            // this shouldn't happen, since we are Cloneable
654 >            throw new InternalError();
655 >        }
656      }
657  
658      /**
# Line 676 | Line 680 | public class Vector<E>
680       * does not contain any null elements.)
681       *
682       * @param a the array into which the elements of the Vector are to
683 <     *          be stored, if it is big enough; otherwise, a new array of the
684 <     *          same runtime type is allocated for this purpose.
683 >     *          be stored, if it is big enough; otherwise, a new array of the
684 >     *          same runtime type is allocated for this purpose.
685       * @return an array containing the elements of the Vector
686       * @throws ArrayStoreException if the runtime type of a is not a supertype
687       * of the runtime type of every element in this Vector
688       * @throws NullPointerException if the given array is null
689       * @since 1.2
690       */
691 +    @SuppressWarnings("unchecked")
692      public synchronized <T> T[] toArray(T[] a) {
693          if (a.length < elementCount)
694              return (T[]) Arrays.copyOf(elementData, elementCount, a.getClass());
695  
696 <        System.arraycopy(elementData, 0, a, 0, elementCount);
696 >        System.arraycopy(elementData, 0, a, 0, elementCount);
697  
698          if (a.length > elementCount)
699              a[elementCount] = null;
# Line 698 | Line 703 | public class Vector<E>
703  
704      // Positional Access Operations
705  
706 +    @SuppressWarnings("unchecked")
707 +    E elementData(int index) {
708 +        return (E) elementData[index];
709 +    }
710 +
711      /**
712       * Returns the element at the specified position in this Vector.
713       *
# Line 708 | Line 718 | public class Vector<E>
718       * @since 1.2
719       */
720      public synchronized E get(int index) {
721 <        if (index >= elementCount)
722 <            throw new ArrayIndexOutOfBoundsException(index);
721 >        if (index >= elementCount)
722 >            throw new ArrayIndexOutOfBoundsException(index);
723  
724 <        return (E)elementData[index];
724 >        return elementData(index);
725      }
726  
727      /**
# Line 722 | Line 732 | public class Vector<E>
732       * @param element element to be stored at the specified position
733       * @return the element previously at the specified position
734       * @throws ArrayIndexOutOfBoundsException if the index is out of range
735 <     *         ({@code index < 0 || index >= size()})
735 >     *         ({@code index < 0 || index >= size()})
736       * @since 1.2
737       */
738      public synchronized E set(int index, E element) {
739 <        if (index >= elementCount)
740 <            throw new ArrayIndexOutOfBoundsException(index);
739 >        if (index >= elementCount)
740 >            throw new ArrayIndexOutOfBoundsException(index);
741  
742 <        Object oldValue = elementData[index];
743 <        elementData[index] = element;
744 <        return (E)oldValue;
742 >        E oldValue = elementData(index);
743 >        elementData[index] = element;
744 >        return oldValue;
745      }
746  
747      /**
# Line 742 | Line 752 | public class Vector<E>
752       * @since 1.2
753       */
754      public synchronized boolean add(E e) {
755 <        modCount++;
756 <        ensureCapacityHelper(elementCount + 1);
757 <        elementData[elementCount++] = e;
755 >        modCount++;
756 >        ensureCapacityHelper(elementCount + 1);
757 >        elementData[elementCount++] = e;
758          return true;
759      }
760  
# Line 790 | Line 800 | public class Vector<E>
800       * @since 1.2
801       */
802      public synchronized E remove(int index) {
803 <        modCount++;
804 <        if (index >= elementCount)
805 <            throw new ArrayIndexOutOfBoundsException(index);
806 <        Object oldValue = elementData[index];
807 <
808 <        int numMoved = elementCount - index - 1;
809 <        if (numMoved > 0)
810 <            System.arraycopy(elementData, index+1, elementData, index,
811 <                             numMoved);
812 <        elementData[--elementCount] = null; // Let gc do its work
803 >        modCount++;
804 >        if (index >= elementCount)
805 >            throw new ArrayIndexOutOfBoundsException(index);
806 >        E oldValue = elementData(index);
807 >
808 >        int numMoved = elementCount - index - 1;
809 >        if (numMoved > 0)
810 >            System.arraycopy(elementData, index+1, elementData, index,
811 >                             numMoved);
812 >        elementData[--elementCount] = null; // Let gc do its work
813  
814 <        return (E)oldValue;
814 >        return oldValue;
815      }
816  
817      /**
# Line 823 | Line 833 | public class Vector<E>
833       * @param   c a collection whose elements will be tested for containment
834       *          in this Vector
835       * @return true if this Vector contains all of the elements in the
836 <     *         specified collection
836 >     *         specified collection
837       * @throws NullPointerException if the specified collection is null
838       */
839      public synchronized boolean containsAll(Collection<?> c) {
# Line 844 | Line 854 | public class Vector<E>
854       * @since 1.2
855       */
856      public synchronized boolean addAll(Collection<? extends E> c) {
857 <        modCount++;
857 >        modCount++;
858          Object[] a = c.toArray();
859          int numNew = a.length;
860 <        ensureCapacityHelper(elementCount + numNew);
860 >        ensureCapacityHelper(elementCount + numNew);
861          System.arraycopy(a, 0, elementData, elementCount, numNew);
862          elementCount += numNew;
863 <        return numNew != 0;
863 >        return numNew != 0;
864      }
865  
866      /**
# Line 909 | Line 919 | public class Vector<E>
919       * @since 1.2
920       */
921      public synchronized boolean addAll(int index, Collection<? extends E> c) {
922 <        modCount++;
923 <        if (index < 0 || index > elementCount)
924 <            throw new ArrayIndexOutOfBoundsException(index);
922 >        modCount++;
923 >        if (index < 0 || index > elementCount)
924 >            throw new ArrayIndexOutOfBoundsException(index);
925  
926          Object[] a = c.toArray();
927 <        int numNew = a.length;
928 <        ensureCapacityHelper(elementCount + numNew);
927 >        int numNew = a.length;
928 >        ensureCapacityHelper(elementCount + numNew);
929  
930 <        int numMoved = elementCount - index;
931 <        if (numMoved > 0)
932 <            System.arraycopy(elementData, index, elementData, index + numNew,
933 <                             numMoved);
930 >        int numMoved = elementCount - index;
931 >        if (numMoved > 0)
932 >            System.arraycopy(elementData, index, elementData, index + numNew,
933 >                             numMoved);
934  
935          System.arraycopy(a, 0, elementData, index, numNew);
936 <        elementCount += numNew;
937 <        return numNew != 0;
936 >        elementCount += numNew;
937 >        return numNew != 0;
938      }
939  
940      /**
# Line 959 | Line 969 | public class Vector<E>
969      }
970  
971      /**
972 <     * Removes from this List all of the elements whose index is between
973 <     * fromIndex, inclusive and toIndex, exclusive.  Shifts any succeeding
974 <     * elements to the left (reduces their index).
975 <     * This call shortens the Vector by (toIndex - fromIndex) elements.  (If
976 <     * toIndex==fromIndex, this operation has no effect.)
972 >     * Returns a view of the portion of this List between fromIndex,
973 >     * inclusive, and toIndex, exclusive.  (If fromIndex and toIndex are
974 >     * equal, the returned List is empty.)  The returned List is backed by this
975 >     * List, so changes in the returned List are reflected in this List, and
976 >     * vice-versa.  The returned List supports all of the optional List
977 >     * operations supported by this List.
978 >     *
979 >     * <p>This method eliminates the need for explicit range operations (of
980 >     * the sort that commonly exist for arrays).  Any operation that expects
981 >     * a List can be used as a range operation by operating on a subList view
982 >     * instead of a whole List.  For example, the following idiom
983 >     * removes a range of elements from a List:
984 >     * <pre>
985 >     *      list.subList(from, to).clear();
986 >     * </pre>
987 >     * Similar idioms may be constructed for indexOf and lastIndexOf,
988 >     * and all of the algorithms in the Collections class can be applied to
989 >     * a subList.
990       *
991 <     * @param fromIndex index of first element to be removed
992 <     * @param toIndex index after last element to be removed
991 >     * <p>The semantics of the List returned by this method become undefined if
992 >     * the backing list (i.e., this List) is <i>structurally modified</i> in
993 >     * any way other than via the returned List.  (Structural modifications are
994 >     * those that change the size of the List, or otherwise perturb it in such
995 >     * a fashion that iterations in progress may yield incorrect results.)
996 >     *
997 >     * @param fromIndex low endpoint (inclusive) of the subList
998 >     * @param toIndex high endpoint (exclusive) of the subList
999 >     * @return a view of the specified range within this List
1000 >     * @throws IndexOutOfBoundsException if an endpoint index value is out of range
1001 >     *         {@code (fromIndex < 0 || toIndex > size)}
1002 >     * @throws IllegalArgumentException if the endpoint indices are out of order
1003 >     *         {@code (fromIndex > toIndex)}
1004 >     */
1005 >    public synchronized List<E> subList(int fromIndex, int toIndex) {
1006 >        return Collections.synchronizedList(super.subList(fromIndex, toIndex),
1007 >                                            this);
1008 >    }
1009 >
1010 >    /**
1011 >     * Removes from this list all of the elements whose index is between
1012 >     * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
1013 >     * Shifts any succeeding elements to the left (reduces their index).
1014 >     * This call shortens the list by {@code (toIndex - fromIndex)} elements.
1015 >     * (If {@code toIndex==fromIndex}, this operation has no effect.)
1016       */
1017      protected synchronized void removeRange(int fromIndex, int toIndex) {
1018 <        modCount++;
1019 <        int numMoved = elementCount - toIndex;
1018 >        modCount++;
1019 >        int numMoved = elementCount - toIndex;
1020          System.arraycopy(elementData, toIndex, elementData, fromIndex,
1021                           numMoved);
1022  
1023 <        // Let gc do its work
1024 <        int newElementCount = elementCount - (toIndex-fromIndex);
1025 <        while (elementCount != newElementCount)
1026 <            elementData[--elementCount] = null;
1023 >        // Let gc do its work
1024 >        int newElementCount = elementCount - (toIndex-fromIndex);
1025 >        while (elementCount != newElementCount)
1026 >            elementData[--elementCount] = null;
1027      }
1028  
1029      /**
# Line 988 | Line 1034 | public class Vector<E>
1034      private synchronized void writeObject(java.io.ObjectOutputStream s)
1035          throws java.io.IOException
1036      {
1037 <        s.defaultWriteObject();
1037 >        s.defaultWriteObject();
1038      }
1039  
1040      /**
1041 <     * Returns a list-iterator of the elements in this list (in proper
1041 >     * Returns a list iterator over the elements in this list (in proper
1042       * sequence), starting at the specified position in the list.
1043 <     * Obeys the general contract of {@link List#listIterator(int)}.
1043 >     * The specified index indicates the first element that would be
1044 >     * returned by an initial call to {@link ListIterator#next next}.
1045 >     * An initial call to {@link ListIterator#previous previous} would
1046 >     * return the element with the specified index minus one.
1047 >     *
1048 >     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
1049       *
999     * <p>The list-iterator is <i>fail-fast</i>: if the list is structurally
1000     * modified at any time after the Iterator is created, in any way except
1001     * through the list-iterator's own {@code remove} or {@code add}
1002     * methods, the list-iterator will throw a
1003     * {@code ConcurrentModificationException}.  Thus, in the face of
1004     * concurrent modification, the iterator fails quickly and cleanly, rather
1005     * than risking arbitrary, non-deterministic behavior at an undetermined
1006     * time in the future.
1007     *
1008     * @param index index of the first element to be returned from the
1009     *        list-iterator (by a call to {@link ListIterator#next})
1010     * @return a list-iterator of the elements in this list (in proper
1011     *         sequence), starting at the specified position in the list
1050       * @throws IndexOutOfBoundsException {@inheritDoc}
1051       */
1052      public synchronized ListIterator<E> listIterator(int index) {
1053 <        if (index < 0 || index > elementCount)
1053 >        if (index < 0 || index > elementCount)
1054              throw new IndexOutOfBoundsException("Index: "+index);
1055 <        return new VectorIterator(index, elementCount);
1055 >        return new ListItr(index);
1056      }
1057  
1058      /**
1059 <     * {@inheritDoc}
1059 >     * Returns a list iterator over the elements in this list (in proper
1060 >     * sequence).
1061 >     *
1062 >     * <p>The returned list iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
1063 >     *
1064 >     * @see #listIterator(int)
1065       */
1066      public synchronized ListIterator<E> listIterator() {
1067 <        return new VectorIterator(0, elementCount);
1067 >        return new ListItr(0);
1068      }
1069  
1070      /**
1071       * Returns an iterator over the elements in this list in proper sequence.
1072       *
1073 +     * <p>The returned iterator is <a href="#fail-fast"><i>fail-fast</i></a>.
1074 +     *
1075       * @return an iterator over the elements in this list in proper sequence
1076       */
1077      public synchronized Iterator<E> iterator() {
1078 <        return new VectorIterator(0, elementCount);
1078 >        return new Itr();
1079      }
1080  
1081      /**
1082 <     * Helper method to access array elements under synchronization by
1038 <     * iterators. The caller performs index check with respect to
1039 <     * expected bounds, so errors accessing the element are reported
1040 <     * as ConcurrentModificationExceptions.
1082 >     * An optimized version of AbstractList.Itr
1083       */
1084 <    final synchronized Object iteratorGet(int index, int expectedModCount) {
1085 <        if (modCount == expectedModCount) {
1086 <            try {
1087 <                return elementData[index];
1046 <            } catch(IndexOutOfBoundsException fallThrough) {
1047 <            }
1048 <        }
1049 <        throw new ConcurrentModificationException();
1050 <    }
1051 <
1052 <    /**
1053 <     * Streamlined specialization of AbstractList version of iterator.
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> {
1058 <        int cursor;              // Index of next element to return;
1059 <        int fence;               // Upper bound on cursor (cache of size())
1060 <        int lastRet;             // Index of last element, or -1 if no such
1061 <        int expectedModCount;    // To check for CME
1062 <
1063 <        VectorIterator(int index, int fence) {
1064 <            this.cursor = index;
1065 <            this.fence = fence;
1066 <            this.lastRet = -1;
1067 <            this.expectedModCount = Vector.this.modCount;
1068 <        }
1069 <
1070 <        public boolean hasNext() {
1071 <            return cursor < fence;
1072 <        }
1084 >    private class Itr implements Iterator<E> {
1085 >        int cursor;       // index of next element to return
1086 >        int lastRet = -1; // index of last element returned; -1 if no such
1087 >        int expectedModCount = modCount;
1088  
1089 <        public boolean hasPrevious() {
1090 <            return cursor > 0;
1091 <        }
1092 <
1078 <        public int nextIndex() {
1079 <            return cursor;
1080 <        }
1081 <
1082 <        public int previousIndex() {
1083 <            return cursor - 1;
1084 <        }
1085 <
1086 <        public E next() {
1087 <            int i = cursor;
1088 <            if (i >= fence)
1089 <                throw new NoSuchElementException();
1090 <            Object next = Vector.this.iteratorGet(i, expectedModCount);
1091 <            lastRet = i;
1092 <            cursor = i + 1;
1093 <            return (E)next;
1094 <        }
1095 <
1096 <        public E previous() {
1097 <            int i = cursor - 1;
1098 <            if (i < 0)
1099 <                throw new NoSuchElementException();
1100 <            Object prev = Vector.this.iteratorGet(i, expectedModCount);
1101 <            lastRet = i;
1102 <            cursor = i;
1103 <            return (E)prev;
1089 >        public boolean hasNext() {
1090 >            // Racy but within spec, since modifications are checked
1091 >            // within or after synchronization in next/previous
1092 >            return cursor != elementCount;
1093          }
1094  
1095 <        public void set(E e) {
1096 <            if (lastRet < 0)
1097 <                throw new IllegalStateException();
1109 <            if (Vector.this.modCount != expectedModCount)
1110 <                throw new ConcurrentModificationException();
1111 <            try {
1112 <                Vector.this.set(lastRet, e);
1113 <                expectedModCount = Vector.this.modCount;
1114 <            } catch (IndexOutOfBoundsException ex) {
1115 <                throw new ConcurrentModificationException();
1116 <            }
1117 <        }
1118 <
1119 <        public void remove() {
1120 <            int i = lastRet;
1121 <            if (i < 0)
1122 <                throw new IllegalStateException();
1123 <            if (Vector.this.modCount != expectedModCount)
1124 <                throw new ConcurrentModificationException();
1125 <            try {
1126 <                Vector.this.remove(i);
1127 <                if (i < cursor)
1128 <                    cursor--;
1129 <                lastRet = -1;
1130 <                fence = Vector.this.size();
1131 <                expectedModCount = Vector.this.modCount;
1132 <            } catch (IndexOutOfBoundsException ex) {
1133 <                throw new ConcurrentModificationException();
1134 <            }
1135 <        }
1136 <
1137 <        public void add(E e) {
1138 <            if (Vector.this.modCount != expectedModCount)
1139 <                throw new ConcurrentModificationException();
1140 <            try {
1095 >        public E next() {
1096 >            synchronized (Vector.this) {
1097 >                checkForComodification();
1098                  int i = cursor;
1099 <                Vector.this.add(i, e);
1099 >                if (i >= elementCount)
1100 >                    throw new NoSuchElementException();
1101                  cursor = i + 1;
1102 <                lastRet = -1;
1145 <                fence = Vector.this.size();
1146 <                expectedModCount = Vector.this.modCount;
1147 <            } catch (IndexOutOfBoundsException ex) {
1148 <                throw new ConcurrentModificationException();
1149 <            }
1150 <        }
1151 <    }
1152 <
1153 <    /**
1154 <     * Returns a view of the portion of this List between fromIndex,
1155 <     * inclusive, and toIndex, exclusive.  (If fromIndex and toIndex are
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.
1160 <     *
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
1165 <     * removes a range of elements from a List:
1166 <     * <pre>
1167 <     *      list.subList(from, to).clear();
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.
1172 <     *
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
1177 <     * a fashion that iterations in progress may yield incorrect results.)
1178 <     *
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 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);
1189 <    }
1190 <
1191 <    /**
1192 <     * This class specializes the AbstractList version of SubList to
1193 <     * avoid the double-indirection penalty that would arise using a
1194 <     * synchronized wrapper, as well as to avoid some unnecessary
1195 <     * checks in sublist iterators.
1196 <     */
1197 <    private static final class VectorSubList<E> extends AbstractList<E> implements RandomAccess {
1198 <        final Vector<E> base;             // base list
1199 <        final AbstractList<E> parent;     // Creating list
1200 <        final int baseOffset;             // index wrt Vector
1201 <        final int parentOffset;           // index wrt parent
1202 <        int length;                       // length of sublist
1203 <
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);
1208 <            if (toIndex > parent.size())
1209 <                throw new IndexOutOfBoundsException("toIndex = " + toIndex);
1210 <            if (fromIndex > toIndex)
1211 <                throw new IllegalArgumentException("fromIndex(" + fromIndex +
1212 <                                                   ") > toIndex(" + toIndex + ")");
1213 <
1214 <            this.base = base;
1215 <            this.parent = parent;
1216 <            this.baseOffset = baseOffset;
1217 <            this.parentOffset = fromIndex;
1218 <            this.length = toIndex - fromIndex;
1219 <            modCount = base.modCount;
1220 <        }
1221 <
1222 <        /**
1223 <         * Returns an IndexOutOfBoundsException with nicer message
1224 <         */
1225 <        private IndexOutOfBoundsException indexError(int index) {
1226 <            return new IndexOutOfBoundsException("Index: " + index +
1227 <                                                 ", Size: " + length);
1228 <        }
1229 <
1230 <        public E set(int index, E element) {
1231 <            synchronized(base) {
1232 <                if (index < 0 || index >= length)
1233 <                    throw indexError(index);
1234 <                if (base.modCount != modCount)
1235 <                    throw new ConcurrentModificationException();
1236 <                return base.set(index + baseOffset, element);
1237 <            }
1238 <        }
1239 <
1240 <        public E get(int index) {
1241 <            synchronized(base) {
1242 <                if (index < 0 || index >= length)
1243 <                    throw indexError(index);
1244 <                if (base.modCount != modCount)
1245 <                    throw new ConcurrentModificationException();
1246 <                return base.get(index + baseOffset);
1247 <            }
1248 <        }
1249 <
1250 <        public int size() {
1251 <            synchronized(base) {
1252 <                if (base.modCount != modCount)
1253 <                    throw new ConcurrentModificationException();
1254 <                return length;
1255 <            }
1256 <        }
1257 <
1258 <        public void add(int index, E element) {
1259 <            synchronized(base) {
1260 <                if (index < 0 || index > length)
1261 <                    throw indexError(index);
1262 <                if (base.modCount != modCount)
1263 <                    throw new ConcurrentModificationException();
1264 <                parent.add(index + parentOffset, element);
1265 <                length++;
1266 <                modCount = base.modCount;
1267 <            }
1268 <        }
1269 <
1270 <        public E remove(int index) {
1271 <            synchronized(base) {
1272 <                if (index < 0 || index >= length)
1273 <                    throw indexError(index);
1274 <                if (base.modCount != modCount)
1275 <                    throw new ConcurrentModificationException();
1276 <                E result = parent.remove(index + parentOffset);
1277 <                length--;
1278 <                modCount = base.modCount;
1279 <                return result;
1102 >                return elementData(lastRet = i);
1103              }
1104          }
1105  
1106 <        protected void removeRange(int fromIndex, int toIndex) {
1107 <            synchronized(base) {
1108 <                if (base.modCount != modCount)
1109 <                    throw new ConcurrentModificationException();
1110 <                parent.removeRange(fromIndex + parentOffset,
1111 <                                   toIndex + parentOffset);
1112 <                length -= (toIndex-fromIndex);
1290 <                modCount = base.modCount;
1106 >        public void remove() {
1107 >            if (lastRet == -1)
1108 >                throw new IllegalStateException();
1109 >            synchronized (Vector.this) {
1110 >                checkForComodification();
1111 >                Vector.this.remove(lastRet);
1112 >                expectedModCount = modCount;
1113              }
1114 +            cursor = lastRet;
1115 +            lastRet = -1;
1116          }
1117  
1118 <        public boolean addAll(Collection<? extends E> c) {
1119 <            return addAll(length, c);
1120 <        }
1297 <
1298 <        public boolean addAll(int index, Collection<? extends E> c) {
1299 <            synchronized(base) {
1300 <                if (index < 0 || index > length)
1301 <                    throw indexError(index);
1302 <                int cSize = c.size();
1303 <                if (cSize==0)
1304 <                    return false;
1305 <
1306 <                if (base.modCount != modCount)
1307 <                    throw new ConcurrentModificationException();
1308 <                parent.addAll(parentOffset + index, c);
1309 <                modCount = base.modCount;
1310 <                length += cSize;
1311 <                return true;
1312 <            }
1313 <        }
1314 <
1315 <        public boolean equals(Object o) {
1316 <            synchronized(base) {return super.equals(o);}
1317 <        }
1318 <
1319 <        public int hashCode() {
1320 <            synchronized(base) {return super.hashCode();}
1321 <        }
1322 <
1323 <        public int indexOf(Object o) {
1324 <            synchronized(base) {return super.indexOf(o);}
1325 <        }
1326 <
1327 <        public int lastIndexOf(Object o) {
1328 <            synchronized(base) {return super.lastIndexOf(o);}
1118 >        final void checkForComodification() {
1119 >            if (modCount != expectedModCount)
1120 >                throw new ConcurrentModificationException();
1121          }
1122 +    }
1123  
1124 <        public List<E> subList(int fromIndex, int toIndex) {
1125 <            return new VectorSubList(base, this, fromIndex + baseOffset,
1126 <                                     fromIndex, toIndex);
1124 >    /**
1125 >     * An optimized version of AbstractList.ListItr
1126 >     */
1127 >    final class ListItr extends Itr implements ListIterator<E> {
1128 >        ListItr(int index) {
1129 >            super();
1130 >            cursor = index;
1131          }
1132  
1133 <        public Iterator<E> iterator() {
1134 <            synchronized(base) {
1338 <                return new VectorSubListIterator(this, 0);
1339 <            }
1133 >        public boolean hasPrevious() {
1134 >            return cursor != 0;
1135          }
1136  
1137 <        public synchronized ListIterator<E> listIterator() {
1138 <            synchronized(base) {
1344 <                return new VectorSubListIterator(this, 0);
1345 <            }
1137 >        public int nextIndex() {
1138 >            return cursor;
1139          }
1140  
1141 <        public ListIterator<E> listIterator(int index) {
1142 <            synchronized(base) {
1350 <                if (index < 0 || index > length)
1351 <                    throw indexError(index);
1352 <                return new VectorSubListIterator(this, index);
1353 <            }
1141 >        public int previousIndex() {
1142 >            return cursor - 1;
1143          }
1144  
1145 <        /**
1146 <         * Same idea as VectorIterator, except routing structural
1147 <         * change operations through the sublist.
1359 <         */
1360 <        private static final class VectorSubListIterator<E> implements ListIterator<E> {
1361 <            final Vector<E> base;         // base list
1362 <            final VectorSubList<E> outer; // Sublist creating this iteraor
1363 <            final int offset;             // cursor offset wrt base
1364 <            int cursor;                   // Current index
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 <
1369 <            VectorSubListIterator(VectorSubList<E> list, int index) {
1370 <                this.lastRet = -1;
1371 <                this.cursor = index;
1372 <                this.outer = list;
1373 <                this.offset = list.baseOffset;
1374 <                this.fence = list.length;
1375 <                this.base = list.base;
1376 <                this.expectedModCount = base.modCount;
1377 <            }
1378 <
1379 <            public boolean hasNext() {
1380 <                return cursor < fence;
1381 <            }
1382 <
1383 <            public boolean hasPrevious() {
1384 <                return cursor > 0;
1385 <            }
1386 <
1387 <            public int nextIndex() {
1388 <                return cursor;
1389 <            }
1390 <
1391 <            public int previousIndex() {
1392 <                return cursor - 1;
1393 <            }
1394 <
1395 <            public E next() {
1396 <                int i = cursor;
1397 <                if (cursor >= fence)
1398 <                    throw new NoSuchElementException();
1399 <                Object next = base.iteratorGet(i + offset, expectedModCount);
1400 <                lastRet = i;
1401 <                cursor = i + 1;
1402 <                return (E)next;
1403 <            }
1404 <
1405 <            public E previous() {
1145 >        public E previous() {
1146 >            synchronized (Vector.this) {
1147 >                checkForComodification();
1148                  int i = cursor - 1;
1149                  if (i < 0)
1150                      throw new NoSuchElementException();
1409                Object prev = base.iteratorGet(i + offset, expectedModCount);
1410                lastRet = i;
1151                  cursor = i;
1152 <                return (E)prev;
1413 <            }
1414 <
1415 <            public void set(E e) {
1416 <                if (lastRet < 0)
1417 <                    throw new IllegalStateException();
1418 <                if (base.modCount != expectedModCount)
1419 <                    throw new ConcurrentModificationException();
1420 <                try {
1421 <                    outer.set(lastRet, e);
1422 <                    expectedModCount = base.modCount;
1423 <                } catch (IndexOutOfBoundsException ex) {
1424 <                    throw new ConcurrentModificationException();
1425 <                }
1152 >                return elementData(lastRet = i);
1153              }
1154 +        }
1155  
1156 <            public void remove() {
1157 <                int i = lastRet;
1158 <                if (i < 0)
1159 <                    throw new IllegalStateException();
1160 <                if (base.modCount != expectedModCount)
1161 <                    throw new ConcurrentModificationException();
1434 <                try {
1435 <                    outer.remove(i);
1436 <                    if (i < cursor)
1437 <                        cursor--;
1438 <                    lastRet = -1;
1439 <                    fence = outer.length;
1440 <                    expectedModCount = base.modCount;
1441 <                } catch (IndexOutOfBoundsException ex) {
1442 <                    throw new ConcurrentModificationException();
1443 <                }
1156 >        public void set(E e) {
1157 >            if (lastRet == -1)
1158 >                throw new IllegalStateException();
1159 >            synchronized (Vector.this) {
1160 >                checkForComodification();
1161 >                Vector.this.set(lastRet, e);
1162              }
1163 +        }
1164  
1165 <            public void add(E e) {
1166 <                if (base.modCount != expectedModCount)
1167 <                    throw new ConcurrentModificationException();
1168 <                try {
1169 <                    int i = cursor;
1170 <                    outer.add(i, e);
1452 <                    cursor = i + 1;
1453 <                    lastRet = -1;
1454 <                    fence = outer.length;
1455 <                    expectedModCount = base.modCount;
1456 <                } catch (IndexOutOfBoundsException ex) {
1457 <                    throw new ConcurrentModificationException();
1458 <                }
1165 >        public void add(E e) {
1166 >            int i = cursor;
1167 >            synchronized (Vector.this) {
1168 >                checkForComodification();
1169 >                Vector.this.add(i, e);
1170 >                expectedModCount = modCount;
1171              }
1172 +            cursor = i + 1;
1173 +            lastRet = -1;
1174          }
1175      }
1176   }
1463
1464
1465

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines