Module com.machinezoo.noexception
Interface OptionalBinaryOperator<T>
-
- Type Parameters:
-
T- seeBinaryOperator
- All Superinterfaces:
-
BiFunction<T,T,Optional<T>>
- 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 OptionalBinaryOperator<T> extends BiFunction<T,T,Optional<T>>
Variation ofBinaryOperatorthat returnsOptionalinstead of the raw value.OptionalBinaryOperatoris typically obtained fromExceptionHandler.fromBinaryOperator(BinaryOperator), in which case its return value is empty when the underlyingBinaryOperatorthrows an exception. See noexception tutorial.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Optional<T>apply(T left, T right)Variation ofBiFunction.apply(Object, Object)that returnsOptional.default BinaryOperator<T>orElse(T result)Converts thisOptionalBinaryOperatorto plainBinaryOperatorusing default value.default BinaryOperator<T>orElseGet(Supplier<T> source)-
Methods inherited from interface java.util.function.BiFunction
andThen
-
-
-
-
Method Detail
-
apply
Optional<T> apply(T left, T right)
Variation ofBiFunction.apply(Object, Object)that returnsOptional. If thisOptionalBinaryOperatoris obtained fromExceptionHandler.fromBinaryOperator(BinaryOperator), theOptionalwill be empty only if the underlyingBinaryOperatorthrows. Otherwise the returnedOptionaljust wraps the return value of underlyingBinaryOperator(possiblynull).- Specified by:
-
applyin interfaceBiFunction<T,T,Optional<T>> - Parameters:
-
left- seeBiFunction.apply(Object, Object) -
right- seeBiFunction.apply(Object, Object) - Returns:
-
Optionaltypically wrapping return value ofBiFunction.apply(Object, Object), or an emptyOptional(typically signifying an exception) - See Also:
-
ExceptionHandler.fromBinaryOperator(BinaryOperator),BiFunction.apply(Object, Object)
-
orElse
default BinaryOperator<T> orElse(T result)
Converts thisOptionalBinaryOperatorto plainBinaryOperatorusing default value. The returnedBinaryOperatorwill unwrap present value from theOptionalif possible, or returnresultif theOptionalis empty.- Parameters:
-
result- default value to return instead of an emptyOptional - Returns:
-
plain
BinaryOperatorthat either unwrapsOptionalor returns default value - See Also:
-
orElseGet(Supplier),Optional.orElse(Object)
-
orElseGet
default BinaryOperator<T> orElseGet(Supplier<T> source)
Converts thisOptionalBinaryOperatorto plainBinaryOperatorusing fallbackSupplier. The returnedBinaryOperatorwill unwrap present value from theOptionalif possible, or fall back to callingsourceif theOptionalis empty.- Parameters:
-
source-Supplierto query for fallback value whenOptionalis empty - Returns:
-
plain
BinaryOperatorthat either unwrapsOptionalor falls back tosource - See Also:
-
orElse(Object),Optional.orElseGet(Supplier)
-
-