Module com.machinezoo.noexception
Interface OptionalIntUnaryOperator
-
- All Superinterfaces:
-
IntFunction<OptionalInt>
- 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 OptionalIntUnaryOperator extends IntFunction<OptionalInt>
Variation ofIntUnaryOperator
that returnsOptionalInt
instead of the raw value.OptionalIntUnaryOperator
is typically obtained fromExceptionHandler.fromIntUnaryOperator(IntUnaryOperator)
, in which case its return value is empty when the underlyingIntUnaryOperator
throws an exception. See noexception tutorial.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description OptionalInt
apply(int operand)
Variation ofIntUnaryOperator.applyAsInt(int)
that returnsOptionalInt
.default IntUnaryOperator
orElse(int result)
Converts thisOptionalIntUnaryOperator
to plainIntUnaryOperator
using default value.default IntUnaryOperator
orElseGet(IntSupplier source)
-
-
-
Method Detail
-
apply
OptionalInt apply(int operand)
Variation ofIntUnaryOperator.applyAsInt(int)
that returnsOptionalInt
. If thisOptionalIntUnaryOperator
is obtained fromExceptionHandler.fromIntUnaryOperator(IntUnaryOperator)
, theOptionalInt
will be empty only if the underlyingIntUnaryOperator
throws. Otherwise the returnedOptionalInt
just wraps the return value of underlyingIntUnaryOperator
.- Specified by:
-
apply
in interfaceIntFunction<OptionalInt>
- Parameters:
-
operand
- seeIntUnaryOperator.applyAsInt(int)
- Returns:
-
OptionalInt
typically wrapping return value ofIntUnaryOperator.applyAsInt(int)
, or an emptyOptionalInt
(typically signifying an exception) - See Also:
-
ExceptionHandler.fromIntUnaryOperator(IntUnaryOperator)
,IntUnaryOperator.applyAsInt(int)
-
orElse
default IntUnaryOperator orElse(int result)
Converts thisOptionalIntUnaryOperator
to plainIntUnaryOperator
using default value. The returnedIntUnaryOperator
will unwrap present value from theOptionalInt
if possible, or returnresult
if theOptionalInt
is empty.- Parameters:
-
result
- default value to return instead of an emptyOptionalInt
- Returns:
-
plain
IntUnaryOperator
that either unwrapsOptionalInt
or returns default value - See Also:
-
orElseGet(IntSupplier)
,OptionalInt.orElse(int)
-
orElseGet
default IntUnaryOperator orElseGet(IntSupplier source)
Converts thisOptionalIntUnaryOperator
to plainIntUnaryOperator
using fallbackIntSupplier
. The returnedIntUnaryOperator
will unwrap present value from theOptionalInt
if possible, or fall back to callingsource
if theOptionalInt
is empty.- Parameters:
-
source
-IntSupplier
to query for fallback value whenOptionalInt
is empty - Returns:
-
plain
IntUnaryOperator
that either unwrapsOptionalInt
or falls back tosource
- See Also:
-
orElse(int)
,OptionalInt.orElseGet(IntSupplier)
-
-