Class OpenRecord
java.lang.Object
cloud.opencode.base.reflect.record.OpenRecord
Record Facade Entry Class
Record门面入口类
Provides common record operations API.
提供常用record操作API。
Features | 主要功能:
- Record detection - Record检测
- Component access - 组件访问
- Record creation - Record创建
- Record copying - Record复制
Usage Examples | 使用示例:
// Check if record
boolean isRecord = OpenRecord.isRecord(User.class);
// Get component values
Map<String, Object> values = OpenRecord.toMap(userRecord);
// Copy with modifications
User modified = OpenRecord.copyWith(user, Map.of("name", "Alice"));
Security | 安全性:
- Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
- Null-safe: No (caller must ensure non-null arguments) - 空值安全: 否(调用方须确保非空参数)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Record>
RecordBuilder<T> Creates a record builder 创建record构建器static <T extends Record>
Tcopy(T record) Creates a copy of a record 创建record的副本static <T extends Record>
TCreates a copy with a single modified value 创建带单个修改值的副本static <T extends Record>
TCreates a copy with modified values 创建带修改值的副本static <T extends Record>
TCreates a record from values 从值创建recordCompares two records component by component 逐组件比较两个recordstatic <T extends Record>
TCreates a record from a map 从map创建recordstatic RecordComponentgetComponent(Class<?> recordClass, int index) Gets component by index 按索引获取组件static RecordComponentgetComponent(Class<?> recordClass, String componentName) Gets component by name 按名称获取组件static intgetComponentCount(Class<?> recordClass) Gets number of components 获取组件数量getComponentNames(Class<?> recordClass) Gets component names 获取组件名称static List<RecordComponent> getComponents(Class<?> recordClass) Gets record components 获取record组件getComponentTypes(Class<?> recordClass) Gets component types 获取组件类型static ObjectGets component value from a record 从record获取组件值static <T> TGets component value with type 获取组件值(带类型)static Object[]Gets all component values 获取所有组件值static booleanChecks if a class is a record 检查类是否为recordstatic booleanisRecordInstance(Object obj) Checks if an object is a record instance 检查对象是否为record实例static <T> Class<T> requireRecord(Class<T> clazz) Requires class to be a record 要求类为recordConverts record to map 将record转换为mapstatic booleanvaluesEqual(Record record1, Record record2) Checks if two records have the same values 检查两个record是否有相同的值
-
Method Details
-
isRecord
Checks if a class is a record 检查类是否为record- Parameters:
clazz- the class | 类- Returns:
- true if record | 如果是record返回true
-
isRecordInstance
Checks if an object is a record instance 检查对象是否为record实例- Parameters:
obj- the object | 对象- Returns:
- true if record instance | 如果是record实例返回true
-
requireRecord
Requires class to be a record 要求类为record- Type Parameters:
T- the type | 类型- Parameters:
clazz- the class | 类- Returns:
- the class | 类
- Throws:
IllegalArgumentException- if not a record | 如果不是record
-
getComponents
Gets record components 获取record组件- Parameters:
recordClass- the record class | record类- Returns:
- list of components | 组件列表
-
getComponent
Gets component by name 按名称获取组件- Parameters:
recordClass- the record class | record类componentName- the component name | 组件名- Returns:
- the component or null | 组件或null
-
getComponent
Gets component by index 按索引获取组件- Parameters:
recordClass- the record class | record类index- the index | 索引- Returns:
- the component | 组件
-
getComponentNames
-
getComponentTypes
-
getComponentCount
Gets number of components 获取组件数量- Parameters:
recordClass- the record class | record类- Returns:
- the count | 数量
-
getValue
-
getValue
Gets component value with type 获取组件值(带类型)- Type Parameters:
T- the value type | 值类型- Parameters:
record- the record | recordcomponentName- the component name | 组件名type- the expected type | 期望类型- Returns:
- the value | 值
-
getValues
-
toMap
-
builder
Creates a record builder 创建record构建器- Type Parameters:
T- the record type | record类型- Parameters:
recordClass- the record class | record类- Returns:
- the builder | 构建器
-
create
-
fromMap
-
copy
Creates a copy of a record 创建record的副本- Type Parameters:
T- the record type | record类型- Parameters:
record- the record to copy | 要复制的record- Returns:
- the copy | 副本
-
copyWith
Creates a copy with modified values 创建带修改值的副本- Type Parameters:
T- the record type | record类型- Parameters:
record- the record to copy | 要复制的recordmodifications- the modifications | 修改- Returns:
- the modified copy | 修改后的副本
-
copyWith
Creates a copy with a single modified value 创建带单个修改值的副本- Type Parameters:
T- the record type | record类型- Parameters:
record- the record to copy | 要复制的recordcomponentName- the component to modify | 要修改的组件newValue- the new value | 新值- Returns:
- the modified copy | 修改后的副本
-
diff
-
valuesEqual
-