Class FunctionRegistry
java.lang.Object
cloud.opencode.base.expression.function.FunctionRegistry
Function Registry
函数注册表
Manages function registration and lookup for expression evaluation.
管理表达式求值的函数注册和查找。
Features | 主要功能:
- Case-insensitive function name lookup - 不区分大小写的函数名查找
- Global registry with built-in functions (string, math, collection, date, type) - 全局注册表,内置函数
- Register/unregister custom functions - 注册/注销自定义函数
- Create isolated registries - 创建隔离的注册表
Usage Examples | 使用示例:
FunctionRegistry registry = FunctionRegistry.create();
registry.register("greet", args -> "Hello, " + args[0]);
boolean exists = registry.has("upper"); // true (built-in)
Function fn = registry.get("greet");
Security | 安全性:
- Thread-safe: Yes, ConcurrentHashMap for function storage - 线程安全: 是,函数存储使用ConcurrentHashMap
- Null-safe: Yes, null name returns null/ignored - 空值安全: 是,null名称返回null/被忽略
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all functions 清除所有函数static FunctionRegistrycreate()Create new registry with global functions 创建包含全局函数的新注册表static FunctionRegistryempty()Create empty registry 创建空注册表Get a function by name 按名称获取函数static FunctionRegistryGet global function registry 获取全局函数注册表getNames()Get all function names 获取所有函数名booleanCheck if function exists 检查函数是否存在Register a function 注册函数registerAll(Map<String, Function> funcs) Register multiple functions 注册多个函数intsize()Get function count 获取函数数量unregister(String name) Unregister a function 注销函数
-
Constructor Details
-
FunctionRegistry
public FunctionRegistry()
-
-
Method Details
-
getGlobal
Get global function registry 获取全局函数注册表- Returns:
- the global registry | 全局注册表
-
create
Create new registry with global functions 创建包含全局函数的新注册表- Returns:
- the new registry | 新注册表
-
empty
Create empty registry 创建空注册表- Returns:
- the empty registry | 空注册表
-
register
Register a function 注册函数- Parameters:
name- the function name | 函数名function- the function | 函数- Returns:
- this registry for chaining | 用于链式调用的注册表
-
registerAll
Register multiple functions 注册多个函数- Parameters:
funcs- the functions map | 函数映射- Returns:
- this registry for chaining | 用于链式调用的注册表
-
unregister
Unregister a function 注销函数- Parameters:
name- the function name | 函数名- Returns:
- this registry for chaining | 用于链式调用的注册表
-
get
-
has
Check if function exists 检查函数是否存在- Parameters:
name- the function name | 函数名- Returns:
- true if exists | 如果存在返回true
-
getNames
-
size
public int size()Get function count 获取函数数量- Returns:
- the count | 数量
-
clear
public void clear()Clear all functions 清除所有函数
-