mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
commit
0299a2a2ad
@ -264,18 +264,6 @@ public class EasyStream<T> extends AbstractEnhancedWrappedStream<T, EasyStream<T
|
||||
return new EasyStream<>(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为子类实现
|
||||
*
|
||||
* @param stream 流
|
||||
* @return 子类实现
|
||||
*/
|
||||
@Override
|
||||
public EasyStream<T> transform(final Stream<T> stream) {
|
||||
this.stream = stream;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 建造者
|
||||
*
|
||||
|
@ -756,18 +756,6 @@ public class EntryStream<K, V> extends AbstractEnhancedWrappedStream<Map.Entry<K
|
||||
return new EntryStream<>(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为子类实现
|
||||
*
|
||||
* @param stream 流
|
||||
* @return 子类实现
|
||||
*/
|
||||
@Override
|
||||
public EntryStream<K, V> transform(Stream<Map.Entry<K, V>> stream) {
|
||||
this.stream = stream;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* key重复时直接抛出异常
|
||||
*/
|
||||
|
@ -289,18 +289,6 @@ public interface TerminableWrappedStream<T, S extends TerminableWrappedStream<T,
|
||||
|
||||
// region ============ to optional ============
|
||||
|
||||
/**
|
||||
* 将当前流转为另一对象。用于提供针对流本身而非流中元素的操作
|
||||
*
|
||||
* @param <R> 转换类型
|
||||
* @param transform 转换
|
||||
* @return 转换后的流
|
||||
*/
|
||||
default <R> Optional<R> transform(final Function<? super S, R> transform) {
|
||||
Objects.requireNonNull(transform);
|
||||
return Optional.ofNullable(transform.apply(wrap(this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取与给定断言匹配的第一个元素
|
||||
*
|
||||
|
@ -269,7 +269,7 @@ public interface TransformableWrappedStream<T, S extends TransformableWrappedStr
|
||||
Objects.requireNonNull(action);
|
||||
if (isParallel()) {
|
||||
final Map<Integer, T> idxMap = easyStream().toIdxMap();
|
||||
return transform(EasyStream.of(idxMap.entrySet())
|
||||
return wrap(EasyStream.of(idxMap.entrySet())
|
||||
.parallel(isParallel())
|
||||
.peek(e -> action.accept(e.getValue(), e.getKey()))
|
||||
.map(Map.Entry::getValue));
|
||||
@ -373,7 +373,7 @@ public interface TransformableWrappedStream<T, S extends TransformableWrappedStr
|
||||
Objects.requireNonNull(predicate);
|
||||
if (isParallel()) {
|
||||
final Map<Integer, T> idxMap = easyStream().toIdxMap();
|
||||
return transform(EasyStream.of(idxMap.entrySet())
|
||||
return wrap(EasyStream.of(idxMap.entrySet())
|
||||
.parallel(isParallel())
|
||||
.filter(e -> predicate.test(e.getValue(), e.getKey()))
|
||||
.map(Map.Entry::getValue));
|
||||
|
@ -603,12 +603,4 @@ public interface WrappedStream<T, S extends WrappedStream<T, S>> extends Stream<
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为子类实现
|
||||
*
|
||||
* @param stream 流
|
||||
* @return 子类实现
|
||||
*/
|
||||
S transform(Stream<T> stream);
|
||||
|
||||
}
|
||||
|
@ -97,12 +97,6 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
}, toZip);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransform() {
|
||||
final List<Integer> list = wrap(1, 2, 3).transform(Wrapper::toList).orElse(null);
|
||||
Assert.assertEquals(asList(1, 2, 3), list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindFirst() {
|
||||
final List<Integer> list = asList(1, 2, 3);
|
||||
@ -181,6 +175,7 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
final List<Integer> list = asList(1, 2, 3);
|
||||
final Map<Boolean, List<Integer>> map = new HashMap<Boolean, List<Integer>>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
{
|
||||
put(Boolean.TRUE, singletonList(2));
|
||||
put(Boolean.FALSE, asList(1, 3));
|
||||
@ -624,6 +619,7 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
public void testToEntries() {
|
||||
final Map<Integer, Integer> expect = new HashMap<Integer, Integer>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
{
|
||||
put(1, 1);
|
||||
put(2, 2);
|
||||
@ -704,18 +700,6 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
return new Wrapper<>(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为子类实现
|
||||
*
|
||||
* @param stream 流
|
||||
* @return 子类实现
|
||||
*/
|
||||
@Override
|
||||
public Wrapper<T> transform(final Stream<T> stream) {
|
||||
this.stream = stream;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Setter
|
||||
|
@ -556,13 +556,4 @@ public class EasyStreamTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransform() {
|
||||
final boolean result = EasyStream.of(1, 2, 3)
|
||||
.transform(EasyStream::toList)
|
||||
.map(List::isEmpty)
|
||||
.orElse(false);
|
||||
Assert.assertFalse(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user