Class DefaultYmlNode

java.lang.Object
cloud.opencode.base.yml.DefaultYmlNode
All Implemented Interfaces:
YmlNode, Iterable<YmlNode>

public final class DefaultYmlNode extends Object implements YmlNode
Default YmlNode Implementation - Wraps raw YAML data as a node tree 默认 YmlNode 实现 - 将原始 YAML 数据包装为节点树

Features | 主要功能:

  • Wrap raw YAML data as a navigable node tree - 将原始 YAML 数据包装为可导航的节点树
  • Type-safe value access (int, long, boolean, double, String) - 类型安全的值访问
  • Dot-notation path navigation - 点号路径导航
  • Object binding via YmlBinder - 通过 YmlBinder 进行对象绑定

Usage Examples | 使用示例:

YmlNode node = DefaultYmlNode.of(data);
String name = node.get("user").get("name").asText();
int port = node.at("server.port").asInt(8080);

Security | 安全性:

  • Thread-safe: No (immutable after creation, but wraps mutable data) - 线程安全: 否(创建后不可变,但包装的数据可变)
  • Null-safe: Yes (returns NULL_NODE for missing keys) - 空值安全: 是(缺失键返回空节点)
Since:
JDK 25, opencode-base-yml V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • of

      public static YmlNode of(Object value)
      Creates a node from a raw value. 从原始值创建节点。
      Parameters:
      value - the raw value | 原始值
      Returns:
      the node | 节点
    • nullNode

      public static YmlNode nullNode()
      Creates a null node. 创建空节点。
      Returns:
      the null node | 空节点
    • getType

      public YmlNode.NodeType getType()
      Description copied from interface: YmlNode
      Gets the node type. 获取节点类型。
      Specified by:
      getType in interface YmlNode
      Returns:
      the node type | 节点类型
    • asText

      public String asText()
      Description copied from interface: YmlNode
      Gets the string value. 获取字符串值。
      Specified by:
      asText in interface YmlNode
      Returns:
      the string value | 字符串值
    • asText

      public String asText(String defaultValue)
      Description copied from interface: YmlNode
      Gets the string value with default. 获取字符串值(带默认值)。
      Specified by:
      asText in interface YmlNode
      Parameters:
      defaultValue - the default value | 默认值
      Returns:
      the string value or default | 字符串值或默认值
    • asInt

      public int asInt()
      Description copied from interface: YmlNode
      Gets the integer value. 获取整数值。
      Specified by:
      asInt in interface YmlNode
      Returns:
      the integer value | 整数值
    • asInt

      public int asInt(int defaultValue)
      Description copied from interface: YmlNode
      Gets the integer value with default. 获取整数值(带默认值)。
      Specified by:
      asInt in interface YmlNode
      Parameters:
      defaultValue - the default value | 默认值
      Returns:
      the integer value or default | 整数值或默认值
    • asLong

      public long asLong()
      Description copied from interface: YmlNode
      Gets the long value. 获取长整数值。
      Specified by:
      asLong in interface YmlNode
      Returns:
      the long value | 长整数值
    • asLong

      public long asLong(long defaultValue)
      Description copied from interface: YmlNode
      Gets the long value with default. 获取长整数值(带默认值)。
      Specified by:
      asLong in interface YmlNode
      Parameters:
      defaultValue - the default value | 默认值
      Returns:
      the long value or default | 长整数值或默认值
    • asBoolean

      public boolean asBoolean()
      Description copied from interface: YmlNode
      Gets the boolean value. 获取布尔值。
      Specified by:
      asBoolean in interface YmlNode
      Returns:
      the boolean value | 布尔值
    • asBoolean

      public boolean asBoolean(boolean defaultValue)
      Description copied from interface: YmlNode
      Gets the boolean value with default. 获取布尔值(带默认值)。
      Specified by:
      asBoolean in interface YmlNode
      Parameters:
      defaultValue - the default value | 默认值
      Returns:
      the boolean value or default | 布尔值或默认值
    • asDouble

      public double asDouble()
      Description copied from interface: YmlNode
      Gets the double value. 获取双精度值。
      Specified by:
      asDouble in interface YmlNode
      Returns:
      the double value | 双精度值
    • asDouble

      public double asDouble(double defaultValue)
      Description copied from interface: YmlNode
      Gets the double value with default. 获取双精度值(带默认值)。
      Specified by:
      asDouble in interface YmlNode
      Parameters:
      defaultValue - the default value | 默认值
      Returns:
      the double value or default | 双精度值或默认值
    • get

      public YmlNode get(String key)
      Description copied from interface: YmlNode
      Gets a child node by key (for mapping nodes). 通过键获取子节点(用于映射节点)。
      Specified by:
      get in interface YmlNode
      Parameters:
      key - the key | 键
      Returns:
      the child node, or null node if not found | 子节点,如果未找到则返回空节点
    • get

      public YmlNode get(int index)
      Description copied from interface: YmlNode
      Gets a child node by index (for sequence nodes). 通过索引获取子节点(用于序列节点)。
      Specified by:
      get in interface YmlNode
      Parameters:
      index - the index | 索引
      Returns:
      the child node | 子节点
    • at

      public YmlNode at(String path)
      Description copied from interface: YmlNode
      Gets a node using dot-notation path. 使用点号路径获取节点。
      Specified by:
      at in interface YmlNode
      Parameters:
      path - the path (e.g., "a.b.c" or "items[0].name") | 路径(如:"a.b.c" 或 "items[0].name")
      Returns:
      the node at path, or null node if not found | 路径处的节点,如果未找到则返回空节点
    • has

      public boolean has(String key)
      Description copied from interface: YmlNode
      Checks if the mapping contains a key. 检查映射是否包含键。
      Specified by:
      has in interface YmlNode
      Parameters:
      key - the key | 键
      Returns:
      true if contains | 如果包含则返回 true
    • size

      public int size()
      Description copied from interface: YmlNode
      Gets the size (for sequence or mapping nodes). 获取大小(用于序列或映射节点)。
      Specified by:
      size in interface YmlNode
      Returns:
      the size | 大小
    • keys

      public Set<String> keys()
      Description copied from interface: YmlNode
      Gets all keys (for mapping nodes). 获取所有键(用于映射节点)。
      Specified by:
      keys in interface YmlNode
      Returns:
      the keys | 键集合
    • values

      public List<YmlNode> values()
      Description copied from interface: YmlNode
      Gets all child nodes. 获取所有子节点。
      Specified by:
      values in interface YmlNode
      Returns:
      the child nodes | 子节点列表
    • toObject

      public <T> T toObject(Class<T> clazz)
      Description copied from interface: YmlNode
      Converts to a Java object. 转换为 Java 对象。
      Specified by:
      toObject in interface YmlNode
      Type Parameters:
      T - the type parameter | 类型参数
      Parameters:
      clazz - the target type | 目标类型
      Returns:
      the object | 对象
    • toMap

      public Map<String,Object> toMap()
      Description copied from interface: YmlNode
      Converts to a Map. 转换为 Map。
      Specified by:
      toMap in interface YmlNode
      Returns:
      the Map | Map
    • toList

      public List<Object> toList()
      Description copied from interface: YmlNode
      Converts to a List. 转换为 List。
      Specified by:
      toList in interface YmlNode
      Returns:
      the List | List
    • toYaml

      public String toYaml()
      Description copied from interface: YmlNode
      Converts to a YAML string. 转换为 YAML 字符串。
      Specified by:
      toYaml in interface YmlNode
      Returns:
      the YAML string | YAML 字符串
    • getRawValue

      public Object getRawValue()
      Description copied from interface: YmlNode
      Gets the raw underlying value. 获取原始底层值。
      Specified by:
      getRawValue in interface YmlNode
      Returns:
      the raw value | 原始值
    • iterator

      public Iterator<YmlNode> iterator()
      Specified by:
      iterator in interface Iterable<YmlNode>
    • 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