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
;
12 * A {@link Rule} combines {@link java.util.function.Predicate} and {@link java.util.function.Consumer} interfaces and
13 * can be evaluated with a {@link RuleEngine} using a {@link Context}.
19 * Check whether a rule would fire inside a given context:
23 * Context<X> context = ...;
24 * Rule<Context<X>> rule = ...;
26 * boolean canFire = rule.fires(context);
32 * Run a rule inside a given context:
35 * Context<X> context = ...;
36 * Rule<Context<X>> rule = ...;
43 * @param <CONTEXT> The context type.
48 public interface Rule
<CONTEXT
extends Context
<?
>> {
51 * @param <CONTEXT> The context type.
52 * @return A new builder to construct rules.
54 static <CONTEXT
extends Context
<?
>> RuleBuilder
<CONTEXT
> called(final String name
) {
55 return new FluentRuleBuilder
<CONTEXT
>().called(name
);
59 * @return The human readable name of this rule.
64 * Checks whether this rule would fire for a given context.
66 * @param context The context to check.
67 * @return <code>true</code> if this rule would fire, <code>false</code> otherwise.
69 boolean fires(CONTEXT context
);
72 * Runs this rule inside a given context. A rule should only run iff {@link #fires(Context)} returns
75 * @param context The context to use.
77 void run(CONTEXT context
);