mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
predicate.test的返回结果不能为null;
This commit is contained in:
parent
705a15c3e5
commit
aba35cc6c2
@ -313,11 +313,8 @@ public class EasyStream<T> extends AbstractEnhancedWrappedStream<T, EasyStream<T
|
||||
final Predicate<T> parentPredicate) {
|
||||
Objects.requireNonNull(parentPredicate);
|
||||
final List<T> list = toList();
|
||||
final List<T> parents = EasyStream.of(list).filter(e ->
|
||||
// 此处是为了适配 parentPredicate.test空指针 情况
|
||||
// 因为Predicate.test的返回值是boolean,所以如果 e -> null 这种返回null的情况,会直接抛出NPE
|
||||
Opt.ofTry(() -> parentPredicate.test(e)).filter(Boolean::booleanValue).isPresent())
|
||||
.toList();
|
||||
// 根节点列表
|
||||
final List<T> parents = EasyStream.of(list).filter(parentPredicate).toList();
|
||||
return getChildrenFromMapByPidAndSet(idGetter, childrenSetter, EasyStream.of(list).group(pIdGetter), parents);
|
||||
}
|
||||
|
||||
|
@ -476,7 +476,7 @@ public class EasyStreamTest {
|
||||
Student.builder().id(8L).name("jobob").parentId(5L).build()
|
||||
)
|
||||
// just 4 lambda ,top by condition
|
||||
.toTree(Student::getId, Student::getParentId, Student::setChildren, Student::getMatchParent);
|
||||
.toTree(Student::getId, Student::getParentId, Student::setChildren, Student::isMatchParent);
|
||||
Assert.assertEquals(asList(
|
||||
Student.builder().id(1L).name("dromara").matchParent(true)
|
||||
.children(asList(Student.builder().id(3L).name("hutool").parentId(1L)
|
||||
@ -540,7 +540,7 @@ public class EasyStreamTest {
|
||||
private Long id;
|
||||
private Long parentId;
|
||||
private List<Student> children;
|
||||
private Boolean matchParent = false;
|
||||
private boolean matchParent;
|
||||
|
||||
@Tolerate
|
||||
public Student() {
|
||||
|
Loading…
Reference in New Issue
Block a user