T - Type of contained elementspublic interface MultiElement<T> extends Iterable<T>, NaryStream<T>
Stream.Builder<T>| 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
|
<R> R |
collect(Supplier<R> supplier,
BiConsumer<R,? super T> accumulator)
Performs a mutable
reduction operation on the elements of this stream.
|
List<T> |
collectToList()
Returns the content of this nary in a list.
This method is a shorthand of calling collect(Collectors.toList()). This nary, as stream, will be consumed in the operation. |
Set<T> |
collectToSet()
Returns the content of this nary in a set.
This method is a shorthand of calling collect(Collectors.toSet()) This nary, as stream, will be consumed in the operation. |
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
|
Unary<T> |
findAnyNary()
|
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 |
<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. |
default void |
forEach(Consumer<? super T> action)
Solves conflict between
Iterable and Stream because Iterable defines a default
implementation.We use Iterable.forEach(Consumer) definition |
<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 |
Unary<T> |
maxNary(Comparator<? super T> comparator)
|
Unary<T> |
minNary(Comparator<? super T> comparator)
|
Unary<T> |
reduceNary(BinaryOperator<T> accumulator)
|
default Spliterator<T> |
spliterator()
Solves conflict between
Iterable and Stream because Iterable defines a default
implementation.We use Iterable.spliterator() definition |
Unary<T> |
unique()
Treats this instance as having a single element.
|
distinct, filter, flatMap, limit, map, peek, skip, sorted, sortedallMatch, anyMatch, builder, collect, collect, concat, count, empty, findAny, findFirst, flatMapToDouble, flatMapToInt, flatMapToLong, forEachOrdered, generate, iterate, mapToDouble, mapToInt, mapToLong, max, min, noneMatch, of, of, reduce, reduce, reduce, toArray, toArrayclose, isParallel, iterator, onClose, parallel, sequential, unordereddefault Spliterator<T> spliterator()
Iterable and Stream because Iterable defines a default
implementation.Iterable.spliterator() definitionspliterator in interface BaseStream<T,Stream<T>>spliterator in interface Iterable<T>default void forEach(Consumer<? super T> action)
Iterable and Stream because Iterable defines a default
implementation.Iterable.forEach(Consumer) definitionList<T> collectToList()
Set<T> collectToSet()
Nary<T> concat(Stream<? extends T> other)
other - The stream to combine after thisNary<T> concat(Optional<? extends T> other)
Optionalother - The optional to join elements withNary<T> add(T... others)
others - The elements to append to this stream<R> R collect(Supplier<R> supplier, BiConsumer<R,? super T> accumulator)
ArrayList, 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();
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 resultUnary<T> findLast()
Unary<T> reduceNary(BinaryOperator<T> accumulator)
accumulator - The associative function to reduce the elements of this nary to a result of the same typefor a complete referenceUnary<T> minNary(Comparator<? super T> comparator)
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 elementsNullPointerException - if the minimum element is nullUnary<T> maxNary(Comparator<? super T> comparator)
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 elementsNullPointerException - if the maximum element is nullUnary<T> findFirstNary()
Nary describing the first element of this stream,
or an empty Nary if the stream is emptyNullPointerException - if the element selected is nullUnary<T> findAnyNary()
Nary describing some element of this stream, or an
empty Nary if the stream is emptyNullPointerException - if the element selected is nullStream.findFirst()<U> Nary<U> mapFilteringNullResult(Function<? super T,? extends U> mapper)
null, 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 resultsU - The type of the result of the mapping functionmapper - a mapping function to apply to the value, if present<U> Nary<U> flatMapOptional(Function<? super T,Optional<U>> mapper)
Stream.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.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 elementsUnary<T> unique() throws MoreThanOneElementException
Unary
because expectations between runtime and compile time won't matchMoreThanOneElementException - If this instance has more than one elementCopyright © 2020. All rights reserved.