static List < Dependency > rootCycleAt ( List < Dependency > cycle , Key < ? > key ) { for ( int i = 0 ; i < cycle . size ( ) ; ++ i ) { if ( key . equals ( cycle . get ( i ) . getSource ( ) ) ) { List < Dependency > returnValue = new ArrayList < Dependency > ( ) ; returnValue . addAll ( cycle . subList ( i , cycle . size ( ) ) ) ; returnValue . addAll ( cycle . subList ( 0 , i ) ) ; return returnValue ; } } return cycle ; }
Attempts to root the given dependency cycle at the given key . If the key is present in the cycle rotates the dependency cycle so that the key is the first source . Otherwise returns the cycle unchanged .