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 ofSupplier
that returnsOptional
instead of the raw value.OptionalSupplier
is typically obtained fromExceptionHandler.supplier(Supplier)
, in which case its return value is empty when the underlyingSupplier
throws 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 thisOptionalSupplier
to plainSupplier
using default value.default Supplier<T>
orElseGet(Supplier<T> source)
-
-
-
Method Detail
-
get
Optional<T> get()
Variation ofSupplier.get()
that returnsOptional
. If thisOptionalSupplier
is obtained fromExceptionHandler.supplier(Supplier)
, theOptional
will be empty only if the underlyingSupplier
throws. Otherwise the returnedOptional
just wraps the return value of underlyingSupplier
(possiblynull
).- Specified by:
-
get
in interfaceSupplier<T>
- Returns:
-
Optional
typically 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 thisOptionalSupplier
to plainSupplier
using default value. The returnedSupplier
will unwrap present value from theOptional
if possible, or returnresult
if theOptional
is empty.- Parameters:
-
result
- default value to return instead of an emptyOptional
- Returns:
-
plain
Supplier
that either unwrapsOptional
or returns default value - See Also:
-
orElseGet(Supplier)
,Optional.orElse(Object)
-
orElseGet
default Supplier<T> orElseGet(Supplier<T> source)
Converts thisOptionalSupplier
to plainSupplier
using fallbackSupplier
. The returnedSupplier
will unwrap present value from theOptional
if possible, or fall back to callingsource
if theOptional
is empty.- Parameters:
-
source
-Supplier
to query for fallback value whenOptional
is empty - Returns:
-
plain
Supplier
that either unwrapsOptional
or falls back tosource
- See Also:
-
orElse(Object)
,Optional.orElseGet(Supplier)
-
-