mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
fix test
This commit is contained in:
parent
3b3498c8a1
commit
738519d6db
@ -320,19 +320,35 @@ public class ListUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对List自然排序,排序会修改原List
|
||||
*
|
||||
* @param <T> 元素类型
|
||||
* @param list 被排序的List
|
||||
* @return 原list
|
||||
* @see Collections#sort(List, Comparator)
|
||||
*/
|
||||
public static <T> List<T> sort(final List<T> list) {
|
||||
return sort(list, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对List排序,排序会修改原List
|
||||
*
|
||||
* @param <T> 元素类型
|
||||
* @param list 被排序的List
|
||||
* @param c {@link Comparator}
|
||||
* @param c {@link Comparator},null表示自然排序(null安全的)
|
||||
* @return 原list
|
||||
* @see Collections#sort(List, Comparator)
|
||||
*/
|
||||
public static <T> List<T> sort(final List<T> list, final Comparator<? super T> c) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> List<T> sort(final List<T> list, Comparator<? super T> c) {
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return list;
|
||||
}
|
||||
if(null == c){
|
||||
c = Comparator.nullsFirst((Comparator<? super T>) Comparator.naturalOrder());
|
||||
}
|
||||
list.sort(c);
|
||||
return list;
|
||||
}
|
||||
|
@ -181,7 +181,9 @@ public class EasyStreamTest {
|
||||
final List<Integer> distinctBy2 = EasyStream.of(list).parallel().distinct(String::valueOf).toList();
|
||||
|
||||
Assert.assertEquals(collect1, distinctBy1);
|
||||
Assert.assertEquals(collect2, distinctBy2);
|
||||
|
||||
// 并行流测试
|
||||
Assert.assertEquals(ListUtil.sort(collect2), ListUtil.sort(distinctBy2));
|
||||
|
||||
Assert.assertEquals(
|
||||
4, EasyStream.of(1, 2, 2, null, 3, null).parallel(true).distinct(t -> Objects.isNull(t) ? null : t.toString()).sequential().count()
|
||||
|
Loading…
Reference in New Issue
Block a user