io.polyapi.plugin.service.template.ConditionHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of polyapi-maven-plugin Show documentation
Show all versions of polyapi-maven-plugin Show documentation
Maven plugin to run handle Poly API functions.
package io.polyapi.plugin.service.template;
import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;
import java.io.IOException;
import java.util.function.BiPredicate;
/**
* {@link Helper} class that takes a {@link BiPredicate} and evaluates the parameters of the {@link Helper#apply(Object, Options)} method in it.
* If true, the function result will be {@link Options#fn()}, otherwise {@link Options#inverse()}
*
* @param The type of the Helper.
* @see Helper
*/
public class ConditionHelper implements Helper {
private final BiPredicate predicate;
public ConditionHelper(BiPredicate predicate) {
this.predicate = predicate;
}
@Override
public Object apply(T value, Options options) throws IOException {
return predicate.test(value, options) ? options.fn() : options.inverse();
}
}