417 |
|
return (E) elementData[index]; |
418 |
|
} |
419 |
|
|
420 |
+ |
@SuppressWarnings("unchecked") |
421 |
+ |
static <E> E elementAt(Object[] es, int index) { |
422 |
+ |
return (E) es[index]; |
423 |
+ |
} |
424 |
+ |
|
425 |
|
/** |
426 |
|
* Returns the element at the specified position in this list. |
427 |
|
* |
1440 |
|
} |
1441 |
|
|
1442 |
|
@Override |
1438 |
– |
@SuppressWarnings("unchecked") |
1443 |
|
public void replaceAll(UnaryOperator<E> operator) { |
1444 |
+ |
replaceAllRange(operator, 0, size); |
1445 |
+ |
} |
1446 |
+ |
|
1447 |
+ |
private void replaceAllRange(UnaryOperator<E> operator, int i, int end) { |
1448 |
|
Objects.requireNonNull(operator); |
1449 |
|
final int expectedModCount = modCount; |
1450 |
< |
final int size = this.size; |
1451 |
< |
for (int i=0; modCount == expectedModCount && i < size; i++) { |
1452 |
< |
elementData[i] = operator.apply((E) elementData[i]); |
1453 |
< |
} |
1446 |
< |
if (modCount != expectedModCount) { |
1450 |
> |
final Object[] es = elementData; |
1451 |
> |
for (; modCount == expectedModCount && i < end; i++) |
1452 |
> |
es[i] = operator.apply(elementAt(es, i)); |
1453 |
> |
if (modCount != expectedModCount) |
1454 |
|
throw new ConcurrentModificationException(); |
1455 |
< |
} |
1449 |
< |
modCount++; |
1455 |
> |
// checkInvariants(); |
1456 |
|
} |
1457 |
|
|
1458 |
|
@Override |