Class GraphDiff

java.lang.Object
cloud.opencode.base.graph.GraphDiff

public final class GraphDiff extends Object
Graph Diff - Utility for comparing two graphs and computing their differences 图差异 - 比较两个图并计算差异的工具类

Compares a "before" graph and an "after" graph, producing a GraphDiff.DiffResult that details added, removed, and common vertices and edges.

比较"前"图和"后"图,生成详细说明已添加、已删除和共同的顶点和边的 GraphDiff.DiffResult

Features | 主要功能:

  • Vertex-level diff (added, removed, common) - 顶点级差异(已添加、已删除、共同)
  • Edge-level diff (added, removed, common) - 边级差异(已添加、已删除、共同)
  • Edge comparison uses record equals (from, to, weight) - 边比较使用记录equals(from, to, weight)

Usage Examples | 使用示例:

Graph<String> before = OpenGraph.directed();
before.addEdge("A", "B");
Graph<String> after = OpenGraph.directed();
after.addEdge("A", "C");

GraphDiff.DiffResult<String> diff = GraphDiff.compare(before, after);
Set<String> added = diff.addedVertices();
Since:
JDK 25, opencode-base-graph V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • compare

      public static <V> GraphDiff.DiffResult<V> compare(Graph<V> before, Graph<V> after)
      Compare two graphs and compute their differences 比较两个图并计算差异
      Type Parameters:
      V - the vertex type | 顶点类型
      Parameters:
      before - the original graph | 原始图
      after - the modified graph | 修改后的图
      Returns:
      the diff result | 差异结果
      Throws:
      NullPointerException - if either graph is null | 当任一图为null时抛出