Class CollectionHandler

java.lang.Object
cloud.opencode.base.deepclone.handler.CollectionHandler
All Implemented Interfaces:
TypeHandler<Collection<?>>

public final class CollectionHandler extends Object implements TypeHandler<Collection<?>>
Handler for cloning Collection types 集合类型克隆处理器

Handles all Collection types including List, Set, Queue, and their implementations. Elements are deep cloned recursively.

处理所有Collection类型,包括List、Set、Queue及其实现。元素会被递归深度克隆。

Supported Types | 支持的类型:

  • ArrayList, LinkedList, Vector, Stack
  • HashSet, LinkedHashSet, TreeSet
  • ArrayDeque, PriorityQueue
  • ConcurrentLinkedQueue, CopyOnWriteArrayList, etc.

Features | 主要功能:

  • Deep clone all Collection types - 深度克隆所有Collection类型
  • Preserves original collection type - 保留原始集合类型
  • Recursive element cloning - 递归元素克隆

Usage Examples | 使用示例:

CollectionHandler handler = new CollectionHandler();
List<User> cloned = (List<User>) handler.clone(originalList, cloner, context);

Security | 安全性:

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

    • CollectionHandler

      public CollectionHandler()
  • Method Details

    • clone

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

      public <T> List<T> cloneList(List<T> list, Cloner cloner, CloneContext context)
      Clones a List 克隆List
      Type Parameters:
      T - the element type | 元素类型
      Parameters:
      list - the original list | 原始列表
      cloner - the cloner | 克隆器
      context - the context | 上下文
      Returns:
      the cloned list | 克隆的列表
    • cloneSet

      public <T> Set<T> cloneSet(Set<T> set, Cloner cloner, CloneContext context)
      Clones a Set 克隆Set
      Type Parameters:
      T - the element type | 元素类型
      Parameters:
      set - the original set | 原始集合
      cloner - the cloner | 克隆器
      context - the context | 上下文
      Returns:
      the cloned set | 克隆的集合
    • cloneQueue

      public <T> Queue<T> cloneQueue(Queue<T> queue, Cloner cloner, CloneContext context)
      Clones a Queue 克隆Queue
      Type Parameters:
      T - the element type | 元素类型
      Parameters:
      queue - the original queue | 原始队列
      cloner - the cloner | 克隆器
      context - the context | 上下文
      Returns:
      the cloned queue | 克隆的队列
    • createInstance

      public <T> Collection<T> createInstance(Class<?> type, int size)
      Creates an instance of the specified collection type 创建指定集合类型的实例
      Type Parameters:
      T - the element type | 元素类型
      Parameters:
      type - the collection type | 集合类型
      size - the expected size | 预期大小
      Returns:
      the new collection instance | 新的集合实例
    • 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<Collection<?>>
      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<Collection<?>>
      Returns:
      the priority | 优先级