Interface DecisionTable

All Known Implementing Classes:
SimpleDecisionTable

public interface DecisionTable
Decision Table Interface - Table-Based Rule Definition 决策表接口 - 基于表格的规则定义

Provides a tabular way to define business rules with input conditions and output actions.

提供一种以表格方式定义业务规则的方法,包含输入条件和输出动作。

Features | 主要功能:

  • Tabular rule definition - 表格式规则定义
  • Multiple hit policies - 多种命中策略
  • Context-based evaluation - 基于上下文的评估

Usage Examples | 使用示例:

DecisionTable table = OpenRules.decisionTable()
    .name("pricing")
    .hitPolicy(HitPolicy.FIRST)
    .input("customerType", String.class)
    .input("amount", Double.class)
    .output("discount", Double.class)
    .row(new Object[]{"VIP", ">= 1000"}, new Object[]{0.15})
    .row(new Object[]{"VIP", "-"}, new Object[]{0.10})
    .row(new Object[]{"-", "-"}, new Object[]{0.0})
    .build();

DecisionResult result = table.evaluate(context);

Security | 安全性:

  • Thread-safe: Implementation dependent - 线程安全: 取决于实现
  • Null-safe: No (context/inputs must not be null) - 空值安全: 否(上下文/输入不能为null)
Since:
JDK 25, opencode-base-rules V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • getName

      String getName()
      Gets the decision table name 获取决策表名称
      Returns:
      the name | 名称
    • getHitPolicy

      HitPolicy getHitPolicy()
      Gets the hit policy 获取命中策略
      Returns:
      the hit policy | 命中策略
    • evaluate

      DecisionResult evaluate(RuleContext context)
      Evaluates the decision table against the given context 针对给定上下文评估决策表
      Parameters:
      context - the rule context | 规则上下文
      Returns:
      the decision result | 决策结果
    • evaluate

      DecisionResult evaluate(Map<String,Object> inputs)
      Evaluates the decision table against the given inputs 针对给定输入评估决策表
      Parameters:
      inputs - the input values | 输入值
      Returns:
      the decision result | 决策结果
    • getRowCount

      int getRowCount()
      Gets the number of rows in the table 获取表中的行数
      Returns:
      row count | 行数
    • getInputColumns

      List<String> getInputColumns()
      Gets the input column names 获取输入列名
      Returns:
      input column names | 输入列名
    • getOutputColumns

      List<String> getOutputColumns()
      Gets the output column names 获取输出列名
      Returns:
      output column names | 输出列名