Class PathResolver
java.lang.Object
cloud.opencode.base.yml.path.PathResolver
Path Resolver - Resolves paths in YAML data structures
路径解析器 - 在 YAML 数据结构中解析路径
This class provides utilities for accessing nested values using path expressions.
此类提供使用路径表达式访问嵌套值的工具。
Features | 主要功能:
- Dot-notation and array-index path resolution - 点号和数组索引路径解析
- Typed value access (String, int, long, boolean, List, Map) - 类型化值访问
- Default value and Optional support - 默认值和 Optional 支持
- Path existence check - 路径存在性检查
Usage Examples | 使用示例:
Map<String, Object> data = OpenYml.load(yaml);
// Get value at path
String port = PathResolver.get(data, "server.port");
// Get with default
int timeout = PathResolver.get(data, "server.timeout", 30);
// Check if path exists
boolean exists = PathResolver.has(data, "database.url");
// Get optional value
Optional<String> value = PathResolver.getOptional(data, "optional.path");
Security | 安全性:
- Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
- Null-safe: Yes (returns null/default for null root or missing paths) - 空值安全: 是(空根或缺失路径返回 null/默认值)
- Since:
- JDK 25, opencode-base-yml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TGets a value at the specified YmlPath.static <T> TGets a value at the specified path.static <T> TGets a value at the specified path with default.static BooleangetBoolean(Object root, String path) Gets a boolean value at the specified path.static booleangetBoolean(Object root, String path, boolean defaultValue) Gets a boolean value at the specified path with default.static IntegerGets an integer value at the specified path.static intGets an integer value at the specified path with default.static <T> List<T> Gets a list value at the specified path.static LongGets a long value at the specified path.Gets a map value at the specified path.static <T> Optional<T> getOptional(Object root, String path) Gets an optional value at the specified path.static StringGets a string value at the specified path.static StringGets a string value at the specified path with default.static booleanChecks if a path exists.static ObjectResolves a path in the given root object.
-
Method Details
-
get
Gets a value at the specified path. 获取指定路径的值。- Type Parameters:
T- the type parameter | 类型参数- Parameters:
root- the root object (Map or List) | 根对象(Map 或 List)path- the path string | 路径字符串- Returns:
- the value at path | 路径处的值
- Throws:
YmlPathException- if path is not found | 如果未找到路径
-
get
Gets a value at the specified path with default. 获取指定路径的值(带默认值)。- Type Parameters:
T- the type parameter | 类型参数- Parameters:
root- the root object | 根对象path- the path string | 路径字符串defaultValue- the default value | 默认值- Returns:
- the value at path or default | 路径处的值或默认值
-
get
Gets a value at the specified YmlPath. 获取指定 YmlPath 的值。- Type Parameters:
T- the type parameter | 类型参数- Parameters:
root- the root object | 根对象path- the path | 路径- Returns:
- the value at path | 路径处的值
- Throws:
YmlPathException- if path is not found | 如果未找到路径
-
getOptional
Gets an optional value at the specified path. 获取指定路径的可选值。- Type Parameters:
T- the type parameter | 类型参数- Parameters:
root- the root object | 根对象path- the path string | 路径字符串- Returns:
- optional containing value if found | 如果找到则包含值的 Optional
-
has
-
getString
-
getString
Gets a string value at the specified path with default. 获取指定路径的字符串值(带默认值)。- Parameters:
root- the root object | 根对象path- the path string | 路径字符串defaultValue- the default value | 默认值- Returns:
- the string value or default | 字符串值或默认值
-
getInt
-
getInt
Gets an integer value at the specified path with default. 获取指定路径的整数值(带默认值)。- Parameters:
root- the root object | 根对象path- the path string | 路径字符串defaultValue- the default value | 默认值- Returns:
- the integer value or default | 整数值或默认值
-
getLong
-
getBoolean
-
getBoolean
Gets a boolean value at the specified path with default. 获取指定路径的布尔值(带默认值)。- Parameters:
root- the root object | 根对象path- the path string | 路径字符串defaultValue- the default value | 默认值- Returns:
- the boolean value or default | 布尔值或默认值
-
getList
-
getMap
-
resolve
-