Class BeanPath
java.lang.Object
cloud.opencode.base.core.bean.BeanPath
Bean Path Utility Class - Nested property path access
Bean 路径访问工具 - 嵌套属性路径访问
Supports nested property access like user.address.city and array/List index access like items[0].name.
支持嵌套属性访问(如 user.address.city)和数组/List 索引访问(如 items[0].name)。
Features | 主要功能:
- Nested property access (user.address.city) - 嵌套属性访问
- Array/List index access (items[0]) - 数组/List 索引访问
- Map key access (map[key]) - Map 键访问
- Path validation and existence check - 路径验证和存在性检查
- Auto-create intermediate objects - 自动创建中间对象
Usage Examples | 使用示例:
// Get nested value - 获取嵌套值
String city = BeanPath.get(user, "address.city", String.class);
// Get array element - 获取数组元素
Item item = BeanPath.get(order, "items[0]", Item.class);
// Set with auto-create - 自动创建设置
BeanPath.setWithCreate(user, "address.city", "Beijing");
// Check path exists - 检查路径存在
boolean exists = BeanPath.exists(user, "address.city");
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: Yes (returns null on null path) - 空值安全: 是
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordIndex segment | 索引段static final recordMap key segment | Map 键段static interfacePath segment interface | 路径段接口static final recordProperty segment | 属性段 -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks if the path exists | 检查路径是否存在static ObjectGets a property value by path | 通过路径获取属性值static <T> TGets a property value by path with type conversion | 通过路径获取属性值(带类型转换)static StringgetLastSegment(String path) Gets the last segment of the path | 获取路径的最后一段static <T> Optional<T> getOptional(Object bean, String path, Class<T> targetType) Safely gets the value as Optional | 安全获取(返回 Optional)static StringgetParentPath(String path) Gets the parent path | 获取路径的父路径static booleanChecks if the value at path is not null | 检查路径值是否非 nullstatic booleanChecks if the value at path is null | 检查路径值是否为 nullstatic StringConcatenates path segments | 拼接路径static List<BeanPath.PathSegment> Parses a path string into segments | 解析路径为段列表static voidSets a property value by path | 通过路径设置属性值static voidsetWithCreate(Object bean, String path, Object value) Sets a property value by path, auto-creating intermediate objects | 通过路径设置属性值(自动创建中间对象)
-
Method Details
-
get
-
get
Gets a property value by path with type conversion | 通过路径获取属性值(带类型转换)- Type Parameters:
T- the target type | 目标类型- Parameters:
bean- the target bean | 目标 Beanpath- the property path | 属性路径targetType- the target class | 目标类- Returns:
- the converted value | 转换后的值
-
getOptional
Safely gets the value as Optional | 安全获取(返回 Optional)- Type Parameters:
T- the target type | 目标类型- Parameters:
bean- the target bean | 目标 Beanpath- the property path | 属性路径targetType- the target class | 目标类- Returns:
- an Optional containing the value | 包含值的 Optional
-
set
-
setWithCreate
-
exists
-
isNull
-
isNotNull
-
parsePath
Parses a path string into segments | 解析路径为段列表- Parameters:
path- the property path | 属性路径- Returns:
- the list of path segments | 路径段列表
-
getParentPath
-
getLastSegment
-
joinPath
-