add methods

This commit is contained in:
Looly
2020-03-26 17:15:43 +08:00
parent 8bb73f3829
commit 85eab64171
4 changed files with 45 additions and 28 deletions

View File

@@ -389,32 +389,6 @@ public class ListUtil {
return result;
}
/**
* 编辑列表,此方法会修改原列表的内容<br>
* 编辑过程通过传入的Editor实现编辑列表中元素内容这个Editor实现可以实现以下功能
*
* <pre>
* 1、修改元素对象返回集合中为修改后的对象
* </pre>
*
* @param <T> 集合元素类型
* @param list 集合
* @param editor 编辑器接口
* @return 编辑后的数组
* @since 4.1.8
*/
public static <T> List<T> edit(List<T> list, Editor<T> editor) {
if (null == list || null == editor) {
return list;
}
for (T t : list) {
editor.edit(t);
}
return list;
}
/**
* 过滤<br>
* 过滤过程通过传入的Editor实现来返回需要的元素内容这个Editor实现可以实现以下功能

View File

@@ -0,0 +1,18 @@
package cn.hutool.core.collection;
import org.junit.Assert;
import org.junit.Test;
import java.util.List;
public class ListUtilTest {
@Test
public void filterTest(){
List<String> a = ListUtil.toLinkedList("1", "2", "3");
final List<String> filter = ListUtil.filter(a, str -> "edit" + str);
Assert.assertEquals("edit1", filter.get(0));
Assert.assertEquals("edit2", filter.get(1));
Assert.assertEquals("edit3", filter.get(2));
}
}