Module com.machinezoo.noexception
Interface OptionalUnaryOperator<T>
-
- Type Parameters:
-
T
- seeUnaryOperator
- 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 OptionalUnaryOperator<T> extends Function<T,Optional<T>>
Variation ofUnaryOperator
that returnsOptional
instead of the raw value.OptionalUnaryOperator
is typically obtained fromExceptionHandler.fromUnaryOperator(UnaryOperator)
, in which case its return value is empty when the underlyingUnaryOperator
throws an exception. See noexception tutorial.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Optional<T>
apply(T operand)
Variation ofFunction.apply(Object)
that returnsOptional
.default UnaryOperator<T>
orElse(T result)
Converts thisOptionalUnaryOperator
to plainUnaryOperator
using default value.default UnaryOperator<T>
orElseGet(Supplier<T> source)
-
-
-
Method Detail
-
apply
Optional<T> apply(T operand)
Variation ofFunction.apply(Object)
that returnsOptional
. If thisOptionalUnaryOperator
is obtained fromExceptionHandler.fromUnaryOperator(UnaryOperator)
, theOptional
will be empty only if the underlyingUnaryOperator
throws. Otherwise the returnedOptional
just wraps the return value of underlyingUnaryOperator
(possiblynull
).- Specified by:
-
apply
in interfaceFunction<T,Optional<T>>
- Parameters:
-
operand
- seeFunction.apply(Object)
- Returns:
-
Optional
typically wrapping return value ofFunction.apply(Object)
, or an emptyOptional
(typically signifying an exception) - See Also:
-
ExceptionHandler.fromUnaryOperator(UnaryOperator)
,Function.apply(Object)
-
orElse
default UnaryOperator<T> orElse(T result)
Converts thisOptionalUnaryOperator
to plainUnaryOperator
using default value. The returnedUnaryOperator
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
UnaryOperator
that either unwrapsOptional
or returns default value - See Also:
-
orElseGet(Supplier)
,Optional.orElse(Object)
-
orElseGet
default UnaryOperator<T> orElseGet(Supplier<T> source)
Converts thisOptionalUnaryOperator
to plainUnaryOperator
using fallbackSupplier
. The returnedUnaryOperator
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
UnaryOperator
that either unwrapsOptional
or falls back tosource
- See Also:
-
orElse(Object)
,Optional.orElseGet(Supplier)
-
-