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

Print this page
rev 7994 : 8024291: Rename Collection.removeIf(Predicate) back to removeAll(Predicate)
Reviewed-by: duke


1238         }
1239     }
1240 
1241     @Override
1242     public synchronized void forEach(Consumer<? super E> action) {
1243         Objects.requireNonNull(action);
1244         final int expectedModCount = modCount;
1245         @SuppressWarnings("unchecked")
1246         final E[] elementData = (E[]) this.elementData;
1247         final int elementCount = this.elementCount;
1248         for (int i=0; modCount == expectedModCount && i < elementCount; i++) {
1249             action.accept(elementData[i]);
1250         }
1251         if (modCount != expectedModCount) {
1252             throw new ConcurrentModificationException();
1253         }
1254     }
1255 
1256     @Override
1257     @SuppressWarnings("unchecked")
1258     public synchronized boolean removeIf(Predicate<? super E> filter) {
1259         Objects.requireNonNull(filter);
1260         // figure out which elements are to be removed
1261         // any exception thrown from the filter predicate at this stage
1262         // will leave the collection unmodified
1263         int removeCount = 0;
1264         final int size = elementCount;
1265         final BitSet removeSet = new BitSet(size);
1266         final int expectedModCount = modCount;
1267         for (int i=0; modCount == expectedModCount && i < size; i++) {
1268             @SuppressWarnings("unchecked")
1269             final E element = (E) elementData[i];
1270             if (filter.test(element)) {
1271                 removeSet.set(i);
1272                 removeCount++;
1273             }
1274         }
1275         if (modCount != expectedModCount) {
1276             throw new ConcurrentModificationException();
1277         }
1278 




1238         }
1239     }
1240 
1241     @Override
1242     public synchronized void forEach(Consumer<? super E> action) {
1243         Objects.requireNonNull(action);
1244         final int expectedModCount = modCount;
1245         @SuppressWarnings("unchecked")
1246         final E[] elementData = (E[]) this.elementData;
1247         final int elementCount = this.elementCount;
1248         for (int i=0; modCount == expectedModCount && i < elementCount; i++) {
1249             action.accept(elementData[i]);
1250         }
1251         if (modCount != expectedModCount) {
1252             throw new ConcurrentModificationException();
1253         }
1254     }
1255 
1256     @Override
1257     @SuppressWarnings("unchecked")
1258     public synchronized boolean removeAll(Predicate<? super E> filter) {
1259         Objects.requireNonNull(filter);
1260         // figure out which elements are to be removed
1261         // any exception thrown from the filter predicate at this stage
1262         // will leave the collection unmodified
1263         int removeCount = 0;
1264         final int size = elementCount;
1265         final BitSet removeSet = new BitSet(size);
1266         final int expectedModCount = modCount;
1267         for (int i=0; modCount == expectedModCount && i < size; i++) {
1268             @SuppressWarnings("unchecked")
1269             final E element = (E) elementData[i];
1270             if (filter.test(element)) {
1271                 removeSet.set(i);
1272                 removeCount++;
1273             }
1274         }
1275         if (modCount != expectedModCount) {
1276             throw new ConcurrentModificationException();
1277         }
1278