Class YmlDiff
java.lang.Object
cloud.opencode.base.yml.diff.YmlDiff
YAML Diff - Compares two YAML documents and produces a list of differences
YAML 差异比较器 - 比较两个 YAML 文档并生成差异列表
This utility class recursively compares two YAML data structures (maps, lists,
and scalar values) and returns a list of DiffEntry describing every
addition, removal, and modification.
此工具类递归比较两个 YAML 数据结构(映射、列表和标量值),并返回描述每个
新增、移除和修改的 DiffEntry 列表。
Features | 主要功能:
- Deep recursive comparison of nested maps - 嵌套映射的深度递归比较
- Index-based list comparison - 基于索引的列表比较
- Dot-notation paths with array index support (e.g. items[0].name) - 点号路径表示法,支持数组索引
- Null-safe: null base = all ADDED, null other = all REMOVED - 空值安全
- Max depth limit of 50 to prevent stack overflow - 最大深度限制 50 防止栈溢出
Usage Examples | 使用示例:
Map<String, Object> base = Map.of("server", Map.of("port", 8080));
Map<String, Object> other = Map.of("server", Map.of("port", 9090));
List<DiffEntry> diffs = YmlDiff.diff(base, other);
// [DiffEntry[type=MODIFIED, path=server.port, oldValue=8080, newValue=9090]]
Security | 安全性:
- Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
- Depth-limited: Yes (max 50 levels) - 深度限制: 是(最多 50 层)
- Since:
- JDK 25, opencode-base-yml V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
-
Method Details
-
diff
Compares two maps and returns a list of differences. 比较两个映射并返回差异列表。- Parameters:
base- the base map (may be null, treated as empty) | 基础映射(可为 null,视为空)other- the other map (may be null, treated as empty) | 另一个映射(可为 null,视为空)- Returns:
- unmodifiable list of diff entries | 不可修改的差异条目列表
- Throws:
OpenYmlException- if nesting depth exceeds limit | 当嵌套深度超过限制时
-
diff
Compares two YAML documents and returns a list of differences. 比较两个 YAML 文档并返回差异列表。- Parameters:
base- the base document (may be null, treated as empty) | 基础文档(可为 null,视为空)other- the other document (may be null, treated as empty) | 另一个文档(可为 null,视为空)- Returns:
- unmodifiable list of diff entries | 不可修改的差异条目列表
- Throws:
OpenYmlException- if nesting depth exceeds limit | 当嵌套深度超过限制时
-