Class OptionalUtils
- java.lang.Object
-
- com.atlassian.confluence.impl.util.OptionalUtils
-
public final class OptionalUtils extends Object
Utility methods relating to Optionals.- Since:
- 6.7.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,U>
Optional<U>first(Optional<T> maybeT, Function<? super T,Optional<U>>... mappers)
Returns the first non-empty value obtained by separately applying the given mappers to the given Optional.static <T> Optional<T>
firstNonEmpty(Supplier<Optional<T>>... lazyOptionals)
Returns the first of the given Optionals that is non-empty.static <A,B>
Optional<io.atlassian.fugue.Pair<A,B>>zip(Optional<A> o1, Optional<B> o2)
Zips the two given optionals into an optional of a pair.
-
-
-
Method Detail
-
zip
public static <A,B> Optional<io.atlassian.fugue.Pair<A,B>> zip(Optional<A> o1, Optional<B> o2)
Zips the two given optionals into an optional of a pair. This method can be deleted once we're on Fugue 4.6.0 or later, when itsPair
type will contain this method.- Type Parameters:
A
- the first typeB
- the second type- Parameters:
o1
- the first optionalo2
- the second optional- Returns:
- empty if either or both optionals are empty
-
first
@SafeVarargs public static <T,U> Optional<U> first(Optional<T> maybeT, Function<? super T,Optional<U>>... mappers)
Returns the first non-empty value obtained by separately applying the given mappers to the given Optional.- Type Parameters:
T
- the input typeU
- the output type- Parameters:
maybeT
- the optional to which to apply the mappersmappers
- the mappers to apply one by one- Returns:
- empty if the given Optional is empty or all the given mappers return an empty
-
firstNonEmpty
@SafeVarargs public static <T> Optional<T> firstNonEmpty(Supplier<Optional<T>>... lazyOptionals)
Returns the first of the given Optionals that is non-empty.- Type Parameters:
T
- the type of value- Parameters:
lazyOptionals
- the optionals to inspect- Returns:
- empty if all of the given optionals are empty
-
-