Package software.amazon.smithy.utils
Class OptionalUtils
java.lang.Object
software.amazon.smithy.utils.OptionalUtils
Functions that make working with optionals easier.
- 
Method Summary
Modifier and TypeMethodDescriptionstatic <T> voidifPresentOrElse(Optional<T> value, Consumer<T> action, Runnable emptyAction) Invokes a consumer if the Optional has a value, otherwise invoked a Runnable when the Optional is empty.static <T> Optional<T>Retrieves the value of the optional if present or invokes the supplier for a value.static <T> Stream<T>Converts an Optional into a Stream that can be used in a flatmap. 
- 
Method Details
- 
or
Retrieves the value of the optional if present or invokes the supplier for a value.- Type Parameters:
 T- Type of value.- Parameters:
 value- Value to check.supplier- Supplier for a value if no value is present.- Returns:
 - A value of type T.
 
 - 
stream
Converts an Optional into a Stream that can be used in a flatmap.This is a polyfill of Java 9's
Optional#stream.- Type Parameters:
 T- Value type.- Parameters:
 value- Value to convert to a stream.- Returns:
 - A stream that contains a present value or a stream that is empty.
 
 - 
ifPresentOrElse
Invokes a consumer if the Optional has a value, otherwise invoked a Runnable when the Optional is empty.- Type Parameters:
 T- Type of value.- Parameters:
 value- Value to check.action- Action to invoke if a value is present.emptyAction- Runnable to invoke if a value is not present.
 
 -