mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add methods
This commit is contained in:
@@ -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实现可以实现以下功能:
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user