Class CycleDetector
java.lang.Object
cloud.opencode.base.tree.validation.CycleDetector
Cycle Detector
循环检测器
Detects cycles in tree or graph structures.
检测树或图结构中的循环。
Features | 主要功能:
- Cycle detection in tree structures - 树结构中的循环检测
- Cycle path extraction - 循环路径提取
- Flat list cycle detection - 扁平列表循环检测
Usage Examples | 使用示例:
boolean hasCycle = CycleDetector.hasCycle(roots);
Optional<List<ID>> path = CycleDetector.findCyclePath(roots);
CycleDetector.checkNoCycle(roots); // throws CycleDetectedException
Security | 安全性:
- Thread-safe: No - 否
- Null-safe: No (roots must not be null) - 否(根节点不能为null)
- Since:
- JDK 25, opencode-base-tree V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Treeable<T,ID>, ID>
voidcheckNoCycle(List<T> roots) Check for cycle and throw if found 检查循环,如果发现则抛出异常findCyclePath(List<T> roots) Detect cycle and return path 检测循环并返回路径static <T extends Treeable<T,ID>, ID>
booleanCheck if tree has cycles 检查树是否有循环static <T extends Treeable<T,ID>, ID>
booleanhasPotentialCycle(List<T> nodes) Check flat list for potential cycles 检查扁平列表中的潜在循环
-
Method Details
-
hasCycle
-
findCyclePath
-
checkNoCycle
Check for cycle and throw if found 检查循环,如果发现则抛出异常- Type Parameters:
T- the node type | 节点类型ID- the ID type | ID类型- Parameters:
roots- the root nodes | 根节点- Throws:
CycleDetectedException- if cycle is found | 如果发现循环抛出异常
-
hasPotentialCycle
Check flat list for potential cycles 检查扁平列表中的潜在循环- Type Parameters:
T- the node type | 节点类型ID- the ID type | ID类型- Parameters:
nodes- the nodes to check | 要检查的节点- Returns:
- true if potential cycle exists | 如果存在潜在循环返回true
-