Class ConditionDependencyGraph

java.lang.Object
software.amazon.smithy.rulesengine.logic.cfg.ConditionDependencyGraph

public final class ConditionDependencyGraph extends Object
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
  • Constructor Details

    • ConditionDependencyGraph

      public ConditionDependencyGraph(List<Condition> conditions)
      Creates a dependency graph by analyzing the given conditions.
      Parameters:
      conditions - the conditions to analyze
  • Method Details

    • getDependencies

      public Set<Condition> getDependencies(Condition condition)
      Gets the dependencies for a condition.
      Parameters:
      condition - the condition to query
      Returns:
      set of conditions that must come before it (never null)
    • getPredecessors

      public Set<Integer> getPredecessors(int index)
      Gets the predecessors (dependencies) for a condition by index.
      Parameters:
      index - the condition index
      Returns:
      set of predecessor indices
    • getSuccessors

      public Set<Integer> getSuccessors(int index)
      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 index
      to - the dependency condition index
      Returns:
      true if 'from' depends on 'to'
    • createOrderConstraints

      public ConditionDependencyGraph.OrderConstraints createOrderConstraints(List<Condition> ordering)
      Creates order constraints for a specific ordering of conditions.
      Parameters:
      ordering - the ordering to compute constraints for
      Returns:
      the order constraints
    • getConditionToIndex

      public Map<Condition,Integer> 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