This commit is contained in:
Looly 2022-11-17 01:09:14 +08:00
parent 4aba88e828
commit c67adf4387
3 changed files with 14 additions and 17 deletions

View File

@ -1078,17 +1078,14 @@ public class CollUtil {
* @since 5.3.5 * @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) { 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) return StreamUtil.of(collection)
// 检查映射前的结果 // 检查映射前的结果
.filter(Objects::nonNull) .filter((e) -> (false == ignoreNull) || null != e)
.map(mapper) .map(mapper)
// 检查映射后的结果 // 检查映射后的结果
.filter(Objects::nonNull) .filter((e) -> (false == ignoreNull) || null != e)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
return StreamUtil.of(collection).map(mapper).collect(Collectors.toList());
}
/** /**
* 获取给定Bean列表中指定字段名对应字段值的列表<br> * 获取给定Bean列表中指定字段名对应字段值的列表<br>

View File

@ -433,7 +433,7 @@ public class ListUtil {
* @param element 新元素 * @param element 新元素
* @param paddingElement 填充的值 * @param paddingElement 填充的值
* @return 原List * @return 原List
* @since 5.8.4 * @since 58.4
*/ */
public static <T> List<T> setOrPadding(final List<T> list, final int index, final T element, final T paddingElement) { 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 !"); Assert.notNull(list, "List must be not null !");

View File

@ -1028,7 +1028,7 @@ public class ArrayUtil extends PrimitiveArrayUtil {
* @param <T> 数组元素类型 * @param <T> 数组元素类型
* @param array 数组对象 * @param array 数组对象
* @param index 下标支持负数 * @param index 下标支持负数
* @return 越界返回null * @return
* @since 4.0.6 * @since 4.0.6
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -1037,14 +1037,14 @@ public class ArrayUtil extends PrimitiveArrayUtil {
return null; return null;
} }
final int length = Array.getLength(array);
if (index < 0) { if (index < 0) {
index += length; index += Array.getLength(array);
} }
if (index < 0 || index >= length) { try {
return (T) Array.get(array, index);
} catch (final ArrayIndexOutOfBoundsException e) {
return null; return null;
} }
return (T) Array.get(array, index);
} }
/** /**