Class RecordHandler

java.lang.Object
cloud.opencode.base.deepclone.handler.RecordHandler
All Implemented Interfaces:
TypeHandler<Record>

public final class RecordHandler extends Object implements TypeHandler<Record>
Handler for cloning Record types Record类型克隆处理器

Handles JDK 16+ Record classes by extracting component values, deep cloning them, and constructing a new Record instance.

通过提取组件值、深度克隆并构造新的Record实例来处理JDK 16+的Record类。

Usage Examples | 使用示例:

record Point(int x, int y, String label) {}

RecordHandler handler = new RecordHandler();
Point original = new Point(10, 20, "origin");
Point cloned = handler.cloneRecord(original, cloner, context);

Features | 主要功能:

  • Record component extraction and cloning - Record组件提取和克隆
  • Canonical constructor invocation - 规范构造函数调用
  • JDK 16+ Record support - JDK 16+ Record支持

Security | 安全性:

  • Thread-safe: Yes (stateless) - 线程安全: 是(无状态)
Since:
JDK 25, opencode-base-deepclone V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • RecordHandler

      public RecordHandler()
  • Method Details

    • clone

      public Record clone(Record original, Cloner cloner, CloneContext context)
      Description copied from interface: TypeHandler
      Clones the object 克隆对象
      Specified by:
      clone in interface TypeHandler<Record>
      Parameters:
      original - the original object | 原始对象
      cloner - the cloner for recursive cloning | 用于递归克隆的克隆器
      context - the clone context | 克隆上下文
      Returns:
      the cloned object | 克隆的对象
    • cloneRecord

      public <T extends Record> T cloneRecord(T record, Cloner cloner, CloneContext context)
      Clones a Record 克隆Record
      Type Parameters:
      T - the record type | Record类型
      Parameters:
      record - the original record | 原始Record
      cloner - the cloner | 克隆器
      context - the context | 上下文
      Returns:
      the cloned record | 克隆的Record
    • getComponents

      public Object[] getComponents(Record record)
      Gets the component values of a Record 获取Record的组件值
      Parameters:
      record - the record | Record
      Returns:
      the component values array | 组件值数组
    • createInstance

      public <T extends Record> T createInstance(Class<T> type, Object[] values)
      Creates a new Record instance with the given component values 使用给定的组件值创建新的Record实例
      Type Parameters:
      T - the record type | Record类型
      Parameters:
      type - the record class | Record类
      values - the component values | 组件值
      Returns:
      the new record instance | 新的Record实例
    • supports

      public boolean supports(Class<?> type)
      Description copied from interface: TypeHandler
      Checks if this handler supports the given type 检查此处理器是否支持给定类型
      Specified by:
      supports in interface TypeHandler<Record>
      Parameters:
      type - the type to check | 要检查的类型
      Returns:
      true if supported | 如果支持返回true
    • priority

      public int priority()
      Description copied from interface: TypeHandler
      Gets the priority of this handler 获取此处理器的优先级

      Lower values indicate higher priority. Default is 100.

      较小的值表示较高的优先级。默认值为100。

      Specified by:
      priority in interface TypeHandler<Record>
      Returns:
      the priority | 优先级