Interface Action

All Known Implementing Classes:
CompositeAction, ConsumerAction
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Action
Action Interface - Rule Action Abstraction 动作接口 - 规则动作抽象

Represents an action to be executed when a rule fires.

表示规则触发时要执行的动作。

Features | 主要功能:

  • Context modification - 上下文修改
  • Result setting - 结果设置
  • Chainable execution - 可链式执行

Usage Examples | 使用示例:

// Simple action
Action action = ctx -> ctx.setResult("discount", 0.1);

// Chained actions
Action combined = action1.andThen(action2);

Security | 安全性:

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

    Modifier and Type
    Method
    Description
    default Action
    andThen(Action after)
    Returns an action that executes this action followed by another 返回先执行此动作然后执行另一个动作的动作
    void
    Executes this action with the given context 使用给定上下文执行此动作
    static Action
    An action that does nothing 什么都不做的动作
  • Method Details

    • execute

      void execute(RuleContext context)
      Executes this action with the given context 使用给定上下文执行此动作
      Parameters:
      context - the rule context | 规则上下文
    • andThen

      default Action andThen(Action after)
      Returns an action that executes this action followed by another 返回先执行此动作然后执行另一个动作的动作
      Parameters:
      after - the action to execute after this | 在此之后执行的动作
      Returns:
      the combined action | 组合动作
    • noOp

      static Action noOp()
      An action that does nothing 什么都不做的动作
      Returns:
      the no-op action | 空操作动作