mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
!808 EasyStream.toTree移除对predicate.test的返回结果为null的支持
Merge pull request !808 from emptypoint/EasyStream-issue
This commit is contained in:
@@ -40,7 +40,7 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
@Test
|
||||
public void testToSet() {
|
||||
final List<Integer> list = asList(1, 2, 3);
|
||||
Set<String> toSet = wrap(list).map(String::valueOf).toSet();
|
||||
final Set<String> toSet = wrap(list).map(String::valueOf).toSet();
|
||||
Assert.assertEquals(new HashSet<>(asList("1", "2", "3")), toSet);
|
||||
}
|
||||
|
||||
@@ -636,7 +636,7 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
List<String> zip = wrap(orders).zip(list, (e1, e2) -> e1 + "." + e2).toList();
|
||||
Assert.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), zip);
|
||||
|
||||
zip = wrap((Stream<? extends Object>) EasyStream.iterate(1, i -> i + 1)).limit(10).zip(list, (e1, e2) -> e1 + "." + e2).toList();
|
||||
zip = this.wrap((Stream<Integer>)EasyStream.iterate(1, i -> i + 1)).limit(10).zip(list, (e1, e2) -> e1 + "." + e2).toList();
|
||||
Assert.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), zip);
|
||||
}
|
||||
|
||||
@@ -663,15 +663,15 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private static <T> Wrapper<T> wrap(T... array) {
|
||||
private final <T> Wrapper<T> wrap(final T... array) {
|
||||
return new Wrapper<>(Stream.of(array));
|
||||
}
|
||||
|
||||
private static <T> Wrapper<T> wrap(Iterable<T> iterable) {
|
||||
private <T> Wrapper<T> wrap(final Iterable<T> iterable) {
|
||||
return new Wrapper<>(StreamSupport.stream(iterable.spliterator(), false));
|
||||
}
|
||||
|
||||
private static <T> Wrapper<T> wrap(Stream<T> stream) {
|
||||
private <T> Wrapper<T> wrap(final Stream<T> stream) {
|
||||
return new Wrapper<>(stream);
|
||||
}
|
||||
|
||||
@@ -683,12 +683,12 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
* @param stream 包装的流对象
|
||||
* @throws NullPointerException 当{@code unwrap}为{@code null}时抛出
|
||||
*/
|
||||
protected Wrapper(Stream<T> stream) {
|
||||
protected Wrapper(final Stream<T> stream) {
|
||||
super(stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Wrapper<T> wrap(Stream<T> source) {
|
||||
public Wrapper<T> wrap(final Stream<T> source) {
|
||||
return new Wrapper<>(source);
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,7 @@ package cn.hutool.core.stream;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.BooleanUtil;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Tolerate;
|
||||
import org.junit.Assert;
|
||||
@@ -181,7 +182,7 @@ public class EasyStreamTest {
|
||||
Assert.assertEquals(collect2, distinctBy2);
|
||||
|
||||
Assert.assertEquals(
|
||||
4, EasyStream.of(1, 2, 2, null, 3, null).parallel(true).distinct(t -> Objects.isNull(t) ? null : t.toString()).sequential().count()
|
||||
4, EasyStream.of(1, 2, 2, null, 3, null).parallel(true).distinct(t -> Objects.isNull(t) ? null : t.toString()).sequential().count()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -476,7 +477,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, s -> BooleanUtil.isTrue(s.getMatchParent()));
|
||||
Assert.assertEquals(asList(
|
||||
Student.builder().id(1L).name("dromara").matchParent(true)
|
||||
.children(asList(Student.builder().id(3L).name("hutool").parentId(1L)
|
||||
@@ -540,7 +541,7 @@ public class EasyStreamTest {
|
||||
private Long id;
|
||||
private Long parentId;
|
||||
private List<Student> children;
|
||||
private Boolean matchParent = false;
|
||||
private Boolean matchParent;
|
||||
|
||||
@Tolerate
|
||||
public Student() {
|
||||
|
Reference in New Issue
Block a user