--- jsr166/src/main/java/util/ArrayList.java 2018/03/28 02:50:41 1.57 +++ jsr166/src/main/java/util/ArrayList.java 2018/05/05 18:29:53 1.58 @@ -1122,6 +1122,10 @@ public class ArrayList extends Abstra return true; } + public void replaceAll(UnaryOperator operator) { + root.replaceAllRange(operator, offset, offset + size); + } + public boolean removeAll(Collection c) { return batchRemove(c, false); } @@ -1591,15 +1595,17 @@ public class ArrayList extends Abstra @Override public void replaceAll(UnaryOperator operator) { + replaceAllRange(operator, 0, size); + } + + private void replaceAllRange(UnaryOperator operator, int from, int to) { Objects.requireNonNull(operator); final int expectedModCount = modCount; final Object[] es = elementData; - final int size = this.size; - for (int i = 0; modCount == expectedModCount && i < size; i++) + for (int i = from; modCount == expectedModCount && i < to; i++) es[i] = operator.apply(elementAt(es, i)); if (modCount != expectedModCount) throw new ConcurrentModificationException(); - modCount++; // checkInvariants(); }