This commit is contained in:
Looly 2022-10-17 22:16:43 +08:00
parent 7c8881eb54
commit dffa682b8f
3 changed files with 13 additions and 5 deletions

View File

@ -40,6 +40,7 @@ import java.util.stream.StreamSupport;
* </ul>
* 不同类型的流可以通过{@link #sequential()}{@link #parallel()}互相转换
*
* @param <T> 对象类型
* @author VampireAchao
* @author emptypoint
* @author huangchengxing
@ -270,7 +271,7 @@ public class EasyStream<T> extends AbstractEnhancedWrappedStream<T, EasyStream<T
* @return 子类实现
*/
@Override
public EasyStream<T> transform(Stream<T> stream) {
public EasyStream<T> transform(final Stream<T> stream) {
this.stream = stream;
return this;
}

View File

@ -32,6 +32,11 @@ import static java.util.Objects.requireNonNull;
*/
public class StreamUtil {
/**
* @param array 数组
* @param <T> 元素类型
* @return {@link Stream}
*/
@SafeVarargs
public static <T> Stream<T> of(final T... array) {
Assert.notNull(array, "Array must be not null!");
@ -66,8 +71,9 @@ public class StreamUtil {
/**
* {@link Iterator} 转换为 {@link Stream}
*
* @param iterator 迭代器
* @param <T> 集合元素类型
* @param <T> 集合元素类型
* @return {@link Stream}
* @throws IllegalArgumentException 如果iterator为null抛出该异常
*/
@ -77,9 +83,10 @@ public class StreamUtil {
/**
* {@link Iterator} 转换为 {@link Stream}
*
* @param iterator 迭代器
* @param parallel 是否并行
* @param <T> 集合元素类型
* @param <T> 集合元素类型
* @return {@link Stream}
* @throws IllegalArgumentException 如果iterator为null抛出该异常
*/

View File

@ -42,8 +42,8 @@ public interface TransformableWrappedStream<T, S extends TransformableWrappedStr
final Iterable<U> other,
final BiFunction<? super T, ? super U, ? extends R> zipper) {
Objects.requireNonNull(zipper);
Map<Integer, T> idxIdentityMap = mapIdx((e, idx) -> MapUtil.entry(idx, e)).collect(CollectorUtil.entryToMap());
Map<Integer, U> idxOtherMap = EasyStream.of(other).mapIdx((e, idx) -> MapUtil.entry(idx, e)).collect(CollectorUtil.entryToMap());
final Map<Integer, T> idxIdentityMap = mapIdx((e, idx) -> MapUtil.entry(idx, e)).collect(CollectorUtil.entryToMap());
final Map<Integer, U> idxOtherMap = EasyStream.of(other).mapIdx((e, idx) -> MapUtil.entry(idx, e)).collect(CollectorUtil.entryToMap());
if (idxIdentityMap.size() <= idxOtherMap.size()) {
return EasyStream.of(idxIdentityMap.keySet(), isParallel()).map(k -> zipper.apply(idxIdentityMap.get(k), idxOtherMap.get(k)));
}