mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
109725da79
commit
5ba1dde50d
@ -1315,20 +1315,20 @@ public class CollUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除集合中的多个元素,并将结果存放到生成的新集合中后返回
|
||||
* 移除集合中的多个元素,并将结果存放到生成的新集合中后返回<br>
|
||||
* 此方法直接修改原集合
|
||||
*
|
||||
* @param <T> 集合类型
|
||||
* @param <E> 集合元素类型
|
||||
* @param targetCollection 被操作移除元素的集合
|
||||
* @param filter 用于是否移除判断的过滤器
|
||||
* @param predicate 用于是否移除判断的过滤器
|
||||
* @return 移除结果的集合
|
||||
* @since 5.7.17
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Collection<E>, E> T removeWithAddIf(T targetCollection, Predicate<? super E> filter) {
|
||||
Collection<E> resultCollection = new ArrayList<>();
|
||||
removeWithAddIf(targetCollection, resultCollection, filter);
|
||||
return (T) resultCollection;
|
||||
public static <T extends Collection<E>, E> List<E> removeWithAddIf(T targetCollection, Predicate<? super E> predicate) {
|
||||
final List<E> removed = new ArrayList<>();
|
||||
removeWithAddIf(targetCollection, removed, predicate);
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,7 +45,7 @@ public class CollUtilTest {
|
||||
ArrayList<Integer> exceptRemovedList = CollUtil.newArrayList(2, 3);
|
||||
ArrayList<Integer> exceptResultList = CollUtil.newArrayList(1);
|
||||
|
||||
ArrayList<Integer> resultList = CollUtil.removeWithAddIf(list, ele -> 1 == ele);
|
||||
List<Integer> resultList = CollUtil.removeWithAddIf(list, ele -> 1 == ele);
|
||||
Assert.assertEquals(list, exceptRemovedList);
|
||||
Assert.assertEquals(resultList, exceptResultList);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user