This commit is contained in:
Looly
2022-09-07 15:53:33 +08:00
parent e21ca277c3
commit 58d1a9a92b
4 changed files with 12 additions and 8 deletions

View File

@@ -342,7 +342,7 @@ public class EasyStream<T> extends AbstractEnhancedWrappedStream<T, EasyStream<T
Objects.requireNonNull(pIdValuesMap);
final MutableObj<Consumer<List<T>>> recursiveRef = new MutableObj<>();
final Consumer<List<T>> recursive = values -> EasyStream.of(values, isParallel()).forEach(value -> {
List<T> children = pIdValuesMap.get(idGetter.apply(value));
final List<T> children = pIdValuesMap.get(idGetter.apply(value));
childrenSetter.accept(value, children);
recursiveRef.get().accept(children);
});

View File

@@ -173,10 +173,10 @@ public interface TerminableWrappedStream<T, S extends TerminableWrappedStream<T,
* @return map
*/
default <K, U, M extends Map<K, U>> M toMap(
final Function<? super T, ? extends K> keyMapper,
final Function<? super T, ? extends U> valueMapper,
final BinaryOperator<U> mergeFunction,
Supplier<M> mapSupplier) {
final Function<? super T, ? extends K> keyMapper,
final Function<? super T, ? extends U> valueMapper,
final BinaryOperator<U> mergeFunction,
final Supplier<M> mapSupplier) {
Objects.requireNonNull(keyMapper);
Objects.requireNonNull(valueMapper);
Objects.requireNonNull(mergeFunction);
@@ -205,7 +205,7 @@ public interface TerminableWrappedStream<T, S extends TerminableWrappedStream<T,
if (this.isParallel()) {
final List<T> keyList = toList();
final Map<T, R> map = new HashMap<>(keyList.size());
for (T key : keyList) {
for (final T key : keyList) {
map.put(key, iterator.hasNext() ? iterator.next() : null);
}
return map;

View File

@@ -155,6 +155,7 @@ public interface TransformableWrappedStream<T, S extends TransformableWrappedStr
* @param items 放入值
* @return 操作后的流
*/
@SuppressWarnings("unchecked")
default S splice(final int start, final int deleteCount, final T... items) {
final List<T> elements = unwrap().collect(Collectors.toList());
return wrap(ListUtil.splice(elements, start, deleteCount, items).stream())
@@ -279,7 +280,7 @@ public interface TransformableWrappedStream<T, S extends TransformableWrappedStr
if (isParallel()) {
return peek(e -> action.accept(e, NOT_FOUND_ELEMENT_INDEX));
} else {
AtomicInteger index = new AtomicInteger(NOT_FOUND_ELEMENT_INDEX);
final AtomicInteger index = new AtomicInteger(NOT_FOUND_ELEMENT_INDEX);
return peek(e -> action.accept(e, index.incrementAndGet()));
}
}
@@ -318,6 +319,7 @@ public interface TransformableWrappedStream<T, S extends TransformableWrappedStr
* @param obj 元素
* @return 流
*/
@SuppressWarnings({"SpellCheckingInspection", "unchecked"})
default S unshift(final T... obj) {
Stream<T> result = unwrap();
if (ArrayUtil.isNotEmpty(obj)) {
@@ -489,6 +491,7 @@ public interface TransformableWrappedStream<T, S extends TransformableWrappedStr
Objects.requireNonNull(childrenGetter);
Objects.requireNonNull(childrenSetter);
final MutableObj<Function<T, EasyStream<T>>> recursiveRef = new MutableObj<>();
@SuppressWarnings("unchecked")
final Function<T, EasyStream<T>> recursive = e -> EasyStream.of(childrenGetter.apply(e))
.flat(recursiveRef.get())
.unshift(e);

View File

@@ -269,6 +269,7 @@ public interface WrappedStream<T, S extends WrappedStream<T, S>> extends Stream<
@Override
default <A> A[] toArray(final IntFunction<A[]> generator) {
Objects.requireNonNull(generator);
//noinspection SuspiciousToArrayCall
return unwrap().toArray(generator);
}
@@ -547,7 +548,7 @@ public interface WrappedStream<T, S extends WrappedStream<T, S>> extends Stream<
* @return 流
*/
@Override
default S onClose(Runnable closeHandler) {
default S onClose(final Runnable closeHandler) {
return wrap(unwrap().onClose(closeHandler));
}