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

io.legaldocml.xpath.eval.StepEval Maven / Gradle / Ivy

package io.legaldocml.xpath.eval;

import io.legaldocml.xpath.cerebro.CerebroLink;

import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;

public final class StepEval {

    private final CerebroLink link;
    private Predicate predicate;
    private Function postFunction;

    public StepEval(CerebroLink link) {
        this.link = link;
    }

    public Object eval(Object param) {

        Object result = link.apply(param);

        if (result instanceof List) {
            if (this.postFunction != null) {
                return this.postFunction.apply((List) result);
            } else  {

            }
        }

        if (this.predicate == null) {
            return result;
        }

        if (predicate.test(result)) {
            return result;
        } else {
            return null;
        }
    }

    public void setPredicate(Predicate predicate) {
        this.predicate = predicate;
    }

    public void setPostFunction(Function postFunction) {
        this.postFunction = postFunction;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy