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 Summary
ConstructorsConstructorDescriptionDependencyGraph(Map<String, Set<String>> adjacency, int classCount, int edgeCount) Canonical constructor with null check and deep defensive copy. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theadjacencyrecord component.intReturns the value of theclassCountrecord component.Get all class names in this graph.dependenciesOf(String className) Get the direct dependencies of a class.dependentsOf(String className) Get the classes that depend on the given class (reverse lookup).intReturns the value of theedgeCountrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
DependencyGraph
-
-
Method Details
-
dependenciesOf
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
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
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
adjacency
-
classCount
public int classCount()Returns the value of theclassCountrecord component.- Returns:
- the value of the
classCountrecord component
-
edgeCount
-