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

cn.schoolwow.quickhttp.document.query.CombiningEvaluator Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
package cn.schoolwow.quickhttp.document.query;

import cn.schoolwow.quickhttp.document.element.Element;

import java.util.List;

public abstract class CombiningEvaluator extends Evaluator {
    protected List evaluatorList;

    public CombiningEvaluator(List evaluatorList) {
        this.evaluatorList = evaluatorList;
    }

    public abstract boolean matches(Element element);

    public static final class And extends CombiningEvaluator {
        public And(List evaluatorList) {
            super(evaluatorList);
        }

        @Override
        public boolean matches(Element element) {
            for (Evaluator evaluator : evaluatorList) {
                if (!evaluator.matches(element)) {
                    return false;
                }
            }
            return true;
        }

        @Override
        public String toString() {
            return "[AND]" + evaluatorList;
        }
    }

    public static final class Or extends CombiningEvaluator {
        public Or(List evaluatorList) {
            super(evaluatorList);
        }

        @Override
        public boolean matches(Element element) {
            for (Evaluator evaluator : evaluatorList) {
                if (evaluator.matches(element)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public String toString() {
            return "[OR]" + evaluatorList;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy