Package io.helidon.common
Class OptionalHelper<T>
- java.lang.Object
- 
- io.helidon.common.OptionalHelper<T>
 
- 
- Type Parameters:
- T- the type of the underlying optional value
 
 public class OptionalHelper<T> extends Object A wrapper on top ofOptionalto replicate some of the new Java9 methods.
- 
- 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<T>asOptional()Get the underlyingOptionalinstance.static <T> OptionalHelper<T>from(Optional<T> optional)Static factory method to create a newOptionalHelperinstance.voidifPresentOrElse(Consumer<T> action, Runnable emptyAction)If a value is present, performs the given action with the value, otherwise performs the given empty-based action.OptionalHelper<T>or(Supplier<? extends Optional<T>> supplier)If the underlyingOptionaldoes not have a value, set it to theOptionalproduced by the supplying function.Stream<T>stream()If a value is present, returns a sequentialStreamcontaining only that value, otherwise returns an emptyStream.
 
- 
- 
- 
Method Detail- 
frompublic static <T> OptionalHelper<T> from(Optional<T> optional) Static factory method to create a newOptionalHelperinstance.- Type Parameters:
- T- the type of the underly optional value
- Parameters:
- optional- the optional to wrap
- Returns:
- the created OptionalHelperinstance
 
 - 
asOptionalpublic Optional<T> asOptional() Get the underlyingOptionalinstance.- Returns:
- the wrapped Optional
 
 - 
orpublic OptionalHelper<T> or(Supplier<? extends Optional<T>> supplier) If the underlyingOptionaldoes not have a value, set it to theOptionalproduced by the supplying function.- Parameters:
- supplier- the supplying function that produces an- Optional
- Returns:
- returns this instance of OptionalHelperwith the same the underlyingOptionalif a value is present, otherwise with theOptionalproduced by the supplying function.
- Throws:
- NullPointerException- if the supplying function is- nullor produces a- nullresult
 
 - 
ifPresentOrElsepublic void ifPresentOrElse(Consumer<T> action, Runnable emptyAction) If a value is present, performs the given action with the value, otherwise performs the given empty-based action.- Parameters:
- action- the action to be performed, if a value is present
- emptyAction- the empty-based action to be performed, if no value is present
- Throws:
- NullPointerException- if a value is present and the given action is- null, or no value is present and the given empty-based action is- null.
 
 
- 
 
-