java.lang.Object
net.luis.utils.io.token.rule.TokenRuleEngine
A rule engine for processing tokens based on defined rules.
A rule can either validate or transform tokens.
The engine applies the rules in the order they were added.
If a rule matches, it replaces the matched tokens with the result of the action.
If no rule matches, the engine moves to the next token.
A rule can either validate or transform tokens.
The engine applies the rules in the order they were added.
If a rule matches, it replaces the matched tokens with the result of the action.
If no rule matches, the engine moves to the next token.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final record
A record that holds a token rule and its associated action. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List
<TokenRuleEngine.RuleAction> List of rule actions to be applied to the tokens. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a validation rule to the engine.
The rule is only used to validate tokens and does not modify them.void
addRule
(@NotNull TokenRule tokenRule, @NotNull TokenAction action) Adds a transformation rule to the engine.
The rule is used to transform tokens and can modify them.
The rule is applied to the tokens and the result is used to replace the matched tokens.Processes the given list of tokens using the defined rules.
The rules are applied in the order they were added.
If a rule matches, the matched tokens are replaced with the result of the action.
If no rule matches, the engine moves to the next token.
-
Field Details
-
ruleActions
List of rule actions to be applied to the tokens.
-
-
Constructor Details
-
TokenRuleEngine
public TokenRuleEngine()
-
-
Method Details
-
addRule
Adds a validation rule to the engine.
The rule is only used to validate tokens and does not modify them.- Parameters:
tokenRule
- The rule to be added- Throws:
NullPointerException
- If the rule is null
-
addRule
Adds a transformation rule to the engine.
The rule is used to transform tokens and can modify them.
The rule is applied to the tokens and the result is used to replace the matched tokens.- Parameters:
tokenRule
- The rule to be addedaction
- The action to be applied to the matched tokens- Throws:
NullPointerException
- If the rule or action is null
-
process
Processes the given list of tokens using the defined rules.
The rules are applied in the order they were added.
If a rule matches, the matched tokens are replaced with the result of the action.
If no rule matches, the engine moves to the next token.- Parameters:
tokens
- The list of tokens to be processed- Returns:
- A new unmodifiable list of tokens after processing
- Throws:
NullPointerException
- If the list of tokens is null
-