T
- the type of the stream elements.public interface RichStream<T> extends java.util.stream.Stream<T>
The default Java 8 Stream implementation is deliberately spartan in API methods in order to
avoid dependencies on Collections, and to focus on parallelism. This wrapper adds common
operations to the Stream API, mostly inspired by Guava's FluentIterable
.
java.util.stream.Stream.Builder<T>
Modifier and Type | Method and Description |
---|---|
default RichStream<T> |
concat(java.util.stream.Stream<? extends T> other) |
RichStream<T> |
distinct() |
static <T> RichStream<T> |
empty() |
default <U> RichStream<U> |
filter(Class<U> cls)
Filter stream elements, returning only those that is an instance of the given class.
|
RichStream<T> |
filter(java.util.function.Predicate<? super T> predicate) |
<R> RichStream<R> |
flatMap(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> mapper) |
<E extends Exception> |
forEachOrderedThrowing(ThrowingConsumer<? super T,E> action)
A variant of
Stream.forEachOrdered(java.util.function.Consumer<? super T>) that can safely throw a checked exception. |
<E extends Exception> |
forEachThrowing(ThrowingConsumer<? super T,E> action)
A variant of
Stream.forEach(java.util.function.Consumer<? super T>) that can safely throw a checked exception. |
static <T> RichStream<T> |
from(Iterable<T> iterable) |
static <T> RichStream<T> |
from(Iterator<T> iterator) |
static <T> RichStream<T> |
from(Optional<T> optional) |
static <T> RichStream<T> |
from(java.util.stream.Stream<T> stream) |
static <T> RichStream<T> |
from(T[] array) |
static <T> RichStream<T> |
fromSupplierOfIterable(java.util.function.Supplier<? extends Iterable<T>> supplier) |
RichStream<T> |
limit(long maxSize) |
<R> RichStream<R> |
map(java.util.function.Function<? super T,? extends R> mapper) |
static <T> RichStream<T> |
of(T... values) |
static <T> RichStream<T> |
of(T value) |
RichStream<T> |
onClose(Runnable closeHandler) |
RichStream<T> |
parallel() |
RichStream<T> |
peek(java.util.function.Consumer<? super T> action) |
RichStream<T> |
sequential() |
RichStream<T> |
skip(long n) |
RichStream<T> |
sorted() |
RichStream<T> |
sorted(Comparator<? super T> comparator) |
default com.google.common.collect.ImmutableList<T> |
toImmutableList() |
default com.google.common.collect.ImmutableSet<T> |
toImmutableSet() |
default com.google.common.collect.ImmutableSortedSet<T> |
toImmutableSortedSet(Comparator<? super T> ordering) |
default Iterable<T> |
toOnceIterable() |
RichStream<T> |
unordered() |
allMatch, anyMatch, builder, collect, collect, concat, count, findAny, findFirst, flatMapToDouble, flatMapToInt, flatMapToLong, forEach, forEachOrdered, generate, iterate, mapToDouble, mapToInt, mapToLong, max, min, noneMatch, reduce, reduce, reduce, toArray, toArray
close, isParallel, iterator, spliterator
static <T> RichStream<T> empty()
empty
in interface java.util.stream.Stream<T>
static <T> RichStream<T> of(T value)
of
in interface java.util.stream.Stream<T>
@SafeVarargs static <T> RichStream<T> of(T... values)
of
in interface java.util.stream.Stream<T>
static <T> RichStream<T> from(T[] array)
static <T> RichStream<T> from(Iterable<T> iterable)
static <T> RichStream<T> from(Iterator<T> iterator)
static <T> RichStream<T> from(Optional<T> optional)
static <T> RichStream<T> fromSupplierOfIterable(java.util.function.Supplier<? extends Iterable<T>> supplier)
static <T> RichStream<T> from(java.util.stream.Stream<T> stream)
default RichStream<T> concat(java.util.stream.Stream<? extends T> other)
other
- Stream to concatenate into the current one.default <U> RichStream<U> filter(Class<U> cls)
U
- Class to cast to.cls
- Class instance of the class to cast to.cls
.default com.google.common.collect.ImmutableList<T> toImmutableList()
default com.google.common.collect.ImmutableSet<T> toImmutableSet()
default com.google.common.collect.ImmutableSortedSet<T> toImmutableSortedSet(Comparator<? super T> ordering)
<E extends Exception> void forEachThrowing(ThrowingConsumer<? super T,E> action) throws E extends Exception
Stream.forEach(java.util.function.Consumer<? super T>)
that can safely throw a checked exception.E
- Exception that may be thrown by the action.E
- Exception thrown by the action.E extends Exception
<E extends Exception> void forEachOrderedThrowing(ThrowingConsumer<? super T,E> action) throws E extends Exception
Stream.forEachOrdered(java.util.function.Consumer<? super T>)
that can safely throw a checked exception.E
- Exception that may be thrown by the action.E
- Exception thrown by the action.E extends Exception
RichStream<T> filter(java.util.function.Predicate<? super T> predicate)
filter
in interface java.util.stream.Stream<T>
<R> RichStream<R> map(java.util.function.Function<? super T,? extends R> mapper)
map
in interface java.util.stream.Stream<T>
<R> RichStream<R> flatMap(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> mapper)
flatMap
in interface java.util.stream.Stream<T>
RichStream<T> distinct()
distinct
in interface java.util.stream.Stream<T>
RichStream<T> sorted()
sorted
in interface java.util.stream.Stream<T>
RichStream<T> sorted(Comparator<? super T> comparator)
sorted
in interface java.util.stream.Stream<T>
RichStream<T> peek(java.util.function.Consumer<? super T> action)
peek
in interface java.util.stream.Stream<T>
RichStream<T> limit(long maxSize)
limit
in interface java.util.stream.Stream<T>
RichStream<T> skip(long n)
skip
in interface java.util.stream.Stream<T>
RichStream<T> sequential()
sequential
in interface java.util.stream.BaseStream<T,java.util.stream.Stream<T>>
RichStream<T> parallel()
parallel
in interface java.util.stream.BaseStream<T,java.util.stream.Stream<T>>
RichStream<T> unordered()
unordered
in interface java.util.stream.BaseStream<T,java.util.stream.Stream<T>>
RichStream<T> onClose(Runnable closeHandler)
onClose
in interface java.util.stream.BaseStream<T,java.util.stream.Stream<T>>