Class RecordUtil
java.lang.Object
cloud.opencode.base.core.reflect.RecordUtil
Record Utility Class - Java Record type operations
Record 工具类 - Java Record 类型操作
Provides utilities for working with Java Record types (JDK 16+).
提供 Java Record 类型(JDK 16+)的操作工具。
Features | 主要功能:
- Record type detection - Record 类型检测
- Component access (names, types, values) - 组件访问(名称、类型、值)
- Record to/from Map conversion - Record 与 Map 转换
- Immutable copy with modifications - 不可变复制(带修改)
Usage Examples | 使用示例:
// Check if record - 检查是否为 Record
boolean isRecord = RecordUtil.isRecord(User.class);
// Record to Map - Record 转 Map
Map<String, Object> map = RecordUtil.toMap(userRecord);
// Copy with modification - 带修改复制
User updated = RecordUtil.copyWith(user, "name", "NewName");
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: Partial (throws on null record) - 空值安全: 部分 (null 抛异常)
Performance | 性能特性:
- Time complexity: O(n) where n = record components - O(n), n为记录组件数
- Space complexity: O(n) for component array - 组件数组 O(n)
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Record>
TCopies a Record and modifies the specified component 复制 Record 并修改指定组件static <T extends Record>
TCopies a Record and modifies multiple components 复制 Record 并修改多个组件static booleanCompares two Records for equality (based on components) 比较两个 Record 是否相等(基于组件)static <T extends Record>
TConverts a Map to Record Map 转 Recordstatic intgetComponentCount(Class<?> recordClass) Gets the Record component count 获取 Record 组件数量static TypegetComponentGenericType(Class<?> recordClass, String componentName) Gets the generic type of a component 获取组件的泛型类型getComponentNames(Class<?> recordClass) Gets the list of Record component names 获取 Record 组件名列表static RecordComponent[]getComponents(Class<?> recordClass) Gets all components of the Record 获取 Record 的所有组件getComponentTypes(Class<?> recordClass) Gets the Record component type mapping 获取 Record 组件类型映射static <T> TgetComponentValue(Object record, String componentName) Gets the Record component value 获取 Record 组件值static booleanhasComponent(Class<?> recordClass, String componentName) Checks if the Record has the specified component 检查 Record 是否有指定组件static booleanChecks if the class is a Record type 检查类是否为 Record 类型static booleanChecks if the object is a Record instance 检查对象是否为 Record 实例Converts a Record to Map Record 转 Map
-
Method Details
-
isRecord
Checks if the class is a Record type 检查类是否为 Record 类型 -
isRecord
Checks if the object is a Record instance 检查对象是否为 Record 实例 -
getComponents
Gets all components of the Record 获取 Record 的所有组件 -
getComponentNames
-
getComponentTypes
-
getComponentValue
-
toMap
-
fromMap
-
copyWith
-
copyWith
-
equals
-
getComponentCount
Gets the Record component count 获取 Record 组件数量 -
hasComponent
-
getComponentGenericType
-