Record Class RuleResult
java.lang.Object
java.lang.Record
cloud.opencode.base.rules.RuleResult
- Record Components:
success- whether execution was successful | 执行是否成功firedRules- list of fired rule names | 已触发的规则名称列表skippedRules- list of skipped rule names | 已跳过的规则名称列表failedRules- list of failed rule names | 已失败的规则名称列表results- map of execution results | 执行结果MapexecutionTime- total execution time | 总执行时间errors- list of errors | 错误列表
public record RuleResult(boolean success, List<String> firedRules, List<String> skippedRules, List<String> failedRules, Map<String,Object> results, Duration executionTime, List<RuleResult.RuleError> errors)
extends Record
Rule Result - Immutable Record of Rule Execution Outcome
规则结果 - 规则执行结果的不可变记录
Contains information about which rules were fired, skipped, or failed, along with execution results and timing information.
包含哪些规则被触发、跳过或失败的信息,以及执行结果和时间信息。
Features | 主要功能:
- Fired rules tracking - 已触发规则跟踪
- Skipped rules tracking - 已跳过规则跟踪
- Failed rules with errors - 失败规则及错误
- Execution results collection - 执行结果收集
- Execution time measurement - 执行时间测量
Usage Examples | 使用示例:
RuleResult result = engine.fire(context);
if (result.success()) {
System.out.println("Fired: " + result.firedCount());
Double discount = result.getResult("discount");
}
if (result.wasFired("VIP-discount")) {
// handle VIP discount
}
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Since:
- JDK 25, opencode-base-rules V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for RuleResult RuleResult的构建器static final recordRule Error - Details about a rule execution failure 规则错误 - 规则执行失败的详细信息 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.errors()Returns the value of theerrorsrecord component.Returns the value of theexecutionTimerecord component.intGets the count of failed rules 获取已失败规则的数量Returns the value of thefailedRulesrecord component.static RuleResult.Builderfailure()Creates a failure result builder 创建失败结果构建器intGets the count of fired rules 获取已触发规则的数量Returns the value of thefiredRulesrecord component.<T> TGets a result value by key 按键获取结果值<T> TGets a result value with default 获取结果值,带默认值booleanChecks if a specific rule failed 检查特定规则是否失败booleanhasFired()Checks if any rules were fired 检查是否有规则被触发final inthashCode()Returns a hash code value for this object.booleanChecks if a result exists 检查结果是否存在results()Returns the value of theresultsrecord component.intGets the count of skipped rules 获取已跳过规则的数量Returns the value of theskippedRulesrecord component.booleansuccess()Returns the value of thesuccessrecord component.static RuleResult.BuilderCreates a success result builder 创建成功结果构建器final StringtoString()Returns a string representation of this record class.booleanChecks if a specific rule was fired 检查特定规则是否被触发booleanwasSkipped(String ruleName) Checks if a specific rule was skipped 检查特定规则是否被跳过
-
Constructor Details
-
RuleResult
public RuleResult(boolean success, List<String> firedRules, List<String> skippedRules, List<String> failedRules, Map<String, Object> results, Duration executionTime, List<RuleResult.RuleError> errors) Creates an instance of aRuleResultrecord class.- Parameters:
success- the value for thesuccessrecord componentfiredRules- the value for thefiredRulesrecord componentskippedRules- the value for theskippedRulesrecord componentfailedRules- the value for thefailedRulesrecord componentresults- the value for theresultsrecord componentexecutionTime- the value for theexecutionTimerecord componenterrors- the value for theerrorsrecord component
-
-
Method Details
-
firedCount
public int firedCount()Gets the count of fired rules 获取已触发规则的数量- Returns:
- fired rule count | 已触发规则数量
-
skippedCount
public int skippedCount()Gets the count of skipped rules 获取已跳过规则的数量- Returns:
- skipped rule count | 已跳过规则数量
-
failedCount
public int failedCount()Gets the count of failed rules 获取已失败规则的数量- Returns:
- failed rule count | 已失败规则数量
-
hasFired
public boolean hasFired()Checks if any rules were fired 检查是否有规则被触发- Returns:
- true if at least one rule was fired | 如果至少有一个规则被触发返回true
-
wasFired
Checks if a specific rule was fired 检查特定规则是否被触发- Parameters:
ruleName- the rule name | 规则名称- Returns:
- true if the rule was fired | 如果规则被触发返回true
-
wasSkipped
Checks if a specific rule was skipped 检查特定规则是否被跳过- Parameters:
ruleName- the rule name | 规则名称- Returns:
- true if the rule was skipped | 如果规则被跳过返回true
-
hasFailed
Checks if a specific rule failed 检查特定规则是否失败- Parameters:
ruleName- the rule name | 规则名称- Returns:
- true if the rule failed | 如果规则失败返回true
-
getResult
Gets a result value by key 按键获取结果值- Type Parameters:
T- the result type | 结果类型- Parameters:
key- the result key | 结果键- Returns:
- the result value, or null if not found | 结果值,如果未找到则为null
-
getResult
Gets a result value with default 获取结果值,带默认值- Type Parameters:
T- the result type | 结果类型- Parameters:
key- the result key | 结果键defaultValue- the default value | 默认值- Returns:
- the result value or default | 结果值或默认值
-
hasResult
Checks if a result exists 检查结果是否存在- Parameters:
key- the result key | 结果键- Returns:
- true if exists | 如果存在返回true
-
successBuilder
Creates a success result builder 创建成功结果构建器- Returns:
- builder instance | 构建器实例
-
failure
Creates a failure result builder 创建失败结果构建器- Returns:
- builder instance | 构建器实例
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
success
-
firedRules
Returns the value of thefiredRulesrecord component.- Returns:
- the value of the
firedRulesrecord component
-
skippedRules
Returns the value of theskippedRulesrecord component.- Returns:
- the value of the
skippedRulesrecord component
-
failedRules
Returns the value of thefailedRulesrecord component.- Returns:
- the value of the
failedRulesrecord component
-
results
-
executionTime
Returns the value of theexecutionTimerecord component.- Returns:
- the value of the
executionTimerecord component
-
errors
-