Class ConditionDependencyGraph
java.lang.Object
software.amazon.smithy.rulesengine.logic.cfg.ConditionDependencyGraph
Graph of dependencies between conditions based on variable definitions and usage.
This class performs AST analysis once to extract:
- Variable definitions - which conditions define which variables
- Variable usage - which conditions use which variables
- Dependencies - which conditions must come before others
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal class
Order-specific constraints for a particular condition ordering. -
Constructor Summary
ConstructorsConstructorDescriptionConditionDependencyGraph
(List<Condition> conditions) Creates a dependency graph by analyzing the given conditions. -
Method Summary
Modifier and TypeMethodDescriptioncreateOrderConstraints
(List<Condition> ordering) Creates order constraints for a specific ordering of conditions.Gets the index mapping for conditions.getDependencies
(Condition condition) Gets the dependencies for a condition.int
getPredecessorCount
(int index) Gets the number of predecessors for a condition.getPredecessors
(int index) Gets the predecessors (dependencies) for a condition by index.int
getSuccessorCount
(int index) Gets the number of successors for a condition.getSuccessors
(int index) Gets the successors (dependents) for a condition by index.boolean
hasDependency
(int from, int to) Checks if there's a dependency from one condition to another.int
size()
Gets the number of conditions in this dependency graph.
-
Constructor Details
-
ConditionDependencyGraph
Creates a dependency graph by analyzing the given conditions.- Parameters:
conditions
- the conditions to analyze
-
-
Method Details
-
getDependencies
Gets the dependencies for a condition.- Parameters:
condition
- the condition to query- Returns:
- set of conditions that must come before it (never null)
-
getPredecessors
Gets the predecessors (dependencies) for a condition by index.- Parameters:
index
- the condition index- Returns:
- set of predecessor indices
-
getSuccessors
Gets the successors (dependents) for a condition by index.- Parameters:
index
- the condition index- Returns:
- set of successor indices
-
getPredecessorCount
public int getPredecessorCount(int index) Gets the number of predecessors for a condition.- Parameters:
index
- the condition index- Returns:
- the predecessor count
-
getSuccessorCount
public int getSuccessorCount(int index) Gets the number of successors for a condition.- Parameters:
index
- the condition index- Returns:
- the successor count
-
hasDependency
public boolean hasDependency(int from, int to) Checks if there's a dependency from one condition to another.- Parameters:
from
- the dependent condition indexto
- the dependency condition index- Returns:
- true if 'from' depends on 'to'
-
createOrderConstraints
Creates order constraints for a specific ordering of conditions.- Parameters:
ordering
- the ordering to compute constraints for- Returns:
- the order constraints
-
getConditionToIndex
Gets the index mapping for conditions.- Returns:
- map from condition to index
-
size
public int size()Gets the number of conditions in this dependency graph.- Returns:
- the number of conditions
-