Module com.machinezoo.noexception
Interface OptionalToLongFunction<T>
-
- Type Parameters:
-
T
- seeToLongFunction
- All Superinterfaces:
-
Function<T,OptionalLong>
- 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 OptionalToLongFunction<T> extends Function<T,OptionalLong>
Variation ofToLongFunction
that returnsOptionalLong
instead of the raw value.OptionalToLongFunction
is typically obtained fromExceptionHandler.fromToLongFunction(ToLongFunction)
, in which case its return value is empty when the underlyingToLongFunction
throws an exception. See noexception tutorial.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description OptionalLong
apply(T value)
Variation ofToLongFunction.applyAsLong(Object)
that returnsOptionalLong
.default ToLongFunction<T>
orElse(long result)
Converts thisOptionalToLongFunction
to plainToLongFunction
using default value.default ToLongFunction<T>
orElseGet(LongSupplier source)
-
-
-
Method Detail
-
apply
OptionalLong apply(T value)
Variation ofToLongFunction.applyAsLong(Object)
that returnsOptionalLong
. If thisOptionalToLongFunction
is obtained fromExceptionHandler.fromToLongFunction(ToLongFunction)
, theOptionalLong
will be empty only if the underlyingToLongFunction
throws. Otherwise the returnedOptionalLong
just wraps the return value of underlyingToLongFunction
.- Specified by:
-
apply
in interfaceFunction<T,OptionalLong>
- Parameters:
-
value
- seeToLongFunction.applyAsLong(Object)
- Returns:
-
OptionalLong
typically wrapping return value ofToLongFunction.applyAsLong(Object)
, or an emptyOptionalLong
(typically signifying an exception) - See Also:
-
ExceptionHandler.fromToLongFunction(ToLongFunction)
,ToLongFunction.applyAsLong(Object)
-
orElse
default ToLongFunction<T> orElse(long result)
Converts thisOptionalToLongFunction
to plainToLongFunction
using default value. The returnedToLongFunction
will unwrap present value from theOptionalLong
if possible, or returnresult
if theOptionalLong
is empty.- Parameters:
-
result
- default value to return instead of an emptyOptionalLong
- Returns:
-
plain
ToLongFunction
that either unwrapsOptionalLong
or returns default value - See Also:
-
orElseGet(LongSupplier)
,OptionalLong.orElse(long)
-
orElseGet
default ToLongFunction<T> orElseGet(LongSupplier source)
Converts thisOptionalToLongFunction
to plainToLongFunction
using fallbackLongSupplier
. The returnedToLongFunction
will unwrap present value from theOptionalLong
if possible, or fall back to callingsource
if theOptionalLong
is empty.- Parameters:
-
source
-LongSupplier
to query for fallback value whenOptionalLong
is empty - Returns:
-
plain
ToLongFunction
that either unwrapsOptionalLong
or falls back tosource
- See Also:
-
orElse(long)
,OptionalLong.orElseGet(LongSupplier)
-
-