mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
back
This commit is contained in:
parent
4aba88e828
commit
c67adf4387
@ -363,7 +363,7 @@ public class CollUtil {
|
|||||||
* 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c]<br>
|
* 例如:集合1:[a, b, c, c, c],集合2:[a, b, c, c]<br>
|
||||||
* 结果:[a, b, c],此结果中只保留了一个c
|
* 结果:[a, b, c],此结果中只保留了一个c
|
||||||
*
|
*
|
||||||
* @param <T> 集合元素类型
|
* @param <T> 集合元素类型
|
||||||
* @param colls 集合列表
|
* @param colls 集合列表
|
||||||
* @return 交集的集合,返回 {@link LinkedHashSet}
|
* @return 交集的集合,返回 {@link LinkedHashSet}
|
||||||
* @since 5.3.9
|
* @since 5.3.9
|
||||||
@ -1078,16 +1078,13 @@ 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((e) -> (false == ignoreNull) || null != e)
|
||||||
.filter(Objects::nonNull)
|
.map(mapper)
|
||||||
.map(mapper)
|
// 检查映射后的结果
|
||||||
// 检查映射后的结果
|
.filter((e) -> (false == ignoreNull) || null != e)
|
||||||
.filter(Objects::nonNull)
|
.collect(Collectors.toList());
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
return StreamUtil.of(collection).map(mapper).collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -433,7 +433,7 @@ public class ListUtil {
|
|||||||
* @param element 新元素
|
* @param element 新元素
|
||||||
* @param paddingElement 填充的值
|
* @param paddingElement 填充的值
|
||||||
* @return 原List
|
* @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) {
|
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 !");
|
||||||
|
@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user