Class ClonerBuilder
java.lang.Object
cloud.opencode.base.deepclone.ClonerBuilder
Builder for creating configured Cloner instances
用于创建配置的Cloner实例的构建器
Provides a fluent API for configuring and building cloner instances with custom settings, handlers, and immutable type registrations.
提供流畅的API来配置和构建具有自定义设置、处理器和不可变类型注册的克隆器实例。
Usage Examples | 使用示例:
Cloner cloner = OpenClone.builder()
.reflective()
.registerImmutable(Money.class, CustomValue.class)
.registerHandler(MyType.class, new MyTypeHandler())
.maxDepth(50)
.cloneTransient(true)
.build();
Features | 主要功能:
- Fluent builder API - 流式构建器API
- Strategy selection (reflective, serializing, unsafe) - 策略选择
- Custom type handler registration - 自定义类型处理器注册
- Immutable type registration - 不可变类型注册
Security | 安全性:
- Thread-safe: No (builder is not thread-safe, built Cloner is) - 线程安全: 否(构建器非线程安全,构建的克隆器是)
Performance | 性能特性:
- Time complexity: O(t) to build where t is the number of registered types/handlers - 时间复杂度: O(t),t 为注册的类型/处理器数量
- Space complexity: O(t) for registered type and handler maps - 空间复杂度: O(t) 注册类型和处理器映射
- Since:
- JDK 25, opencode-base-deepclone V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the configured Cloner instance 构建配置的Cloner实例cloneTransient(boolean cloneTransient) Sets whether to clone transient fields 设置是否克隆transient字段filter(FieldFilter filter) Sets the field filter for programmatic field exclusion 设置编程式字段排除的字段过滤器listener(CloneListener listener) Sets the clone listener for lifecycle events 设置克隆生命周期事件的监听器maxDepth(int maxDepth) Sets the maximum clone depth 设置最大克隆深度policy(ClonePolicy policy) Sets the clone policy 设置克隆策略Uses the reflective cloning strategy (default) 使用反射克隆策略(默认)<T> ClonerBuilderregisterCloner(Class<T> type, UnaryOperator<T> cloner) Registers a custom cloning function for a type 为类型注册自定义克隆函数<T> ClonerBuilderregisterHandler(Class<T> type, TypeHandler<T> handler) Registers a custom type handler 注册自定义类型处理器registerImmutable(Class<?>... types) Registers types as immutable (will not be cloned) 注册类型为不可变(不会被克隆)Uses the serialization cloning strategy 使用序列化克隆策略unsafe()Uses the Unsafe cloning strategy 使用Unsafe克隆策略useCache(boolean useCache) Sets whether to use caching 设置是否使用缓存
-
Method Details
-
reflective
Uses the reflective cloning strategy (default) 使用反射克隆策略(默认)- Returns:
- this builder | 此构建器
-
serializing
Uses the serialization cloning strategy 使用序列化克隆策略- Returns:
- this builder | 此构建器
-
unsafe
Uses the Unsafe cloning strategy 使用Unsafe克隆策略- Returns:
- this builder | 此构建器
-
registerImmutable
Registers types as immutable (will not be cloned) 注册类型为不可变(不会被克隆)- Parameters:
types- the types to register | 要注册的类型- Returns:
- this builder | 此构建器
-
registerHandler
Registers a custom type handler 注册自定义类型处理器- Type Parameters:
T- the type parameter | 类型参数- Parameters:
type- the type | 类型handler- the handler | 处理器- Returns:
- this builder | 此构建器
-
registerCloner
Registers a custom cloning function for a type 为类型注册自定义克隆函数- Type Parameters:
T- the type parameter | 类型参数- Parameters:
type- the type | 类型cloner- the cloning function | 克隆函数- Returns:
- this builder | 此构建器
-
cloneTransient
Sets whether to clone transient fields 设置是否克隆transient字段- Parameters:
cloneTransient- whether to clone | 是否克隆- Returns:
- this builder | 此构建器
-
useCache
Sets whether to use caching 设置是否使用缓存- Parameters:
useCache- whether to cache | 是否缓存- Returns:
- this builder | 此构建器
-
maxDepth
Sets the maximum clone depth 设置最大克隆深度- Parameters:
maxDepth- the max depth | 最大深度- Returns:
- this builder | 此构建器
-
policy
Sets the clone policy 设置克隆策略- Parameters:
policy- the clone policy | 克隆策略- Returns:
- this builder | 此构建器
-
filter
Sets the field filter for programmatic field exclusion 设置编程式字段排除的字段过滤器- Parameters:
filter- the field filter | 字段过滤器- Returns:
- this builder | 此构建器
-
listener
Sets the clone listener for lifecycle events 设置克隆生命周期事件的监听器- Parameters:
listener- the clone listener | 克隆监听器- Returns:
- this builder | 此构建器
-
build
-