Class YmlDocument
java.lang.Object
cloud.opencode.base.yml.YmlDocument
YAML Document - Represents a parsed YAML document
YAML 文档 - 表示解析后的 YAML 文档
This class provides a wrapper around parsed YAML data with convenient access methods.
此类提供解析后 YAML 数据的包装器,带有便捷的访问方法。
Features | 主要功能:
- Typed value access (String, int, long, boolean, List, Map) - 类型化值访问
- Dot-notation path navigation - 点号路径导航
- Optional value support - 可选值支持
- Sub-document extraction - 子文档提取
Usage Examples | 使用示例:
YmlDocument doc = YmlDocument.of(data);
// Get values
String name = doc.getString("app.name");
int port = doc.getInt("server.port", 8080);
// Navigate
YmlDocument server = doc.get("server");
Security | 安全性:
- Thread-safe: No (wraps mutable data structures) - 线程安全: 否(包装可变数据结构)
- Null-safe: Yes (returns defaults or empty for missing paths) - 空值安全: 是(缺失路径返回默认值或空值)
- Since:
- JDK 25, opencode-base-yml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<T> List<T> asList()Gets the root as a List.asMap()Gets the root as a Map.static YmlDocumentempty()Creates an empty document.boolean<T> TGets a value at the specified path.<T> TGets a value at the specified path with default.getBoolean(String path) Gets a boolean value.booleangetBoolean(String path, boolean defaultValue) Gets a boolean value with default.getDocument(String path) Gets a sub-document at the specified path.Gets an integer value.intGets an integer value with default.<T> List<T> Gets a list value.Gets a long value.Gets a map value.<T> Optional<T> getOptional(String path) Gets an optional value.getRoot()Gets the root data.Gets a string value.Gets a string value with default.booleanChecks if a path exists.inthashCode()booleanisEmpty()Checks if the document is empty.keys()Gets all keys at the root level.static YmlDocumentCreates a document from parsed data.intsize()Gets the size of the root element.toString()
-
Method Details
-
of
Creates a document from parsed data. 从解析的数据创建文档。- Parameters:
data- the parsed data | 解析的数据- Returns:
- the document | 文档
-
empty
Creates an empty document. 创建空文档。- Returns:
- an empty document | 空文档
-
getRoot
-
asMap
-
asList
-
get
Gets a value at the specified path. 获取指定路径的值。- Type Parameters:
T- the type parameter | 类型参数- Parameters:
path- the path string | 路径字符串- Returns:
- the value | 值
-
get
Gets a value at the specified path with default. 获取指定路径的值(带默认值)。- Type Parameters:
T- the type parameter | 类型参数- Parameters:
path- the path string | 路径字符串defaultValue- the default value | 默认值- Returns:
- the value or default | 值或默认值
-
getDocument
Gets a sub-document at the specified path. 获取指定路径的子文档。- Parameters:
path- the path string | 路径字符串- Returns:
- the sub-document | 子文档
-
getString
-
getString
-
getInt
-
getInt
Gets an integer value with default. 获取整数值(带默认值)。- Parameters:
path- the path | 路径defaultValue- the default | 默认值- Returns:
- the integer value or default | 整数值或默认值
-
getLong
-
getBoolean
-
getBoolean
Gets a boolean value with default. 获取布尔值(带默认值)。- Parameters:
path- the path | 路径defaultValue- the default | 默认值- Returns:
- the boolean value or default | 布尔值或默认值
-
getList
-
getMap
-
has
Checks if a path exists. 检查路径是否存在。- Parameters:
path- the path | 路径- Returns:
- true if exists | 如果存在则返回 true
-
getOptional
-
keys
-
size
public int size()Gets the size of the root element. 获取根元素的大小。- Returns:
- the size | 大小
-
isEmpty
public boolean isEmpty()Checks if the document is empty. 检查文档是否为空。- Returns:
- true if empty | 如果为空则返回 true
-
toString
-
equals
-
hashCode
-