fix: optimize split for list

This commit is contained in:
easepan
2020-10-14 13:16:15 +08:00
parent 2a24b7fd6e
commit 8913aeaf33
3 changed files with 65 additions and 0 deletions

View File

@@ -1,12 +1,39 @@
package cn.hutool.core.collection;
import cn.hutool.core.date.StopWatch;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
public class ListUtilTest {
@Test
public void split() {
List<String> list = new ArrayList<>();
CollUtil.padRight(list, RandomUtil.randomInt(1000_0000, 1_0000_0000), "test");
int size = RandomUtil.randomInt(10, 1000);
Console.log("\nlist size: {}", list.size());
Console.log("partition size: {}\n", size);
StopWatch stopWatch = new StopWatch();
stopWatch.start("CollUtil#split");
List<List<String>> CollSplitResult = CollUtil.split(list, size);
stopWatch.stop();
stopWatch.start("ListUtil#split");
List<List<String>> ListSplitResult = ListUtil.split(list, size);
stopWatch.stop();
Assert.assertEquals(CollSplitResult, ListSplitResult);
Console.log(stopWatch.prettyPrint());
}
@Test
public void filterTest(){
List<String> a = ListUtil.toLinkedList("1", "2", "3");