Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2016, 2017, 2018, 2019 HaiYang Li
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.landawn.abacus.util.stream;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.security.SecureRandom;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.BinaryOperator;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.DoubleConsumer;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.IntConsumer;
import java.util.function.IntFunction;
import java.util.function.LongConsumer;
import java.util.function.LongFunction;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import java.util.function.ToLongFunction;
import java.util.function.UnaryOperator;
import java.util.regex.Pattern;
import java.util.stream.Collector;
import com.landawn.abacus.annotation.Beta;
import com.landawn.abacus.annotation.IntermediateOp;
import com.landawn.abacus.annotation.LazyEvaluation;
import com.landawn.abacus.annotation.ParallelSupported;
import com.landawn.abacus.annotation.SequentialOnly;
import com.landawn.abacus.annotation.TerminalOp;
import com.landawn.abacus.annotation.TerminalOpTriggered;
import com.landawn.abacus.util.Array;
import com.landawn.abacus.util.AsyncExecutor;
import com.landawn.abacus.util.ByteIterator;
import com.landawn.abacus.util.CharIterator;
import com.landawn.abacus.util.Charsets;
import com.landawn.abacus.util.Comparators;
import com.landawn.abacus.util.ContinuableFuture;
import com.landawn.abacus.util.DataSet;
import com.landawn.abacus.util.Difference;
import com.landawn.abacus.util.DoubleIterator;
import com.landawn.abacus.util.Duration;
import com.landawn.abacus.util.FloatIterator;
import com.landawn.abacus.util.Fn;
import com.landawn.abacus.util.Fn.BiConsumers;
import com.landawn.abacus.util.Fn.Suppliers;
import com.landawn.abacus.util.Holder;
import com.landawn.abacus.util.IOUtil;
import com.landawn.abacus.util.ImmutableMap;
import com.landawn.abacus.util.Indexed;
import com.landawn.abacus.util.IntIterator;
import com.landawn.abacus.util.IntList;
import com.landawn.abacus.util.InternalUtil;
import com.landawn.abacus.util.Iterables;
import com.landawn.abacus.util.Iterators;
import com.landawn.abacus.util.LineIterator;
import com.landawn.abacus.util.ListMultimap;
import com.landawn.abacus.util.LongIterator;
import com.landawn.abacus.util.MergeResult;
import com.landawn.abacus.util.Multimap;
import com.landawn.abacus.util.MutableBoolean;
import com.landawn.abacus.util.MutableInt;
import com.landawn.abacus.util.MutableLong;
import com.landawn.abacus.util.N;
import com.landawn.abacus.util.NoCachingNoUpdating;
import com.landawn.abacus.util.ObjIterator;
import com.landawn.abacus.util.Pair;
import com.landawn.abacus.util.Percentage;
import com.landawn.abacus.util.ShortIterator;
import com.landawn.abacus.util.Splitter;
import com.landawn.abacus.util.Throwables;
import com.landawn.abacus.util.cs;
import com.landawn.abacus.util.u.Optional;
import com.landawn.abacus.util.u.OptionalDouble;
import com.landawn.abacus.util.u.OptionalInt;
import com.landawn.abacus.util.u.OptionalLong;
import com.landawn.abacus.util.function.ByteBiFunction;
import com.landawn.abacus.util.function.ByteNFunction;
import com.landawn.abacus.util.function.ByteTriFunction;
import com.landawn.abacus.util.function.CharBiFunction;
import com.landawn.abacus.util.function.CharNFunction;
import com.landawn.abacus.util.function.CharTriFunction;
import com.landawn.abacus.util.function.DoubleBiFunction;
import com.landawn.abacus.util.function.DoubleNFunction;
import com.landawn.abacus.util.function.DoubleTriFunction;
import com.landawn.abacus.util.function.FloatBiFunction;
import com.landawn.abacus.util.function.FloatNFunction;
import com.landawn.abacus.util.function.FloatTriFunction;
import com.landawn.abacus.util.function.IntBiFunction;
import com.landawn.abacus.util.function.IntNFunction;
import com.landawn.abacus.util.function.IntTriFunction;
import com.landawn.abacus.util.function.LongBiFunction;
import com.landawn.abacus.util.function.LongNFunction;
import com.landawn.abacus.util.function.LongTriFunction;
import com.landawn.abacus.util.function.ShortBiFunction;
import com.landawn.abacus.util.function.ShortNFunction;
import com.landawn.abacus.util.function.ShortTriFunction;
import com.landawn.abacus.util.function.ToByteFunction;
import com.landawn.abacus.util.function.ToCharFunction;
import com.landawn.abacus.util.function.ToFloatFunction;
import com.landawn.abacus.util.function.ToShortFunction;
import com.landawn.abacus.util.function.TriFunction;
import com.landawn.abacus.util.function.TriPredicate;
import com.landawn.abacus.util.stream.ObjIteratorEx.BufferedIterator;
// Tested performance with below code. It seems there is no meaningful performance improvement brought by Seq(CheckedStream), comparing with Stream.
// Remove the CheckedStream for now???
// @Test
// public void test_try_catch_perf() {
// final int len = 1000_000;
// final int loopNum = 100;
//
// Profiler.run(1, loopNum, 3, "noTryCatch", () -> {
// final long count = Stream.range(0, len).map(it -> notThrowSQLException()).count();
//
// assertEquals(len, count);
// }).printResult();
//
// Profiler.run(1, loopNum, 3, "cmdWithTryCatch", () -> {
// final long count = Stream.range(0, len).map(Fn.ff(it -> maybeThrowSQLException())).count();
//
// assertEquals(len, count);
// }).printResult();
//
// Profiler.run(1, loopNum, 3, "cmdByCheckedStream", () -> {
// try {
// final long count = CheckedStream. range(0, len).map(it -> maybeThrowSQLException()).count();
// assertEquals(len, count);
// } catch (final SQLException e) {
// throw ExceptionUtil.toRuntimeException(e, true);
// }
// }).printResult();
//
// }
//
// @SuppressWarnings("unused")
// String maybeThrowSQLException() throws SQLException {
// return "abc"; // Strings.uuid();
// }
//
// String notThrowSQLException() {
// return "abc"; // Strings.uuid();
// }
/**
* Note: This class includes codes copied from StreamEx: StreamEx under Apache License, version 2.0.
*
*
* The Stream class is an abstract class that represents a stream of elements and supports different kinds of computations.
* The Stream operations are divided into intermediate and terminal operations, and are combined to form stream pipelines.
*
*
* The Stream will be automatically closed after a terminal method is called/triggered.
*
*
* Refer to {@code com.landawn.abacus.util.stream.BaseStream}
*
* @param the type of the stream elements
* @see com.landawn.abacus.util.stream.BaseStream
* @see com.landawn.abacus.util.stream.EntryStream
* @see com.landawn.abacus.util.stream.IntStream
* @see com.landawn.abacus.util.stream.LongStream
* @see com.landawn.abacus.util.stream.DoubleStream
* @see com.landawn.abacus.util.stream.Collectors
* @see com.landawn.abacus.util.Fn
* @see com.landawn.abacus.util.Comparators
* @see com.landawn.abacus.util.Seq
*/
@com.landawn.abacus.annotation.Immutable
@LazyEvaluation
@SuppressWarnings({ "java:S1192", "java:S1845" })
public abstract class Stream extends StreamBase, Consumer super T>, Optional, Indexed, ObjIterator, Stream> {
static final Random RAND = new SecureRandom();
private static final Splitter lineSplitter = Splitter.forLines();
private static final Splitter trimLineSplitter = Splitter.forLines().trimResults();
private static final Splitter omitEmptyLinesLineSplitter = Splitter.forLines().omitEmptyStrings();
private static final Splitter trimAndOmitEmptyLinesLineSplitter = Splitter.forLines().trimResults().omitEmptyStrings();
Stream(final boolean sorted, final Comparator super T> cmp, final Collection closeHandlers) {
super(sorted, cmp, closeHandlers);
}
/**
* Returns a stream consisting of the elements of this stream that match the given predicate.
*
* @param predicate the condition to test the elements of the stream
* @return a new Stream consisting of the elements that match the given predicate
*/
@ParallelSupported
@IntermediateOp
@Override
public abstract Stream filter(Predicate super T> predicate);
/**
* Returns a stream consisting of the elements of this stream that match the given predicate.
* If an element does not match the predicate, the provided action {@code actionOnDroppedItem} is applied to that element.
*
* This is an intermediate operation.
*
* @param predicate the condition to test the elements of the stream
* @param actionOnDroppedItem the action to perform on the elements that do not match the predicate.
* This action is only applied to the elements that do not match the predicate and pulled by downstream/terminal operation.
* @return a new Stream consisting of the elements that match the given predicate
*/
@Beta
@ParallelSupported
@IntermediateOp
@Override
public abstract Stream filter(Predicate super T> predicate, Consumer super T> actionOnDroppedItem);
/**
* Keeps the elements until the given predicate returns {@code false}.
* The stream should be sorted, which means if x is the first element: {@code predicate.test(x)} returns {@code false}, any element y behind x: {@code predicate.test(y)} should return {@code false}.
*
* In parallel Streams, the elements after the first element which {@code predicate} returns {@code false} may be tested by predicate too.
*
*
* For example:
*
*
* // For sequential stream:
* Stream.of(1, 2, 3, 4, 5, 6).takeWhile(it -> it < 5).toList() ===> [1, 2, 3, 4]
* Stream.of(1, 2, 5, 6, 3, 4).takeWhile(it -> it < 5).toList() ===> [1, 2]
* Stream.of(5, 6, 1, 2, 3, 4).takeWhile(it -> it < 5).toList() ===> []
*
*
* // For parallel stream:
* Stream.of(1, 2, 3, 4, 5, 6).parallel().takeWhile(it -> it < 5).toList() ===> [1, 2, 3, 4] // Order could be different since it's in parallel stream.
* Stream.of(1, 2, 5, 6, 3, 4).parallel().takeWhile(it -> it < 5).toList() ===> [1, 2] // or [1, 2, 3] or [1, 2, 3, 4] // Order could be different since it's in parallel stream.
* Stream.of(5, 6, 1, 2, 3, 4).parallel().takeWhile(it -> it < 5).toList() ===> any sub set of [1, 2, 3, 4], including [] // Order could be different since it's in parallel stream.
*
*
*
* @param predicate
* @return
*/
@ParallelSupported
@IntermediateOp
@Override
public abstract Stream takeWhile(Predicate super T> predicate);
/**
* Removes the elements until the given predicate returns {@code false}.
* The stream should be sorted, which means if x is the first element: {@code predicate.test(x)} returns {@code true}, any element y behind x: {@code predicate.test(y)} should return {@code true}.
*
* In parallel Streams, the elements after the first element which {@code predicate} returns {@code false} may be tested by predicate too.
*
*
* For example:
*
* // For sequential stream:
* Stream.of(1, 2, 3, 4, 5, 6).dropWhile(it -> it < 4).toList() ===> [4, 5, 6]
* Stream.of(1, 2, 5, 6, 3, 4).dropWhile(it -> it < 4).toList() ===> [5, 6, 3, 4]
* Stream.of(5, 6, 1, 2, 3, 4).dropWhile(it -> it < 4).toList() ===> [5, 6, 1, 2, 3, 4]
*
*
* // For parallel stream:
* Stream.of(1, 2, 3, 4, 5, 6).parallel().dropWhile(it -> it < 4).toList() ===> [4, 5, 6] // Order could be different since it's in parallel stream.
* Stream.of(1, 2, 5, 6, 3, 4).parallel().dropWhile(it -> it < 4).toList() ===> [5, 6, 4] // or [5, 6, 3, 4] // Order could be different since it's in parallel stream.
* Stream.of(5, 6, 1, 2, 3, 4).parallel().dropWhile(it -> it < 4).toList() ===> [5, 6] + any sub set of [1, 2, 3, 4] // Order could be different since it's in parallel stream.
*
*
* @param predicate
* @return
*/
@ParallelSupported
@IntermediateOp
@Override
public abstract Stream dropWhile(Predicate super T> predicate);
/**
* Removes the elements of this stream until the given predicate returns {@code false}.
* The stream should be sorted, which means if x is the first element: {@code predicate.test(x)} returns {@code true}, any element y behind x: {@code predicate.test(y)} should return {@code true}.
*
* In parallel Streams, the elements after the first element which {@code predicate} returns {@code false} may be tested by predicate too.
*
* @param predicate the condition to test the elements of the stream
* @param actionOnDroppedItem the action to perform on the elements that do not match the predicate
* This action is only applied to the elements that do not match the predicate and pulled by downstream/terminal operation.
* @return a new Stream consisting of the remaining elements after the elements that do not match the predicate have been removed
*/
@Beta
@ParallelSupported
@IntermediateOp
@Override
public abstract Stream dropWhile(Predicate super T> predicate, Consumer super T> actionOnDroppedItem);
/**
* Skips elements in the stream until the given predicate returns {@code true}.
* The stream should be sorted, which means if x is the first element: {@code predicate.test(x)} returns {@code true}, any element y behind x: {@code predicate.test(y)} should return {@code true}.
*
* In parallel Streams, the elements after the first element which {@code predicate} returns {@code true} may be tested by predicate too.
*
* @param predicate the condition to test the elements of the stream
* @return a new Stream consisting of the remaining elements after the elements that do not match the predicate have been skipped
* @see #dropWhile(Predicate)
*/
@Beta
@ParallelSupported
@IntermediateOp
@Override
public abstract Stream skipUntil(Predicate super T> predicate);
/**
* Performs the given action on the elements pulled by downstream/terminal operation.
* This is an intermediate operation.
*
*
* Same as {@code peek}.
*
* @param action The action to be performed on the elements pulled by downstream/terminal operation
* @return A new Stream consisting of the elements of this stream with the provided action applied to each element.
* @see #peek(Consumer)
*/
@Beta
@ParallelSupported
@IntermediateOp
@Override
public abstract Stream onEach(Consumer super T> action);
/**
* Performs the provided action on the elements pulled by downstream/terminal operation. Mostly it's used for debugging
* This is an intermediate operation.
*
* @param action The action to be performed on the elements pulled by downstream/terminal operation
* @return A new Stream consisting of the elements of this stream with the provided action applied to each element.
* @see #onEach(Consumer)
*/
@ParallelSupported
@IntermediateOp
@Override
public Stream peek(final Consumer super T> action) {
return onEach(action);
}
/**
* Selects the elements that belong to the specified {@code targetType}, including its subtypes.
* This is an intermediate operation.
*
* @param the type of the elements to be selected
* @param targetType the class of the type to be selected
* @return a new Stream containing elements of the specified type
*/
@SequentialOnly
@IntermediateOp
public abstract Stream select(final Class extends U> targetType);
/**
* Pairs each element in the stream with the result of applying the provided function to that element.
* This is an intermediate operation.
*
* @param The type of the paired value.
* @param extractor The function to be applied to each element in the stream.
* @return A new Stream of Pairs, where each Pair consists of an element from the original stream and its corresponding value obtained by applying the extractor function.
*/
@ParallelSupported
@IntermediateOp
public abstract Stream> pairWith(final Function super T, ? extends U> extractor);
/**
* Transforms the elements in the stream by applying a function to each element.
* This is an intermediate operation.
*
* @param The type of the result elements.
* @param mapper The function to be applied to each element in the stream.
* @return A new Stream consisting of the results of applying the given function to the elements of this stream.
*/
@ParallelSupported
@IntermediateOp
public abstract Stream map(final Function super T, ? extends R> mapper);
/**
* Transforms the elements in the stream by applying a function to each element if it's not {@code null}, otherwise skips it.
* This is an intermediate operation.
*
*
* @implSpec it's equivalent to {@code skipNulls().map(mapper)}.
*
* @param the type of the result elements
* @param mapper the function to be applied to each element in the stream
* @return a new Stream consisting of the results of applying the given function to the elements of this stream, skipping {@code null} elements
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract Stream mapIfNotNull(final Function super T, ? extends R> mapper);
/**
* Applies a sliding map operation on the stream.
* It takes a BiFunction as an argument which is applied to each pair of consecutive elements in the stream.
* {@code Null} will be passed as the second argument to the BiFunction for last non-paired element(s) in the stream.
* The result is a new stream consisting of the results of applying the BiFunction.
*
* @param the type of the output stream
* @param mapper a BiFunction that takes two consecutive elements and produces a new element of type R
* @return a new Stream consisting of the results of applying the BiFunction to each pair of consecutive elements
*/
@ParallelSupported
@IntermediateOp
public abstract Stream slidingMap(BiFunction super T, ? super T, ? extends R> mapper);
/**
* Applies a sliding map operation on the stream with a specified increment.
* It takes an integer as the increment and a BiFunction as an argument which is applied to each pair of consecutive elements in the stream.
* {@code Null} will be passed as the second argument to the BiFunction for last non-paired element(s) in the stream.
* The result is a new stream consisting of the results of applying the BiFunction.
*
* @param the type of the output stream
* @param increment the step size for sliding over the elements in the stream
* @param mapper a BiFunction that takes two consecutive elements and produces a new element of type R
* @return a new Stream consisting of the results of applying the BiFunction to each pair of consecutive elements
*/
@ParallelSupported
@IntermediateOp
public abstract Stream slidingMap(int increment, BiFunction super T, ? super T, ? extends R> mapper);
/**
* Applies a sliding map operation on the stream with a specified increment and a flag to ignore unpaired elements.
* It takes an integer as the increment, a boolean to ignore unpaired elements, and a BiFunction as an argument which is applied to each pair of consecutive elements in the stream.
* {@code Null} will be passed as the second argument to the BiFunction for last non-paired element(s) in the stream if the {@code ignoreNotPaired} flag is set to {@code false}.
* The result is a new stream consisting of the results of applying the BiFunction.
*
* @param the type of the output stream
* @param increment the step size for sliding over the elements in the stream
* @param ignoreNotPaired a flag to indicate whether to ignore unpaired elements in the stream
* @param mapper a BiFunction that takes two consecutive elements and produces a new element of type R
* @return a new Stream consisting of the results of applying the BiFunction to each pair of consecutive elements
*/
@ParallelSupported
@IntermediateOp
public abstract Stream slidingMap(int increment, boolean ignoreNotPaired, BiFunction super T, ? super T, ? extends R> mapper);
/**
* Applies a sliding map operation on the stream.
* It takes a TriFunction as an argument which is applied to each triplet of consecutive elements in the stream.
* {@code Nulls} will be passed as the second and third arguments to the TriFunction for last non-paired element(s) in the stream.
* The result is a new stream consisting of the results of applying the TriFunction.
*
* @param the type of the output stream
* @param mapper a TriFunction that takes three consecutive elements and produces a new element of type R
* @return a new Stream consisting of the results of applying the TriFunction to each triplet of consecutive elements
*/
@ParallelSupported
@IntermediateOp
public abstract Stream slidingMap(TriFunction super T, ? super T, ? super T, ? extends R> mapper);
/**
* Applies a sliding map operation on the stream with a specified increment.
* It takes an integer as the increment and a TriFunction as an argument which is applied to each triplet of consecutive elements in the stream.
* {@code Nulls} will be passed as the second and third arguments to the TriFunction for last non-paired element(s) in the stream.
* The result is a new stream consisting of the results of applying the TriFunction.
*
* @param the type of the output stream
* @param increment the step size for sliding over the elements in the stream
* @param mapper a TriFunction that takes three consecutive elements and produces a new element of type R
* @return a new Stream consisting of the results of applying the TriFunction to each triplet of consecutive elements
*/
@ParallelSupported
@IntermediateOp
public abstract Stream slidingMap(int increment, TriFunction super T, ? super T, ? super T, ? extends R> mapper);
/**
* Applies a sliding map operation on the stream with a specified increment and a flag to ignore unpaired elements.
* It takes an integer as the increment, a boolean to ignore unpaired elements, and a TriFunction as an argument which is applied to each triplet of consecutive elements in the stream.
* {@code Nulls} will be passed as the second and third arguments to the TriFunction for last non-paired element(s) in the stream if the {@code ignoreNotPaired} flag is set to {@code false}.
* The result is a new stream consisting of the results of applying the TriFunction.
*
* @param the type of the output stream
* @param increment the step size for sliding over the elements in the stream
* @param ignoreNotPaired a flag to indicate whether to ignore unpaired elements in the stream
* @param mapper a TriFunction that takes three consecutive elements and produces a new element of type R
* @return a new Stream consisting of the results of applying the TriFunction to each triplet of consecutive elements
*/
@ParallelSupported
@IntermediateOp
public abstract Stream slidingMap(int increment, boolean ignoreNotPaired, TriFunction super T, ? super T, ? super T, ? extends R> mapper);
/**
* Note: copied from StreamEx: StreamEx
*
*
* Applies a range map operation on the stream.
* It takes a BiPredicate and a BiFunction as arguments. The BiPredicate is used to determine if two consecutive elements belong to the same range.
* The BiFunction is applied to the borders of each range in the stream.
* Returns a stream consisting of results of applying the given function to the ranges created from the source elements.
*
*
*
* Stream.of("a", "ab", "ac", "b", "c", "cb").rangeMap((a, b) -> b.startsWith(a), (a, b) -> a + "->" + b).toList(); // a->ac, b->b, c->cb
*
*
*
*
* @param the type of the resulting elements
* @param sameRange a non-interfering, stateless predicate to apply to
* the leftmost and next elements which returns {@code true} for elements
* which belong to the same range.
* @param mapper a non-interfering, stateless function to apply to the
* range borders and produce the resulting element. If value was
* not merged to the interval, then mapper will receive the same
* value twice, otherwise it will receive the leftmost and the
* rightmost values which were merged to the range.
* @return
* @see #collapse(BiPredicate, BiFunction)
*/
@SequentialOnly
@IntermediateOp
public abstract Stream rangeMap(final BiPredicate super T, ? super T> sameRange, final BiFunction super T, ? super T, ? extends U> mapper);
/**
* Applies a mapping function to the first element of the stream and returns a new stream.
* The mapping function takes an element of type T and returns a new element of type T.
* This is an intermediate operation.
*
*
* This method will always run sequentially, even in parallel stream.
*
* @param mapperForFirst the mapping function to apply to the first element
* @return a new Stream consisting of the first element transformed by the mapping function and the rest of the elements unchanged
*/
@SequentialOnly
@IntermediateOp
public abstract Stream mapFirst(Function super T, ? extends T> mapperForFirst);
/**
* Applies a mapping function to the first element of the stream and a different mapping function to the rest of the elements,
* and returns a new stream consisting of the transformed elements.
* This is an intermediate operation.
*
* @param the type of the output stream
* @param mapperForFirst the mapping function to apply to the first element
* @param mapperForElse the mapping function to apply to the rest of the elements
* @return a new Stream consisting of the first element transformed by the first mapping function and the rest of the elements transformed by the second mapping function
*/
@ParallelSupported
@IntermediateOp
public abstract Stream mapFirstOrElse(Function super T, ? extends R> mapperForFirst, Function super T, ? extends R> mapperForElse);
/**
* Applies a mapping function to the last element of the stream and returns a new stream.
* The mapping function takes an element of type T and returns a new element of type T.
* This is an intermediate operation.
*
*
* This method will always run sequentially, even in parallel stream.
*
* @param mapperForLast the mapping function to apply to the last element
* @return a new Stream consisting of the last element transformed by the mapping function and the rest of the elements unchanged
*/
@SequentialOnly
@IntermediateOp
public abstract Stream mapLast(Function super T, ? extends T> mapperForLast);
/**
* Applies a mapping function to the last element of the stream and a different mapping function to the rest of the elements,
* and returns a new stream consisting of the transformed elements.
* This is an intermediate operation.
*
* @param the type of the output stream
* @param mapperForLast the mapping function to apply to the last element
* @param mapperForElse the mapping function to apply to the rest of the elements
* @return a new Stream consisting of the last element transformed by the first mapping function and the rest of the elements transformed by the second mapping function
*/
@ParallelSupported
@IntermediateOp
public abstract Stream mapLastOrElse(Function super T, ? extends R> mapperForLast, Function super T, ? extends R> mapperForElse);
/**
* Transforms this stream to a {@code CharStream} by applying the specified {@code ToCharFunction} to each element.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new CharStream consisting of the results of applying the given function to the elements of this stream.
*/
@ParallelSupported
@IntermediateOp
public abstract CharStream mapToChar(ToCharFunction super T> mapper);
/**
* Transforms this stream to a {@code ByteStream} by applying the specified {@code ToByteFunction} to each element.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new ByteStream consisting of the results of applying the given function to the elements of this stream.
*/
@ParallelSupported
@IntermediateOp
public abstract ByteStream mapToByte(ToByteFunction super T> mapper);
/**
* Transforms this stream to a {@code ShortStream} by applying the specified {@code ToShortFunction} to each element.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new ShortStream consisting of the results of applying the given function to the elements of this stream.
*/
@ParallelSupported
@IntermediateOp
public abstract ShortStream mapToShort(ToShortFunction super T> mapper);
/**
* Transforms this stream to an {@code IntStream} by applying the specified {@code ToIntFunction} to each element.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new IntStream consisting of the results of applying the given function to the elements of this stream.
*/
@ParallelSupported
@IntermediateOp
public abstract IntStream mapToInt(ToIntFunction super T> mapper);
/**
* Transforms this stream to a {@code LongStream} by applying the specified {@code ToLongFunction} to each element.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new LongStream consisting of the results of applying the given function to the elements of this stream.
*/
@ParallelSupported
@IntermediateOp
public abstract LongStream mapToLong(ToLongFunction super T> mapper);
/**
* Transforms this stream to a {@code FloatStream} by applying the specified {@code ToFloatFunction} to each element.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new FloatStream consisting of the results of applying the given function to the elements of this stream.
*/
@ParallelSupported
@IntermediateOp
public abstract FloatStream mapToFloat(ToFloatFunction super T> mapper);
/**
* Transforms this stream to a {@code DoubleStream} by applying the specified {@code ToDoubleFunction} to each element.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new DoubleStream consisting of the results of applying the given function to the elements of this stream.
*/
@ParallelSupported
@IntermediateOp
public abstract DoubleStream mapToDouble(ToDoubleFunction super T> mapper);
// public abstract EntryStream mapToEntry();
/**
* Transforms the elements in the stream into Map.Entry instances by applying the provided function to each element.
* This is an intermediate operation.
*
* @param The type of the key in the Map.Entry.
* @param The type of the value in the Map.Entry.
* @param mapper The function to be applied to each element in the stream, which should return a Map.Entry instance.
* @return A new EntryStream consisting of Map.Entry instances obtained by applying the mapper function to the elements of this stream.
*/
@ParallelSupported
@IntermediateOp
public abstract EntryStream mapToEntry(Function super T, ? extends Map.Entry extends K, ? extends V>> mapper);
/**
* Transforms the elements in the stream into Map.Entry instances by applying the provided key and value mapping functions to each element.
* This is an intermediate operation.
*
* @param The type of the key in the Map.Entry.
* @param The type of the value in the Map.Entry.
* @param keyMapper The function to be applied to each element in the stream to generate the key.
* @param valueMapper The function to be applied to each element in the stream to generate the value.
* @return A new EntryStream consisting of Map.Entry instances obtained by applying the key and value mapping functions to the elements of this stream.
*/
@ParallelSupported
@IntermediateOp
public abstract EntryStream mapToEntry(Function super T, ? extends K> keyMapper, Function super T, ? extends V> valueMapper);
// public abstract Stream mapp(Function super T, Optional extends U>> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a Stream of elements.
* This is an intermediate operation.
*
* @param The type of the elements in the returned Stream.
* @param mapper The function to be applied to each element in the stream.
* @return A new Stream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped stream produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract Stream flatMap(Function super T, ? extends Stream extends R>> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a Collection of elements.
* This is an intermediate operation.
*
* @param The type of the elements in the returned Collection.
* @param mapper The function to be applied to each element in the stream.
* @return A new Stream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped collection produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract Stream flatmap(Function super T, ? extends Collection extends R>> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return an array of elements.
* This is an intermediate operation.
*
* @param The type of the elements in the returned array.
* @param mapper The function to be applied to each element in the stream.
* @return A new Stream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped array produced by applying the provided mapping function to each element.
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract Stream flattMap(Function super T, R[]> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a java.util.stream.Stream of elements.
* This is an intermediate operation.
*
* @param The type of the elements in the returned Stream.
* @param mapper The function to be applied to each element in the stream.
* @return A new Stream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped stream produced by applying the provided mapping function to each element.
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract Stream flattmap(Function super T, ? extends java.util.stream.Stream extends R>> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a CharStream of elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new CharStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped CharStream produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract CharStream flatMapToChar(Function super T, ? extends CharStream> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a char array of elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new CharStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped char array produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract CharStream flatmapToChar(Function super T, char[]> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a ByteStream of elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new ByteStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped ByteStream produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract ByteStream flatMapToByte(Function super T, ? extends ByteStream> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a byte array of elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new ByteStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped byte array produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract ByteStream flatmapToByte(Function super T, byte[]> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a ShortStream of elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new ShortStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped ShortStream produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract ShortStream flatMapToShort(Function super T, ? extends ShortStream> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a short array of elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new ShortStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped short array produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract ShortStream flatmapToShort(Function super T, short[]> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return an IntStream of elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new IntStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped IntStream produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract IntStream flatMapToInt(Function super T, ? extends IntStream> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return an array of int elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new IntStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped int array produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract IntStream flatmapToInt(Function super T, int[]> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a LongStream of elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new LongStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped LongStream produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract LongStream flatMapToLong(Function super T, ? extends LongStream> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a long array of elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new LongStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped long array produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract LongStream flatmapToLong(Function super T, long[]> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a FloatStream of elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new FloatStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped FloatStream produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract FloatStream flatMapToFloat(Function super T, ? extends FloatStream> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a float array of elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new FloatStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped float array produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract FloatStream flatmapToFloat(Function super T, float[]> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a DoubleStream of elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new DoubleStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped DoubleStream produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract DoubleStream flatMapToDouble(Function super T, ? extends DoubleStream> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a double array of elements.
* This is an intermediate operation.
*
* @param mapper The function to be applied to each element in the stream.
* @return A new DoubleStream consisting of the elements obtained by replacing each element of this stream
* with the contents of a mapped double array produced by applying the provided mapping function to each element.
*/
@ParallelSupported
@IntermediateOp
public abstract DoubleStream flatmapToDouble(Function super T, double[]> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a Stream of Map.Entry instances.
* This is an intermediate operation.
*
* @param The type of the key in the Map.Entry.
* @param The type of the value in the Map.Entry.
* @param mapper The function to be applied to each element in the stream.
* @return A new EntryStream consisting of Map.Entry instances obtained by applying the mapper function to the elements of this stream.
*/
@ParallelSupported
@IntermediateOp
public abstract EntryStream flatMapToEntry(Function super T, ? extends Stream extends Map.Entry extends K, ? extends V>>> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return a Map of key-value pairs.
* This is an intermediate operation.
*
* @param The type of the key in the Map.
* @param The type of the value in the Map.
* @param mapper The function to be applied to each element in the stream.
* @return A new EntryStream consisting of Map.Entry instances obtained by transforming each element of this stream
* into a Map and then flattening these Maps into a stream of their entries.
*/
@ParallelSupported
@IntermediateOp
public abstract EntryStream flatmapToEntry(Function super T, ? extends Map extends K, ? extends V>> mapper);
/**
* Transforms the elements in the stream by applying a function to each element.
* The function should return an EntryStream of key-value pairs.
* This is an intermediate operation.
*
* @param The type of the key in the EntryStream.
* @param The type of the value in the EntryStream.
* @param mapper The function to be applied to each element in the stream.
* @return A new EntryStream consisting of key-value pairs obtained by transforming each element of this stream
* into an EntryStream and then flattening these EntryStreams into a single EntryStream.
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract EntryStream flattMapToEntry(Function super T, ? extends EntryStream extends K, ? extends V>> mapper); //NOSONAR
/**
* Applies a flat mapping operation on the stream, but only for {@code non-null} elements.
* It takes a Function as an argument which is applied to each {@code non-null} element in the stream.
* The Function returns a Collection of new elements. Each element in these collections is included in the resulting stream.
*
* This is an intermediate operation.
*
* @implNote it's equivalent to: {@code skipNulls().flatmap(mapper)}
*
* @param the type of elements in the resulting stream
* @param mapper a Function that takes an element and produces a Collection of new elements
* @return a new Stream consisting of the results of applying the Function to each {@code non-null} element
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract Stream flatmapIfNotNull(final Function super T, ? extends Collection extends R>> mapper);
/**
* Applies a flat mapping operation on the stream, but only for {@code non-null} elements.
* It takes two Functions as arguments which are applied to each {@code non-null} element in the stream.
* The first Function returns a Collection of intermediate elements.
* The second Function is then applied to each intermediate element, producing a Collection of new elements.
* Each element in these collections is included in the resulting stream.
*
* This is an intermediate operation.
*
* @implNote it's equivalent to: {@code skipNulls().flatmap(mapper).skipNulls().flatmap(mapper2)}
*
* @param the type of the intermediate elements
* @param the type of elements in the resulting stream
* @param mapper a Function that takes an element and produces a Collection of intermediate elements
* @param mapper2 a Function that takes an intermediate element and produces a Collection of new elements
* @return a new Stream consisting of the results of applying the Functions to each {@code non-null} element
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract Stream flatmapIfNotNull(final Function super T, ? extends Collection extends U>> mapper,
final Function super U, ? extends Collection extends R>> mapper2);
/**
* Applies a mapping operation on the stream with multiple output elements for each input element.
* It takes a BiConsumer as an argument which is applied to each element in the stream and a Consumer that accepts multiple output elements.
* The result is a new stream consisting of all output elements produced by the BiConsumer for each input element.
*
* This is an intermediate operation.
*
* @param the type of the output stream
* @param mapper a BiConsumer that takes an input element and a Consumer for output elements, and produces multiple output elements for each input element.
* @return a new Stream consisting of all output elements produced by the BiConsumer for each input element.
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract Stream mapMulti(BiConsumer super T, ? super Consumer> mapper);
/**
* Applies a mapping operation on the stream with multiple output integers for each input element.
* It takes a BiConsumer as an argument which is applied to each element in the stream and an IntConsumer that accepts multiple output integers.
* The result is a new IntStream consisting of all output integers produced by the BiConsumer for each input element.
*
* This is an intermediate operation.
*
* @param mapper a BiConsumer that takes an input element and an IntConsumer for output integers, and produces multiple output integers for each input element.
* @return a new IntStream consisting of all output integers produced by the BiConsumer for each input element.
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract IntStream mapMultiToInt(BiConsumer super T, ? super IntConsumer> mapper);
/**
* Applies a mapping operation on the stream with multiple output longs for each input element.
* It takes a BiConsumer as an argument which is applied to each element in the stream and a LongConsumer that accepts multiple output longs.
* The result is a new LongStream consisting of all output longs produced by the BiConsumer for each input element.
*
* This is an intermediate operation.
*
* @param mapper a BiConsumer that takes an input element and a LongConsumer for output longs, and produces multiple output longs for each input element.
* @return a new LongStream consisting of all output longs produced by the BiConsumer for each input element.
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract LongStream mapMultiToLong(BiConsumer super T, ? super LongConsumer> mapper);
/**
* Applies a mapping operation on the stream with multiple output doubles for each input element.
* It takes a BiConsumer as an argument which is applied to each element in the stream and a DoubleConsumer that accepts multiple output doubles.
* The result is a new DoubleStream consisting of all output doubles produced by the BiConsumer for each input element.
*
* This is an intermediate operation.
*
* @param mapper a BiConsumer that takes an input element and a DoubleConsumer for output doubles, and produces multiple output doubles for each input element.
* @return a new DoubleStream consisting of all output doubles produced by the BiConsumer for each input element.
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract DoubleStream mapMultiToDouble(BiConsumer super T, ? super DoubleConsumer> mapper);
/**
* Note: copied from StreamEx: StreamEx
*
*
* Applies a partial mapping operation on the stream.
* It takes a Function as an argument which is applied to each element in the stream.
* The Function returns an Optional. If the Optional is empty, the element is not included in the resulting stream.
* If the Optional contains a value, that value is included in the resulting stream.
*
* @param the type of the output stream
* @param mapper a Function that takes an element and produces an Optional of a new element of type R
* @return a new Stream consisting of the results of applying the Function to each element
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract Stream mapPartial(Function super T, Optional extends R>> mapper);
/**
* Note: copied from StreamEx: StreamEx
*
*
* Applies a partial mapping operation on the stream.
* It takes a Function as an argument which is applied to each element in the stream.
* The Function returns an OptionalInt. If the OptionalInt is empty, the element is not included in the resulting IntStream.
* If the OptionalInt contains a value, that value is included in the resulting IntStream.
*
* @param mapper a Function that takes an element and produces an OptionalInt of a new element
* @return a new IntStream consisting of the results of applying the Function to each element
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract IntStream mapPartialToInt(Function super T, OptionalInt> mapper);
/**
* Note: copied from StreamEx: StreamEx
*
*
* Applies a partial mapping operation on the stream.
* It takes a Function as an argument which is applied to each element in the stream.
* The Function returns an OptionalLong. If the OptionalLong is empty, the element is not included in the resulting LongStream.
* If the OptionalLong contains a value, that value is included in the resulting LongStream.
*
* @param mapper a Function that takes an element and produces an OptionalLong of a new element
* @return a new LongStream consisting of the results of applying the Function to each element
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract LongStream mapPartialToLong(Function super T, OptionalLong> mapper);
/**
* Note: copied from StreamEx: StreamEx
*
*
* Applies a partial mapping operation on the stream.
* It takes a Function as an argument which is applied to each element in the stream.
* The Function returns an OptionalDouble. If the OptionalDouble is empty, the element is not included in the resulting DoubleStream.
* If the OptionalDouble contains a value, that value is included in the resulting DoubleStream.
*
* @param mapper a Function that takes an element and produces an OptionalDouble of a new element
* @return a new DoubleStream consisting of the results of applying the Function to each element
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract DoubleStream mapPartialToDouble(Function super T, OptionalDouble> mapper);
/**
* Note: copied from StreamEx: StreamEx
*
*
* Applies a partial mapping operation on the stream.
* It takes a Function as an argument which is applied to each element in the stream.
* The Function returns a java.util.Optional. If the Optional is empty, the element is not included in the resulting stream.
* If the Optional contains a value, that value is included in the resulting stream.
*
* This is an intermediate operation.
*
* @param the type of the output stream
* @param mapper a Function that takes an element and produces a java.util.Optional of a new element of type R
* @return a new Stream consisting of the results of applying the Function to each element
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract Stream mapPartialJdk(Function super T, java.util.Optional extends R>> mapper);
/**
* Note: copied from StreamEx: StreamEx
*
*
* Applies a partial mapping operation on the stream.
* It takes a Function as an argument which is applied to each element in the stream.
* The Function returns a java.util.OptionalInt. If the OptionalInt is empty, the element is not included in the resulting IntStream.
* If the OptionalInt contains a value, that value is included in the resulting IntStream.
*
* This is an intermediate operation.
*
* @param mapper a Function that takes an element and produces a java.util.OptionalInt of a new element
* @return a new IntStream consisting of the results of applying the Function to each element
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract IntStream mapPartialToIntJdk(Function super T, java.util.OptionalInt> mapper);
/**
* Note: copied from StreamEx: StreamEx
*
*
* Applies a partial mapping operation on the stream.
* It takes a Function as an argument which is applied to each element in the stream.
* The Function returns a java.util.OptionalLong. If the OptionalLong is empty, the element is not included in the resulting LongStream.
* If the OptionalLong contains a value, that value is included in the resulting LongStream.
*
* This is an intermediate operation.
*
* @param mapper a Function that takes an element and produces a java.util.OptionalLong of a new element
* @return a new LongStream consisting of the results of applying the Function to each element
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract LongStream mapPartialToLongJdk(Function super T, java.util.OptionalLong> mapper);
/**
* Note: copied from StreamEx: StreamEx
*
*
* Applies a partial mapping operation on the stream.
* It takes a Function as an argument which is applied to each element in the stream.
* The Function returns a java.util.OptionalDouble. If the OptionalDouble is empty, the element is not included in the resulting DoubleStream.
* If the OptionalDouble contains a value, that value is included in the resulting DoubleStream.
*
* This is an intermediate operation.
*
* @param mapper a Function that takes an element and produces a java.util.OptionalDouble of a new element
* @return a new DoubleStream consisting of the results of applying the Function to each element
*/
@Beta
@ParallelSupported
@IntermediateOp
public abstract DoubleStream mapPartialToDoubleJdk(Function super T, java.util.OptionalDouble> mapper);
/**
* Groups the elements of the stream by the classification function provided.
* This is an intermediate operation.
*
* @param The type of the key in the resulting Map.Entry.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @return A new Stream consisting of Map.Entry instances where the key is the group identifier and the value is a list of elements belonging to that group.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract Stream>> groupBy(final Function super T, ? extends K> keyMapper);
/**
* Groups the elements of the stream by applying a key mapping function to each element.
* The result is a Stream where each entry's key is the group identifier (determined by the key mapping function),
* and the value is a list of elements belonging to that group.
* This is an intermediate operation.
*
* @param The type of the key in the resulting Map.Entry.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @return A new Stream consisting of entries where the key is the group identifier and the value is a list of elements belonging to that group.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract Stream>> groupBy(final Function super T, ? extends K> keyMapper,
final Supplier extends Map>> mapFactory);
/**
* Groups the elements of the stream by applying a key mapping function and a value mapping function to each element.
* The result is a Stream where each entry's key is the group identifier (determined by the key mapping function),
* and the value is a list of elements that mapped to the corresponding key by the value mapping function.
* This is an intermediate operation.
*
* @param The type of the key in the resulting Map.Entry.
* @param The type of the value in the resulting Map.Entry.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param valueMapper The function to be applied to each element in the stream to determine its value in the group.
* @return A new Stream consisting of entries where the key is the group identifier and the value is a list of elements that mapped to the corresponding key.
* @see Collectors#toMultimap(Function, Function)
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract Stream>> groupBy(Function super T, ? extends K> keyMapper, Function super T, ? extends V> valueMapper);
/**
* Groups the elements of the stream by applying a key mapping function and a value mapping function to each element.
* The result is a Stream where each entry's key is the group identifier (determined by the key mapping function),
* and the value is a list of elements that mapped to the corresponding key by the value mapping function.
* This is an intermediate operation.
*
* @param The type of the key in the resulting Map.Entry.
* @param The type of the value in the resulting Map.Entry.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param valueMapper The function to be applied to each element in the stream to determine its value in the group.
* @param mapFactory The supplier providing a new empty Map into which the results will be inserted.
* @return A new Stream consisting of entries where the key is the group identifier and the value is a list of elements that mapped to the corresponding key.
* @see Collectors#toMultimap(Function, Function, Supplier)
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract Stream>> groupBy(Function super T, ? extends K> keyMapper, Function super T, ? extends V> valueMapper,
Supplier extends Map>> mapFactory);
/**
* Groups the elements of the stream by the classification function provided and then applies a Collector to the elements of each group.
* This is an intermediate operation.
*
* @param The type of the key in the resulting Map.Entry.
* @param The result type of the Collector.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param downstream The Collector to be applied to the elements of each group.
* @return A new Stream consisting of Map.Entry instances where the key is the group identifier and the value is the result of applying the Collector to the elements of the group.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract Stream> groupBy(Function super T, ? extends K> keyMapper, Collector super T, ?, D> downstream);
/**
* Groups the elements of the stream by the classification function provided and then applies a Collector to the elements of each group.
* This is an intermediate operation.
*
* @param The type of the key in the resulting Map.Entry.
* @param The result type of the Collector.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param downstream The Collector to be applied to the elements of each group.
* @param mapFactory The supplier providing a new empty Map into which the results will be inserted.
* @return A new Stream consisting of Map.Entry instances where the key is the group identifier and the value is the result of applying the Collector to the elements of the group.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract Stream> groupBy(Function super T, ? extends K> keyMapper, Collector super T, ?, D> downstream,
Supplier extends Map> mapFactory);
/**
* Groups the elements of the stream by applying a key mapping function and a value mapping function to each element,
* and then applies a Collector to the values of each group.
* This is an intermediate operation.
*
* @param The type of the key in the resulting Map.Entry.
* @param The type of the value to be collected in the resulting Map.Entry.
* @param The result type of the Collector.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param valueMapper The function to be applied to each element in the stream to determine its value in the group.
* @param downstream The Collector to be applied to the values of each group.
* @return A new Stream consisting of Map.Entry instances where the key is the group identifier and the value is the result of applying the Collector to the values of the group.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract Stream> groupBy(Function super T, ? extends K> keyMapper, Function super T, ? extends V> valueMapper,
Collector super V, ?, D> downstream);
/**
* Groups the elements of the stream by applying a key mapping function and a value mapping function to each element,
* and then applies a Collector to the values of each group. The result is a Stream where each entry's key is the group identifier
* (determined by the key mapping function), and the value is the result of applying the Collector to the values of the group.
* This is an intermediate operation.
*
* @param The type of the key in the resulting Map.Entry.
* @param The type of the value to be collected in the resulting Map.Entry.
* @param The result type of the Collector.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param valueMapper The function to be applied to each element in the stream to determine its value in the group.
* @param downstream The Collector to be applied to the values of each group.
* @param mapFactory The supplier providing a new empty Map into which the results will be inserted.
* @return A new Stream consisting of Map.Entry instances where the key is the group identifier and the value is the result of applying the Collector to the values of the group.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract Stream> groupBy(Function super T, ? extends K> keyMapper, Function super T, ? extends V> valueMapper,
Collector super V, ?, D> downstream, Supplier extends Map> mapFactory);
/**
* Groups the elements of the stream by applying a key mapping function and a value mapping function to each element,
* and then merges the values of each group using a merge function.
* This is an intermediate operation.
*
* @param The type of the key in the resulting Map.Entry.
* @param The type of the value in the resulting Map.Entry.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param valueMapper The function to be applied to each element in the stream to determine its value in the group.
* @param mergeFunction The function to be applied for merging the values of each group.
* @return A new Stream consisting of Map.Entry instances where the key is the group identifier and the value is the result of merging the values of the group using the merge function.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract Stream> groupBy(Function super T, ? extends K> keyMapper, final Function super T, ? extends V> valueMapper,
BinaryOperator mergeFunction);
/**
* Groups the elements of the stream by applying a key mapping function and a value mapping function to each element.
* Then merges the values using the provided merge function.
* This is an intermediate operation.
*
* @param The type of the key in the resulting Map.Entry.
* @param The type of the value in the resulting Map.Entry.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param valueMapper The function to be applied to each element in the stream to determine its value in the group.
* @param mergeFunction The function to be used for merging values in case of key collision.
* @param mapFactory The supplier providing a new empty Map into which the results will be inserted.
* @return A new Stream consisting of Map.Entry instances where the key is the group identifier and the value is the result of applying the value mapping function to the elements of the group and merging them using the merge function.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract Stream> groupBy(Function super T, ? extends K> keyMapper, Function super T, ? extends V> valueMapper,
BinaryOperator mergeFunction, Supplier extends Map> mapFactory);
// @ParallelSupported
// public abstract Stream>> flatGroupBy(final Throwables.Function super T, ? extends Stream extends K>, E> flatKeyExtractor);
//
// @ParallelSupported
// public abstract Stream>> flatGroupBy(final Throwables.Function super T, ? extends Stream extends K>, E> flatKeyExtractor,
// final Supplier extends Map>> mapFactory);
//
// /**
// *
// * @param flatKeyExtractor
// * @param valueMapper
// * @return
// * @see Collectors#toMultimap(Function, Function)
// */
// @ParallelSupported
// public abstract Stream>> flatGroupBy(Throwables.Function super T, ? extends Stream extends K>, E> flatKeyExtractor,
// Throwables.BiFunction super K, ? super T, ? extends V, E2> valueMapper);
//
// /**
// *
// * @param flatKeyExtractor
// * @param valueMapper
// * @param mapFactory
// * @return
// * @see Collectors#toMultimap(Function, Function, Supplier)
// */
// @ParallelSupported
// public abstract Stream>> flatGroupBy(Throwables.Function super T, ? extends Stream extends K>, E> flatKeyExtractor,
// Throwables.BiFunction super K, ? super T, ? extends V, E2> valueMapper, Supplier extends Map>> mapFactory);
//
// @ParallelSupported
// public abstract Stream> flatGroupBy(final Throwables.Function super T, ? extends Stream extends K>, E> flatKeyExtractor,
// final Collector super T, ?, D> downstream);
//
// @ParallelSupported
// public abstract Stream> flatGroupBy(final Throwables.Function super T, ? extends Stream extends K>, E> flatKeyExtractor,
// final Collector super T, ?, D> downstream, final Supplier extends Map> mapFactory);
//
// @ParallelSupported
// public abstract Stream> flatGroupBy(final Throwables.Function super T, ? extends Stream extends K>, E> flatKeyExtractor,
// final Throwables.BiFunction super K, ? super T, ? extends V, E2> valueMapper, final Collector super V, ?, D> downstream);
//
// @ParallelSupported
// public abstract Stream> flatGroupBy(final Throwables.Function super T, ? extends Stream extends K>, E> flatKeyExtractor,
// final Throwables.BiFunction super K, ? super T, ? extends V, E2> valueMapper, final Collector super V, ?, D> downstream,
// final Supplier extends Map> mapFactory);
//
// @ParallelSupported
// public abstract Stream> flatGroupBy(final Throwables.Function super T, ? extends Stream extends K>, E> flatKeyExtractor,
// final Throwables.BiFunction super K, ? super T, ? extends V, E2> valueMapper, BinaryOperator mergeFunction);
//
// @ParallelSupported
// public abstract Stream> flatGroupBy(final Throwables.Function super T, ? extends Stream extends K>, E> flatKeyExtractor,
// final Throwables.BiFunction super K, ? super T, ? extends V, E2> valueMapper, final BinaryOperator mergeFunction,
// final Supplier extends Map> mapFactory);
//
// @ParallelSupported
// public abstract Stream>> flattGroupBy(final Throwables.Function super T, ? extends Collection extends K>, E> flatKeyExtractor);
//
// @ParallelSupported
// public abstract Stream>> flattGroupBy(final Throwables.Function super T, ? extends Collection extends K>, E> flatKeyExtractor,
// final Supplier extends Map>> mapFactory);
//
// /**
// *
// * @param flatKeyExtractor
// * @param valueMapper
// * @return
// * @see Collectors#toMultimap(Function, Function)
// */
// @ParallelSupported
// public abstract Stream>> flattGroupBy(Throwables.Function super T, ? extends Collection extends K>, E> flatKeyExtractor,
// Throwables.BiFunction super K, ? super T, ? extends V, E2> valueMapper);
//
// /**
// *
// * @param flatKeyExtractor
// * @param valueMapper
// * @param mapFactory
// * @return
// * @see Collectors#toMultimap(Function, Function, Supplier)
// */
// @ParallelSupported
// public abstract Stream>> flattGroupBy(Throwables.Function super T, ? extends Collection extends K>, E> flatKeyExtractor,
// Throwables.BiFunction super K, ? super T, ? extends V, E2> valueMapper, Supplier extends Map>> mapFactory);
//
// @ParallelSupported
// public abstract Stream> flattGroupBy(final Throwables.Function super T, ? extends Collection extends K>, E> flatKeyExtractor,
// final Collector super T, ?, D> downstream);
//
// @ParallelSupported
// public abstract Stream> flattGroupBy(final Throwables.Function super T, ? extends Collection extends K>, E> flatKeyExtractor,
// final Collector super T, ?, D> downstream, final Supplier extends Map> mapFactory);
//
// @ParallelSupported
// public abstract Stream> flattGroupBy(final Throwables.Function super T, ? extends Collection extends K>, E> flatKeyExtractor,
// final Throwables.BiFunction super K, ? super T, ? extends V, E2> valueMapper, final Collector super V, ?, D> downstream);
//
// @ParallelSupported
// public abstract Stream> flattGroupBy(final Throwables.Function super T, ? extends Collection extends K>, E> flatKeyExtractor,
// final Throwables.BiFunction super K, ? super T, ? extends V, E2> valueMapper, final Collector super V, ?, D> downstream,
// final Supplier extends Map> mapFactory);
//
// @ParallelSupported
// public abstract Stream> flattGroupBy(final Throwables.Function super T, ? extends Collection extends K>, E> flatKeyExtractor,
// final Throwables.BiFunction super K, ? super T, ? extends V, E2> valueMapper, BinaryOperator mergeFunction);
//
// @ParallelSupported
// public abstract Stream> flattGroupBy(final Throwables.Function super T, ? extends Collection extends K>, E> flatKeyExtractor,
// final Throwables.BiFunction super K, ? super T, ? extends V, E2> valueMapper, final BinaryOperator mergeFunction,
// final Supplier extends Map> mapFactory);
/**
* Groups the elements of the stream by applying a key mapping function to each element.
* The result is an EntryStream where each entry's key is the group identifier (determined by the key mapping function),
* and the value is a list of elements belonging to that group.
* This is an intermediate operation.
*
* @param The type of the key in the resulting EntryStream.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @return A new EntryStream consisting of entries where the key is the group identifier and the value is a list of elements belonging to that group.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract EntryStream> groupByToEntry(Function super T, ? extends K> keyMapper);
/**
* Groups the elements of the stream by applying a key mapping function to each element.
* The result is an EntryStream where each entry's key is the group identifier (determined by the key mapping function),
* and the value is a list of elements belonging to that group.
* This is an intermediate operation.
*
* @param The type of the key in the resulting EntryStream.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param mapFactory The supplier providing a new empty Map into which the results will be inserted.
* @return A new EntryStream consisting of entries where the key is the group identifier and the value is a list of elements belonging to that group.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract EntryStream> groupByToEntry(Function super T, ? extends K> keyMapper, Supplier extends Map>> mapFactory);
/**
* Groups the elements of the stream by applying a key mapping function and a value mapping function to each element.
* The result is an EntryStream where each entry's key is the group identifier (determined by the key mapping function),
* and the value is a list of elements that were mapped to that key.
* This is an intermediate operation.
*
* @param The type of the key in the resulting EntryStream.
* @param The type of the value in the resulting EntryStream.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param valueMapper The function to be applied to each element in the stream to determine its value in the group.
* @return A new EntryStream consisting of entries where the key is the group identifier and the value is a list of elements that were mapped to that key.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract EntryStream> groupByToEntry(Function super T, ? extends K> keyMapper, Function super T, ? extends V> valueMapper);
/**
* Groups the elements of the stream by applying a key mapping function and a value mapping function to each element.
* The result is an EntryStream where each entry's key is the group identifier (determined by the key mapping function),
* and the value is a list of elements that were mapped to that key.
* This is an intermediate operation.
*
* @param The type of the key in the resulting EntryStream.
* @param The type of the value in the resulting EntryStream.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param valueMapper The function to be applied to each element in the stream to determine its value in the group.
* @param mapFactory The supplier providing a new empty Map into which the results will be inserted.
* @return A new EntryStream consisting of entries where the key is the group identifier and the value is a list of elements that were mapped to that key.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract EntryStream> groupByToEntry(Function super T, ? extends K> keyMapper, Function super T, ? extends V> valueMapper,
Supplier extends Map>> mapFactory);
/**
* Groups the elements of the stream by applying a key mapping function to each element.
* The result is an EntryStream where each entry's key is the group identifier (determined by the key mapping function),
* and the value is the result of applying a Collector to the elements of the group.
* This is an intermediate operation.
*
* @param The type of the key in the resulting EntryStream.
* @param The type of the value in the resulting EntryStream. The type is determined by the result type of the Collector.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param downstream The Collector to be applied to the elements of each group.
* @return A new EntryStream consisting of entries where the key is the group identifier and the value is the result of applying the Collector to the elements of the group.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract EntryStream groupByToEntry(Function super T, ? extends K> keyMapper, Collector super T, ?, D> downstream);
/**
* Groups the elements of the stream by applying a key mapping function to each element.
* The result is an EntryStream where each entry's key is the group identifier (determined by the key mapping function),
* and the value is the result of applying a Collector to the elements of the group.
* This is an intermediate operation.
*
* @param The type of the key in the resulting EntryStream.
* @param The type of the value in the resulting EntryStream. The type is determined by the result type of the Collector.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param downstream The Collector to be applied to the elements of each group.
* @param mapFactory The supplier providing a new empty Map into which the results will be inserted.
* @return A new EntryStream consisting of entries where the key is the group identifier and the value is the result of applying the Collector to the elements of the group.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract EntryStream groupByToEntry(Function super T, ? extends K> keyMapper, Collector super T, ?, D> downstream,
Supplier extends Map> mapFactory);
/**
* Groups the elements of the stream by applying a key mapping function, a value mapping function, and a Collector to each element.
* The result is an EntryStream where each entry's key is the group identifier (determined by the key mapping function),
* and the value is the result of applying the Collector to the values of the group.
* This is an intermediate operation.
*
* @param The type of the key in the resulting EntryStream.
* @param The type of the intermediate values used in the Collector.
* @param The type of the value in the resulting EntryStream. The type is determined by the result type of the Collector.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param valueMapper The function to be applied to each element in the stream to determine its value for the Collector.
* @param downstream The Collector to be applied to the values of each group.
* @return A new EntryStream consisting of entries where the key is the group identifier and the value is the result of applying the Collector to the values of the group.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract EntryStream groupByToEntry(Function super T, ? extends K> keyMapper, Function super T, ? extends V> valueMapper,
Collector super V, ?, D> downstream);
/**
* Groups the elements of the stream by applying a key mapping function, a value mapping function, and a Collector to each element.
* The result is an EntryStream where each entry's key is the group identifier (determined by the key mapping function),
* and the value is the result of applying the Collector to the values of the group.
* This is an intermediate operation.
*
* @param The type of the key in the resulting EntryStream.
* @param The type of the intermediate values used in the Collector.
* @param The type of the value in the resulting EntryStream. The type is determined by the result type of the Collector.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param valueMapper The function to be applied to each element in the stream to determine its value for the Collector.
* @param downstream The Collector to be applied to the values of each group.
* @param mapFactory The supplier providing a new empty Map into which the results will be inserted.
* @return A new EntryStream consisting of entries where the key is the group identifier and the value is the result of applying the Collector to the values of the group.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract EntryStream groupByToEntry(Function super T, ? extends K> keyMapper, Function super T, ? extends V> valueMapper,
Collector super V, ?, D> downstream, Supplier extends Map> mapFactory);
/**
* Groups the elements of the stream by applying a key mapping function and a value mapping function to each element.
* The result is an EntryStream where each entry's key is the group identifier (determined by the key mapping function),
* and the value is the result of applying a BinaryOperator to the values of the group.
* This is an intermediate operation.
*
* @param The type of the key in the resulting EntryStream.
* @param The type of the value in the resulting EntryStream.
* @param keyMapper The function to be applied to each element in the stream to determine the group it belongs to.
* @param valueMapper The function to be applied to each element in the stream to determine its value for the BinaryOperator.
* @param mergeFunction The BinaryOperator to be applied to the values of each group.
* @return A new EntryStream consisting of entries where the key is the group identifier and the value is the result of applying the BinaryOperator to the values of the group.
*/
@ParallelSupported
@IntermediateOp
@TerminalOpTriggered
public abstract