private void cleanClusters()
	{
		//System.out.println("Clean Clusters");
		Iterator<GridCluster> clusIter = this.cluster_list.iterator();
		ArrayList<GridCluster> toRem = new ArrayList<GridCluster>();

		// Check to see if there are any empty clusters
		while(clusIter.hasNext())
		{
			GridCluster c = clusIter.next();

			if(c.getWeight() == 0)
				toRem.add(c);
		}

		// Remove empty clusters
		if (!toRem.isEmpty())
		{
			clusIter = toRem.iterator();

			while(clusIter.hasNext())
			{
				this.cluster_list.remove(clusIter.next());
			}
		}

		// Adjust remaining clusters as necessary
		clusIter = this.cluster_list.iterator();

		while(clusIter.hasNext())
		{
			GridCluster c = clusIter.next();
			int index = this.cluster_list.indexOf(c);

			c.setClusterLabel(index);
			this.cluster_list.set(index, c);

			Iterator<Map.Entry<DensityGrid, Boolean>> gridsOfClus = c.getGrids().entrySet().iterator();

			while(gridsOfClus.hasNext())
			{
				DensityGrid dg = gridsOfClus.next().getKey();
				CharacteristicVector cv = this.grid_list.get(dg);
				if(cv == null)
				{
					System.out.println("Warning, cv is null for "+dg.toString()+" from cluster "+index+".");
					printGridList();
					printGridClusters();
				}
				//System.out.println("Cluster "+index+": "+dg.toString()+" is here.");
				cv.setLabel(index);
				this.grid_list.put(dg, cv);
			}
		}
	}
private void cleanClusters ( ) { Iterator < GridCluster > clusIter = this . cluster_list . iterator ( ) ; ArrayList < GridCluster > toRem = new ArrayList < GridCluster > ( ) ; while ( clusIter . hasNext ( ) ) { GridCluster c = clusIter . next ( ) ; if ( c . getWeight ( ) == 0 ) toRem . add ( c ) ; } if ( ! toRem . isEmpty ( ) ) { clusIter = toRem . iterator ( ) ; while ( clusIter . hasNext ( ) ) { this . cluster_list . remove ( clusIter . next ( ) ) ; } } clusIter = this . cluster_list . iterator ( ) ; while ( clusIter . hasNext ( ) ) { GridCluster c = clusIter . next ( ) ; int index = this . cluster_list . indexOf ( c ) ; c . setClusterLabel ( index ) ; this . cluster_list . set ( index , c ) ; Iterator < Map . Entry < DensityGrid , Boolean > > gridsOfClus = c . getGrids ( ) . entrySet ( ) . iterator ( ) ; while ( gridsOfClus . hasNext ( ) ) { DensityGrid dg = gridsOfClus . next ( ) . getKey ( ) ; CharacteristicVector cv = this . grid_list . get ( dg ) ; if ( cv == null ) { System . out . println ( "Warning, cv is null for " + dg . toString ( ) + " from cluster " + index + "." ) ; printGridList ( ) ; printGridClusters ( ) ; } cv . setLabel ( index ) ; this . grid_list . put ( dg , cv ) ; } } }
Iterates through cluster_list to ensure that all empty clusters have been removed and
that all cluster IDs match the cluster's index in cluster_list.