@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);
    }
@Test
    void testRegular() throws Exception {
        ChainBuilder chainBuilder = createDependencyHandler();

        addAtoG(chainBuilder);

        Chain<ChainedComponent> res = chainBuilder.orderNodes();

        Iterator<ChainedComponent> i = res.components().iterator();
        for (char j = 0; j < 'G' - 'A'; ++j) {
            assertEquals(String.valueOf((char) ('A' + j)), name(i.next()));
        }
    }