org.joo.libra.common.DerivedLiteralPredicate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of joo-libra Show documentation
Show all versions of joo-libra Show documentation
Java Predicate with SQL-like syntax support
package org.joo.libra.common;
import java.util.function.Function;
import org.joo.libra.LiteralPredicate;
import org.joo.libra.PredicateContext;
import org.joo.libra.support.exceptions.PredicateExecutionException;
/**
* Simple implementation of {@link org.joo.libra.Predicate}
*
* @author griever
*
*/
public class DerivedLiteralPredicate implements CompositionPredicate, LiteralPredicate {
private final HasValue literalValue;
private final Function predicateFunction;
public DerivedLiteralPredicate(final HasValue literalValue, final Function predicateFunction) {
this.literalValue = literalValue;
this.predicateFunction = predicateFunction;
}
@Override
public T calculateLiteralValue(final PredicateContext context) throws PredicateExecutionException {
return literalValue.getValue(context);
}
@Override
public boolean satisfiedBy(final PredicateContext context) throws PredicateExecutionException {
return predicateFunction.apply(literalValue.getValue(context));
}
public String toString() {
return literalValue + "";
}
}