Class YmlPath
java.lang.Object
cloud.opencode.base.yml.path.YmlPath
YAML Path - Represents a path to a value in YAML document
YAML 路径 - 表示 YAML 文档中值的路径
This class represents a path using dot notation (e.g., "server.port") and array index notation (e.g., "items[0].name").
此类使用点号表示法(如 "server.port")和数组索引表示法(如 "items[0].name")表示路径。
Features | 主要功能:
- Parse dot-notation paths (e.g., "a.b.c") - 解析点号路径
- Array index support (e.g., "items[0].name") - 数组索引支持
- Programmatic path construction with child/index - 通过 child/index 程序化构建路径
- Parent path navigation - 父路径导航
- Sealed segment types (PropertySegment, IndexSegment) - 密封段类型
Usage Examples | 使用示例:
// Parse a path
YmlPath path = YmlPath.of("server.port");
// Create path programmatically
YmlPath path = YmlPath.root()
.child("server")
.child("port");
// Array access
YmlPath path = YmlPath.of("items[0].name");
Security | 安全性:
- Thread-safe: Yes (immutable after construction) - 线程安全: 是(构建后不可变)
- Null-safe: Yes (null/empty input returns root path) - 空值安全: 是(空输入返回根路径)
- Since:
- JDK 25, opencode-base-yml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordIndex Segment - Represents an array index access 索引段 - 表示数组索引访问static final recordProperty Segment - Represents a property access 属性段 - 表示属性访问static interfacePath Segment - Base interface for path segments 路径段 - 路径段的基础接口 -
Method Summary
Modifier and TypeMethodDescriptionCreates a child path by appending a property.intdepth()Gets the path depth.booleanGets the last segment.Gets the path segments.inthashCode()index(int index) Creates a child path by appending an array index.booleanisRoot()Checks if this is the root path.static YmlPathParses a path string.static YmlPathCreates a path from segments.parent()Gets the parent path.static YmlPathroot()Gets the root path.toString()
-
Method Details
-
root
-
of
-
of
-
child
-
index
Creates a child path by appending an array index. 通过追加数组索引创建子路径。- Parameters:
index- the array index | 数组索引- Returns:
- the new path | 新路径
-
parent
Gets the parent path. 获取父路径。- Returns:
- the parent path, or root if already at root | 父路径,如果已在根则返回根
-
getSegments
Gets the path segments. 获取路径段。- Returns:
- the segments | 段列表
-
getLastSegment
Gets the last segment. 获取最后一段。- Returns:
- the last segment, or null if root | 最后一段,如果是根则返回 null
-
isRoot
public boolean isRoot()Checks if this is the root path. 检查是否为根路径。- Returns:
- true if root | 如果是根则返回 true
-
depth
public int depth()Gets the path depth. 获取路径深度。- Returns:
- the depth | 深度
-
toString
-
equals
-
hashCode
-