146 |
|
} |
147 |
|
initFromConcurrentlyMutating(c); |
148 |
|
} |
149 |
< |
|
149 |
> |
|
150 |
|
private void initFromConcurrentlyMutating(Collection<? extends E> c) { |
151 |
|
elementData = c.toArray(); |
152 |
|
size = elementData.length; |
154 |
|
if (elementData.getClass() != Object[].class) |
155 |
|
elementData = Arrays.copyOf(elementData, size, Object[].class); |
156 |
|
} |
157 |
< |
|
157 |
> |
|
158 |
|
private final static Object UNALLOCATED = new Object(); |
159 |
< |
|
159 |
> |
|
160 |
|
/** |
161 |
|
* Trims the capacity of this <tt>ArrayList</tt> instance to be the |
162 |
|
* list's current size. An application can use this operation to minimize |
190 |
|
private void growArray(int minCapacity) { |
191 |
|
int oldCapacity = elementData.length; |
192 |
|
// Double size if small; else grow by 50% |
193 |
< |
int newCapacity = ((oldCapacity < 64)? |
193 |
> |
int newCapacity = ((oldCapacity < 64)? |
194 |
|
(oldCapacity * 2): |
195 |
|
((oldCapacity * 3)/2 + 1)); |
196 |
|
if (newCapacity < minCapacity) |
341 |
|
|
342 |
|
// Positional Access Operations |
343 |
|
|
344 |
< |
/** |
345 |
< |
* Create and return an appropriate exception for indexing errors |
344 |
> |
/** |
345 |
> |
* Create and return an appropriate exception for indexing errors |
346 |
|
*/ |
347 |
|
private static IndexOutOfBoundsException rangeException(int i, int s) { |
348 |
|
return new IndexOutOfBoundsException("Index: " + i + ", Size: " + s); |
436 |
|
Object oldValue = elementData[index]; |
437 |
|
int numMoved = s - index; |
438 |
|
if (numMoved > 0) |
439 |
< |
System.arraycopy(elementData, index+1, elementData, index, |
439 |
> |
System.arraycopy(elementData, index+1, elementData, index, |
440 |
|
numMoved); |
441 |
|
elementData[s] = null; // forget removed element |
442 |
|
return (E)oldValue; |
652 |
|
throw new IndexOutOfBoundsException("Index: "+index); |
653 |
|
return new ArrayListIterator(index); |
654 |
|
} |
655 |
< |
|
655 |
> |
|
656 |
|
/** |
657 |
|
* Returns an iterator over the elements in this list in proper sequence. |
658 |
|
* |
663 |
|
} |
664 |
|
|
665 |
|
/** |
666 |
< |
* A streamlined version of AbstractList.Itr |
666 |
> |
* A streamlined version of AbstractList.Itr |
667 |
|
*/ |
668 |
|
final class ArrayListIterator implements ListIterator<E> { |
669 |
|
int cursor; // index of next element to return; |
701 |
|
lastRet = i; |
702 |
|
cursor = i + 1; |
703 |
|
return e; |
704 |
< |
} catch (IndexOutOfBoundsException fallthrough) { |
704 |
> |
} catch (IndexOutOfBoundsException fallthrough) { |
705 |
|
} |
706 |
|
} |
707 |
|
} |
720 |
|
lastRet = i; |
721 |
|
cursor = i; |
722 |
|
return e; |
723 |
< |
} catch (IndexOutOfBoundsException fallthrough) { |
723 |
> |
} catch (IndexOutOfBoundsException fallthrough) { |
724 |
|
} |
725 |
|
} |
726 |
|
} |
732 |
|
public void remove() { |
733 |
|
if (lastRet < 0) |
734 |
|
throw new IllegalStateException(); |
735 |
< |
if (modCount != expectedModCount) |
735 |
> |
if (modCount != expectedModCount) |
736 |
|
throw new ConcurrentModificationException(); |
737 |
|
ArrayList.this.remove(lastRet); |
738 |
|
if (lastRet < cursor) |
744 |
|
public void set(E e) { |
745 |
|
if (lastRet < 0) |
746 |
|
throw new IllegalStateException(); |
747 |
< |
if (modCount != expectedModCount) |
747 |
> |
if (modCount != expectedModCount) |
748 |
|
throw new ConcurrentModificationException(); |
749 |
|
ArrayList.this.set(lastRet, e); |
750 |
|
expectedModCount = modCount; |
751 |
|
} |
752 |
|
|
753 |
|
public void add(E e) { |
754 |
< |
if (modCount != expectedModCount) |
754 |
> |
if (modCount != expectedModCount) |
755 |
|
throw new ConcurrentModificationException(); |
756 |
|
ArrayList.this.add(cursor++, e); |
757 |
|
lastRet = -1; |