public abstract class NarySupport<T> extends Object implements Nary<T>
Created by kfgodel on 07/03/16.
Stream.Builder<T>| Constructor and Description |
|---|
NarySupport() |
| Modifier and Type | Method and Description |
|---|---|
Nary<T> |
add(T... others)
Creates a new Nary with the elements of this instance and the ones passed as var arg array
|
boolean |
allMatch(Predicate<? super T> predicate) |
boolean |
anyMatch(Predicate<? super T> predicate) |
protected abstract Stream<T> |
asStream()
Gets a stream with the elements of this instance.
|
void |
close() |
<R,A> R |
collect(Collector<? super T,A,R> collector) |
<R> R |
collect(Supplier<R> supplier,
BiConsumer<R,? super T> accumulator)
Performs a mutable
reduction operation on the elements of this stream.
|
<R> R |
collect(Supplier<R> supplier,
BiConsumer<R,? super T> accumulator,
BiConsumer<R,R> combiner) |
Nary<T> |
concat(Optional<? extends T> other)
Creates a concatenated Nary with the elements of this instance and the one (if any) on the given
Optional |
Nary<T> |
concat(Stream<? extends T> other)
Creates another nary that will contain the elements of this instance and the given stream
|
long |
count() |
Nary<T> |
distinct() |
boolean |
equals(Object obj)
This method is redefined so two instances of
Nary are equal only if they contain
equal elements, comparing them in iteration order |
Nary<T> |
filter(Predicate<? super T> predicate) |
Optional<T> |
findAny() |
Unary<T> |
findAnyNary()
|
Optional<T> |
findFirst() |
Unary<T> |
findFirstNary()
|
Unary<T> |
findLast()
Returns the last element in this nary, if present.
Depending on the amount of elements on this Nary, the result may be empty or contain the last element |
<R> Nary<R> |
flatMap(Function<? super T,? extends Stream<? extends R>> mapper) |
<U> Nary<U> |
flatMapOptional(Function<? super T,Optional<U>> mapper)
Makes a normal
Stream.flatMap(Function) transformation but accepts Optional
as result for the mapper instead of Stream.This method is the semantic equivalent of Optional.flatMap(Function) but it can be applied to more
than one element. |
DoubleStream |
flatMapToDouble(Function<? super T,? extends DoubleStream> mapper) |
IntStream |
flatMapToInt(Function<? super T,? extends IntStream> mapper) |
LongStream |
flatMapToLong(Function<? super T,? extends LongStream> mapper) |
void |
forEach(Consumer<? super T> action)
Solves conflict between
Iterable and Stream because Iterable defines a default
implementation.We use Iterable.forEach(Consumer) definition |
void |
forEachOrdered(Consumer<? super T> action) |
int |
hashCode()
This method is redefined so the hashcode of a
Nary is based on its contained elements. |
boolean |
isParallel() |
Iterator<T> |
iterator() |
Nary<T> |
limit(long maxSize) |
<R> Nary<R> |
map(Function<? super T,? extends R> mapper) |
<U> Nary<U> |
mapFilteringNullResult(Function<? super T,? extends U> mapper)
Map each element on this instance and filter null results out.
If the result of mapping an element produces null, then it's skipped, reducing the
amount of elements contained in the returned Nary.This is semantically equivalent to Optional.map(Function) and
different from Stream.map(Function) that takes null
as valid results |
DoubleStream |
mapToDouble(ToDoubleFunction<? super T> mapper) |
IntStream |
mapToInt(ToIntFunction<? super T> mapper) |
LongStream |
mapToLong(ToLongFunction<? super T> mapper) |
Optional<T> |
max(Comparator<? super T> comparator) |
Unary<T> |
maxNary(Comparator<? super T> comparator)
|
Optional<T> |
min(Comparator<? super T> comparator) |
Unary<T> |
minNary(Comparator<? super T> comparator)
|
boolean |
noneMatch(Predicate<? super T> predicate) |
Stream<T> |
onClose(Runnable closeHandler) |
Stream<T> |
parallel() |
Nary<T> |
peek(Consumer<? super T> action) |
Optional<T> |
reduce(BinaryOperator<T> accumulator) |
T |
reduce(T identity,
BinaryOperator<T> accumulator) |
<U> U |
reduce(U identity,
BiFunction<U,? super T,U> accumulator,
BinaryOperator<U> combiner) |
Unary<T> |
reduceNary(BinaryOperator<T> accumulator)
|
protected Unary<T> |
returningNaryDo(Optional<T> nativeOptional)
Wraps the native optional in a nary to conform to nary interface
|
protected <R> Nary<R> |
returningNaryDo(Stream<R> nativeStream)
Wraps the native stream in a nary to conform to nary interface
|
Stream<T> |
sequential() |
Nary<T> |
skip(long n) |
Nary<T> |
sorted() |
Nary<T> |
sorted(Comparator<? super T> comparator) |
Spliterator<T> |
spliterator()
Solves conflict between
Iterable and Stream because Iterable defines a default
implementation.We use Iterable.spliterator() definition |
Object[] |
toArray() |
<A> A[] |
toArray(IntFunction<A[]> generator) |
Stream<T> |
unordered() |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitempty, from, from, from, from, from, from, from, from, from, from, of, ofNonNullable, ofNonNullable, toStringcollectToList, collectToSet, uniquepublic Nary<T> concat(Stream<? extends T> other)
MultiElementconcat in interface MultiElement<T>other - The stream to combine after thispublic Nary<T> concat(Optional<? extends T> other)
MultiElementOptionalconcat in interface MultiElement<T>other - The optional to join elements withpublic Nary<T> add(T... others)
MultiElementadd in interface MultiElement<T>others - The elements to append to this streampublic <U> Nary<U> mapFilteringNullResult(Function<? super T,? extends U> mapper)
MultiElementnull, then it's skipped, reducing the
amount of elements contained in the returned Nary.Optional.map(Function) and
different from Stream.map(Function) that takes null
as valid resultsmapFilteringNullResult in interface MultiElement<T>U - The type of the result of the mapping functionmapper - a mapping function to apply to the value, if presentpublic <U> Nary<U> flatMapOptional(Function<? super T,Optional<U>> mapper) throws MoreThanOneElementException
MultiElementStream.flatMap(Function) transformation but accepts Optional
as result for the mapper instead of Stream.Optional.flatMap(Function) but it can be applied to more
than one element.flatMapOptional in interface MultiElement<T>U - The type parameter to the Optional returned bymapper - a mapping function to apply to the value, if present
the mapping functionOptional-bearing mapping
function to the elements of this instance which may be 0, 1, or more elementsMoreThanOneElementExceptionpublic <R> R collect(Supplier<R> supplier, BiConsumer<R,? super T> accumulator)
MultiElementArrayList, and elements are incorporated by updating
the state of the result rather than by replacing the result. This
produces a result equivalent to:
R result = supplier.asUni().get();
for (T element : this stream)
accumulator.accept(result, element);
return result;
This is a terminal operation.
There are many existing classes in the JDK whose signatures are
well-suited for use with method references as arguments to collect().
For example, the following will accumulate strings into an ArrayList:
List<String> asList = stringStream.collect(ArrayList::new, ArrayList::add);
The following will take a stream of strings and concatenates them into a single string:
String concat = stringStream.collect(StringBuilder::new, StringBuilder::append)
.toString();
collect in interface MultiElement<T>R - type of the resultsupplier - a function that creates a new result container. For a
parallel execution, this function may be called
multiple times and must return a fresh value each time.accumulator - an associative,
non-interfering,
stateless
function for incorporating an additional element into a resultprotected abstract Stream<T> asStream()
public IntStream mapToInt(ToIntFunction<? super T> mapper)
public LongStream mapToLong(ToLongFunction<? super T> mapper)
public DoubleStream mapToDouble(ToDoubleFunction<? super T> mapper)
mapToDouble in interface Stream<T>public IntStream flatMapToInt(Function<? super T,? extends IntStream> mapper)
flatMapToInt in interface Stream<T>public LongStream flatMapToLong(Function<? super T,? extends LongStream> mapper)
flatMapToLong in interface Stream<T>public DoubleStream flatMapToDouble(Function<? super T,? extends DoubleStream> mapper)
flatMapToDouble in interface Stream<T>public void forEach(Consumer<? super T> action)
MultiElementIterable and Stream because Iterable defines a default
implementation.Iterable.forEach(Consumer) definitionpublic void forEachOrdered(Consumer<? super T> action)
forEachOrdered in interface Stream<T>public <A> A[] toArray(IntFunction<A[]> generator)
public T reduce(T identity, BinaryOperator<T> accumulator)
public Optional<T> reduce(BinaryOperator<T> accumulator)
public <U> U reduce(U identity,
BiFunction<U,? super T,U> accumulator,
BinaryOperator<U> combiner)
public <R> R collect(Supplier<R> supplier, BiConsumer<R,? super T> accumulator, BiConsumer<R,R> combiner)
public Optional<T> min(Comparator<? super T> comparator)
public Optional<T> max(Comparator<? super T> comparator)
public Spliterator<T> spliterator()
MultiElementIterable and Stream because Iterable defines a default
implementation.Iterable.spliterator() definitionspliterator in interface MultiElement<T>spliterator in interface Iterable<T>spliterator in interface BaseStream<T,Stream<T>>public boolean isParallel()
isParallel in interface BaseStream<T,Stream<T>>public Stream<T> sequential()
sequential in interface BaseStream<T,Stream<T>>public Stream<T> onClose(Runnable closeHandler)
onClose in interface BaseStream<T,Stream<T>>public void close()
close in interface AutoCloseableclose in interface BaseStream<T,Stream<T>>public Unary<T> findLast()
MultiElementfindLast in interface MultiElement<T>public Nary<T> sorted(Comparator<? super T> comparator)
public Unary<T> reduceNary(BinaryOperator<T> accumulator)
MultiElementreduceNary in interface MultiElement<T>accumulator - The associative function to reduce the elements of this nary to a result of the same typefor a complete referencepublic Unary<T> minNary(Comparator<? super T> comparator)
MultiElementminNary in interface MultiElement<T>comparator - a non-interfering,
stateless
Comparator to compare elements of this streamNary describing the minimum element of this stream,
or an empty if there are no elementspublic Unary<T> maxNary(Comparator<? super T> comparator)
MultiElementmaxNary in interface MultiElement<T>comparator - a non-interfering,
stateless
Comparator to compare elements of this streamNary describing the maximum element of this stream,
or an empty if there are no elementspublic Unary<T> findFirstNary()
MultiElementfindFirstNary in interface MultiElement<T>Nary describing the first element of this stream,
or an empty Nary if the stream is emptypublic Unary<T> findAnyNary()
MultiElementfindAnyNary in interface MultiElement<T>Nary describing some element of this stream, or an
empty Nary if the stream is emptyStream.findFirst()public boolean equals(Object obj)
NaryNary are equal only if they contain
equal elements, comparing them in iteration orderpublic int hashCode()
NaryNary is based on its contained elements.protected <R> Nary<R> returningNaryDo(Stream<R> nativeStream)
R - type of expected elementsnativeStream - The stream to wrapCopyright © 2020. All rights reserved.