com.jnape.palatable.lambda.functions.builtin.fn3.LTEWith 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.Fn3;
import com.jnape.palatable.lambda.functions.builtin.fn2.LTE;
import com.jnape.palatable.lambda.functions.specialized.BiPredicate;
import com.jnape.palatable.lambda.functions.specialized.Predicate;
import java.util.Comparator;
import static com.jnape.palatable.lambda.functions.builtin.fn3.GTWith.gtWith;
import static com.jnape.palatable.lambda.functions.specialized.Predicate.predicate;
/**
* Given a {@link Comparator} from some type A
and two values of type A
,
* return true
if the second value is less than or equal to the first value in
* terms of their mapped B
results according to {@link Comparator#compare(Object, Object)};
* otherwise, return false.
*
* @param the value type
* @see LTE
* @see LTEBy
* @see GTEWith
*/
public final class LTEWith implements Fn3, A, A, Boolean> {
private static final LTEWith> INSTANCE = new LTEWith<>();
private LTEWith() {
}
@Override
public BiPredicate apply(Comparator compareFn) {
return Fn3.super.apply(compareFn)::apply;
}
@Override
public Predicate apply(Comparator compareFn, A x) {
return predicate(Fn3.super.apply(compareFn, x));
}
@Override
public Boolean checkedApply(Comparator comparator, A a, A a2) {
return !gtWith(comparator, a, a2);
}
@SuppressWarnings("unchecked")
public static LTEWith lteWith() {
return (LTEWith) INSTANCE;
}
public static BiPredicate lteWith(Comparator comparator) {
return LTEWith.lteWith().apply(comparator);
}
public static Predicate lteWith(Comparator comparator, A y) {
return LTEWith.lteWith(comparator).apply(y);
}
public static Boolean lteWith(Comparator comparator, A y, A x) {
return lteWith(comparator, y).apply(x);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy