All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.polyapi.plugin.service.template.ConditionHelper Maven / Gradle / Ivy

There is a newer version: 0.15.3
Show newest version
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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy