package com.aperture_software.glados_wiki.entities.functions;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
/**
* Created by jhyun on 14. 3. 12.
*/
public class TeeConsumeFunction<A, B> implements Function<A, B> {
private Predicate<A> predicate;
private Function<A, B> falseCase;
private Function<A, B> trueCase;
public TeeConsumeFunction(Predicate<A> predicate, Function<A, B> trueCase, Function<A, B> falseCase) {
this.predicate = predicate;
this.trueCase = trueCase;
this.falseCase = falseCase;
}
public Predicate<A> getPredicate() {
return predicate;
}
public void setPredicate(Predicate<A> predicate) {
this.predicate = predicate;
}
public Function<A, B> getFalseCase() {
return falseCase;
}
public void setFalseCase(Function<A, B> falseCase) {
this.falseCase = falseCase;
}
public Function<A, B> getTrueCase() {
return trueCase;
}
public void setTrueCase(Function<A, B> trueCase) {
this.trueCase = trueCase;
}
@Override
public B apply(A input) {
if (predicate.apply(input)) {
return trueCase.apply(input);
} else {
return falseCase.apply(input);
}
}
}