public final class StreamUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <T> java.util.stream.Stream<List<T>> |
aggregate(java.util.stream.Stream<T> source,
java.util.function.BiPredicate<T,T> predicate)
Aggregates items from source stream into list of items while supplied predicate is true when evaluated on previous and current item.
|
static <T> java.util.stream.Stream<List<T>> |
aggregate(java.util.stream.Stream<T> source,
int size)
Aggregates items from source stream into list of items with fixed size
|
static <T> java.util.stream.Stream<List<T>> |
aggregateOnListCondition(java.util.stream.Stream<T> source,
java.util.function.BiPredicate<List<T>,T> predicate)
Aggregates items from source stream.
|
static <T extends Comparable<T>> |
groupRuns(java.util.stream.Stream<T> source)
Constructs a stream that represents grouped run using the default comparator.
|
static <T> java.util.stream.Stream<List<T>> |
groupRuns(java.util.stream.Stream<T> source,
Comparator<T> comparator)
Constructs a stream that represents grouped run using the default comparator.
|
static java.util.stream.LongStream |
indices()
Constructs an infinite (although in practice bounded by Long.MAX_VALUE) stream of longs 0, 1, 2, 3...
|
static <T> java.util.stream.Stream<T> |
interleave(java.util.function.Function<T[],Integer> selector,
List<java.util.stream.Stream<T>> streams)
Construct a stream which interleaves the supplied streams, picking items using the supplied selector function.
|
static <T> java.util.stream.Stream<T> |
interleave(java.util.function.Function<T[],Integer> selector,
java.util.stream.Stream<T>... streams)
Construct a stream which interleaves the supplied streams, picking items using the supplied selector function.
|
static <T,O> java.util.stream.Stream<O> |
merge(java.util.function.Supplier<O> unitSupplier,
java.util.function.BiFunction<O,T,O> merger,
java.util.stream.Stream<T>... streams)
Construct a stream which merges together values from the supplied streams, somewhat in the manner of the
stream constructed by
zip(java.util.stream.Stream, java.util.stream.Stream, java.util.function.BiFunction) ,
but for an arbitrary number of streams and using a merger to merge the values from multiple streams
into an accumulator. |
static <T> java.util.stream.Stream<List<T>> |
mergeToList(java.util.stream.Stream<T>... streams)
Construct a stream which merges together values from the supplied streams into lists of values, somewhat in the manner of the
stream constructed by
zip(java.util.stream.Stream, java.util.stream.Stream, java.util.function.BiFunction) ,
but for an arbitrary number of streams. |
static <T> java.util.stream.Stream<T> |
reject(java.util.stream.Stream<T> source,
java.util.function.Predicate<? super T> predicate)
Filter with the condition negated.
|
static <T> java.util.stream.Stream<T> |
skipUntil(java.util.stream.Stream<T> source,
java.util.function.Predicate<T> condition)
Construct a stream which skips values from the source stream for as long as they do not meet the supplied condition,
then streams every remaining value as soon as the first value is found which does meet the condition.
|
static <T> java.util.stream.Stream<T> |
skipWhile(java.util.stream.Stream<T> source,
java.util.function.Predicate<T> condition)
Construct a stream which skips values from the source stream for as long as they meet the supplied condition,
then streams every remaining value as soon as the first value is found which does not meet the condition.
|
static <T> java.util.stream.Stream<T> |
stream(Iterable<T> iterable)
Converts an Iterable into a Stream.
|
static <T> java.util.stream.Stream<T> |
stream(Optional<T> optional)
Converts an Optional value to a stream of 0..1 values
|
static <T> java.util.stream.Stream<T> |
takeUntil(java.util.stream.Stream<T> source,
java.util.function.Predicate<T> condition)
Construct a stream which takes values from the source stream until one of them meets the supplied condition,
and then stops.
|
static <T> java.util.stream.Stream<T> |
takeWhile(java.util.stream.Stream<T> source,
java.util.function.Predicate<T> condition)
Construct a stream which takes values from the source stream for as long as they meet the supplied condition, and stops
as soon as a value is encountered which does not meet the condition.
|
static <T> java.util.stream.Stream<T> |
unfold(T seed,
java.util.function.Function<T,Optional<T>> generator)
Construct a stream which takes the seed value and applies the generator to create the next value, feeding each
new value back into the generator to create subsequent values.
|
static <T> java.util.stream.Stream<List<T>> |
windowed(java.util.stream.Stream<T> source,
int windowSize)
Constructs a stream that is a windowed view of the source stream of the size window size
with a default overlap of one item
|
static <T> java.util.stream.Stream<List<T>> |
windowed(java.util.stream.Stream<T> source,
int windowSize,
int skip)
Constructs a windowed stream where each element is a list of the window size
and the skip is the offset from the start of each window.
|
static <L,M,R,O> java.util.stream.Stream<O> |
zip(java.util.stream.Stream<L> lefts,
java.util.stream.Stream<M> middles,
java.util.stream.Stream<R> rights,
TriFunction<L,M,R,O> combiner)
Zip together the "left", "middle" and "right" streams until any stream runs out of values.
|
static <L,R,O> java.util.stream.Stream<O> |
zip(java.util.stream.Stream<L> lefts,
java.util.stream.Stream<R> rights,
java.util.function.BiFunction<L,R,O> combiner)
Zip together the "left" and "right" streams until either runs out of values.
|
static <T> java.util.stream.Stream<Indexed<T>> |
zipWithIndex(java.util.stream.Stream<T> source)
Zip the source stream together with the stream of indices() to provide a stream of indexed values.
|
public static java.util.stream.LongStream indices()
public static <T> java.util.stream.Stream<Indexed<T>> zipWithIndex(java.util.stream.Stream<T> source)
T
- The type over which the source stream streams.source
- The source stream.public static <L,R,O> java.util.stream.Stream<O> zip(java.util.stream.Stream<L> lefts, java.util.stream.Stream<R> rights, java.util.function.BiFunction<L,R,O> combiner)
L
- The type over which the "left" stream streams.R
- The type over which the "right" stream streams.O
- The type created by the combiner out of pairs of "left" and "right" values, over which the resulting
stream streams.lefts
- The "left" stream to zip.rights
- The "right" stream to zip.combiner
- The function to combine "left" and "right" values.public static <L,M,R,O> java.util.stream.Stream<O> zip(java.util.stream.Stream<L> lefts, java.util.stream.Stream<M> middles, java.util.stream.Stream<R> rights, TriFunction<L,M,R,O> combiner)
L
- The type over which the "left" stream streams.M
- The type over which the "middle" stream streams.R
- The type over which the "right" stream streams.O
- The type created by the combiner out of triples of "left", "middle" and "right" values, over which the resulting
stream streams.lefts
- The "left" stream to zip.middles
- The "middle" stream to zip.rights
- The "right" stream to zip.combiner
- The function to combine "left", "middle" and "right" values.public static <T> java.util.stream.Stream<T> takeWhile(java.util.stream.Stream<T> source, java.util.function.Predicate<T> condition)
T
- The type over which the stream streams.source
- The source stream.condition
- The condition to apply to elements of the source stream.public static <T> java.util.stream.Stream<T> takeUntil(java.util.stream.Stream<T> source, java.util.function.Predicate<T> condition)
T
- The type over which the stream streams.source
- The source stream.condition
- The condition to apply to elements of the source stream.public static <T> java.util.stream.Stream<T> skipWhile(java.util.stream.Stream<T> source, java.util.function.Predicate<T> condition)
T
- The type over which the stream streams.source
- The source stream.condition
- The condition to apply to elements of the source stream.public static <T> java.util.stream.Stream<T> skipUntil(java.util.stream.Stream<T> source, java.util.function.Predicate<T> condition)
T
- The type over which the stream streams.source
- The source stream.condition
- The condition to apply to elements of the source stream.public static <T> java.util.stream.Stream<T> unfold(T seed, java.util.function.Function<T,Optional<T>> generator)
T
- The type over which the stream streams.seed
- The seed value.generator
- The generator to use to create new values.public static <T> java.util.stream.Stream<List<T>> windowed(java.util.stream.Stream<T> source, int windowSize)
T
- The type over which to streamsource
- The source streamwindowSize
- The window sizepublic static <T> java.util.stream.Stream<List<T>> windowed(java.util.stream.Stream<T> source, int windowSize, int skip)
T
- The type over which to streamsource
- The input streamwindowSize
- The window sizeskip
- The skip amount between windowspublic static <T extends Comparable<T>> java.util.stream.Stream<List<T>> groupRuns(java.util.stream.Stream<T> source)
T
- The type over which to streamsource
- The input streampublic static <T> java.util.stream.Stream<List<T>> groupRuns(java.util.stream.Stream<T> source, Comparator<T> comparator)
T
- The type over which to streamsource
- The input streamcomparator
- The comparator to determine if neighbor elements are the samepublic static <T> java.util.stream.Stream<T> interleave(java.util.function.Function<T[],Integer> selector, java.util.stream.Stream<T>... streams)
Selectors
class for ready-made selectors for round-robin and sorted
item selection.T
- The type over which the interleaved streams stream.selector
- The selector function to use.streams
- The streams to interleave.public static <T> java.util.stream.Stream<T> interleave(java.util.function.Function<T[],Integer> selector, List<java.util.stream.Stream<T>> streams)
Selectors
class for ready-made selectors for round-robin and sorted
item selection.T
- The type over which the interleaved streams stream.selector
- The selector function to use.streams
- The streams to interleave.public static <T,O> java.util.stream.Stream<O> merge(java.util.function.Supplier<O> unitSupplier, java.util.function.BiFunction<O,T,O> merger, java.util.stream.Stream<T>... streams)
zip(java.util.stream.Stream, java.util.stream.Stream, java.util.function.BiFunction)
,
but for an arbitrary number of streams and using a merger to merge the values from multiple streams
into an accumulator.T
- The type over which the merged streams stream.O
- The type of the accumulator, over which the constructed stream streams.unitSupplier
- Supplies the initial "zero" or "unit" value for the accumulator.merger
- Merges each item from the collection of values taken from the source streams into the accumulator value.streams
- The streams to merge.public static <T> java.util.stream.Stream<List<T>> mergeToList(java.util.stream.Stream<T>... streams)
zip(java.util.stream.Stream, java.util.stream.Stream, java.util.function.BiFunction)
,
but for an arbitrary number of streams.T
- The type over which the merged streams stream.streams
- The streams to merge.public static <T> java.util.stream.Stream<T> reject(java.util.stream.Stream<T> source, java.util.function.Predicate<? super T> predicate)
T
- The type over which the stream streams.source
- The source stream.predicate
- The filter condition.public static <T> java.util.stream.Stream<List<T>> aggregate(java.util.stream.Stream<T> source, java.util.function.BiPredicate<T,T> predicate)
T
- The type over which the stream streams.source
- - source streampredicate
- - predicate specifying boundary between groups of itemspublic static <T> java.util.stream.Stream<List<T>> aggregate(java.util.stream.Stream<T> source, int size)
T
- The type over which the stream streams.source
- - source streamsize
- - size of the aggregated listpublic static <T> java.util.stream.Stream<List<T>> aggregateOnListCondition(java.util.stream.Stream<T> source, java.util.function.BiPredicate<List<T>,T> predicate)
T
- The type over which the stream streams.source
- - source streampredicate
- - predicate specifying boundary between groups of itemspublic static <T> java.util.stream.Stream<T> stream(Optional<T> optional)
T
- The type of the optional valueoptional
- source optional valuepublic static <T> java.util.stream.Stream<T> stream(Iterable<T> iterable)
T
- The type of the iterableiterable
- The iterable to stream.Copyright © 2015. All rights reserved.