test/java/util/Collection/ListDefaults.java
Print this page
rev 7994 : 8024291: Rename Collection.removeIf(Predicate) back to removeAll(Predicate)
Reviewed-by: duke
@@ -125,11 +125,11 @@
try {
list.replaceAll(null);
fail("expected NPE not thrown");
} catch (NullPointerException npe) {}
try {
- list.removeIf(null);
+ list.removeAll((Predicate<Integer>)null);
fail("expected NPE not thrown");
} catch (NullPointerException npe) {}
try {
list.sort(null);
} catch (Throwable t) {
@@ -179,19 +179,19 @@
});
}
}
@Test
- public void testRemoveIf() throws Exception {
+ public void testRemoveAll() throws Exception {
final CollectionSupplier supplier = new CollectionSupplier(LIST_CLASSES, SIZE);
for (final CollectionSupplier.TestCase test : supplier.get()) {
final List<Integer> original = ((List<Integer>) test.original);
final List<Integer> list = ((List<Integer>) test.collection);
try {
- list.removeIf(null);
+ list.removeAll((Predicate<Integer>)null);
fail("expected NPE not thrown");
} catch (NullPointerException npe) {}
CollectionAsserts.assertContents(list, original);
final AtomicInteger offset = new AtomicInteger(1);
@@ -201,20 +201,20 @@
}
for (final CollectionSupplier.TestCase test : supplier.get()) {
final List<Integer> original = ((List<Integer>) test.original);
final List<Integer> list = ((List<Integer>) test.collection);
- list.removeIf(pOdd);
+ list.removeAll(pOdd);
for (int i : list) {
assertTrue((i % 2) == 0);
}
for (int i : original) {
if (i % 2 == 0) {
assertTrue(list.contains(i));
}
}
- list.removeIf(pEven);
+ list.removeAll(pEven);
assertTrue(list.isEmpty());
}
for (final CollectionSupplier.TestCase test : supplier.get()) {
final List<Integer> original = ((List<Integer>) test.original);
@@ -222,22 +222,22 @@
final List<Integer> listCopy = new ArrayList<>(list);
if (original.size() > SUBLIST_SIZE) {
final List<Integer> subList = list.subList(SUBLIST_FROM, SUBLIST_TO);
final List<Integer> subListCopy = new ArrayList<>(subList);
listCopy.removeAll(subList);
- subList.removeIf(pOdd);
+ subList.removeAll(pOdd);
for (int i : subList) {
assertTrue((i % 2) == 0);
}
for (int i : subListCopy) {
if (i % 2 == 0) {
assertTrue(subList.contains(i));
} else {
assertFalse(subList.contains(i));
}
}
- subList.removeIf(pEven);
+ subList.removeAll(pEven);
assertTrue(subList.isEmpty());
// elements outside the view should remain
CollectionAsserts.assertContents(list, listCopy);
}
}
@@ -246,11 +246,11 @@
final List<Integer> list = ((List<Integer>) test.collection);
trimmedSubList(list, new Callback() {
@Override
public void call(final List<Integer> list) {
final List<Integer> copy = new ArrayList<>(list);
- list.removeIf(pOdd);
+ list.removeAll(pOdd);
for (int i : list) {
assertTrue((i % 2) == 0);
}
for (int i : copy) {
if (i % 2 == 0) {
@@ -265,11 +265,11 @@
}
// remove the first element
private void removeFirst(final List<Integer> original, final List<Integer> list, final AtomicInteger offset) {
final AtomicBoolean first = new AtomicBoolean(true);
- list.removeIf(x -> first.getAndSet(false));
+ list.removeAll(x -> first.getAndSet(false));
CollectionAsserts.assertContents(original.subList(offset.getAndIncrement(), original.size()), list);
}
@Test
public void testReplaceAll() throws Exception {
@@ -445,21 +445,21 @@
}
}
}
@Test
- public void testRemoveIfThrowsCME() throws Exception {
+ public void testRemoveAllThrowsCME() throws Exception {
final CollectionSupplier supplier = new CollectionSupplier(LIST_CME_CLASSES, SIZE);
for (final CollectionSupplier.TestCase test : supplier.get()) {
final List<Integer> list = ((List<Integer>) test.collection);
if (list.size() <= 1) {
continue;
}
boolean gotException = false;
try {
// bad predicate that modifies its list, should throw CME
- list.removeIf((x) -> {return list.add(x);});
+ list.removeAll((x) -> {return list.add(x);});
} catch (ConcurrentModificationException cme) {
gotException = true;
}
if (!gotException) {
fail("expected CME was not thrown from " + test);
@@ -522,15 +522,15 @@
cases.add(new Object[] { new CopyOnWriteArrayList<>(Arrays.asList(DATA)) });
return cases.toArray(new Object[0][cases.size()]);
}
@Test(dataProvider = "shortIntListProvider")
- public void testRemoveIfFromSlice(final List<Integer> list) throws Exception {
+ public void testRemoveAllFromSlice(final List<Integer> list) throws Exception {
final List<Integer> sublist = list.subList(3, 6);
- assertTrue(sublist.removeIf(x -> x == 4));
+ assertTrue(sublist.removeAll(x -> x == 4));
CollectionAsserts.assertContents(list, SLICED_EXPECTED);
final List<Integer> sublist2 = list.subList(2, 5);
- assertTrue(sublist2.removeIf(x -> x == 3));
+ assertTrue(sublist2.removeAll(x -> x == 3));
CollectionAsserts.assertContents(list, SLICED_EXPECTED2);
}
}