Class DefaultRule
java.lang.Object
cloud.opencode.base.rules.engine.DefaultRule
- All Implemented Interfaces:
Rule, Comparable<Rule>
Default Rule Implementation
默认规则实现
Standard implementation of the Rule interface with condition and action.
带条件和动作的规则接口标准实现。
Features | 主要功能:
- Immutable rule configuration - 不可变规则配置
- Priority and group support - 优先级和分组支持
- Enable/disable toggle - 启用/禁用开关
Usage Examples | 使用示例:
Rule rule = new DefaultRule("discount", "VIP discount", 1, "pricing",
true,
ctx -> "VIP".equals(ctx.get("type")),
ctx -> ctx.setResult("discount", 0.15));
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Since:
- JDK 25, opencode-base-rules V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
Fields inherited from interface Rule
DEFAULT_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionDefaultRule(String name, String description, int priority, String group, boolean enabled, Condition condition, Action action) Creates a default rule 创建默认规则DefaultRule(String name, String description, int priority, String group, boolean enabled, Condition condition, Action action, boolean terminal) Creates a default rule with terminal flag 创建带终止标志的默认规则 -
Method Summary
Modifier and TypeMethodDescriptionbooleanevaluate(RuleContext context) Evaluates the rule condition against the given context 根据给定上下文评估规则条件voidexecute(RuleContext context) Executes the rule action with the given context 使用给定上下文执行规则动作Gets the action 获取动作Gets the condition 获取条件Gets the description of this rule 获取此规则的描述getGroup()Gets the group this rule belongs to 获取此规则所属的分组getName()Gets the unique name of this rule 获取此规则的唯一名称intGets the priority of this rule (lower value = higher priority) 获取此规则的优先级(值越小优先级越高)booleanChecks if this rule is enabled 检查此规则是否启用booleanChecks if this rule is terminal (stops engine execution when fired) 检查此规则是否是终止规则(触发时停止引擎执行)toString()
-
Constructor Details
-
DefaultRule
public DefaultRule(String name, String description, int priority, String group, boolean enabled, Condition condition, Action action) Creates a default rule 创建默认规则- Parameters:
name- the rule name | 规则名称description- the description | 描述priority- the priority | 优先级group- the group | 分组enabled- whether enabled | 是否启用condition- the condition | 条件action- the action | 动作
-
DefaultRule
public DefaultRule(String name, String description, int priority, String group, boolean enabled, Condition condition, Action action, boolean terminal) Creates a default rule with terminal flag 创建带终止标志的默认规则- Parameters:
name- the rule name | 规则名称description- the description | 描述priority- the priority | 优先级group- the group | 分组enabled- whether enabled | 是否启用condition- the condition | 条件action- the action | 动作terminal- whether the rule is terminal | 是否为终止规则- Since:
- JDK 25, opencode-base-rules V1.0.3
-
-
Method Details
-
getName
-
getDescription
Description copied from interface:RuleGets the description of this rule 获取此规则的描述- Specified by:
getDescriptionin interfaceRule- Returns:
- the rule description, may be null | 规则描述,可能为null
-
getPriority
public int getPriority()Description copied from interface:RuleGets the priority of this rule (lower value = higher priority) 获取此规则的优先级(值越小优先级越高)- Specified by:
getPriorityin interfaceRule- Returns:
- the priority value | 优先级值
-
getGroup
-
isEnabled
-
evaluate
Description copied from interface:RuleEvaluates the rule condition against the given context 根据给定上下文评估规则条件 -
execute
Description copied from interface:RuleExecutes the rule action with the given context 使用给定上下文执行规则动作 -
getCondition
-
getAction
-
isTerminal
public boolean isTerminal()Description copied from interface:RuleChecks if this rule is terminal (stops engine execution when fired) 检查此规则是否是终止规则(触发时停止引擎执行)- Specified by:
isTerminalin interfaceRule- Returns:
- true if the rule is terminal | 如果规则是终止规则返回true
-
toString
-