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

info.lostred.ruler.engine.DetailRulesEngine Maven / Gradle / Ivy

package info.lostred.ruler.engine;

import info.lostred.ruler.core.AbstractRule;
import info.lostred.ruler.core.IterationEngine;
import info.lostred.ruler.core.RulesEngine;
import info.lostred.ruler.domain.Report;
import info.lostred.ruler.domain.Result;
import info.lostred.ruler.factory.RuleFactory;

import java.util.Collection;
import java.util.Iterator;

/**
 * 详细执行的规则引擎
 *
 * @param  规则约束的参数类型
 * @author lostred
 */
public abstract class DetailRulesEngine extends RulesEngine implements IterationEngine {

    public DetailRulesEngine(RuleFactory ruleFactory, String businessType, Collection> abstractRules) {
        super(ruleFactory, businessType, abstractRules);
    }

    @Override
    public Result execute(E object) {
        super.checkBefore(object);
        logger.config("invoke method=execute, valid object=" + object);
        Result result = Result.of();
        Iterator> iterator = this.abstractRules.iterator();
        while (iterator.hasNext() && this.toNext(result.getGrade())) {
            AbstractRule abstractRule = iterator.next();
            if (abstractRule.isSupported(object)) {
                Report report = this.doBuildReport(object, abstractRule);
                if (report != null) {
                    result.addReport(report);
                    result.updateGrade(report);
                }
            }
        }
        return result.statistic();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy