| Modifier and Type | Method and Description |
|---|---|
static <T> Collector<T,OneTimeAssignment<T>,Optional<T>> |
allowAtMostOne()
This is a collector for accessing the expected singular only element of a
Stream, as
it will throw an exception if more than one element is processed. |
static <T> Collector<T,OneTimeAssignment<T>,Optional<T>> |
allowAtMostOneOrElseThrow(BiFunction<? super T,? super T,? extends RuntimeException> exceptionOnExcessiveElements)
This is a collector for accessing the expected singular only element of a
Stream, as
it will throw the exception yielded from the given function if more than one element is processed. |
static <X extends Throwable> |
asSuppressedExceptionsOf(X exception)
Add exceptions as
suppressed exception to a given
exception. |
static <T1,T2> Collector<ViewableAsTuple<T1,Optional<T2>>,?,Map<T1,List<T2>>> |
toMultimap()
A multimap maps from keys to lists, and this collector will arrange
tuples
by putting each distinct first tuple-element as keys of the resulting map, mapping
them to a List, and adding each second tuple-element to the list. |
static <T,K,V> Collector<T,?,Map<K,List<V>>> |
toMultimap(Function<? super T,K> keyExtractor,
Function<? super T,Optional<V>> extractor) |
static <T,V> Collector<T,?,Map<T,List<V>>> |
toMultimap(Function<? super T,Optional<V>> extractor) |
static <T1,T2> Collector<ViewableAsTuple<T1,Optional<T2>>,?,Optional<Tuple<T1,List<T2>>>> |
toMultituple()
A multituple is similar to a multimap in that it consists of one
first value and a List of
values as the second value,
and this collector will collect tuples where it is expected that all the first tuple-elements
are equal, and re-arrange them by putting the distinct first element into a new Tuple, and collate each of the second
elements into a new List which is set as the second element of the new Tuple. |
static <T1,T2> Collector<ViewableAsTuple<T1,Optional<T2>>,?,Optional<Tuple<T1,List<T2>>>> |
toMultitupleOrThrowIfNonDistinct(BiFunction<? super Tuple<T1,List<T2>>,? super Tuple<T1,Optional<T2>>,? extends RuntimeException> exceptionOnNonDistinctFirstElement)
A multituple is similar to a multimap in that it consists of one
first value and a List of
values as the second value,
and this collector will collect tuples where it is expected that all the first tuple-elements
are equal, and re-arrange them by putting the distinct first element into a new Tuple, and collate each of the second
elements into a new List which is set as the second element of the new Tuple. |
static <X extends Throwable> |
toSingleExceptionWithSuppressed()
Collapse exceptions by taking the first (if any) and add every exception after the first
as
suppressed to the first one. |
public static <T1,T2> Collector<ViewableAsTuple<T1,Optional<T2>>,?,Optional<Tuple<T1,List<T2>>>> toMultituple()
first value and a List of
values as the second value,
and this collector will collect tuples where it is expected that all the first tuple-elements
are equal, and re-arrange them by putting the distinct first element into a new Tuple, and collate each of the second
elements into a new List which is set as the second element of the new Tuple. If non-distinct values of the first elements of the
tuples are collected, a ConflictingElementEncountered is thrown.T1 - The type of the first tuple element, which will also become the type of the first element of the resulting Tuple.T2 - The type of the second tuple element, which will become the List<T2> type of the second element of the
resulting Tuple.public static <T1,T2> Collector<ViewableAsTuple<T1,Optional<T2>>,?,Optional<Tuple<T1,List<T2>>>> toMultitupleOrThrowIfNonDistinct(BiFunction<? super Tuple<T1,List<T2>>,? super Tuple<T1,Optional<T2>>,? extends RuntimeException> exceptionOnNonDistinctFirstElement)
first value and a List of
values as the second value,
and this collector will collect tuples where it is expected that all the first tuple-elements
are equal, and re-arrange them by putting the distinct first element into a new Tuple, and collate each of the second
elements into a new List which is set as the second element of the new Tuple. If non-distinct values of the first elements of the
tuples are collected, the exception returned from the given exceptionOnNonDistinctFirstElement function is thrown.T1 - The type of the first tuple element, which will also become the type of the first element of the resulting Tuple.T2 - The type of the second tuple element, which will become the List<T2> type of the second element of the
resulting Tuple.exceptionOnNonDistinctFirstElement - the function will be given the already collected multituple as its first argument and the
unexpected conflicting tuple with non-distinct first value as the second,
which may be used to construct an exception to be thrown.public static <T1,T2> Collector<ViewableAsTuple<T1,Optional<T2>>,?,Map<T1,List<T2>>> toMultimap()
tuples
by putting each distinct first tuple-element as keys of the resulting map, mapping
them to a List, and adding each second tuple-element to the list.T1 - The type of the first tuple element, which will become the key type of the resulting Map.T2 - The type of the second tuple element, which will become the List<T2> value type of the
resulting Map.public static <T,V> Collector<T,?,Map<T,List<V>>> toMultimap(Function<? super T,Optional<V>> extractor)
public static <T,K,V> Collector<T,?,Map<K,List<V>>> toMultimap(Function<? super T,K> keyExtractor, Function<? super T,Optional<V>> extractor)
public static <T> Collector<T,OneTimeAssignment<T>,Optional<T>> allowAtMostOne()
Stream, as
it will throw an exception if more than one element is processed. This should be used in
preference of the Stream.findFirst() or Stream.findAny() when it is imperative
that the stream indeed yields a maximum of one single element, and any more elements is
considered a programming error.public static <T> Collector<T,OneTimeAssignment<T>,Optional<T>> allowAtMostOneOrElseThrow(BiFunction<? super T,? super T,? extends RuntimeException> exceptionOnExcessiveElements)
Stream, as
it will throw the exception yielded from the given function if more than one element is processed.exceptionOnExcessiveElements - the function will be given the first element yielded from the stream
as its first argument and the unexpected excess one as the second,
which may be used to construct an exception to be thrown.allowAtMostOne()public static <X extends Throwable> Collector<Throwable,?,X> asSuppressedExceptionsOf(X exception)
suppressed exception to a given
exception.exception - The exception to add the suppressed exceptions to.public static <X extends Throwable> Collector<X,?,Optional<X>> toSingleExceptionWithSuppressed()
suppressed to the first one.Copyright © 2019 Digipost. All rights reserved.