add removeWithAddIf methods

This commit is contained in:
scruel
2021-11-30 11:02:42 +08:00
parent 26c98330d2
commit e46c5e1c0c
2 changed files with 57 additions and 0 deletions

View File

@@ -39,6 +39,23 @@ public class CollUtilTest {
Assert.assertFalse(CollUtil.contains(list, s -> s.startsWith("d")));
}
@Test
public void testRemoveWithAddIf() {
ArrayList<Integer> list = CollUtil.newArrayList(1, 2, 3);
ArrayList<Integer> exceptRemovedList = CollUtil.newArrayList(2, 3);
ArrayList<Integer> exceptResultList = CollUtil.newArrayList(1);
ArrayList<Integer> resultList = CollUtil.removeWithAddIf(list, ele -> 1 == ele);
Assert.assertEquals(list, exceptRemovedList);
Assert.assertEquals(resultList, exceptResultList);
list = CollUtil.newArrayList(1, 2, 3);
resultList = new ArrayList<>();
CollUtil.removeWithAddIf(list, resultList, ele -> 1 == ele);
Assert.assertEquals(list, exceptRemovedList);
Assert.assertEquals(resultList, exceptResultList);
}
@Test
public void testPadLeft() {
List<String> srcList = CollUtil.newArrayList();