public CommitOrderDependencyNode nodeFor(ClassDescriptor d) {
   for (Enumeration e = nodes.elements(); e.hasMoreElements(); ) {
     CommitOrderDependencyNode n = (CommitOrderDependencyNode) e.nextElement();
     if (n.getDescriptor() == d) {
       return n;
     }
   }
   return null;
 }
  /**
   * Calculate the commit order. Do a depth first search on the graph, skipping nodes that we have
   * already visited or are in the process of visiting. Keep a counter and note when we first
   * encounter a node and when we finish visiting it. Once we've visited everything, sort nodes by
   * finishing time
   */
  public void orderCommits() {
    depthFirstSearch();

    Object[] nodeArray = new Object[nodes.size()];
    nodes.copyInto(nodeArray);

    quicksort(nodeArray);
    Vector result = new Vector(nodes.size());
    for (int i = 0; i < nodes.size(); i++) {
      CommitOrderDependencyNode node = (CommitOrderDependencyNode) nodeArray[i];
      result.addElement(node.getDescriptor());
    }
    this.orderedDescriptors = result;
  }
  public void depthFirstSearch() {

    /*
     * Traverse the entire graph in breadth-first order. When finished, every node will have a
     * predecessor which indicates the node that came before it in the search
     * It will also have a discovery time (the value of the counter when we first saw it) and
     * finishingTime (the value of the counter after we've visited all the adjacent nodes).
     * See Cormen, Leiserson and Rivest, Section 23.3, page 477 for a full explanation of the algorithm
     */

    // Setup
    for (Enumeration e = getNodes().elements(); e.hasMoreElements(); ) {
      CommitOrderDependencyNode node = (CommitOrderDependencyNode) e.nextElement();
      node.markNotVisited();
      node.setPredecessor(null);
    }
    currentTime = 0;

    // Execution
    for (Enumeration e = getNodes().elements(); e.hasMoreElements(); ) {
      CommitOrderDependencyNode node = (CommitOrderDependencyNode) e.nextElement();
      if (node.hasNotBeenVisited()) {
        node.visit();
      }
    }
  }
 /** Add to each node the dependent nodes */
 public void calculateSpecifiedDependencies() {
   for (Enumeration e = nodes.elements(); e.hasMoreElements(); ) {
     CommitOrderDependencyNode node = (CommitOrderDependencyNode) e.nextElement();
     node.recordSpecifiedDependencies();
   }
 }