Module com.machinezoo.noexception
Interface OptionalSupplier<T>
-
- Type Parameters:
-
T- seeSupplier
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface OptionalSupplier<T> extends Supplier<Optional<T>>
Variation ofSupplierthat returnsOptionalinstead of the raw value.OptionalSupplieris typically obtained fromExceptionHandler.supplier(Supplier), in which case its return value is empty when the underlyingSupplierthrows an exception. See noexception tutorial.- See Also:
-
ExceptionHandler.supplier(Supplier),Supplier
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Optional<T>get()Variation ofSupplier.get()that returnsOptional.default Supplier<T>orElse(T result)Converts thisOptionalSupplierto plainSupplierusing default value.default Supplier<T>orElseGet(Supplier<T> source)
-
-
-
Method Detail
-
get
Optional<T> get()
Variation ofSupplier.get()that returnsOptional. If thisOptionalSupplieris obtained fromExceptionHandler.supplier(Supplier), theOptionalwill be empty only if the underlyingSupplierthrows. Otherwise the returnedOptionaljust wraps the return value of underlyingSupplier(possiblynull).- Specified by:
-
getin interfaceSupplier<T> - Returns:
-
Optionaltypically wrapping return value ofSupplier.get(), or an emptyOptional(typically signifying an exception) - See Also:
-
ExceptionHandler.supplier(Supplier),Supplier.get()
-
orElse
default Supplier<T> orElse(T result)
Converts thisOptionalSupplierto plainSupplierusing default value. The returnedSupplierwill unwrap present value from theOptionalif possible, or returnresultif theOptionalis empty.- Parameters:
-
result- default value to return instead of an emptyOptional - Returns:
-
plain
Supplierthat either unwrapsOptionalor returns default value - See Also:
-
orElseGet(Supplier),Optional.orElse(Object)
-
orElseGet
default Supplier<T> orElseGet(Supplier<T> source)
Converts thisOptionalSupplierto plainSupplierusing fallbackSupplier. The returnedSupplierwill unwrap present value from theOptionalif possible, or fall back to callingsourceif theOptionalis empty.- Parameters:
-
source-Supplierto query for fallback value whenOptionalis empty - Returns:
-
plain
Supplierthat either unwrapsOptionalor falls back tosource - See Also:
-
orElse(Object),Optional.orElseGet(Supplier)
-
-