Class ExpressionCompiler
java.lang.Object
cloud.opencode.base.expression.compiler.ExpressionCompiler
Expression Compiler
表达式编译器
Compiles expression strings into optimized AST nodes that can be efficiently evaluated. Supports caching and optimization for frequently used expressions.
将表达式字符串编译为可高效求值的优化 AST 节点。支持对常用表达式进行缓存和优化。
Features | 主要功能:
- Compile expressions with optional optimization - 编译表达式,可选优化
- Configurable caching strategy - 可配置的缓存策略
- Builder pattern for customization - 构建器模式用于自定义
- Factory methods for common configurations - 常见配置的工厂方法
Usage Examples | 使用示例:
// Default compiler with cache and optimization
ExpressionCompiler compiler = ExpressionCompiler.getDefault();
CompiledExpression expr = compiler.compile("a + b * c");
// Custom compiler via builder
ExpressionCompiler custom = ExpressionCompiler.builder()
.cacheSize(500)
.optimization(true)
.build();
Security | 安全性:
- Thread-safe: Yes, delegates to thread-safe cache - 线程安全: 是,委托给线程安全的缓存
- Null-safe: No, null expression not supported - 空值安全: 否,不支持null表达式
Performance | 性能特性:
- Time complexity: compile() O(1) for cached expressions; O(n) for first compilation where n is the expression length - 时间复杂度: 缓存命中时 compile() 为 O(1);首次编译为 O(n),n为表达式长度
- Space complexity: O(n) for the AST; O(c) for the cache where c is the cache size - 空间复杂度: AST 为 O(n);缓存为 O(c),c为缓存大小
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for ExpressionCompiler ExpressionCompiler 构建器 -
Constructor Summary
ConstructorsConstructorDescriptionCreate compiler with default settings 使用默认设置创建编译器ExpressionCompiler(ExpressionCache cache, Optimizer optimizer, boolean optimizationEnabled) Create compiler with custom settings 使用自定义设置创建编译器 -
Method Summary
Modifier and TypeMethodDescriptionstatic ExpressionCompiler.Builderbuilder()Create a builder for ExpressionCompiler 创建 ExpressionCompiler 的构建器voidClear the cache 清除缓存Compile expression string 编译表达式字符串Compile expression with explicit optimization setting 使用显式优化设置编译表达式compileWithoutCache(String expression) Compile expression without caching 编译表达式不使用缓存static ExpressionCompilercreate()Create a new compiler 创建新编译器getCache()Get the cache 获取缓存static ExpressionCompilerGet the default compiler instance 获取默认编译器实例Get the optimizer 获取优化器booleanCheck if expression is cached 检查表达式是否已缓存booleanCheck if optimization is enabled 检查是否启用优化static ExpressionCompilerCreate a compiler without caching 创建不带缓存的编译器static ExpressionCompilerCreate a compiler without optimization 创建不带优化的编译器
-
Constructor Details
-
ExpressionCompiler
public ExpressionCompiler()Create compiler with default settings 使用默认设置创建编译器 -
ExpressionCompiler
Create compiler with custom settings 使用自定义设置创建编译器- Parameters:
cache- the expression cache | 表达式缓存optimizer- the optimizer | 优化器optimizationEnabled- whether optimization is enabled | 是否启用优化
-
-
Method Details
-
getDefault
Get the default compiler instance 获取默认编译器实例- Returns:
- the default compiler | 默认编译器
-
create
-
withoutCache
Create a compiler without caching 创建不带缓存的编译器- Returns:
- the compiler | 编译器
-
withoutOptimization
Create a compiler without optimization 创建不带优化的编译器- Returns:
- the compiler | 编译器
-
compile
Compile expression string 编译表达式字符串- Parameters:
expression- the expression string | 表达式字符串- Returns:
- the compiled expression | 编译后的表达式
-
compileWithoutCache
Compile expression without caching 编译表达式不使用缓存- Parameters:
expression- the expression string | 表达式字符串- Returns:
- the compiled expression | 编译后的表达式
-
compile
Compile expression with explicit optimization setting 使用显式优化设置编译表达式- Parameters:
expression- the expression string | 表达式字符串optimize- whether to optimize | 是否优化- Returns:
- the compiled expression | 编译后的表达式
-
isCached
Check if expression is cached 检查表达式是否已缓存- Parameters:
expression- the expression string | 表达式字符串- Returns:
- true if cached | 如果已缓存返回 true
-
getCache
-
getOptimizer
-
isOptimizationEnabled
public boolean isOptimizationEnabled()Check if optimization is enabled 检查是否启用优化- Returns:
- true if enabled | 如果启用返回 true
-
clearCache
public void clearCache()Clear the cache 清除缓存 -
builder
Create a builder for ExpressionCompiler 创建 ExpressionCompiler 的构建器- Returns:
- the builder | 构建器
-