Class AbstractCloner
java.lang.Object
cloud.opencode.base.deepclone.cloner.AbstractCloner
- All Implemented Interfaces:
Cloner
- Direct Known Subclasses:
ReflectiveCloner, SerializingCloner, UnsafeCloner
public abstract sealed class AbstractCloner
extends Object
implements Cloner
permits ReflectiveCloner, SerializingCloner, UnsafeCloner
Abstract base class for cloners (sealed hierarchy)
克隆器的抽象基类(密封层次结构)
Provides common functionality for all cloner implementations including immutable type detection, type handlers, and circular reference handling.
为所有克隆器实现提供通用功能,包括不可变类型检测、类型处理器和循环引用处理。
Features | 主要功能:
- Immutable type registry - 不可变类型注册
- Type handler management - 类型处理器管理
- Circular reference detection - 循环引用检测
- DeepCloneable interface support - DeepCloneable接口支持
Usage Examples | 使用示例:
// Extend to implement custom cloning logic
public final class MyCloner extends AbstractCloner {
@Override
protected Object cloneInternal(Object obj, CloneContext ctx) {
// custom clone logic
}
}
Security | 安全性:
- Thread-safe: Yes (immutable type registry, ConcurrentHashMap cache) - 线程安全: 是(不可变类型注册,ConcurrentHashMap缓存)
- Since:
- JDK 25, opencode-base-deepclone V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ArrayHandlerDefault handlers 默认处理器protected booleanWhether to clone transient fields 是否克隆transient字段protected final CollectionHandlerCustom immutable types 自定义不可变类型protected final EnumHandlerprotected FieldFilterField filter 字段过滤器protected CloneListenerClone listener 克隆监听器protected final MapHandlerprotected intMax clone depth 最大克隆深度protected final OptionalHandlerprotected ClonePolicyClone policy 克隆策略protected final RecordHandlerprotected final Map<Class<?>, TypeHandler<?>> Type handlers 类型处理器 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Tclone(T original) Deep clones an object 深度克隆对象<T> Tclone(T original, CloneContext context) Deep clones an object using a specific context 使用特定上下文深度克隆对象protected ObjectcloneArray(Object array, CloneContext context) Clones an array 克隆数组protected <T> Collection<T> cloneCollection(Collection<T> collection, CloneContext context) Clones a collection 克隆集合protected <K,V> Map <K, V> cloneMap(Map<K, V> map, CloneContext context) Clones a map 克隆Mapprotected abstract <T> TdoClone(T original, CloneContext context) Performs the actual cloning logic 执行实际的克隆逻辑Gets the field filter 获取字段过滤器protected <T> TypeHandler<T> getHandler(Class<T> type) Gets the type handler for a type 获取类型的处理器Gets registered immutable types 获取注册的不可变类型protected booleanisBuiltinImmutable(Class<?> type) Checks if a type is a built-in immutable type 检查类型是否为内置不可变类型protected booleanisImmutable(Class<?> type) Checks if a type is immutable 检查类型是否不可变<T> voidregisterHandler(Class<T> type, TypeHandler<T> handler) Registers a type handler 注册类型处理器voidregisterImmutable(Class<?>... types) Registers custom immutable types 注册自定义不可变类型voidsetCloneTransient(boolean cloneTransient) Sets whether to clone transient fields 设置是否克隆transient字段voidsetFieldFilter(FieldFilter fieldFilter) Sets the field filter 设置字段过滤器voidsetListener(CloneListener listener) Sets the clone listener 设置克隆监听器voidsetMaxDepth(int maxDepth) Sets the max clone depth 设置最大克隆深度voidsetPolicy(ClonePolicy policy) Sets the clone policy 设置克隆策略Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Cloner
getStrategyName, supports
-
Field Details
-
customImmutableTypes
-
typeHandlers
Type handlers 类型处理器 -
arrayHandler
Default handlers 默认处理器 -
collectionHandler
-
mapHandler
-
recordHandler
-
enumHandler
-
optionalHandler
-
maxDepth
protected volatile int maxDepthMax clone depth 最大克隆深度 -
cloneTransient
protected volatile boolean cloneTransientWhether to clone transient fields 是否克隆transient字段 -
policy
Clone policy 克隆策略 -
fieldFilter
Field filter 字段过滤器 -
listener
Clone listener 克隆监听器
-
-
Constructor Details
-
AbstractCloner
public AbstractCloner()
-
-
Method Details
-
clone
-
clone
Description copied from interface:ClonerDeep clones an object using a specific context 使用特定上下文深度克隆对象 -
doClone
Performs the actual cloning logic 执行实际的克隆逻辑- Type Parameters:
T- the object type | 对象类型- Parameters:
original- the original object | 原始对象context- the clone context | 克隆上下文- Returns:
- the cloned object | 克隆的对象
-
getImmutableTypes
-
isImmutable
Checks if a type is immutable 检查类型是否不可变- Parameters:
type- the type | 类型- Returns:
- true if immutable | 如果不可变返回true
-
isBuiltinImmutable
Checks if a type is a built-in immutable type 检查类型是否为内置不可变类型- Parameters:
type- the type | 类型- Returns:
- true if built-in immutable | 如果是内置不可变返回true
-
registerImmutable
Registers custom immutable types 注册自定义不可变类型- Parameters:
types- the types to register | 要注册的类型
-
getHandler
Gets the type handler for a type 获取类型的处理器- Type Parameters:
T- the type parameter | 类型参数- Parameters:
type- the type | 类型- Returns:
- the handler, or null if none | 处理器,如果没有则为null
-
registerHandler
Registers a type handler 注册类型处理器- Type Parameters:
T- the type parameter | 类型参数- Parameters:
type- the type | 类型handler- the handler | 处理器
-
cloneArray
Clones an array 克隆数组- Parameters:
array- the array | 数组context- the context | 上下文- Returns:
- the cloned array | 克隆的数组
-
cloneCollection
Clones a collection 克隆集合- Type Parameters:
T- the element type | 元素类型- Parameters:
collection- the collection | 集合context- the context | 上下文- Returns:
- the cloned collection | 克隆的集合
-
cloneMap
Clones a map 克隆Map- Type Parameters:
K- the key type | 键类型V- the value type | 值类型- Parameters:
map- the map | Mapcontext- the context | 上下文- Returns:
- the cloned map | 克隆的Map
-
setMaxDepth
public void setMaxDepth(int maxDepth) Sets the max clone depth 设置最大克隆深度- Parameters:
maxDepth- the max depth | 最大深度
-
setCloneTransient
public void setCloneTransient(boolean cloneTransient) Sets whether to clone transient fields 设置是否克隆transient字段- Parameters:
cloneTransient- whether to clone | 是否克隆
-
setPolicy
Sets the clone policy 设置克隆策略- Parameters:
policy- the policy | 策略
-
setFieldFilter
Sets the field filter 设置字段过滤器- Parameters:
fieldFilter- the filter | 过滤器
-
getFieldFilter
Gets the field filter 获取字段过滤器- Returns:
- the field filter, may be null | 字段过滤器,可能为null
-
setListener
Sets the clone listener 设置克隆监听器- Parameters:
listener- the listener | 监听器
-