Record Class TreeDiffResult<T>

java.lang.Object
java.lang.Record
cloud.opencode.base.tree.diff.TreeDiffResult<T>
Type Parameters:
T - the node type | 节点类型
Record Components:
added - the added nodes | 新增的节点
removed - the removed nodes | 删除的节点
modified - the modified nodes | 修改的节点
unchanged - the unchanged nodes | 未变化的节点

public record TreeDiffResult<T>(List<T> added, List<T> removed, List<TreeDiffResult.ModifiedNode<T>> modified, List<T> unchanged) extends Record
Tree Diff Result 树差异结果

Result of comparing two trees.

比较两棵树的结果。

Features | 主要功能:

  • Immutable diff result record - 不可变差异结果记录
  • Change count statistics - 变化数量统计
  • Summary string generation - 摘要字符串生成

Usage Examples | 使用示例:

TreeDiffResult<MyNode> result = TreeDiff.diff(oldRoots, newRoots);
boolean equal = result.isEqual();
int totalChanges = result.getTotalChanges();
String summary = result.getSummary();

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 是(不可变记录)
  • Null-safe: Yes (null lists default to empty) - 是(null列表默认为空)
Since:
JDK 25, opencode-base-tree V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

  • Method Details

    • empty

      public static <T> TreeDiffResult<T> empty()
      Create empty result 创建空结果
      Type Parameters:
      T - the node type | 节点类型
      Returns:
      the empty result | 空结果
    • isEqual

      public boolean isEqual()
      Check if trees are equal 检查两棵树是否相等
      Returns:
      true if equal | 如果相等返回true
    • hasChanges

      public boolean hasChanges()
      Check if has changes 检查是否有变化
      Returns:
      true if has changes | 如果有变化返回true
    • getTotalChanges

      public int getTotalChanges()
      Get total change count 获取总变化数量
      Returns:
      the total changes | 总变化数量
    • getAddedCount

      public int getAddedCount()
      Get added count 获取新增数量
      Returns:
      the added count | 新增数量
    • getRemovedCount

      public int getRemovedCount()
      Get removed count 获取删除数量
      Returns:
      the removed count | 删除数量
    • getModifiedCount

      public int getModifiedCount()
      Get modified count 获取修改数量
      Returns:
      the modified count | 修改数量
    • getSummary

      public String getSummary()
      Get summary string 获取摘要字符串
      Returns:
      the summary | 摘要
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • added

      public List<T> added()
      Returns the value of the added record component.
      Returns:
      the value of the added record component
    • removed

      public List<T> removed()
      Returns the value of the removed record component.
      Returns:
      the value of the removed record component
    • modified

      public List<TreeDiffResult.ModifiedNode<T>> modified()
      Returns the value of the modified record component.
      Returns:
      the value of the modified record component
    • unchanged

      public List<T> unchanged()
      Returns the value of the unchanged record component.
      Returns:
      the value of the unchanged record component