Class YmlPath

java.lang.Object
cloud.opencode.base.yml.path.YmlPath

public final class YmlPath extends Object
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:
  • Method Details

    • root

      public static YmlPath root()
      Gets the root path. 获取根路径。
      Returns:
      the root path | 根路径
    • of

      public static YmlPath of(String path)
      Parses a path string. 解析路径字符串。
      Parameters:
      path - the path string (e.g., "a.b.c" or "items[0].name") | 路径字符串
      Returns:
      the parsed path | 解析后的路径
    • of

      public static YmlPath of(String... segments)
      Creates a path from segments. 从段创建路径。
      Parameters:
      segments - the path segments | 路径段
      Returns:
      the path | 路径
    • child

      public YmlPath child(String property)
      Creates a child path by appending a property. 通过追加属性创建子路径。
      Parameters:
      property - the property name | 属性名称
      Returns:
      the new path | 新路径
    • index

      public YmlPath index(int index)
      Creates a child path by appending an array index. 通过追加数组索引创建子路径。
      Parameters:
      index - the array index | 数组索引
      Returns:
      the new path | 新路径
    • parent

      public YmlPath parent()
      Gets the parent path. 获取父路径。
      Returns:
      the parent path, or root if already at root | 父路径,如果已在根则返回根
    • getSegments

      public List<YmlPath.Segment> getSegments()
      Gets the path segments. 获取路径段。
      Returns:
      the segments | 段列表
    • getLastSegment

      public YmlPath.Segment 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

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object