class ChainBuilder {

    @SuppressWarnings("unchecked")
    public Chain<T> orderNodes() {
        List<T> chain = new ArrayList<>();
        OrderedReadyNodes readyNodes = getReadyNodes();

        while (!readyNodes.isEmpty() || popAllPhase(readyNodes) ) {
            Node candidate = readyNodes.pop();

            candidate.removed(readyNodes);

            if ( candidate instanceof ComponentNode)
                chain.add(((ComponentNode<T>)candidate).getComponent());
        }

        if (  chain.size() != numComponents)
            throw new CycleDependenciesException(nameProviders);

        //prevent accidental reuse
        nameProviders = null;

        return new Chain<>(id, chain);
    }

    public  ChainBuilder(ComponentId id);

}