public LinkedList<LinkedList<Node>> computeWeaklyConnectedComponents(Graph graph, HashMap<Node, Integer> indices) {
        int N = graph.getNodeCount();

        //Keep track of which nodes have been seen
        int[] color = new int[N];

        Progress.start(progress, N);

        int seenCount = 0;

        LinkedList<LinkedList<Node>> components = new LinkedList<>();
        while (seenCount < N) {
            //The search Q
            LinkedList<Node> Q = new LinkedList<>();
            //The component-list
            LinkedList<Node> component = new LinkedList<>();

            //Seed the search Q
            NodeIterable iter = graph.getNodes();
            for (Node next : iter) {
                if (color[indices.get(next)] == 0) {
                    Q.add(next);
                    iter.doBreak();
                    break;
                }
            }

            //While there are more nodes to search
            while (!Q.isEmpty()) {

                if (isCanceled) {
                    return new LinkedList<>();
                }
                //Get the next Node and add it to the component list
                Node u = Q.removeFirst();
                component.add(u);

                color[indices.get(u)] = 2;

                //Iterate over all of u's neighbors
                EdgeIterable edgeIter = graph.getEdges(u);

                //For each neighbor
                for (Edge edge : edgeIter) {
                    Node reachable = graph.getOpposite(u, edge);
                    int id = indices.get(reachable);
                    //If this neighbor is unvisited
                    if (color[id] == 0) {
                        //Mark it as used 
                        color[id] = 1;
                        //Add it to the search Q
                        Q.addLast(reachable);
                    }
                }

                seenCount++;
                Progress.progress(progress, seenCount);
            }

            components.add(component);
        }

        return components;
    }
@Test
    public void testComputeSelfLoopNodeAndIsolatedNodeWeaklyConnectedComponents() {
        GraphModel graphModel = GraphModel.Factory.newInstance();
        UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
        Node node1 = graphModel.factory().newNode("0");
        Node node2 = graphModel.factory().newNode("1");
        Node node3 = graphModel.factory().newNode("2");
        undirectedGraph.addNode(node1);
        undirectedGraph.addNode(node2);
        undirectedGraph.addNode(node3);
        Edge edge11 = graphModel.factory().newEdge(node1, node1, false);
        Edge edge12 = graphModel.factory().newEdge(node1, node2, false);
        undirectedGraph.addEdge(edge11);
        undirectedGraph.addEdge(edge12);

        ConnectedComponents c = new ConnectedComponents();
        HashMap<Node, Integer> indices = new HashMap<>();

        indices.put(node1, 0);
        indices.put(node2, 1);
        indices.put(node3, 2);

        LinkedList<LinkedList<Node>> components = c.computeWeaklyConnectedComponents(undirectedGraph, indices);
        assertEquals(components.size(), 2);
    }