Module com.machinezoo.noexception
Interface OptionalIntSupplier
-
- All Superinterfaces:
-
Supplier<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 OptionalIntSupplier extends Supplier<OptionalInt>
Variation ofIntSupplier
that returnsOptionalInt
instead of the raw value.OptionalIntSupplier
is typically obtained fromExceptionHandler.fromIntSupplier(IntSupplier)
, in which case its return value is empty when the underlyingIntSupplier
throws an exception. See noexception tutorial.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description OptionalInt
get()
Variation ofIntSupplier.getAsInt()
that returnsOptionalInt
.default IntSupplier
orElse(int result)
Converts thisOptionalIntSupplier
to plainIntSupplier
using default value.default IntSupplier
orElseGet(IntSupplier source)
-
-
-
Method Detail
-
get
OptionalInt get()
Variation ofIntSupplier.getAsInt()
that returnsOptionalInt
. If thisOptionalIntSupplier
is obtained fromExceptionHandler.fromIntSupplier(IntSupplier)
, theOptionalInt
will be empty only if the underlyingIntSupplier
throws. Otherwise the returnedOptionalInt
just wraps the return value of underlyingIntSupplier
.- Specified by:
-
get
in interfaceSupplier<OptionalInt>
- Returns:
-
OptionalInt
typically wrapping return value ofIntSupplier.getAsInt()
, or an emptyOptionalInt
(typically signifying an exception) - See Also:
-
ExceptionHandler.fromIntSupplier(IntSupplier)
,IntSupplier.getAsInt()
-
orElse
default IntSupplier orElse(int result)
Converts thisOptionalIntSupplier
to plainIntSupplier
using default value. The returnedIntSupplier
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
IntSupplier
that either unwrapsOptionalInt
or returns default value - See Also:
-
orElseGet(IntSupplier)
,OptionalInt.orElse(int)
-
orElseGet
default IntSupplier orElseGet(IntSupplier source)
Converts thisOptionalIntSupplier
to plainIntSupplier
using fallbackIntSupplier
. The returnedIntSupplier
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
IntSupplier
that either unwrapsOptionalInt
or falls back tosource
- See Also:
-
orElse(int)
,OptionalInt.orElseGet(IntSupplier)
-
-