| Modifier and Type | Method and Description |
|---|---|
static <T,A,R> Collector<CompletableFuture<T>,?,CompletableFuture<R>> |
completableFutures(Collector<T,A,R> collector)
|
static <T,A,R> Collector<CompletionStage<T>,?,CompletableFuture<R>> |
completionStages(Collector<T,A,R> collector)
|
static <T> Collector<T,?,Optional<T>> |
findSingle()
Returns a
Collector that finds the single element of a stream, or Optional.empty() if the stream is empty. |
static <T> Collector<T,?,Optional<T>> |
findSingle(Supplier<? extends RuntimeException> exceptionSupplier)
Returns a
Collector that finds the single element of a stream, or Optional.empty() if the stream is empty. |
static <T> Collector<T,?,Optional<T>> |
findUnique()
Returns a
Collector that finds a unique element of a stream, or Optional.empty() if the stream is empty. |
static <T> Collector<T,?,Optional<T>> |
findUnique(Supplier<? extends RuntimeException> exceptionSupplier)
Returns a
Collector that finds the unique element of a stream, or Optional.empty() if the stream is empty. |
static <T,A1,R1,A2,R2> |
partitioning(int partitionSize,
Collector<? super T,A1,R1> downstream,
Collector<? super R1,A2,R2> partitioner)
Returns a
Collector that partitions the input elements into portions of a maximum size. |
static <T,A,R> Collector<T,A,R> |
sequentialOnly(Supplier<A> supplier,
BiConsumer<A,T> accumulator,
Function<A,R> finisher,
Collector.Characteristics... characteristics)
Returns a new
Collector that only supports sequential streams. |
static <T,R> Collector<T,R,R> |
sequentialOnly(Supplier<R> supplier,
BiConsumer<R,T> accumulator,
Collector.Characteristics... characteristics)
Returns a new
Collector that only supports sequential streams. |
static <T,K,V,M extends Map<K,V>> |
toMapWithSupplier(Function<? super T,? extends K> keyMapper,
Function<? super T,? extends V> valueMapper,
Supplier<M> mapFactory)
|
public static <T,R> Collector<T,R,R> sequentialOnly(Supplier<R> supplier, BiConsumer<R,T> accumulator, Collector.Characteristics... characteristics)
Collector that only supports sequential streams.
If used in a parallel stream, the combine operation will throw an exception.T - The type of input elements for the new Collector.R - The final result type of the new Collector.supplier - The supplier function for the new Collector.accumulator - The accumulator function for the new Collector.characteristics - The Collector characteristics for the new Collector.Collector.NullPointerException - If any argument is null.Collector.of(Supplier, BiConsumer, BinaryOperator, Characteristics...)public static <T,A,R> Collector<T,A,R> sequentialOnly(Supplier<A> supplier, BiConsumer<A,T> accumulator, Function<A,R> finisher, Collector.Characteristics... characteristics)
Collector that only supports sequential streams.
If used in a parallel stream, the combine operation will throw an exception.T - The type of input elements for the new Collector.A - The intermediate accumulation type of the new Collector.R - The final result type of the new Collector.supplier - The supplier function for the new Collector.accumulator - The accumulator function for the new Collector.finisher - The finisher function for the new Collectorcharacteristics - The Collector characteristics for the new Collector.Collector.NullPointerException - If any argument is null.Collector.of(Supplier, BiConsumer, BinaryOperator, Function, Characteristics...)public static <T> Collector<T,?,Optional<T>> findSingle()
Collector that finds the single element of a stream, or Optional.empty() if the stream is empty.
If the stream contains more than one element, the returned Collector will throw an IllegalStateException.
If the stream contains null values, the returned Collector will throw a NullPointerException.
T - The type of input element.Collector that results the single element of a streampublic static <T> Collector<T,?,Optional<T>> findSingle(Supplier<? extends RuntimeException> exceptionSupplier)
Collector that finds the single element of a stream, or Optional.empty() if the stream is empty.
If the stream contains more than one element, the returned Collector will throw an exception provided by the given Supplier.
If the stream contains null values, the returned Collector will throw a NullPointerException.
public static <T> Collector<T,?,Optional<T>> findUnique()
Collector that finds a unique element of a stream, or Optional.empty() if the stream is empty.
Uniqueness is determined using Object.equals(Object).
If the stream contains more than one different element, the returned Collector will throw an IllegalStateException.
If the stream contains null values, the returned Collector will throw a NullPointerException.
T - The type of input element.Collector that results the unique element of a streampublic static <T> Collector<T,?,Optional<T>> findUnique(Supplier<? extends RuntimeException> exceptionSupplier)
Collector that finds the unique element of a stream, or Optional.empty() if the stream is empty.
Uniqueness is determined using Object.equals(Object).
If the stream contains more than one different element, the returned Collector will throw an exception provided by the given
Supplier. If the stream contains null values, the returned Collector will throw a NullPointerException.
public static <T,K,V,M extends Map<K,V>> Collector<T,?,M> toMapWithSupplier(Function<? super T,? extends K> keyMapper, Function<? super T,? extends V> valueMapper, Supplier<M> mapFactory)
Collector that accumulates elements into a Map.
This method is like Collectors.toMap(Function, Function) but with a custom map factory.
It's a convenient alternative to using Collectors.toMap(Function, Function, BinaryOperator, Supplier) without having to write the
merge function. Like Collectors.toMap(Function, Function), the value mapping function cannot return null values.T - The type of input element.K - The output type of the key mapping function.V - The output type of the value mapping function.M - The type of resulting Map.keyMapper - A mapping function to produce map keys.valueMapper - A mapping function to produce map values.mapFactory - A supplier providing a new empty Map into which the results will be inserted.Collector that accumulates elements into a Map.public static <T,A,R> Collector<CompletionStage<T>,?,CompletableFuture<R>> completionStages(Collector<T,A,R> collector)
Collector that accumulates CompletionStage instances into a new CompletableFuture.
If the CompletionStage results need to be mapped or filtered before collecting, use FutureValue instead.T - The result type of the CompletionStage instances.A - The intermediate accumulation type of the Collector.R - The result type of the collected CompletableFuture.collector - The collector for the CompletionStage results.Collector that collects CompletionStage instances.NullPointerException - If the given Collector is null.public static <T,A,R> Collector<CompletableFuture<T>,?,CompletableFuture<R>> completableFutures(Collector<T,A,R> collector)
Collector that accumulates CompletableFuture instances into a new CompletableFuture.
If the CompletableFuture results need to be mapped or filtered before collecting, use FutureValue instead.T - The result type of the CompletableFuture instances.A - The intermediate accumulation type of the Collector.R - The result type of the collected CompletableFuture.collector - The collector for the CompletableFuture results.Collector that collects CompletableFuture instances.NullPointerException - If the given Collector is null.public static <T,A1,R1,A2,R2> Collector<T,?,R2> partitioning(int partitionSize, Collector<? super T,A1,R1> downstream, Collector<? super R1,A2,R2> partitioner)
Collector that partitions the input elements into portions of a maximum size. Each partition is fed into a downstream
Collector, and the results of this downstream Collector are fed into a partitioning Collector.
Note: the returned Collector does not support concurrent streams.
T - The type of input elements for the Collector.A1 - The intermediate accumulation type of the downstream Collector.R1 - The result type of the downstream Collector.A2 - The intermediate accumulation type of the partitioning Collector.R2 - The result type of the partitioning Collector.partitionSize - The maximum size of each partition.downstream - The downstream Collector to use.
It should not contain any state of its own other than the supplier, accumulator, combiner, finisher and characteristics.
Its supplier may be called several times, and each call should yield an "empty" object, and not contain any state from
any previous time it is called.partitioner - The partitioning Collector to use.Collector that partitions the input elements as described.IllegalArgumentException - If the partition size is not at least 1.NullPointerException - If either Collector is null.Copyright © 2021–2022. All rights reserved.