mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +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
|
* 针对List排序,排序会修改原List
|
||||||
*
|
*
|
||||||
* @param <T> 元素类型
|
* @param <T> 元素类型
|
||||||
* @param list 被排序的List
|
* @param list 被排序的List
|
||||||
* @param c {@link Comparator}
|
* @param c {@link Comparator},null表示自然排序(null安全的)
|
||||||
* @return 原list
|
* @return 原list
|
||||||
* @see Collections#sort(List, Comparator)
|
* @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)) {
|
if (CollUtil.isEmpty(list)) {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
if(null == c){
|
||||||
|
c = Comparator.nullsFirst((Comparator<? super T>) Comparator.naturalOrder());
|
||||||
|
}
|
||||||
list.sort(c);
|
list.sort(c);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,9 @@ public class EasyStreamTest {
|
|||||||
final List<Integer> distinctBy2 = EasyStream.of(list).parallel().distinct(String::valueOf).toList();
|
final List<Integer> distinctBy2 = EasyStream.of(list).parallel().distinct(String::valueOf).toList();
|
||||||
|
|
||||||
Assert.assertEquals(collect1, distinctBy1);
|
Assert.assertEquals(collect1, distinctBy1);
|
||||||
Assert.assertEquals(collect2, distinctBy2);
|
|
||||||
|
// 并行流测试
|
||||||
|
Assert.assertEquals(ListUtil.sort(collect2), ListUtil.sort(distinctBy2));
|
||||||
|
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
4, EasyStream.of(1, 2, 2, null, 3, null).parallel(true).distinct(t -> Objects.isNull(t) ? null : t.toString()).sequential().count()
|
4, EasyStream.of(1, 2, 2, null, 3, null).parallel(true).distinct(t -> Objects.isNull(t) ? null : t.toString()).sequential().count()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user