Class RecordBuilder<T extends Record>
java.lang.Object
cloud.opencode.base.reflect.record.RecordBuilder<T>
- Type Parameters:
T- the record type | record类型
Record Builder
Record构建器
Fluent builder for creating record instances.
用于创建record实例的流式构建器。
Features | 主要功能:
- Fluent record instance creation - 流式record实例创建
- Named component value setting - 命名组件值设置
- Type-safe record construction - 类型安全的record构造
Usage Examples | 使用示例:
User user = RecordBuilder.of(User.class)
.set("name", "Alice")
.set("age", 25)
.build();
Security | 安全性:
- Thread-safe: No (builder pattern, not thread-safe during construction) - 线程安全: 否(构建器模式,构建期间非线程安全)
- Null-safe: No (record class must be non-null) - 空值安全: 否(record类须非空)
Performance | 性能特性:
- Time complexity: build() O(c) where c is the number of record components - 时间复杂度: build() 为 O(c),c为 record 组件数量
- Space complexity: O(c) for storing component values - 空间复杂度: O(c),存储组件值
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the record instance 构建record实例Builds the record with validation 构建record(带验证)Clears a specific value 清除特定值clearAll()Clears all values 清除所有值Sets all values from an existing record 从现有record设置所有值static <T extends Record>
RecordBuilder<T> from(T record) Creates a RecordBuilder copying from an existing record 从现有record复制创建RecordBuilderGets the components 获取组件Gets the record class 获取record类Gets the current value for a component 获取组件的当前值booleanChecks if a value is set 检查是否已设置值static <T extends Record>
RecordBuilder<T> Creates a RecordBuilder for a record class 为record类创建RecordBuilderSets a component value by index 按索引设置组件值Sets a component value by name 按名称设置组件值Sets multiple values from a map 从map设置多个值setIfAbsent(String name, Object value) Sets a value if absent 如果不存在则设置值setIfNotNull(String name, Object value) Sets a value if not null 如果非null则设置值
-
Constructor Details
-
RecordBuilder
-
-
Method Details
-
of
Creates a RecordBuilder for a record class 为record类创建RecordBuilder- Type Parameters:
T- the record type | record类型- Parameters:
recordClass- the record class | record类- Returns:
- the builder | 构建器
-
from
Creates a RecordBuilder copying from an existing record 从现有record复制创建RecordBuilder- Type Parameters:
T- the record type | record类型- Parameters:
record- the record to copy | 要复制的record- Returns:
- the builder | 构建器
-
set
Sets a component value by name 按名称设置组件值- Parameters:
name- the component name | 组件名value- the value | 值- Returns:
- this builder | 此构建器
-
set
Sets a component value by index 按索引设置组件值- Parameters:
index- the component index | 组件索引value- the value | 值- Returns:
- this builder | 此构建器
-
setAll
Sets multiple values from a map 从map设置多个值- Parameters:
map- the values map | 值映射- Returns:
- this builder | 此构建器
-
copyFrom
Sets all values from an existing record 从现有record设置所有值- Parameters:
record- the record | record- Returns:
- this builder | 此构建器
-
setIfAbsent
Sets a value if absent 如果不存在则设置值- Parameters:
name- the component name | 组件名value- the value | 值- Returns:
- this builder | 此构建器
-
setIfNotNull
Sets a value if not null 如果非null则设置值- Parameters:
name- the component name | 组件名value- the value | 值- Returns:
- this builder | 此构建器
-
clear
Clears a specific value 清除特定值- Parameters:
name- the component name | 组件名- Returns:
- this builder | 此构建器
-
clearAll
-
getValue
-
hasValue
Checks if a value is set 检查是否已设置值- Parameters:
name- the component name | 组件名- Returns:
- true if set | 如果已设置返回true
-
getRecordClass
-
getComponents
Gets the components 获取组件- Returns:
- list of components | 组件列表
-
build
-
buildValidated
Builds the record with validation 构建record(带验证)- Returns:
- the record | record
- Throws:
IllegalStateException- if required values are missing | 如果缺少必需值
-