mirror of
https://gitee.com/dromara/hutool.git
synced 2025-07-30 22:10:27 +08:00
commit
7d962754fb
@ -1078,12 +1078,17 @@ 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) {
|
||||
if (ignoreNull) {
|
||||
return StreamUtil.of(collection)
|
||||
// 检查映射前的结果
|
||||
.filter(Objects::nonNull)
|
||||
.map(mapper)
|
||||
// 检查映射后的结果
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return StreamUtil.of(collection)
|
||||
// 检查映射前的结果
|
||||
.filter((e) -> (false == ignoreNull) || null != e)
|
||||
.map(mapper)
|
||||
// 检查映射后的结果
|
||||
.filter((e) -> (false == ignoreNull) || null != e)
|
||||
.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 !");
|
||||
|
@ -1036,15 +1036,14 @@ public class ArrayUtil extends PrimitiveArrayUtil {
|
||||
if (null == array) {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,7 +147,7 @@ public class GraphTest {
|
||||
Assert.assertEquals(asSet(2, 0), graph.getAdjacentPoints(3));
|
||||
}
|
||||
|
||||
|
||||
@SafeVarargs
|
||||
private static <T> Set<T> asSet(T... ts) {
|
||||
return new LinkedHashSet<>(Arrays.asList(ts));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user