Class CycleDetector

java.lang.Object
com.tngtech.archunit.library.cycle_detection.CycleDetector

@PublicAPI(usage=ACCESS, state=EXPERIMENTAL) public final class CycleDetector extends Object
See Also:
  • Method Details

    • detectCycles

      @PublicAPI(usage=ACCESS, state=EXPERIMENTAL) public static <NODE, EDGE extends Edge<NODE>> Cycles<EDGE> detectCycles(Collection<NODE> nodes, Collection<EDGE> edges)
      Detects cycles in directed graphs consisting of nodes of type NODE which are connected by directed edges of type EDGE.
      All reported cycles are "simple" cycles, i.e. they pass each node at most once. The algorithm reports all such simple cycles, even if nodes / edges are already part of another cycle. Consider the following case:

      Then both cycles, red and blue, would be reported.

      For performance reasons the CycleDetector has a maximum number of cycles to detect. Once this limit is reached the algorithm will terminate and all cycles so far will be reported. For further information please refer to Cycles.maxNumberOfCyclesReached().

      Note that the given edges must only reference the given nodes as their origin and target or an exception will be thrown.
      Also, the passed NODE types must implement an appropriate and reasonably performant Object.equals(Object) and Object.hashCode().
      Parameters:
      nodes - The nodes of the graph to create
      edges - The edges connecting the nodes of the graph
      Returns:
      All cycles within the graph created from the passed nodes and edges.