private List < ClasspathElement > findClasspathOrder ( final Set < ClasspathElement > uniqueClasspathElements , final Queue < Entry < Integer , ClasspathElement > > toplevelClasspathEltsIndexed ) { final List < ClasspathElement > toplevelClasspathEltsOrdered = orderClasspathElements ( toplevelClasspathEltsIndexed ) ; for ( final ClasspathElement classpathElt : uniqueClasspathElements ) { classpathElt . childClasspathElementsOrdered = orderClasspathElements ( classpathElt . childClasspathElementsIndexed ) ; } final Set < ClasspathElement > visitedClasspathElts = new HashSet <> ( ) ; final List < ClasspathElement > order = new ArrayList <> ( ) ; for ( final ClasspathElement toplevelClasspathElt : toplevelClasspathEltsOrdered ) { findClasspathOrderRec ( toplevelClasspathElt , visitedClasspathElts , order ) ; } return order ; }
Recursively perform a depth - first traversal of child classpath elements breaking cycles if necessary to determine the final classpath element order . This causes child classpath elements to be inserted in - place in the classpath order after the parent classpath element that contained them .