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); |
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() { |
756 |
|
public void add(E e) { |
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 |
|
} |