private void handleNextState(DependencyGraph graph, LinkedList<Object> instances, Injector injector, ClassMapper classMapper, AtomicBoolean hasAnythingChanged, AtomicInteger nextState) {
        Set<DependencyNode> unfinished;// Get a set of the nodes that has not yet reached that state,
        // and operate upon it until it is empty
        while (!(unfinished = graph.nodes()
            .filter(n -> n.getCurrentState().ordinal() < nextState.get())
            .collect(toSet())).isEmpty()) {

            hasAnythingChanged.set(false);

            unfinished.forEach(n -> {
                // Determine the next state of this node.
                final State state = n.getCurrentState().next();

                // Check if all its dependencies have been satisfied.
                if (n.canBe(state)) {

                    INTERNAL_LOGGER.debug(HORIZONTAL_LINE);

                    // Retrieve the instance for that node
                    final Object instance = findIn(
                        n.getRepresentedType(),
                        injector,
                        instances,
                        false
                    );
                    // Execute all the executions for the next step.
                    n.getExecutions().stream()
                        .filter(e -> e.getState() == state)
                        .map(exec -> {
                            @SuppressWarnings("unchecked")
                            final Execution<Object> casted =
                                (Execution<Object>) exec;
                            return casted;
                        })
                        .forEach(exec -> executionHandler(graph, classMapper, instance, exec));

                    // Update its state to the new state.
                    n.setState(state);
                    hasAnythingChanged.set(true);

                    INTERNAL_LOGGER.debug(
                        "| %-66s %12s |",
                        limit(n.getRepresentedType().getSimpleName(), 66),
                        limit(state.name(), 12)
                    );
                }
            });

            // The set was not empty when we entered the 'while' clause,
            // and yet nothing has changed. This means that we are stuck
            // in an infinite loop.
            if (!hasAnythingChanged.get()) {
                throw new IllegalStateException("The injector appears to be stuck in an infinite loop.");
            }
        }

        // Every node has reached the desired state.
        // Begin working with the next state.
        nextState.incrementAndGet();
    }
Default implementation of the {@link InjectorBuilder}-interface.

@author Emil Forslund
@since  1.2.0
common-parent/injector/src/main/java/com/speedment/common/injector/internal/InjectorBuilderImpl.java