com.bazoud.elasticsearch.river.git.guava.PredicateFunction Maven / Gradle / Ivy
package com.bazoud.elasticsearch.river.git.guava;
import java.io.Serializable;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
/**
* @author Olivier Bazoud
*/
public class PredicateFunction implements Function, Serializable {
private static ESLogger logger = Loggers.getLogger(PredicateFunction.class);
private Function left;
private Function right;
private Predicate predicate;
public PredicateFunction(Function left, Function right, Predicate predicate) {
this.left = left;
this.right = right;
this.predicate = predicate;
}
@Override
public T apply(F input) {
if (this.predicate.apply(input)) {
logger.info(left.getClass().getName());
return left.apply(input);
} else {
logger.info(right.getClass().getName());
return right.apply(input);
}
}
}