Interface YmlNode
- All Known Implementing Classes:
DefaultYmlNode
YAML Node Interface - Represents a node in YAML document tree
YAML 节点接口 - 表示 YAML 文档树中的节点
This interface represents a node in the YAML document tree structure. A node can be a scalar (string, number, boolean), sequence (list), or mapping (map).
此接口表示 YAML 文档树结构中的节点。 节点可以是标量(字符串、数字、布尔值)、序列(列表)或映射(映射)。
Features | 主要功能:
- Typed value access (scalar, sequence, mapping, null) - 类型化值访问(标量、序列、映射、空)
- Dot-notation path navigation - 点号路径导航
- Object binding support - 对象绑定支持
- Iterable for sequence/mapping traversal - 可迭代的序列/映射遍历
Usage Examples | 使用示例:
YmlNode root = YmlDocument.parse(yaml).getRoot();
// Check node type
if (root.isMapping()) {
String name = root.get("name").asText();
}
// Use path access
String city = root.at("address.city").asText();
// Iterate sequence
for (YmlNode item : root.get("items")) {
System.out.println(item.asText());
}
Security | 安全性:
- Thread-safe: Depends on implementation - 线程安全: 取决于实现
- 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:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumNode Type - Types of YAML nodes 节点类型 - YAML 节点的类型 -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets the boolean value.booleanasBoolean(boolean defaultValue) Gets the boolean value with default.doubleasDouble()Gets the double value.doubleasDouble(double defaultValue) Gets the double value with default.intasInt()Gets the integer value.intasInt(int defaultValue) Gets the integer value with default.longasLong()Gets the long value.longasLong(long defaultValue) Gets the long value with default.asText()Gets the string value.Gets the string value with default.Gets a node using dot-notation path.get(int index) Gets a child node by index (for sequence nodes).Gets a child node by key (for mapping nodes).Gets the raw underlying value.getType()Gets the node type.booleanChecks if the mapping contains a key.default booleanChecks if this is a mapping node.default booleanisNull()Checks if this is a null node.default booleanisScalar()Checks if this is a scalar node.default booleanChecks if this is a sequence node.keys()Gets all keys (for mapping nodes).static YmlNodeCreates a YmlNode from the given value.intsize()Gets the size (for sequence or mapping nodes).toList()Converts to a List.toMap()Converts to a Map.<T> TConverts to a Java object.toYaml()Converts to a YAML string.values()Gets all child nodes.Methods inherited from interface Iterable
forEach, iterator, spliterator
-
Method Details
-
of
-
getType
-
isScalar
default boolean isScalar()Checks if this is a scalar node. 检查是否为标量节点。- Returns:
- true if scalar | 如果是标量则返回 true
-
isSequence
default boolean isSequence()Checks if this is a sequence node. 检查是否为序列节点。- Returns:
- true if sequence | 如果是序列则返回 true
-
isMapping
default boolean isMapping()Checks if this is a mapping node. 检查是否为映射节点。- Returns:
- true if mapping | 如果是映射则返回 true
-
isNull
default boolean isNull()Checks if this is a null node. 检查是否为空节点。- Returns:
- true if null | 如果是空则返回 true
-
asText
-
asText
-
asInt
int asInt()Gets the integer value. 获取整数值。- Returns:
- the integer value | 整数值
-
asInt
int asInt(int defaultValue) Gets the integer value with default. 获取整数值(带默认值)。- Parameters:
defaultValue- the default value | 默认值- Returns:
- the integer value or default | 整数值或默认值
-
asLong
long asLong()Gets the long value. 获取长整数值。- Returns:
- the long value | 长整数值
-
asLong
long asLong(long defaultValue) Gets the long value with default. 获取长整数值(带默认值)。- Parameters:
defaultValue- the default value | 默认值- Returns:
- the long value or default | 长整数值或默认值
-
asBoolean
boolean asBoolean()Gets the boolean value. 获取布尔值。- Returns:
- the boolean value | 布尔值
-
asBoolean
boolean asBoolean(boolean defaultValue) Gets the boolean value with default. 获取布尔值(带默认值)。- Parameters:
defaultValue- the default value | 默认值- Returns:
- the boolean value or default | 布尔值或默认值
-
asDouble
double asDouble()Gets the double value. 获取双精度值。- Returns:
- the double value | 双精度值
-
asDouble
double asDouble(double defaultValue) Gets the double value with default. 获取双精度值(带默认值)。- Parameters:
defaultValue- the default value | 默认值- Returns:
- the double value or default | 双精度值或默认值
-
get
-
get
Gets a child node by index (for sequence nodes). 通过索引获取子节点(用于序列节点)。- Parameters:
index- the index | 索引- Returns:
- the child node | 子节点
-
at
-
has
Checks if the mapping contains a key. 检查映射是否包含键。- Parameters:
key- the key | 键- Returns:
- true if contains | 如果包含则返回 true
-
size
int size()Gets the size (for sequence or mapping nodes). 获取大小(用于序列或映射节点)。- Returns:
- the size | 大小
-
keys
-
values
-
toObject
Converts to a Java object. 转换为 Java 对象。- Type Parameters:
T- the type parameter | 类型参数- Parameters:
clazz- the target type | 目标类型- Returns:
- the object | 对象
-
toMap
-
toList
-
toYaml
-
getRawValue
-