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.11 by jsr166, Mon Nov 28 03:59:23 2005 UTC vs.
Revision 1.14 by jsr166, Mon Dec 5 02:56:59 2005 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  
# Line 189 | Line 189 | public class ArrayList<E> extends Abstra
189       * @param minCapacity the desired minimum capacity
190       */
191      private void growArray(int minCapacity) {
192 <        if (minCapacity < 0)
193 <            throw new OutOfMemoryError(); // int overflow
192 >        if (minCapacity < 0) // overflow
193 >            throw new OutOfMemoryError();
194          int oldCapacity = elementData.length;
195          // Double size if small; else grow by 50%
196          int newCapacity = ((oldCapacity < 64)?
197                             ((oldCapacity + 1) * 2):
198 <                           ((oldCapacity * 3) / 2));
198 >                           ((oldCapacity / 2) * 3));
199 >        if (newCapacity < 0) // overflow
200 >            newCapacity = Integer.MAX_VALUE;
201          if (newCapacity < minCapacity)
202              newCapacity = minCapacity;
203          elementData = Arrays.copyOf(elementData, newCapacity);
# Line 602 | Line 604 | public class ArrayList<E> extends Abstra
604          for (int i=0; i<size; i++)
605              s.writeObject(elementData[i]);
606  
607 <        if (modCount != expectedModCount) {
607 >        if (expectedModCount != modCount) {
608              throw new ConcurrentModificationException();
609          }
610  
# Line 685 | Line 687 | public class ArrayList<E> extends Abstra
687          }
688  
689          public boolean hasNext() {
690 <            return cursor < size;
690 >            return cursor != size;
691          }
692  
693          public boolean hasPrevious() {
694 <            return cursor > 0;
694 >            return cursor != 0;
695          }
696  
697          public int nextIndex() {
# Line 725 | Line 727 | public class ArrayList<E> extends Abstra
727              } catch (IndexOutOfBoundsException ex) {
728                  throw new NoSuchElementException();
729              } finally {
730 <                if (modCount != expectedModCount)
730 >                if (expectedModCount != modCount)
731                      throw new ConcurrentModificationException();
732              }
733          }
# Line 733 | Line 735 | public class ArrayList<E> extends Abstra
735          public void remove() {
736              if (lastRet < 0)
737                  throw new IllegalStateException();
738 <            if (modCount != expectedModCount)
738 >            if (expectedModCount != modCount)
739                  throw new ConcurrentModificationException();
740              ArrayList.this.remove(lastRet);
741              if (lastRet < cursor)
# Line 745 | Line 747 | public class ArrayList<E> extends Abstra
747          public void set(E e) {
748              if (lastRet < 0)
749                  throw new IllegalStateException();
750 <            if (modCount != expectedModCount)
750 >            if (expectedModCount != modCount)
751                  throw new ConcurrentModificationException();
752              ArrayList.this.set(lastRet, e);
753              expectedModCount = modCount;
754          }
755  
756          public void add(E e) {
757 <            if (modCount != expectedModCount)
757 >            if (expectedModCount != modCount)
758                  throw new ConcurrentModificationException();
759 <            ArrayList.this.add(cursor++, e);
760 <            lastRet = -1;
761 <            expectedModCount = modCount;
759 >            try {
760 >                ArrayList.this.add(cursor++, e);
761 >                lastRet = -1;
762 >                expectedModCount = modCount;
763 >            } catch (IndexOutOfBoundsException ex) {
764 >                throw new ConcurrentModificationException();
765 >            }
766          }
767      }
768   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines