Package io.github.brantunger.unruly.api
Class RuleEvaluation
java.lang.Object
io.github.brantunger.unruly.api.RuleEvaluation
What a run found out about one rule: whether its condition was true, false, or never evaluated, or whether the run
skipped the rule. A
run result has one for every loaded rule, in evaluation order, so a caller can
answer "why didn't rule X apply?" without a RuleListener.
It's a final class rather than a record, so a later 2.x release can add accessors without breaking code compiled
against this one. Two evaluations are equal when their rules and outcomes are, whatever their
details: a detail is the language's own object, with whatever equals it has, so it
is left out of equals and hashCode.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumWhat evaluating a rule's condition found, or that the run skipped the rule. -
Method Summary
Modifier and TypeMethodDescription@Nullable Objectdetail()Returns why the rule's condition evaluated as it did, in its language's own terms, such as the operands a comparison read: thedetailthe language returned fromevaluateWithDetail.booleaninthashCode()static RuleEvaluationof(Rule rule, RuleEvaluation.Outcome outcome) Creates an evaluation.static RuleEvaluationof(Rule rule, RuleEvaluation.Outcome outcome, @Nullable Object detail) Creates an evaluation with the detail the rule's condition was explained with.outcome()Returns what evaluating the rule's condition found, or that the run skipped the rule.rule()Returns the rule, the same instance that was passed toRulesEngine.load(java.util.List).toString()Names the rule and its outcome, such asprime-rate=MATCHED.
-
Method Details
-
of
Creates an evaluation. The engine creates its own; this is for a class that implementsRulesEngine, such as a decorator or a test double, and for tests that compare results.- Parameters:
rule- The ruleoutcome- What evaluating its condition found, or that the run skipped it- Returns:
- The evaluation
- Throws:
NullPointerException- if an argument isnull
-
of
Creates an evaluation with the detail the rule's condition was explained with. The engine creates its own; this is for a class that implementsRulesEngine, such as a decorator or a test double, and for tests.- Parameters:
rule- The ruleoutcome- What evaluating its condition found, or that the run skipped itdetail- Why the condition evaluated as it did, in its language's own terms, ornullfor none- Returns:
- The evaluation
- Throws:
NullPointerException- ifruleoroutcomeisnull
-
rule
Returns the rule, the same instance that was passed toRulesEngine.load(java.util.List).- Returns:
- The rule
-
outcome
Returns what evaluating the rule's condition found, or that the run skipped the rule.- Returns:
- The outcome
-
detail
Returns why the rule's condition evaluated as it did, in its language's own terms, such as the operands a comparison read: thedetailthe language returned fromevaluateWithDetail. The engine always records it when the language gives one. What it is, and what it's worth, is up to the language.- Returns:
- The detail, or
nullif there is none. On an evaluation the engine created, that's when the language gave none, or when the rule wasskippedornot evaluated. One created withof(Rule, Outcome, Object)has whatever detail it was given, whatever its outcome.
-
equals
-
hashCode
public int hashCode() -
toString
Names the rule and its outcome, such asprime-rate=MATCHED. The name is shortened to 200 characters, then escaped, as the engine's error messages show it, so a name with a line break can't start a log line of its own.
-