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

Comparing jsr166/src/main/java/util/ArrayList.java (file contents):
Revision 1.9 by dl, Sun Nov 27 14:54:23 2005 UTC vs.
Revision 1.16 by jsr166, Tue Feb 7 20:54:24 2006 UTC

# Line 1 | Line 1
1   /*
2   * %W% %E%
3   *
4 < * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
4 > * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5   * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6   */
7  
8   package java.util;
9 import java.util.*; // for javadoc (till 6280605 is fixed)
9  
10   /**
11   * Resizable-array implementation of the <tt>List</tt> interface.  Implements
# Line 189 | Line 188 | public class ArrayList<E> extends Abstra
188       * @param minCapacity the desired minimum capacity
189       */
190      private void growArray(int minCapacity) {
191 <        if (minCapacity < 0)
192 <            throw new OutOfMemoryError(); // int overflow
191 >        if (minCapacity < 0) // overflow
192 >            throw new OutOfMemoryError();
193          int oldCapacity = elementData.length;
194          // Double size if small; else grow by 50%
195          int newCapacity = ((oldCapacity < 64)?
196                             ((oldCapacity + 1) * 2):
197 <                           ((oldCapacity * 3) / 2));
197 >                           ((oldCapacity / 2) * 3));
198 >        if (newCapacity < 0) // overflow
199 >            newCapacity = Integer.MAX_VALUE;
200          if (newCapacity < minCapacity)
201              newCapacity = minCapacity;
202          elementData = Arrays.copyOf(elementData, newCapacity);
# Line 414 | Line 415 | public class ArrayList<E> extends Abstra
415          modCount++;
416          if (s >= elementData.length)
417              growArray(s + 1);
418 <        System.arraycopy(elementData, index,
418 >        System.arraycopy(elementData, index,
419                           elementData, index + 1, s - index);
420          elementData[index] = element;
421          size = s + 1;
# Line 437 | Line 438 | public class ArrayList<E> extends Abstra
438          E oldValue = (E)elementData[index];
439          int numMoved = s - index;
440          if (numMoved > 0)
441 <            System.arraycopy(elementData, index + 1,
441 >            System.arraycopy(elementData, index + 1,
442                               elementData, index, numMoved);
443          elementData[s] = null;
444          size = s;
# Line 602 | Line 603 | public class ArrayList<E> extends Abstra
603          for (int i=0; i<size; i++)
604              s.writeObject(elementData[i]);
605  
606 <        if (modCount != expectedModCount) {
606 >        if (expectedModCount != modCount) {
607              throw new ConcurrentModificationException();
608          }
609  
# Line 685 | Line 686 | public class ArrayList<E> extends Abstra
686          }
687  
688          public boolean hasNext() {
689 <            return cursor < size;
689 >            return cursor != size;
690          }
691  
692          public boolean hasPrevious() {
693 <            return cursor > 0;
693 >            return cursor != 0;
694          }
695  
696          public int nextIndex() {
# Line 714 | Line 715 | public class ArrayList<E> extends Abstra
715                      throw new ConcurrentModificationException();
716              }
717          }
718 +
719          public E previous() {
720              try {
721                  int i = cursor - 1;
722 <                E next = get(i);
722 >                E prev = get(i);
723                  lastRet = i;
724                  cursor = i;
725 <                return next;
725 >                return prev;
726              } catch (IndexOutOfBoundsException ex) {
727                  throw new NoSuchElementException();
728              } finally {
729 <                if (modCount != expectedModCount)
729 >                if (expectedModCount != modCount)
730                      throw new ConcurrentModificationException();
731              }
732          }
# Line 732 | Line 734 | public class ArrayList<E> extends Abstra
734          public void remove() {
735              if (lastRet < 0)
736                  throw new IllegalStateException();
737 <            if (modCount != expectedModCount)
737 >            if (expectedModCount != modCount)
738                  throw new ConcurrentModificationException();
739              ArrayList.this.remove(lastRet);
740              if (lastRet < cursor)
# Line 744 | Line 746 | public class ArrayList<E> extends Abstra
746          public void set(E e) {
747              if (lastRet < 0)
748                  throw new IllegalStateException();
749 <            if (modCount != expectedModCount)
749 >            if (expectedModCount != modCount)
750                  throw new ConcurrentModificationException();
751              ArrayList.this.set(lastRet, e);
752              expectedModCount = modCount;
753          }
754  
755          public void add(E e) {
756 <            if (modCount != expectedModCount)
756 >            if (expectedModCount != modCount)
757                  throw new ConcurrentModificationException();
758 <            ArrayList.this.add(cursor++, e);
759 <            lastRet = -1;
760 <            expectedModCount = modCount;
758 >            try {
759 >                ArrayList.this.add(cursor++, e);
760 >                lastRet = -1;
761 >                expectedModCount = modCount;
762 >            } catch (IndexOutOfBoundsException ex) {
763 >                throw new ConcurrentModificationException();
764 >            }
765          }
766      }
761
767   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines