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 ofIntSupplierthat returnsOptionalIntinstead of the raw value.OptionalIntSupplieris typically obtained fromExceptionHandler.fromIntSupplier(IntSupplier), in which case its return value is empty when the underlyingIntSupplierthrows an exception. See noexception tutorial.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description OptionalIntget()Variation ofIntSupplier.getAsInt()that returnsOptionalInt.default IntSupplierorElse(int result)Converts thisOptionalIntSupplierto plainIntSupplierusing default value.default IntSupplierorElseGet(IntSupplier source)
-
-
-
Method Detail
-
get
OptionalInt get()
Variation ofIntSupplier.getAsInt()that returnsOptionalInt. If thisOptionalIntSupplieris obtained fromExceptionHandler.fromIntSupplier(IntSupplier), theOptionalIntwill be empty only if the underlyingIntSupplierthrows. Otherwise the returnedOptionalIntjust wraps the return value of underlyingIntSupplier.- Specified by:
-
getin interfaceSupplier<OptionalInt> - Returns:
-
OptionalInttypically 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 thisOptionalIntSupplierto plainIntSupplierusing default value. The returnedIntSupplierwill unwrap present value from theOptionalIntif possible, or returnresultif theOptionalIntis empty.- Parameters:
-
result- default value to return instead of an emptyOptionalInt - Returns:
-
plain
IntSupplierthat either unwrapsOptionalIntor returns default value - See Also:
-
orElseGet(IntSupplier),OptionalInt.orElse(int)
-
orElseGet
default IntSupplier orElseGet(IntSupplier source)
Converts thisOptionalIntSupplierto plainIntSupplierusing fallbackIntSupplier. The returnedIntSupplierwill unwrap present value from theOptionalIntif possible, or fall back to callingsourceif theOptionalIntis empty.- Parameters:
-
source-IntSupplierto query for fallback value whenOptionalIntis empty - Returns:
-
plain
IntSupplierthat either unwrapsOptionalIntor falls back tosource - See Also:
-
orElse(int),OptionalInt.orElseGet(IntSupplier)
-
-