
hm.binkley.util.function.ThrowingBinaryOperator Maven / Gradle / Ivy
The newest version!
package hm.binkley.util.function;
import javax.annotation.Nonnull;
import java.util.Comparator;
import java.util.function.BinaryOperator;
/**
* {@code ThrowingBinaryOperator} is a throwing look-a=like of {@link BinaryOperator}. It
* cannot be a {@code BinaryOperator} as it takes throwing versions of binary operators. Otherwise
* it is a faithful reproduction.
*
* @author B. K. Oxley (binkley)
*/
@SuppressWarnings({"UnusedDeclaration", "JavaDoc"})
@FunctionalInterface
public interface ThrowingBinaryOperator
extends ThrowingBiFunction {
/** @see BinaryOperator#minBy(Comparator) */
@Nonnull
static ThrowingBinaryOperator minBy(
@Nonnull final Comparator super T> comparator) {
return (a, b) -> 0 >= comparator.compare(a, b) ? a : b;
}
/** @see BinaryOperator#maxBy(Comparator) */
@Nonnull
static ThrowingBinaryOperator maxBy(
@Nonnull final Comparator super T> comparator) {
return (a, b) -> 0 <= comparator.compare(a, b) ? a : b;
}
/** Creates a facade {@code BinaryOperator} wrapping this throwing one. */
default BinaryOperator asBinaryOperator(final Defer defer) {
return (u, v) -> defer.as(() -> apply(u, v));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy