, negate() Predicate: , , . , , predicate.test(null) predicate.negate().test(null) true.
. negate boolean. trueValue falseValue. thirdValue true. , , t210 > ( , ).
public static void main(String... args) {
Predicate<String> predicate = lukasiewicz("1", "0", null);
System.out.println(predicate.test("0"));
System.out.println(predicate.test(null));
System.out.println(predicate.test("1"));
System.out.println(predicate.negate().test("0"));
System.out.println(predicate.negate().test(null));
System.out.println(predicate.negate().test("1"));
}
private static <T> Predicate<T> lukasiewicz(T trueValue, T falseValue, T thirdValue) {
class LukasiewiczPredicate implements Predicate<T> {
private boolean negate;
private LukasiewiczPredicate(boolean negate) {
this.negate = negate;
}
@Override
public boolean test(T t) {
if (Objects.equals(trueValue, t)) return negate;
if (Objects.equals(falseValue, t)) return !negate;
if (Objects.equals(thirdValue, t)) return true;
return false;
}
@Override
public Predicate<T> negate() {
return new LukasiewiczPredicate(!negate);
}
};
return new LukasiewiczPredicate(true);
}