Class ConverterRegistry

java.lang.Object
cloud.opencode.base.core.convert.ConverterRegistry

public final class ConverterRegistry extends Object
Converter Registry - Manages registration and retrieval of type converters 转换器注册表 - 管理类型转换器的注册和获取

Central registry for all type converters supporting built-in, array and custom converters.

管理所有类型转换器的注册和获取,支持内置、数组和自定义转换器。

Features | 主要功能:

  • Built-in converters: number, string, date, boolean, char - 内置转换器
  • Array converters: primitive and object arrays - 数组转换器
  • Custom converters: via SPI or manual registration - 自定义转换器
  • Type hierarchy lookup - 类型层级查找

Usage Examples | 使用示例:

// Get converter - 获取转换器
Converter<Integer> conv = ConverterRegistry.getConverter(Integer.class);

// Register custom converter - 注册自定义转换器
ConverterRegistry.register(MyType.class, new MyTypeConverter());

Security | 安全性:

  • Thread-safe: Yes (ConcurrentHashMap) - 线程安全: 是 (并发哈希表)
  • Null-safe: Yes - 空值安全: 是

Performance | 性能特性:

  • Time complexity: O(1) for lookup/register - 查找/注册 O(1)
  • Space complexity: O(n) where n = registered converters - O(n), n为已注册转换器数
Since:
JDK 25, opencode-base-core V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • register

      public static void register(Type type, Converter<?> converter)
      Registers a converter 注册转换器
      Parameters:
      type - the target type | 目标类型
      converter - the value | 转换器
    • getConverter

      public static <T> Converter<T> getConverter(Type type)
      Gets 获取转换器
      Type Parameters:
      T - the target type | 目标类型
      Parameters:
      type - the target type | 目标类型
      Returns:
      the result | 转换器,不存在则返回 null
    • hasConverter

      public static boolean hasConverter(Type type)
      Checks 检查是否存在转换器
      Parameters:
      type - the target type | 目标类型
      Returns:
      the result | 是否存在
    • unregister

      public static void unregister(Type type)
      Removes a converter 移除转换器
      Parameters:
      type - the target type | 目标类型
    • size

      public static int size()
      Gets 获取所有已注册类型数量
      Returns:
      the result | 数量