com.github.dakusui.crest.functions.TransformingPredicate Maven / Gradle / Ivy
package com.github.dakusui.crest.functions;
import java.util.function.Function;
import java.util.function.Predicate;
public class TransformingPredicate implements Predicate {
private final Predicate super P> predicate;
private final Function super O, ? extends P> function;
private final String name;
public TransformingPredicate(Predicate super P> predicate, Function super O, ? extends P> function) {
this(null, predicate, function);
}
public TransformingPredicate(String name, Predicate super P> predicate, Function super O, ? extends P> function) {
this.predicate = predicate;
this.function = function;
this.name = name;
}
@Override
public boolean test(O v) {
////
// This method is usually not called. Because Assertion class invokes function
// and predicate of this object by itself and do not use this method.
return predicate.test(function.apply(v));
}
public Predicate super P> predicate() {
return this.predicate;
}
public Function super O, ? extends P> function() {
return this.function;
}
@Override
public String toString() {
return String.format("%s%s %s", this.name == null ? "" : this.name, function(), predicate());
}
}