Module com.machinezoo.noexception
Interface OptionalToIntFunction<T>
-
- Type Parameters:
-
T
- seeToIntFunction
- All Superinterfaces:
-
Function<T,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 OptionalToIntFunction<T> extends Function<T,OptionalInt>
Variation ofToIntFunction
that returnsOptionalInt
instead of the raw value.OptionalToIntFunction
is typically obtained fromExceptionHandler.fromToIntFunction(ToIntFunction)
, in which case its return value is empty when the underlyingToIntFunction
throws an exception. See noexception tutorial.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description OptionalInt
apply(T value)
Variation ofToIntFunction.applyAsInt(Object)
that returnsOptionalInt
.default ToIntFunction<T>
orElse(int result)
Converts thisOptionalToIntFunction
to plainToIntFunction
using default value.default ToIntFunction<T>
orElseGet(IntSupplier source)
-
-
-
Method Detail
-
apply
OptionalInt apply(T value)
Variation ofToIntFunction.applyAsInt(Object)
that returnsOptionalInt
. If thisOptionalToIntFunction
is obtained fromExceptionHandler.fromToIntFunction(ToIntFunction)
, theOptionalInt
will be empty only if the underlyingToIntFunction
throws. Otherwise the returnedOptionalInt
just wraps the return value of underlyingToIntFunction
.- Specified by:
-
apply
in interfaceFunction<T,OptionalInt>
- Parameters:
-
value
- seeToIntFunction.applyAsInt(Object)
- Returns:
-
OptionalInt
typically wrapping return value ofToIntFunction.applyAsInt(Object)
, or an emptyOptionalInt
(typically signifying an exception) - See Also:
-
ExceptionHandler.fromToIntFunction(ToIntFunction)
,ToIntFunction.applyAsInt(Object)
-
orElse
default ToIntFunction<T> orElse(int result)
Converts thisOptionalToIntFunction
to plainToIntFunction
using default value. The returnedToIntFunction
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
ToIntFunction
that either unwrapsOptionalInt
or returns default value - See Also:
-
orElseGet(IntSupplier)
,OptionalInt.orElse(int)
-
orElseGet
default ToIntFunction<T> orElseGet(IntSupplier source)
Converts thisOptionalToIntFunction
to plainToIntFunction
using fallbackIntSupplier
. The returnedToIntFunction
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
ToIntFunction
that either unwrapsOptionalInt
or falls back tosource
- See Also:
-
orElse(int)
,OptionalInt.orElseGet(IntSupplier)
-
-