void ( RefClass refClass, Set<? super RefClass> newDependencies) { final LinkedList<RefClass> pendingClasses = new LinkedList<>(); final Set<RefClass> processedClasses = new HashSet<>(); pendingClasses.addLast(refClass); while (!pendingClasses.isEmpty()) { final RefClass classToProcess = pendingClasses.removeFirst(); newDependencies.add(classToProcess); processedClasses.add(classToProcess); final Set<RefClass> dependencies = calculateInitializationDependenciesForClass(classToProcess); for (RefClass dependency : dependencies) { if (!pendingClasses.contains(dependency) && !processedClasses.contains(dependency)) { pendingClasses.addLast(dependency); } } } newDependencies.remove(refClass); }