public static < T > void verify ( List < Vertex < T > > vertices ) throws CyclicDependencyException { // Reset the orders of all the vertices. resetVertices ( vertices ) ; // Assert that all vertices are in the vertices list and resolve each of their orders. Iterator < Vertex < T > > it = vertices . iterator ( ) ; while ( it . hasNext ( ) ) { Vertex < T > v = it . next ( ) ; // Make sure that any dependencies are also in the vertices list. This adds // a little bit to the load, but we don't test this and the test would have // failed, this would lead to some very hard to track down problems elsewhere. Iterator < Vertex < T > > dit = v . getDependencies ( ) . iterator ( ) ; while ( dit . hasNext ( ) ) { Vertex < T > dv = dit . next ( ) ; if ( ! vertices . contains ( dv ) ) { throw new IllegalStateException ( "A dependent vertex (" + dv . getName ( ) + ") of " + "vertex (" + v . getName ( ) + ") was not included in the vertices list." ) ; } } v . resolveOrder ( ) ; } }
Verify a set of vertices and all their dependencies have no cycles . All Vertices in the graph must exist in the list .