--- jsr166/src/main/java/util/ArrayList.java 2005/11/28 03:59:23 1.11 +++ jsr166/src/main/java/util/ArrayList.java 2005/12/05 02:56:59 1.14 @@ -1,7 +1,7 @@ /* * %W% %E% * - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ @@ -189,13 +189,15 @@ public class ArrayList extends Abstra * @param minCapacity the desired minimum capacity */ private void growArray(int minCapacity) { - if (minCapacity < 0) - throw new OutOfMemoryError(); // int overflow + if (minCapacity < 0) // overflow + throw new OutOfMemoryError(); int oldCapacity = elementData.length; // Double size if small; else grow by 50% int newCapacity = ((oldCapacity < 64)? ((oldCapacity + 1) * 2): - ((oldCapacity * 3) / 2)); + ((oldCapacity / 2) * 3)); + if (newCapacity < 0) // overflow + newCapacity = Integer.MAX_VALUE; if (newCapacity < minCapacity) newCapacity = minCapacity; elementData = Arrays.copyOf(elementData, newCapacity); @@ -602,7 +604,7 @@ public class ArrayList extends Abstra for (int i=0; i extends Abstra } public boolean hasNext() { - return cursor < size; + return cursor != size; } public boolean hasPrevious() { - return cursor > 0; + return cursor != 0; } public int nextIndex() { @@ -725,7 +727,7 @@ public class ArrayList extends Abstra } catch (IndexOutOfBoundsException ex) { throw new NoSuchElementException(); } finally { - if (modCount != expectedModCount) + if (expectedModCount != modCount) throw new ConcurrentModificationException(); } } @@ -733,7 +735,7 @@ public class ArrayList extends Abstra public void remove() { if (lastRet < 0) throw new IllegalStateException(); - if (modCount != expectedModCount) + if (expectedModCount != modCount) throw new ConcurrentModificationException(); ArrayList.this.remove(lastRet); if (lastRet < cursor) @@ -745,18 +747,22 @@ public class ArrayList extends Abstra public void set(E e) { if (lastRet < 0) throw new IllegalStateException(); - if (modCount != expectedModCount) + if (expectedModCount != modCount) throw new ConcurrentModificationException(); ArrayList.this.set(lastRet, e); expectedModCount = modCount; } public void add(E e) { - if (modCount != expectedModCount) + if (expectedModCount != modCount) throw new ConcurrentModificationException(); - ArrayList.this.add(cursor++, e); - lastRet = -1; - expectedModCount = modCount; + try { + ArrayList.this.add(cursor++, e); + lastRet = -1; + expectedModCount = modCount; + } catch (IndexOutOfBoundsException ex) { + throw new ConcurrentModificationException(); + } } } }