-
public static interface Optional.OrElseThe OrElse interface is an extension to theOptionalinterface. This interface can be used to cascade behaviour when an entity is or is not present in the wrapper.For example if the
Optionalhas no entity contained within then the OrElse can be used to throw an exception or run alternative logic.Example:
API.Option(null) .ifPresent(System.out::println) .elseThrow(() -> new NullPointerException("No value present"))- Since:
- 0.0.1
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default voidelseRun(java.lang.Runnable runner)This operation will run when the precondition of this OrElse is not met.default <X extends java.lang.Throwable>
voidelseThrow(java.util.function.Supplier<X> exceptionSupplier)This operation will create an exception using the providedSupplierand throw it.
-
-
-
Method Detail
-
elseRun
default void elseRun(java.lang.Runnable runner)
This operation will run when the precondition of this OrElse is not met.- Parameters:
runner- the code to be run when the else is running
-
elseThrow
default <X extends java.lang.Throwable> void elseThrow(java.util.function.Supplier<X> exceptionSupplier) throws X extends java.lang.ThrowableThis operation will create an exception using the providedSupplierand throw it.- Type Parameters:
X- the type of exception- Parameters:
exceptionSupplier- the supplier to create the exception- Throws:
X- the exception in case of an OrElse runX extends java.lang.Throwable
-
-