Class GraphAnalyzer
- java.lang.Object
-
- org.mapstruct.ap.internal.model.dependency.GraphAnalyzer
-
public class GraphAnalyzer extends java.lang.ObjectAnalyzes graphs: Discovers all descendants of given nodes and detects cyclic dependencies between nodes if present.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGraphAnalyzer.GraphAnalyzerBuilder
-
Field Summary
Fields Modifier and Type Field Description private java.util.Stack<Node>currentPathprivate java.util.Set<java.util.List<java.lang.String>>cyclesprivate intnextTraversalSequenceprivate java.util.Map<java.lang.String,Node>nodes
-
Constructor Summary
Constructors Modifier Constructor Description privateGraphAnalyzer(java.util.Map<java.lang.String,Node> nodes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidanalyze()Performs a full traversal of the graph, detecting potential cycles and calculates the full list of descendants of the nodes.static GraphAnalyzer.GraphAnalyzerBuilderbuilder()private voiddepthFirstSearch(Node node)private java.util.List<java.lang.String>getCurrentCycle(Node start)java.util.Set<java.util.List<java.lang.String>>getCycles()intgetTraversalSequence(java.lang.String name)Returns the traversal sequence number of the given node.static GraphAnalyzer.GraphAnalyzerBuilderwithNode(java.lang.String name, java.lang.String... descendants)
-
-
-
Constructor Detail
-
GraphAnalyzer
private GraphAnalyzer(java.util.Map<java.lang.String,Node> nodes)
-
-
Method Detail
-
builder
public static GraphAnalyzer.GraphAnalyzerBuilder builder()
-
withNode
public static GraphAnalyzer.GraphAnalyzerBuilder withNode(java.lang.String name, java.lang.String... descendants)
-
analyze
private void analyze()
Performs a full traversal of the graph, detecting potential cycles and calculates the full list of descendants of the nodes.
-
getTraversalSequence
public int getTraversalSequence(java.lang.String name)
Returns the traversal sequence number of the given node. The ascending order of the traversal sequence numbers of multiple nodes represents the depth-first traversal order of those nodes.Note: The traversal sequence numbers will only be complete if the graph contains no cycles.
- Parameters:
name- the node name to get the traversal sequence number for- Returns:
- the traversal sequence number, or
-1if the node doesn't exist or the node was not visited (in case of cycles).
-
getCycles
public java.util.Set<java.util.List<java.lang.String>> getCycles()
-
depthFirstSearch
private void depthFirstSearch(Node node)
-
getCurrentCycle
private java.util.List<java.lang.String> getCurrentCycle(Node start)
-
-