public class OptionalCollectors extends Object
collectors of optional types.| Modifier and Type | Method and Description |
|---|---|
static <T> Collector<T,?,Optional<T>> |
toOptional()
Returns a
Collector that accumulates 0 or 1 input elements into an Optional<T>. |
static <T,O> Collector<T,?,O> |
toOptional(Supplier<O> empty,
Function<T,O> factory)
Returns a
Collector that accumulates 0 or 1 input elements into an arbitrary
optional-style container type. |
static Collector<Double,?,OptionalDouble> |
toOptionalDouble()
Returns a
Collector that accumulates 0 or 1 input Double elements into an
OptionalDouble. |
static Collector<Integer,?,OptionalInt> |
toOptionalInt()
Returns a
Collector that accumulates 0 or 1 input Integer elements into an
OptionalInt. |
static Collector<Long,?,OptionalLong> |
toOptionalLong()
Returns a
Collector that accumulates 0 or 1 input Long elements into an
OptionalLong. |
public static <T> Collector<T,?,Optional<T>> toOptional()
Collector that accumulates 0 or 1 input elements into an Optional<T>.
The returned collector will throw IllegalStateException whenever 2 or more elements
are present in a stream. Null elements are mapped to Optional.empty().T - the collected typeCollector which collects 0 or 1 input elements into an Optional<T>.public static <T,O> Collector<T,?,O> toOptional(Supplier<O> empty, Function<T,O> factory)
Collector that accumulates 0 or 1 input elements into an arbitrary
optional-style container type. The returned collector will throw
IllegalStateException whenever 2 or more elements are present in a stream. Null elements
are mapped to an empty container.T - The optional element type.O - The optional type, which may incorporate the T generic parameter e.g.
Optional<T>.empty - Supplies an instance of the optional type with no value.factory - Returns an instance of the optional type with the input parameter as the value.Collector which collects 0 or 1 input elements into an arbitrary
optional-style container type.public static Collector<Double,?,OptionalDouble> toOptionalDouble()
Collector that accumulates 0 or 1 input Double elements into an
OptionalDouble. The returned collector will throw IllegalStateException
whenever 2 or more elements are present in a stream. Null elements are mapped to
OptionalDouble.empty().Collector which collects 0 or 1 input @{code Double} elements into an
OptionalDouble.public static Collector<Integer,?,OptionalInt> toOptionalInt()
Collector that accumulates 0 or 1 input Integer elements into an
OptionalInt. The returned collector will throw IllegalStateException whenever
2 or more elements are present in a stream. Null elements are mapped to
OptionalInt.empty().Collector which collects 0 or 1 input Integer elements into an
OptionalInt.public static Collector<Long,?,OptionalLong> toOptionalLong()
Collector that accumulates 0 or 1 input Long elements into an
OptionalLong. The returned collector will throw IllegalStateException whenever
2 or more elements are present in a stream. Null elements are mapped to
OptionalLong.empty().Collector which collects 0 or 1 input @{code Long} elements into an
OptionalLong.Copyright © 2019. All rights reserved.