Module com.machinezoo.noexception
Interface OptionalToDoubleFunction<T>
-
- Type Parameters:
-
T
- seeToDoubleFunction
- All Superinterfaces:
-
Function<T,OptionalDouble>
- 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 OptionalToDoubleFunction<T> extends Function<T,OptionalDouble>
Variation ofToDoubleFunction
that returnsOptionalDouble
instead of the raw value.OptionalToDoubleFunction
is typically obtained fromExceptionHandler.fromToDoubleFunction(ToDoubleFunction)
, in which case its return value is empty when the underlyingToDoubleFunction
throws an exception. See noexception tutorial.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description OptionalDouble
apply(T value)
Variation ofToDoubleFunction.applyAsDouble(Object)
that returnsOptionalDouble
.default ToDoubleFunction<T>
orElse(double result)
Converts thisOptionalToDoubleFunction
to plainToDoubleFunction
using default value.default ToDoubleFunction<T>
orElseGet(DoubleSupplier source)
-
-
-
Method Detail
-
apply
OptionalDouble apply(T value)
Variation ofToDoubleFunction.applyAsDouble(Object)
that returnsOptionalDouble
. If thisOptionalToDoubleFunction
is obtained fromExceptionHandler.fromToDoubleFunction(ToDoubleFunction)
, theOptionalDouble
will be empty only if the underlyingToDoubleFunction
throws. Otherwise the returnedOptionalDouble
just wraps the return value of underlyingToDoubleFunction
.- Specified by:
-
apply
in interfaceFunction<T,OptionalDouble>
- Parameters:
-
value
- seeToDoubleFunction.applyAsDouble(Object)
- Returns:
-
OptionalDouble
typically wrapping return value ofToDoubleFunction.applyAsDouble(Object)
, or an emptyOptionalDouble
(typically signifying an exception) - See Also:
-
ExceptionHandler.fromToDoubleFunction(ToDoubleFunction)
,ToDoubleFunction.applyAsDouble(Object)
-
orElse
default ToDoubleFunction<T> orElse(double result)
Converts thisOptionalToDoubleFunction
to plainToDoubleFunction
using default value. The returnedToDoubleFunction
will unwrap present value from theOptionalDouble
if possible, or returnresult
if theOptionalDouble
is empty.- Parameters:
-
result
- default value to return instead of an emptyOptionalDouble
- Returns:
-
plain
ToDoubleFunction
that either unwrapsOptionalDouble
or returns default value - See Also:
-
orElseGet(DoubleSupplier)
,OptionalDouble.orElse(double)
-
orElseGet
default ToDoubleFunction<T> orElseGet(DoubleSupplier source)
Converts thisOptionalToDoubleFunction
to plainToDoubleFunction
using fallbackDoubleSupplier
. The returnedToDoubleFunction
will unwrap present value from theOptionalDouble
if possible, or fall back to callingsource
if theOptionalDouble
is empty.- Parameters:
-
source
-DoubleSupplier
to query for fallback value whenOptionalDouble
is empty - Returns:
-
plain
ToDoubleFunction
that either unwrapsOptionalDouble
or falls back tosource
- See Also:
-
orElse(double)
,OptionalDouble.orElseGet(DoubleSupplier)
-
-