The ComponentForest object keeps track of connected components. Currently it only calculates weak components.

public class ComponentForest{
	
	int weakComponentClusters = 0;
	int maxWeakConnectedNodes = 0;

	//int strongComponentClusters = 0;
	//int maxStrongConnectedNodes = 0;

	int weakNodes;
	//int strongNodes;

	BigDecimal averageWeakConnectedness = new BigDecimal(0.0);
	//BigDecimal averageStrongConnectedness = new BigDecimal(0.0);

	public ComponentForest(){

	}

public HashMap weakComponentCalculation(final Graph grph, NetworkProperties np){
		HashMap clusters = new HashMap();
		HashSet seenNodes = new HashSet();
		int maxNodes = 0;
		int cluster = 0;
		for(Iterator it = grph.nodes(); it.hasNext();){
			Node n = (Node)it.next();
			Integer i = new Integer(n.getRow());
			if(!seenNodes.contains(i)){

				LinkedHashSet tree = np.uDFS(grph, i);
		
					seenNodes.addAll(tree);
					if(tree.size() > maxNodes)
						maxNodes = tree.size();
					
					clusters.put(new Integer(cluster), new HashSet(tree)); 
					cluster++;
				}
			
			
			}
		
		this.weakComponentClusters = clusters.keySet().size();
		this.maxWeakConnectedNodes = maxNodes;
		return clusters;
	}
}