public interface Optionals
Optional
s.Modifier and Type | Method and Description |
---|---|
static <S,T> Optional<T> |
firstNonEmpty(Iterable<S> source,
Function<S,Optional<T>> function)
Applies the given function to the elements of the source and returns the first non-empty result.
|
static <S,T> T |
firstNonEmpty(Iterable<S> source,
Function<S,T> function,
T defaultValue)
Applies the given function to the elements of the source and returns the first non-empty result.
|
static <T> Optional<T> |
firstNonEmpty(Iterable<Supplier<Optional<T>>> suppliers)
|
static <T> Optional<T> |
firstNonEmpty(Supplier<Optional<T>>... suppliers)
|
static <T,S> void |
ifAllPresent(Optional<T> left,
Optional<S> right,
BiConsumer<T,S> consumer)
Invokes the given
BiConsumer if all given Optional are present. |
static <T> void |
ifPresentOrElse(Optional<T> optional,
Consumer<? super T> consumer,
Runnable runnable)
|
static boolean |
isAnyPresent(Optional<?>... optionals)
Returns whether any of the given
Optional s is present. |
static <T,S,R> Optional<R> |
mapIfAllPresent(Optional<T> left,
Optional<S> right,
BiFunction<T,S,R> function)
Maps the values contained in the given
Optional if both of them are present. |
static <T> Optional<T> |
next(Iterator<T> iterator)
Returns the next element of the given
Iterator or Optional.empty() in case there is no next
element. |
static <T> Stream<T> |
toStream(Optional<? extends T>... optionals)
|
static <T,S> Optional<Pair<T,S>> |
withBoth(Optional<T> left,
Optional<S> right)
Returns a
Pair if both Optional instances have values or Optional.empty() if one or both
are missing. |
static boolean isAnyPresent(Optional<?>... optionals)
Optional
s is present.optionals
- must not be null.@SafeVarargs static <T> Stream<T> toStream(Optional<? extends T>... optionals)
optionals
- must not be null.static <S,T> Optional<T> firstNonEmpty(Iterable<S> source, Function<S,Optional<T>> function)
source
- must not be null.function
- must not be null.static <S,T> T firstNonEmpty(Iterable<S> source, Function<S,T> function, T defaultValue)
source
- must not be null.function
- must not be null.@SafeVarargs static <T> Optional<T> firstNonEmpty(Supplier<Optional<T>>... suppliers)
suppliers
- must not be null.static <T> Optional<T> firstNonEmpty(Iterable<Supplier<Optional<T>>> suppliers)
suppliers
- must not be null.static <T> Optional<T> next(Iterator<T> iterator)
Iterator
or Optional.empty()
in case there is no next
element.iterator
- must not be null.static <T,S> Optional<Pair<T,S>> withBoth(Optional<T> left, Optional<S> right)
Pair
if both Optional
instances have values or Optional.empty()
if one or both
are missing.left
- right
- static <T,S> void ifAllPresent(Optional<T> left, Optional<S> right, BiConsumer<T,S> consumer)
BiConsumer
if all given Optional
are present.left
- must not be null.right
- must not be null.consumer
- must not be null.static <T,S,R> Optional<R> mapIfAllPresent(Optional<T> left, Optional<S> right, BiFunction<T,S,R> function)
Optional
if both of them are present.left
- must not be null.right
- must not be null.function
- must not be null.Copyright © 2011–2020 Pivotal Software, Inc.. All rights reserved.