< prev index next >

src/java.base/share/classes/java/util/Vector.java

Print this page
8203662: remove increment of modCount from ArrayList and Vector replaceAll()
Reviewed-by: martin, igerasim, redestad, dholmes, smarks, jrose, plevart


1385         final int size = elementCount;
1386         for (int i = 0; modCount == expectedModCount && i < size; i++)
1387             action.accept(elementAt(es, i));
1388         if (modCount != expectedModCount)
1389             throw new ConcurrentModificationException();
1390     }
1391 
1392     /**
1393      * @throws NullPointerException {@inheritDoc}
1394      */
1395     @Override
1396     public synchronized void replaceAll(UnaryOperator<E> operator) {
1397         Objects.requireNonNull(operator);
1398         final int expectedModCount = modCount;
1399         final Object[] es = elementData;
1400         final int size = elementCount;
1401         for (int i = 0; modCount == expectedModCount && i < size; i++)
1402             es[i] = operator.apply(elementAt(es, i));
1403         if (modCount != expectedModCount)
1404             throw new ConcurrentModificationException();
1405         modCount++;
1406     }
1407 
1408     @SuppressWarnings("unchecked")
1409     @Override
1410     public synchronized void sort(Comparator<? super E> c) {
1411         final int expectedModCount = modCount;
1412         Arrays.sort((E[]) elementData, 0, elementCount, c);
1413         if (modCount != expectedModCount)
1414             throw new ConcurrentModificationException();
1415         modCount++;
1416     }
1417 
1418     /**
1419      * Creates a <em><a href="Spliterator.html#binding">late-binding</a></em>
1420      * and <em>fail-fast</em> {@link Spliterator} over the elements in this
1421      * list.
1422      *
1423      * <p>The {@code Spliterator} reports {@link Spliterator#SIZED},
1424      * {@link Spliterator#SUBSIZED}, and {@link Spliterator#ORDERED}.
1425      * Overriding implementations should document the reporting of additional




1385         final int size = elementCount;
1386         for (int i = 0; modCount == expectedModCount && i < size; i++)
1387             action.accept(elementAt(es, i));
1388         if (modCount != expectedModCount)
1389             throw new ConcurrentModificationException();
1390     }
1391 
1392     /**
1393      * @throws NullPointerException {@inheritDoc}
1394      */
1395     @Override
1396     public synchronized void replaceAll(UnaryOperator<E> operator) {
1397         Objects.requireNonNull(operator);
1398         final int expectedModCount = modCount;
1399         final Object[] es = elementData;
1400         final int size = elementCount;
1401         for (int i = 0; modCount == expectedModCount && i < size; i++)
1402             es[i] = operator.apply(elementAt(es, i));
1403         if (modCount != expectedModCount)
1404             throw new ConcurrentModificationException();

1405     }
1406 
1407     @SuppressWarnings("unchecked")
1408     @Override
1409     public synchronized void sort(Comparator<? super E> c) {
1410         final int expectedModCount = modCount;
1411         Arrays.sort((E[]) elementData, 0, elementCount, c);
1412         if (modCount != expectedModCount)
1413             throw new ConcurrentModificationException();
1414         modCount++;
1415     }
1416 
1417     /**
1418      * Creates a <em><a href="Spliterator.html#binding">late-binding</a></em>
1419      * and <em>fail-fast</em> {@link Spliterator} over the elements in this
1420      * list.
1421      *
1422      * <p>The {@code Spliterator} reports {@link Spliterator#SIZED},
1423      * {@link Spliterator#SUBSIZED}, and {@link Spliterator#ORDERED}.
1424      * Overriding implementations should document the reporting of additional


< prev index next >