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
8 package wtf
.metio
.reguloj
;
10 import java
.util
.Collection
;
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
;
28 public void infer(final Collection
<Rule
<CONTEXT
>> rules
, final CONTEXT context
) {
30 while (currentRuns
++ < maximumNumberOfRuns
&& analyze(rules
, context
)) {
31 rules
.forEach(rule
-> rule
.run(context
));