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); |
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 |
|
|
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() { |
727 |
|
} catch (IndexOutOfBoundsException ex) { |
728 |
|
throw new NoSuchElementException(); |
729 |
|
} finally { |
730 |
< |
if (modCount != expectedModCount) |
730 |
> |
if (expectedModCount != modCount) |
731 |
|
throw new ConcurrentModificationException(); |
732 |
|
} |
733 |
|
} |
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) |
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 |
|
} |