Record Class DependencyGraph

java.lang.Object
java.lang.Record
cloud.opencode.base.classloader.dependency.DependencyGraph
Record Components:
adjacency - class name to set of classes it depends on | 类名到其依赖的类集合的映射
classCount - total number of classes in the graph | 图中类的总数
edgeCount - total number of dependency edges | 依赖边的总数

public record DependencyGraph(Map<String, Set<String>> adjacency, int classCount, int edgeCount) extends Record
Dependency Graph - Immutable graph of class dependencies 依赖图 - 不可变的类依赖关系图

Represents a directed graph where each node is a class name and each edge represents a dependency from one class to another.

表示一个有向图,每个节点是一个类名,每条边表示从一个类到另一个类的依赖关系。

Features | 主要功能:

  • Immutable record with deep defensive copy - 不可变记录,使用深度防御性复制
  • Forward and reverse dependency lookups - 正向和反向依赖查找
  • All class names enumeration - 所有类名枚举

Usage Examples | 使用示例:

Map<String, Set<String>> adj = Map.of("A", Set.of("B", "C"), "B", Set.of("C"));
DependencyGraph graph = new DependencyGraph(adj, 3, 3);
Set<String> deps = graph.dependenciesOf("A"); // [B, C]
Set<String> dependents = graph.dependentsOf("C"); // [A, B]

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
Since:
JDK 25, opencode-base-classloader V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • DependencyGraph

      public DependencyGraph(Map<String, Set<String>> adjacency, int classCount, int edgeCount)
      Canonical constructor with null check and deep defensive copy. 规范构造器,包含空值检查和深度防御性复制。
      Parameters:
      adjacency - the adjacency map | 邻接映射
      classCount - number of classes | 类数量
      edgeCount - number of edges | 边数量
  • Method Details

    • dependenciesOf

      public Set<String> dependenciesOf(String className)
      Get the direct dependencies of a class. 获取一个类的直接依赖。
      Parameters:
      className - the class name | 类名
      Returns:
      set of class names this class depends on, or empty set if not found | 该类依赖的类名集合,若未找到则返回空集合
      Throws:
      NullPointerException - if className is null | 如果类名为 null 则抛出空指针异常
    • dependentsOf

      public Set<String> dependentsOf(String className)
      Get the classes that depend on the given class (reverse lookup). 获取依赖于给定类的类(反向查找)。
      Parameters:
      className - the class name | 类名
      Returns:
      set of class names that depend on the given class | 依赖于给定类的类名集合
      Throws:
      NullPointerException - if className is null | 如果类名为 null 则抛出空指针异常
    • classNames

      public Set<String> classNames()
      Get all class names in this graph. 获取此图中的所有类名。
      Returns:
      unmodifiable set of all class names | 所有类名的不可修改集合
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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.
    • adjacency

      public Map<String, Set<String>> adjacency()
      Returns the value of the adjacency record component.
      Returns:
      the value of the adjacency record component
    • classCount

      public int classCount()
      Returns the value of the classCount record component.
      Returns:
      the value of the classCount record component
    • edgeCount

      public int edgeCount()
      Returns the value of the edgeCount record component.
      Returns:
      the value of the edgeCount record component