update copyright
[reguloj.git] / src / main / java / wtf / metio / reguloj / LimitedRuleEngine.java
blob69f5792c49068d12b5caf9740a5a36b1f34171fb
1 /*
2 * This file is part of reguloj. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of reguloj,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
5 * in the LICENSE file.
6 */
8 package wtf.metio.reguloj;
10 import java.util.Collection;
12 /**
13 * Limits the total number of runs to a user supplied maximum.
15 * @param <CONTEXT> The type of the context.
16 * @see ChainedRuleEngine
17 * @see FirstWinsRuleEngine
19 final class LimitedRuleEngine<CONTEXT extends Context<?>> extends AbstractRuleEngine<CONTEXT> {
21 private final int maximumNumberOfRuns;
23 LimitedRuleEngine(final int maximumNumberOfRuns) {
24 this.maximumNumberOfRuns = maximumNumberOfRuns;
27 @Override
28 public void infer(final Collection<Rule<CONTEXT>> rules, final CONTEXT context) {
29 int currentRuns = 0;
30 while (currentRuns++ < maximumNumberOfRuns && analyze(rules, context)) {
31 rules.forEach(rule -> rule.run(context));