Class FunctionRegistry

java.lang.Object
cloud.opencode.base.expression.function.FunctionRegistry

public class FunctionRegistry extends Object
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 Details

    • FunctionRegistry

      public FunctionRegistry()
  • Method Details

    • getGlobal

      public static FunctionRegistry getGlobal()
      Get global function registry 获取全局函数注册表
      Returns:
      the global registry | 全局注册表
    • create

      public static FunctionRegistry create()
      Create new registry with global functions 创建包含全局函数的新注册表
      Returns:
      the new registry | 新注册表
    • empty

      public static FunctionRegistry empty()
      Create empty registry 创建空注册表
      Returns:
      the empty registry | 空注册表
    • register

      public FunctionRegistry register(String name, Function function)
      Register a function 注册函数
      Parameters:
      name - the function name | 函数名
      function - the function | 函数
      Returns:
      this registry for chaining | 用于链式调用的注册表
    • registerAll

      public FunctionRegistry registerAll(Map<String,Function> funcs)
      Register multiple functions 注册多个函数
      Parameters:
      funcs - the functions map | 函数映射
      Returns:
      this registry for chaining | 用于链式调用的注册表
    • unregister

      public FunctionRegistry unregister(String name)
      Unregister a function 注销函数
      Parameters:
      name - the function name | 函数名
      Returns:
      this registry for chaining | 用于链式调用的注册表
    • get

      public Function get(String name)
      Get a function by name 按名称获取函数
      Parameters:
      name - the function name | 函数名
      Returns:
      the function, or null if not found | 函数,如果未找到则为null
    • has

      public boolean has(String name)
      Check if function exists 检查函数是否存在
      Parameters:
      name - the function name | 函数名
      Returns:
      true if exists | 如果存在返回true
    • getNames

      public Set<String> getNames()
      Get all function names 获取所有函数名
      Returns:
      the function names | 函数名集合
    • size

      public int size()
      Get function count 获取函数数量
      Returns:
      the count | 数量
    • clear

      public void clear()
      Clear all functions 清除所有函数