| Constructor and Description |
|---|
DiggOptionals() |
| Modifier and Type | Method and Description |
|---|---|
static <T,A,R> R |
collect(Optional<T> optional,
Collector<T,A,R> collector)
|
static <T> List<T> |
toList(Optional<T> optional)
Unwrap an
Optional into a zero or one element unmodifiable list. |
static <T> Stream<T> |
toStream(Optional<? extends T>... optionals)
|
static <T> Stream<T> |
toStream(Supplier<Optional<T>>... optionalResolvers)
|
@SafeVarargs public static <T> Stream<T> toStream(Supplier<Optional<T>>... optionalResolvers)
suppliers of Optional to a Stream consisting of only the
present optionals. The returned stream is BaseStream.sequential(), yielding
the present values in the order they are given. Depending on how the stream is consumed, only the necessary
optional values will be attempted resolved. E.g. calling .findFirst() will only resolve
as many Optionals needed until the first present one is encountered.
Optionals in a deterministic
order, or for instance to find the first present value of a prioritized set of possible ways to resolve it. One should
be very (as always with streams) careful with parallelizing the stream, as you generally
have no control with how the resolvers will be run. For instance, .parallel().findAny() will indeed return
the the first resolved value, but still block until the workers already started by the stream has terminated.T - The type of the given Optionals and returned Stream.optionalResolvers - The operations resolving Optionals to convert to a Stream.Stream containing the present Optionals@SafeVarargs public static <T> Stream<T> toStream(Optional<? extends T>... optionals)
T - The type of the given Optionals and returned Stream.optionals - The Optionals to convert to a Stream.Stream containing the present Optionalspublic static <T> List<T> toList(Optional<T> optional)
Optional into a zero or one element unmodifiable list.T - The type of the optional value.optional - The optional value to be wrapped in a list.Optional being present or not.public static <T,A,R> R collect(Optional<T> optional, Collector<T,A,R> collector)
T - The type of the optional value.R - The resulting container type.optional - The optional value to be wrapped in another container.collector - The collector to use for wrapping into another container.Optional being present or not.Copyright © 2019 Digipost. All rights reserved.