Class MapHandler

java.lang.Object
cloud.opencode.base.deepclone.handler.MapHandler
All Implemented Interfaces:
TypeHandler<Map<?,?>>

public final class MapHandler extends Object implements TypeHandler<Map<?,?>>
Handler for cloning Map types Map类型克隆处理器

Handles all Map types including HashMap, TreeMap, LinkedHashMap, and concurrent implementations. Both keys and values can be deep cloned.

处理所有Map类型,包括HashMap、TreeMap、LinkedHashMap和并发实现。 键和值都可以被深度克隆。

Supported Types | 支持的类型:

  • HashMap, LinkedHashMap, TreeMap, WeakHashMap
  • Hashtable, IdentityHashMap, EnumMap
  • ConcurrentHashMap, ConcurrentSkipListMap

Features | 主要功能:

  • Deep clone all Map types - 深度克隆所有Map类型
  • Preserves original map type - 保留原始Map类型
  • Recursive key and value cloning - 递归键值克隆

Usage Examples | 使用示例:

MapHandler handler = new MapHandler();
Map<String, User> cloned = (Map<String, User>) handler.clone(originalMap, 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

    • MapHandler

      public MapHandler()
  • Method Details

    • clone

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

      public <K,V> Map<K,V> cloneDeep(Map<K,V> map, Cloner cloner, CloneContext context)
      Clones a Map with deep cloning of both keys and values 克隆Map并深度克隆键和值
      Type Parameters:
      K - the key type | 键类型
      V - the value type | 值类型
      Parameters:
      map - the original map | 原始Map
      cloner - the cloner | 克隆器
      context - the context | 上下文
      Returns:
      the cloned map | 克隆的Map
    • cloneValues

      public <K,V> Map<K,V> cloneValues(Map<K,V> map, Cloner cloner, CloneContext context)
      Clones a Map with only values deep cloned (keys are shared) 克隆Map并仅深度克隆值(键共享)
      Type Parameters:
      K - the key type | 键类型
      V - the value type | 值类型
      Parameters:
      map - the original map | 原始Map
      cloner - the cloner | 克隆器
      context - the context | 上下文
      Returns:
      the cloned map | 克隆的Map
    • createInstance

      public <K,V> Map<K,V> createInstance(Class<?> type, int size)
      Creates an instance of the specified map type 创建指定Map类型的实例
      Type Parameters:
      K - the key type | 键类型
      V - the value type | 值类型
      Parameters:
      type - the map type | Map类型
      size - the expected size | 预期大小
      Returns:
      the new map instance | 新的Map实例
    • 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<Map<?,?>>
      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<Map<?,?>>
      Returns:
      the priority | 优先级