private boolean tarjan ( final AbstractJobVertex jv , Integer index , final HashMap < AbstractJobVertex , Integer > indexMap , final HashMap < AbstractJobVertex , Integer > lowLinkMap , final Stack < AbstractJobVertex > stack ) { indexMap . put ( jv , Integer . valueOf ( index ) ) ; lowLinkMap . put ( jv , Integer . valueOf ( index ) ) ; index = Integer . valueOf ( index . intValue ( ) + 1 ) ; stack . push ( jv ) ; for ( int i = 0 ; i < jv . getNumberOfForwardConnections ( ) ; i ++ ) { final AbstractJobVertex jv2 = jv . getForwardConnection ( i ) . getConnectedVertex ( ) ; if ( ! indexMap . containsKey ( jv2 ) || stack . contains ( jv2 ) ) { if ( ! indexMap . containsKey ( jv2 ) ) { if ( ! tarjan ( jv2 , index , indexMap , lowLinkMap , stack ) ) { return false ; } } if ( lowLinkMap . get ( jv ) > lowLinkMap . get ( jv2 ) ) { lowLinkMap . put ( jv , Integer . valueOf ( lowLinkMap . get ( jv2 ) ) ) ; } } } if ( lowLinkMap . get ( jv ) . equals ( indexMap . get ( jv ) ) ) { int count = 0 ; while ( stack . size ( ) > 0 ) { final AbstractJobVertex jv2 = stack . pop ( ) ; if ( jv == jv2 ) { break ; } count ++ ; } if ( count > 0 ) { return false ; } } return true ; }
Auxiliary method implementing Tarjan s algorithm for strongly - connected components to determine whether the job graph is acyclic .