mirror of
https://gitee.com/dromara/hutool.git
synced 2025-10-15 18:55:18 +08:00
fix code
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
|
||||
package org.dromara.hutool.core.collection;
|
||||
|
||||
import org.dromara.hutool.core.array.ArrayUtil;
|
||||
import org.dromara.hutool.core.collection.iter.EnumerationIter;
|
||||
import org.dromara.hutool.core.collection.partition.AvgPartition;
|
||||
import org.dromara.hutool.core.collection.partition.Partition;
|
||||
@@ -21,7 +22,6 @@ import org.dromara.hutool.core.comparator.PinyinComparator;
|
||||
import org.dromara.hutool.core.comparator.PropertyComparator;
|
||||
import org.dromara.hutool.core.lang.Assert;
|
||||
import org.dromara.hutool.core.lang.page.PageInfo;
|
||||
import org.dromara.hutool.core.array.ArrayUtil;
|
||||
import org.dromara.hutool.core.util.ObjUtil;
|
||||
|
||||
import java.util.*;
|
||||
@@ -387,11 +387,13 @@ public class ListUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 反序给定List,会在原List基础上直接修改
|
||||
* 反序给定List,会在原List基础上直接修改<br>
|
||||
* 注意此方法不支持不可编辑的列表
|
||||
*
|
||||
* @param <T> 元素类型
|
||||
* @param list 被反转的List
|
||||
* @return 反转后的List
|
||||
* @see Collections#reverse(List)
|
||||
* @since 4.0.6
|
||||
*/
|
||||
public static <T> List<T> reverse(final List<T> list) {
|
||||
@@ -416,7 +418,12 @@ public class ListUtil {
|
||||
// 不支持clone
|
||||
list2 = new ArrayList<>(list);
|
||||
}
|
||||
try {
|
||||
return reverse(list2);
|
||||
} catch (final UnsupportedOperationException e) {
|
||||
// 提供的列表不可编辑,新建列表
|
||||
return reverse(of(list));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -255,4 +255,11 @@ public class ListUtilTest {
|
||||
final CopyOnWriteArrayList<String> strings = ListUtil.ofCopyOnWrite("a", "b");
|
||||
Assertions.assertEquals(2, strings.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void reverseNewTest() {
|
||||
final List<Integer> view = ListUtil.view(1, 2, 3);
|
||||
final List<Integer> reverse = ListUtil.reverseNew(view);
|
||||
Assertions.assertEquals("[3, 2, 1]", reverse.toString());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user