Core Concepts
rulii is built on three building blocks: Conditions, Actions and Bindings. Every rule combines them, following the Production Rule Model.
The Three Building Blocks
Section titled “The Three Building Blocks”- Condition. A question that returns
trueorfalse. - Action. Something that happens: a side effect.
- Binding. A named, typed variable in shared state.
How a Rule Executes
Section titled “How a Rule Executes”- PreCondition. Should this rule run at all? (optional)
- Condition (Given). IF this holds…
- Action (Then). …THEN do this.
- Otherwise. …ELSE do this instead (optional).
Complete Example
Section titled “Complete Example”import static org.rulii.model.condition.Conditions.condition;import static org.rulii.model.action.Actions.action;
// 1. A Condition: is the user old enough?Condition isAdult = condition((Integer age) -> age >= 18);
// 2. Two ActionsAction allow = action(() -> System.out.println("Access granted"));Action reject = action(() -> System.out.println("Too young"));
// 3. The Rule: IF adult THEN allow OTHERWISE rejectRule rule = Rule.builder() .name("AgeGate") .given(isAdult) .then(allow) .otherwise(reject) .build();
// 4. Wrap it in a RuleFlow, the recommended way to run rulesRuleFlow<RuleContext> flow = RuleFlow.builder() .name("AgeGateFlow") .param("age", Integer.class) // checked before the flow runs .run(rule) .build();
// 5. Run with age = 25flow.run(age -> 25);// Output: Access granted
// 6. Run with age = 15flow.run(age -> 15);// Output: Too youngThe rule reads as a sentence: given the user is an adult, then allow access, otherwise reject. That is the pattern you will use throughout rulii.
Scaling Up: RuleSets & RuleFlows
Section titled “Scaling Up: RuleSets & RuleFlows”As the logic grows, related rules are grouped into a RuleSet, and a RuleFlow orchestrates the run: a pipeline that composes rules, rule sets and other flows with conditionals, loops, exception handling and async execution. A rule or rule set can be run directly, but a flow is the recommended entry point from application code.