com.jnape.palatable.lambda.functions.builtin.fn3.CmpEqBy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lambda Show documentation
Show all versions of lambda Show documentation
Functional patterns for Java
package com.jnape.palatable.lambda.functions.builtin.fn3;
import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.functions.Fn3;
import com.jnape.palatable.lambda.functions.builtin.fn2.CmpEq;
import com.jnape.palatable.lambda.functions.specialized.BiPredicate;
import com.jnape.palatable.lambda.functions.specialized.Predicate;
import static com.jnape.palatable.lambda.functions.specialized.Predicate.predicate;
/**
* Given a mapping function from some type A
to some {@link Comparable} type B
and two values
* of type A
, return true
if the first value is strictly equal to the second value (according
* to {@link Comparable#compareTo(Object)} in terms of their mapped B
results; otherwise, return false.
*
* @param the value type
* @param the mapped comparison type
* @see CmpEq
* @see LTBy
* @see GTBy
*/
public final class CmpEqBy> implements Fn3, A, A, Boolean> {
private static final CmpEqBy, ?> INSTANCE = new CmpEqBy<>();
private CmpEqBy() {
}
@Override
public Boolean checkedApply(Fn1 super A, ? extends B> compareFn, A x, A y) {
return compareFn.apply(x).compareTo(compareFn.apply(y)) == 0;
}
@Override
public BiPredicate apply(Fn1 super A, ? extends B> compareFn) {
return Fn3.super.apply(compareFn)::apply;
}
@Override
public Predicate apply(Fn1 super A, ? extends B> compareFn, A x) {
return predicate(Fn3.super.apply(compareFn, x));
}
@SuppressWarnings("unchecked")
public static > CmpEqBy cmpEqBy() {
return (CmpEqBy) INSTANCE;
}
public static > BiPredicate cmpEqBy(Fn1 super A, ? extends B> compareFn) {
return CmpEqBy.cmpEqBy().apply(compareFn);
}
public static > Predicate cmpEqBy(Fn1 super A, ? extends B> compareFn, A x) {
return CmpEqBy.cmpEqBy(compareFn).apply(x);
}
public static > Boolean cmpEqBy(Fn1 super A, ? extends B> compareFn, A x, A y) {
return cmpEqBy(compareFn, x).apply(y);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy