Class CompiledExpression

java.lang.Object
cloud.opencode.base.expression.compiler.CompiledExpression
All Implemented Interfaces:
Expression

public final class CompiledExpression extends Object implements Expression
Compiled Expression 编译后的表达式

A pre-compiled expression for efficient repeated evaluation.

用于高效重复求值的预编译表达式。

Features | 主要功能:

  • Pre-parsed AST for repeated evaluation - 预解析AST用于重复求值
  • Implements Expression interface - 实现Expression接口
  • Type-safe evaluation with conversion - 类型安全求值与转换

Usage Examples | 使用示例:

CompiledExpression expr = CompiledExpression.compile("price * quantity");
// Reuse across multiple contexts
Object result1 = expr.getValue(ctx1);
Object result2 = expr.getValue(ctx2);

Security | 安全性:

  • Thread-safe: Yes, immutable after construction - 线程安全: 是,构造后不可变
  • Null-safe: Yes, null context creates default - 空值安全: 是,null上下文创建默认值
Since:
JDK 25, opencode-base-expression V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • compile

      public static CompiledExpression compile(String expression)
      Compile an expression 编译表达式
      Parameters:
      expression - the expression string | 表达式字符串
      Returns:
      the compiled expression | 编译后的表达式
    • getExpressionString

      public String getExpressionString()
      Description copied from interface: Expression
      Get the expression string 获取表达式字符串
      Specified by:
      getExpressionString in interface Expression
      Returns:
      the expression string | 表达式字符串
    • getValue

      public Object getValue()
      Description copied from interface: Expression
      Evaluate the expression 求值表达式
      Specified by:
      getValue in interface Expression
      Returns:
      the result | 结果
    • getValue

      public Object getValue(EvaluationContext context)
      Description copied from interface: Expression
      Evaluate the expression with context 使用上下文求值表达式
      Specified by:
      getValue in interface Expression
      Parameters:
      context - the evaluation context | 求值上下文
      Returns:
      the result | 结果
    • getValue

      public <T> T getValue(Class<T> targetType)
      Description copied from interface: Expression
      Evaluate the expression and convert to type 求值表达式并转换为指定类型
      Specified by:
      getValue in interface Expression
      Type Parameters:
      T - the target type | 目标类型
      Parameters:
      targetType - the target type | 目标类型
      Returns:
      the typed result | 类型化结果
    • getValue

      public <T> T getValue(EvaluationContext context, Class<T> targetType)
      Description copied from interface: Expression
      Evaluate the expression with context and convert to type 使用上下文求值表达式并转换为指定类型
      Specified by:
      getValue in interface Expression
      Type Parameters:
      T - the target type | 目标类型
      Parameters:
      context - the evaluation context | 求值上下文
      targetType - the target type | 目标类型
      Returns:
      the typed result | 类型化结果
    • getValue

      public Object getValue(Object rootObject)
      Description copied from interface: Expression
      Evaluate the expression with root object 使用根对象求值表达式
      Specified by:
      getValue in interface Expression
      Parameters:
      rootObject - the root object | 根对象
      Returns:
      the result | 结果
    • getValue

      public <T> T getValue(Object rootObject, Class<T> targetType)
      Description copied from interface: Expression
      Evaluate the expression with root object and convert to type 使用根对象求值表达式并转换为指定类型
      Specified by:
      getValue in interface Expression
      Type Parameters:
      T - the target type | 目标类型
      Parameters:
      rootObject - the root object | 根对象
      targetType - the target type | 目标类型
      Returns:
      the typed result | 类型化结果
    • getValueType

      public Class<?> getValueType()
      Description copied from interface: Expression
      Get the value type 获取值类型
      Specified by:
      getValueType in interface Expression
      Returns:
      the value type | 值类型
    • getValueType

      public Class<?> getValueType(EvaluationContext context)
      Description copied from interface: Expression
      Get the value type with context 使用上下文获取值类型
      Specified by:
      getValueType in interface Expression
      Parameters:
      context - the evaluation context | 求值上下文
      Returns:
      the value type | 值类型
    • getAst

      public Node getAst()
      Get the AST root node 获取AST根节点
      Returns:
      the AST root node | AST根节点
    • toString

      public String toString()
      Overrides:
      toString in class Object