mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
fix code
This commit is contained in:
parent
97e0243529
commit
93c6b7e3e7
@ -363,7 +363,7 @@ public class CollUtil {
|
||||
* 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c]<br>
|
||||
* 结果:[a, b, c],此结果中只保留了一个c
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param <T> 集合元素类型
|
||||
* @param colls 集合列表
|
||||
* @return 交集的集合,返回 {@link LinkedHashSet}
|
||||
* @since 5.3.9
|
||||
@ -1078,13 +1078,16 @@ public class CollUtil {
|
||||
* @since 5.3.5
|
||||
*/
|
||||
public static <T, R> List<R> map(final Iterable<T> collection, final Function<? super T, ? extends R> mapper, final boolean ignoreNull) {
|
||||
return StreamUtil.of(collection)
|
||||
// 检查映射前的结果
|
||||
.filter((e) -> (false == ignoreNull) || null != e)
|
||||
.map(mapper)
|
||||
// 检查映射后的结果
|
||||
.filter((e) -> (false == ignoreNull) || null != e)
|
||||
.collect(Collectors.toList());
|
||||
if (ignoreNull) {
|
||||
return StreamUtil.of(collection)
|
||||
// 检查映射前的结果
|
||||
.filter(Objects::nonNull)
|
||||
.map(mapper)
|
||||
// 检查映射后的结果
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return StreamUtil.of(collection).map(mapper).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -433,7 +433,7 @@ public class ListUtil {
|
||||
* @param element 新元素
|
||||
* @param paddingElement 填充的值
|
||||
* @return 原List
|
||||
* @since 5。8.4
|
||||
* @since 5.8.4
|
||||
*/
|
||||
public static <T> List<T> setOrPadding(final List<T> list, final int index, final T element, final T paddingElement) {
|
||||
Assert.notNull(list, "List must be not null !");
|
||||
|
@ -1028,7 +1028,7 @@ public class ArrayUtil extends PrimitiveArrayUtil {
|
||||
* @param <T> 数组元素类型
|
||||
* @param array 数组对象
|
||||
* @param index 下标,支持负数
|
||||
* @return 值
|
||||
* @return 值,越界返回null
|
||||
* @since 4.0.6
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -1037,14 +1037,14 @@ public class ArrayUtil extends PrimitiveArrayUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int length = Array.getLength(array);
|
||||
if (index < 0) {
|
||||
index += Array.getLength(array);
|
||||
index += length;
|
||||
}
|
||||
try {
|
||||
return (T) Array.get(array, index);
|
||||
} catch (final ArrayIndexOutOfBoundsException e) {
|
||||
if (index < 0 || index >= length) {
|
||||
return null;
|
||||
}
|
||||
return (T) Array.get(array, index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,7 @@ public class GraphTest {
|
||||
|
||||
@Test
|
||||
public void testPutEdge() {
|
||||
Graph<Integer> graph = new Graph<>();
|
||||
final Graph<Integer> graph = new Graph<>();
|
||||
graph.putEdge(0, 1);
|
||||
graph.putEdge(1, 2);
|
||||
graph.putEdge(2, 0);
|
||||
@ -30,7 +30,7 @@ public class GraphTest {
|
||||
// 0 -- 1
|
||||
// | |
|
||||
// 3 -- 2
|
||||
Graph<Integer> graph = new Graph<>();
|
||||
final Graph<Integer> graph = new Graph<>();
|
||||
graph.putEdge(0, 1);
|
||||
graph.putEdge(1, 2);
|
||||
graph.putEdge(2, 3);
|
||||
@ -53,7 +53,7 @@ public class GraphTest {
|
||||
|
||||
@Test
|
||||
public void removeEdge() {
|
||||
Graph<Integer> graph = new Graph<>();
|
||||
final Graph<Integer> graph = new Graph<>();
|
||||
graph.putEdge(0, 1);
|
||||
Assert.assertTrue(graph.containsEdge(0, 1));
|
||||
|
||||
@ -66,7 +66,7 @@ public class GraphTest {
|
||||
// 0 -- 1
|
||||
// | |
|
||||
// 3 -- 2
|
||||
Graph<Integer> graph = new Graph<>();
|
||||
final Graph<Integer> graph = new Graph<>();
|
||||
graph.putEdge(0, 1);
|
||||
graph.putEdge(1, 2);
|
||||
graph.putEdge(2, 3);
|
||||
@ -87,7 +87,7 @@ public class GraphTest {
|
||||
// 0 -- 1
|
||||
// | |
|
||||
// 3 -- 2
|
||||
Graph<Integer> graph = new Graph<>();
|
||||
final Graph<Integer> graph = new Graph<>();
|
||||
graph.putEdge(0, 1);
|
||||
graph.putEdge(1, 2);
|
||||
graph.putEdge(2, 3);
|
||||
@ -113,7 +113,7 @@ public class GraphTest {
|
||||
// 0 -- 1
|
||||
// | |
|
||||
// 3 -- 2
|
||||
Graph<Integer> graph = new Graph<>();
|
||||
final Graph<Integer> graph = new Graph<>();
|
||||
graph.putEdge(0, 1);
|
||||
graph.putEdge(1, 2);
|
||||
graph.putEdge(2, 3);
|
||||
@ -130,7 +130,7 @@ public class GraphTest {
|
||||
// 0 -- 1
|
||||
// | |
|
||||
// 3 -- 2
|
||||
Graph<Integer> graph = new Graph<>();
|
||||
final Graph<Integer> graph = new Graph<>();
|
||||
graph.putEdge(0, 1);
|
||||
graph.putEdge(1, 2);
|
||||
graph.putEdge(2, 3);
|
||||
@ -147,8 +147,8 @@ public class GraphTest {
|
||||
Assert.assertEquals(asSet(2, 0), graph.getAdjacentPoints(3));
|
||||
}
|
||||
|
||||
|
||||
private static <T> Set<T> asSet(T... ts) {
|
||||
@SafeVarargs
|
||||
private static <T> Set<T> asSet(final T... ts) {
|
||||
return new LinkedHashSet<>(Arrays.asList(ts));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user