Class SimpleDecisionTable
java.lang.Object
cloud.opencode.base.rules.decision.SimpleDecisionTable
- All Implemented Interfaces:
DecisionTable
Simple Decision Table Implementation
简单决策表实现
A basic implementation of DecisionTable for simple rule scenarios.
用于简单规则场景的DecisionTable基本实现。
Features | 主要功能:
- Condition syntax support (wildcards, comparisons, equality) - 条件语法支持(通配符、比较、相等)
- Multiple hit policy support - 多种命中策略支持
- Context and map-based evaluation - 基于上下文和Map的评估
Usage Examples | 使用示例:
SimpleDecisionTable table = new SimpleDecisionTable(
"pricing", HitPolicy.FIRST,
List.of("type"), List.of("discount"),
List.of(new Object[]{"VIP"}),
List.of(new Object[]{0.15})
);
DecisionResult result = table.evaluate(Map.of("type", "VIP"));
Security | 安全性:
- Thread-safe: No (mutable internal state) - 线程安全: 否(可变内部状态)
- Null-safe: No (inputs must not be null) - 空值安全: 否(输入不能为null)
- Since:
- JDK 25, opencode-base-rules V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionevaluate(RuleContext context) Evaluates the decision table against the given context 针对给定上下文评估决策表Evaluates the decision table against the given inputs 针对给定输入评估决策表Gets the hit policy 获取命中策略Gets the input column names 获取输入列名getName()Gets the decision table name 获取决策表名称Gets the output column names 获取输出列名intGets the number of rows in the table 获取表中的行数
-
Constructor Details
-
SimpleDecisionTable
public SimpleDecisionTable(String name, HitPolicy hitPolicy, List<String> inputColumns, List<String> outputColumns, List<Object[]> inputConditions, List<Object[]> outputValues) Creates a simple decision table 创建简单决策表- Parameters:
name- the table name | 表名hitPolicy- the hit policy | 命中策略inputColumns- the input column names | 输入列名outputColumns- the output column names | 输出列名inputConditions- the input conditions for each row | 每行的输入条件outputValues- the output values for each row | 每行的输出值
-
-
Method Details
-
getName
Description copied from interface:DecisionTableGets the decision table name 获取决策表名称- Specified by:
getNamein interfaceDecisionTable- Returns:
- the name | 名称
-
getHitPolicy
Description copied from interface:DecisionTableGets the hit policy 获取命中策略- Specified by:
getHitPolicyin interfaceDecisionTable- Returns:
- the hit policy | 命中策略
-
evaluate
Description copied from interface:DecisionTableEvaluates the decision table against the given context 针对给定上下文评估决策表- Specified by:
evaluatein interfaceDecisionTable- Parameters:
context- the rule context | 规则上下文- Returns:
- the decision result | 决策结果
-
evaluate
Description copied from interface:DecisionTableEvaluates the decision table against the given inputs 针对给定输入评估决策表- Specified by:
evaluatein interfaceDecisionTable- Parameters:
inputs- the input values | 输入值- Returns:
- the decision result | 决策结果
-
getRowCount
public int getRowCount()Description copied from interface:DecisionTableGets the number of rows in the table 获取表中的行数- Specified by:
getRowCountin interfaceDecisionTable- Returns:
- row count | 行数
-
getInputColumns
Description copied from interface:DecisionTableGets the input column names 获取输入列名- Specified by:
getInputColumnsin interfaceDecisionTable- Returns:
- input column names | 输入列名
-
getOutputColumns
Description copied from interface:DecisionTableGets the output column names 获取输出列名- Specified by:
getOutputColumnsin interfaceDecisionTable- Returns:
- output column names | 输出列名
-