public class UberStream<T>
extends java.lang.Object
implements java.util.stream.Stream<T>
Stream.
Class implements Stream interface, so it can be used as one.
Provides various additional useful methods.| Constructor and Description |
|---|
UberStream(java.util.stream.Stream<T> actual) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
allMatch(java.util.function.Predicate<? super T> predicate) |
boolean |
anyMatch(java.util.function.Predicate<? super T> predicate) |
void |
close() |
<R,A> R |
collect(java.util.stream.Collector<? super T,A,R> collector) |
<R> R |
collect(java.util.function.Supplier<R> supplier,
java.util.function.BiConsumer<R,? super T> accumulator,
java.util.function.BiConsumer<R,R> combiner) |
long |
count() |
UberStream<T> |
distinct() |
UberStream<T> |
drop(java.util.function.Predicate<? super T> predicate)
Filter out all elements that match specified predicate.
|
UberStream<T> |
dropNulls()
Filter out all null elements.
|
UberStream<T> |
filter(java.util.function.Predicate<? super T> predicate) |
<R extends T> |
filterByClass(java.lang.Class<R> filteredClass)
Filter only instances of the specified class (or nulls) and cast them to the specified type.
|
java.util.Optional<T> |
find(java.util.function.Predicate<? super T> predicate)
Find first element matching specified predicate.
|
java.util.Optional<T> |
findAny() |
java.util.Optional<T> |
findFirst() |
<R> UberStream<R> |
flatMap(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> mapper) |
<R> UberStream<R> |
flatMapArr(java.util.function.Function<? super T,R[]> mapper)
Maps each element of the stream into array and them flattens result stream.
|
<R> UberStream<R> |
flatMapCol(java.util.function.Function<? super T,? extends java.util.Collection<? extends R>> mapper)
Maps each element of the stream into collection and them flattens result stream.
|
java.util.stream.DoubleStream |
flatMapToDouble(java.util.function.Function<? super T,? extends java.util.stream.DoubleStream> mapper) |
java.util.stream.IntStream |
flatMapToInt(java.util.function.Function<? super T,? extends java.util.stream.IntStream> mapper) |
java.util.stream.LongStream |
flatMapToLong(java.util.function.Function<? super T,? extends java.util.stream.LongStream> mapper) |
void |
forEach(java.util.function.Consumer<? super T> action) |
void |
forEachOrdered(java.util.function.Consumer<? super T> action) |
boolean |
isParallel() |
java.util.Iterator<T> |
iterator() |
java.lang.String |
join(java.lang.CharSequence delimiter)
All elements of the stream are mapped to string using
String.valueOf(Object). |
java.lang.String |
join(java.lang.CharSequence delimiter,
java.lang.CharSequence prefix,
java.lang.CharSequence suffix)
All elements of the stream are mapped to string using
String.valueOf(Object). |
UberStream<T> |
limit(long maxSize) |
<R> UberStream<R> |
map(java.util.function.Function<? super T,? extends R> mapper) |
java.util.stream.DoubleStream |
mapToDouble(java.util.function.ToDoubleFunction<? super T> mapper) |
java.util.stream.IntStream |
mapToInt(java.util.function.ToIntFunction<? super T> mapper) |
java.util.stream.LongStream |
mapToLong(java.util.function.ToLongFunction<? super T> mapper) |
java.util.Optional<T> |
max(java.util.Comparator<? super T> comparator) |
java.util.Optional<T> |
min(java.util.Comparator<? super T> comparator) |
boolean |
noneMatch(java.util.function.Predicate<? super T> predicate) |
UberStream<T> |
onClose(java.lang.Runnable closeHandler) |
UberStream<T> |
parallel() |
UberStream<T> |
peek(java.util.function.Consumer<? super T> action) |
java.util.Optional<T> |
reduce(java.util.function.BinaryOperator<T> accumulator) |
T |
reduce(T identity,
java.util.function.BinaryOperator<T> accumulator) |
<U> U |
reduce(U identity,
java.util.function.BiFunction<U,? super T,U> accumulator,
java.util.function.BinaryOperator<U> combiner) |
UberStream<T> |
sequential() |
UberStream<T> |
skip(long n) |
UberStream<T> |
sorted() |
UberStream<T> |
sorted(java.util.Comparator<? super T> comparator) |
java.util.Spliterator<T> |
spliterator() |
<C extends java.util.Collection<T>> |
to(java.util.function.Supplier<C> factory)
Collect all elements of the stream into a collection provided by the specified factory.
|
java.lang.Object[] |
toArray() |
<A> A[] |
toArray(java.lang.Class<A> type) |
<A> A[] |
toArray(java.util.function.IntFunction<A[]> generator) |
java.util.List<T> |
toList()
Collect all elements of the stream into a list.
|
<K> java.util.Map<K,T> |
toMap(java.util.function.Function<T,K> keyFunction)
Specified function is applied to each element of the stream.
|
<K,V> java.util.Map<K,V> |
toMap(java.util.function.Function<T,K> keyFunction,
java.util.function.Function<T,V> valFunction)
Specified functions are applied to each element of the stream.
|
<K,V,M extends java.util.Map<K,V>> |
toMap(java.util.function.Function<T,K> keyFunction,
java.util.function.Function<T,V> valFunction,
java.util.function.Supplier<M> mapSupplier)
Specified functions are applied to each element of the stream.
|
<K,M extends java.util.Map<K,T>> |
toMap(java.util.function.Function<T,K> keyFunction,
java.util.function.Supplier<M> mapSupplier)
Specified function is applied to each element of the stream.
|
<K> MapStream<K,T> |
toMapStream(java.util.function.Function<T,K> keyFunction)
Equal to calling
toMap(Function) and then constructing new MapStream. |
<K,V> MapStream<K,V> |
toMapStream(java.util.function.Function<T,K> keyFunction,
java.util.function.Function<T,V> valFunction)
Equal to calling
toMap(Function, Function) and then constructing new MapStream. |
java.util.Set<T> |
toSet()
Collect all elements of the stream into a set.
|
UberStream<T> |
unordered() |
<V> UberStream<UberMaps.Entry<T,V>> |
zip(java.util.function.Function<T,V> mapper) |
public UberStream(java.util.stream.Stream<T> actual)
public java.util.Iterator<T> iterator()
public java.util.Spliterator<T> spliterator()
public boolean isParallel()
public UberStream<T> sequential()
public UberStream<T> parallel()
public UberStream<T> unordered()
public UberStream<T> onClose(java.lang.Runnable closeHandler)
public void close()
public UberStream<T> filter(java.util.function.Predicate<? super T> predicate)
filter in interface java.util.stream.Stream<T>public <R extends T> UberStream<R> filterByClass(java.lang.Class<R> filteredClass)
Filter only instances of the specified class (or nulls) and cast them to the specified type.
#filter(x -> x == null || filteredClass.isInstance(x))
.map(x -> filteredClass.cast(x));
Note: nulls survive the filtering!
Use separate filter or dropNulls() to filter them out!public UberStream<T> drop(java.util.function.Predicate<? super T> predicate)
#filter(not(predicate));
public UberStream<T> dropNulls()
#filter(Objects::nonNull);
public java.util.Optional<T> find(java.util.function.Predicate<? super T> predicate)
#filter(predicate).findFirst();
public <R> UberStream<R> map(java.util.function.Function<? super T,? extends R> mapper)
map in interface java.util.stream.Stream<T>public java.util.stream.IntStream mapToInt(java.util.function.ToIntFunction<? super T> mapper)
mapToInt in interface java.util.stream.Stream<T>public java.util.stream.LongStream mapToLong(java.util.function.ToLongFunction<? super T> mapper)
mapToLong in interface java.util.stream.Stream<T>public java.util.stream.DoubleStream mapToDouble(java.util.function.ToDoubleFunction<? super T> mapper)
mapToDouble in interface java.util.stream.Stream<T>public <R> UberStream<R> flatMap(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> mapper)
flatMap in interface java.util.stream.Stream<T>public <R> UberStream<R> flatMapCol(java.util.function.Function<? super T,? extends java.util.Collection<? extends R>> mapper)
#flatMap(e -> mapper.apply(e).stream())
public <R> UberStream<R> flatMapArr(java.util.function.Function<? super T,R[]> mapper)
#flatMap(e -> Stream.of(mapper.apply(e)))
public java.util.stream.IntStream flatMapToInt(java.util.function.Function<? super T,? extends java.util.stream.IntStream> mapper)
flatMapToInt in interface java.util.stream.Stream<T>public java.util.stream.LongStream flatMapToLong(java.util.function.Function<? super T,? extends java.util.stream.LongStream> mapper)
flatMapToLong in interface java.util.stream.Stream<T>public java.util.stream.DoubleStream flatMapToDouble(java.util.function.Function<? super T,? extends java.util.stream.DoubleStream> mapper)
flatMapToDouble in interface java.util.stream.Stream<T>public <V> UberStream<UberMaps.Entry<T,V>> zip(java.util.function.Function<T,V> mapper)
public UberStream<T> distinct()
distinct in interface java.util.stream.Stream<T>public UberStream<T> sorted()
sorted in interface java.util.stream.Stream<T>public UberStream<T> sorted(java.util.Comparator<? super T> comparator)
sorted in interface java.util.stream.Stream<T>public UberStream<T> peek(java.util.function.Consumer<? super T> action)
peek in interface java.util.stream.Stream<T>public UberStream<T> limit(long maxSize)
limit in interface java.util.stream.Stream<T>public UberStream<T> skip(long n)
skip in interface java.util.stream.Stream<T>public void forEach(java.util.function.Consumer<? super T> action)
forEach in interface java.util.stream.Stream<T>public void forEachOrdered(java.util.function.Consumer<? super T> action)
forEachOrdered in interface java.util.stream.Stream<T>public java.lang.Object[] toArray()
toArray in interface java.util.stream.Stream<T>public <A> A[] toArray(java.util.function.IntFunction<A[]> generator)
toArray in interface java.util.stream.Stream<T>public <A> A[] toArray(java.lang.Class<A> type)
public T reduce(T identity, java.util.function.BinaryOperator<T> accumulator)
reduce in interface java.util.stream.Stream<T>public java.util.Optional<T> reduce(java.util.function.BinaryOperator<T> accumulator)
reduce in interface java.util.stream.Stream<T>public <U> U reduce(U identity,
java.util.function.BiFunction<U,? super T,U> accumulator,
java.util.function.BinaryOperator<U> combiner)
reduce in interface java.util.stream.Stream<T>public <R> R collect(java.util.function.Supplier<R> supplier,
java.util.function.BiConsumer<R,? super T> accumulator,
java.util.function.BiConsumer<R,R> combiner)
collect in interface java.util.stream.Stream<T>public <R,A> R collect(java.util.stream.Collector<? super T,A,R> collector)
collect in interface java.util.stream.Stream<T>public <C extends java.util.Collection<T>> C to(java.util.function.Supplier<C> factory)
public java.util.List<T> toList()
public java.util.Set<T> toSet()
public <K> java.util.Map<K,T> toMap(java.util.function.Function<T,K> keyFunction)
Specified function is applied to each element of the stream. Results are used as keys in the result map. Values are the elements themselves. Equal to:
#collect(MapCollectors.toMap(keyFunction, e -> e));
Note: merges are resolved as "last one is to stay", so keys duplication is allowed.
MapCollectors.toMap(Function, Function)public <K,V> java.util.Map<K,V> toMap(java.util.function.Function<T,K> keyFunction, java.util.function.Function<T,V> valFunction)
Specified functions are applied to each element of the stream. Results are used as key/value pairs in the result map. Equal to:
#collect(MapCollectors.toMap(keyFunction, valFunction));
Note: merges are resolved as "last one is to stay", so keys duplication is allowed.
MapCollectors.toMap(Function, Function)public <K,M extends java.util.Map<K,T>> M toMap(java.util.function.Function<T,K> keyFunction, java.util.function.Supplier<M> mapSupplier)
Specified function is applied to each element of the stream. Results are used as keys in the result map. Values are the elements themselves. Map is created from the specified supplier. Equal to:
#collect(MapCollectors.toMap(keyFunction, e -> e, mapSupplier));
Note: merges are resolved as "last one is to stay", so keys duplication is allowed.
public <K,V,M extends java.util.Map<K,V>> M toMap(java.util.function.Function<T,K> keyFunction, java.util.function.Function<T,V> valFunction, java.util.function.Supplier<M> mapSupplier)
Specified functions are applied to each element of the stream. Results are used as key/value pairs in the result map. Map is created from the specified supplier. Equal to:
#collect(MapCollectors.toMap(keyFunction, valFunction, mapSupplier));
Note: merges are resolved as "last one is to stay", so keys duplication is allowed.
public <K> MapStream<K,T> toMapStream(java.util.function.Function<T,K> keyFunction)
toMap(Function) and then constructing new MapStream.public <K,V> MapStream<K,V> toMapStream(java.util.function.Function<T,K> keyFunction, java.util.function.Function<T,V> valFunction)
toMap(Function, Function) and then constructing new MapStream.public java.lang.String join(java.lang.CharSequence delimiter)
String.valueOf(Object). Then all elements
are concatenated to string using specified delimiter. Equal to:
#map(String::valueOf).collect(Collectors.joining(delimiter));
public java.lang.String join(java.lang.CharSequence delimiter,
java.lang.CharSequence prefix,
java.lang.CharSequence suffix)
String.valueOf(Object). Then all elements
are concatenated to string using specified delimiter, prefix, and suffix. Equal to:
#map(String::valueOf).collect(Collectors.joining(delimiter, prefix, suffix));
public java.util.Optional<T> min(java.util.Comparator<? super T> comparator)
min in interface java.util.stream.Stream<T>public java.util.Optional<T> max(java.util.Comparator<? super T> comparator)
max in interface java.util.stream.Stream<T>public long count()
count in interface java.util.stream.Stream<T>public boolean anyMatch(java.util.function.Predicate<? super T> predicate)
anyMatch in interface java.util.stream.Stream<T>public boolean allMatch(java.util.function.Predicate<? super T> predicate)
allMatch in interface java.util.stream.Stream<T>public boolean noneMatch(java.util.function.Predicate<? super T> predicate)
noneMatch in interface java.util.stream.Stream<T>public java.util.Optional<T> findFirst()
findFirst in interface java.util.stream.Stream<T>