// Path: modularitycheck/src/br/ufmg/dcc/labsoft/aserg/modularitycheck/distribution/control/metrics/TopicFocus.java
// public class TopicFocus extends AbstractSemanticTopicMetric {
// 	
// 	public TopicFocus(DistributionMap distributionMap, int numClusters) {
// 		super(distributionMap, numClusters);
// 	}
// 
// 	private double calculate(int topicIndex) {
// 		double focus = 0D;
// 		for (String packageName : this.distributionMap.getPackages())
// 			focus += this.calculateTopicTouch(topicIndex, packageName) * this.calculatePackageTouch(packageName, topicIndex);
// 		return focus;
// 	}
// 
// 	public Map<String, Double> calculate() {
// 		Map<String, Double> metricMapping = new HashMap<String, Double>();
// 		for (int topicIndex = 0; topicIndex < this.numClusters; topicIndex++)
// 			metricMapping.put(String.valueOf(topicIndex), calculate(topicIndex));
// 		return metricMapping;
// 	}
// }
// 
// Path: modularitycheck/src/br/ufmg/dcc/labsoft/aserg/modularitycheck/distribution/control/metrics/TopicSpread.java
// public class TopicSpread extends AbstractSemanticTopicMetric {
// 	
// 	public TopicSpread(DistributionMap distributionMap, int numClusters) {
// 		super(distributionMap, numClusters);
// 	}
// 	
// 	private double calculate(int topicIndex) {
// 		double spread = 0D;
// 		for (String packageName : this.distributionMap.getPackages())
// 			spread += (this.calculateTopicTouch(topicIndex, packageName) > 0) ? 1 : 0;
// 		return spread;
// 	}
// 
// 	public Map<String, Double> calculate() {
// 		Map<String, Double> metricMapping = new HashMap<String, Double>();
// 		for (int topicIndex = 0; topicIndex < this.numClusters; topicIndex++)
// 			metricMapping.put(String.valueOf(topicIndex), calculate(topicIndex));
// 		return metricMapping;
// 	}
// }


import java.io.File;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import br.ufmg.dcc.labsoft.aserg.modularitycheck.distribution.control.metrics.TopicFocus;
import br.ufmg.dcc.labsoft.aserg.modularitycheck.distribution.control.metrics.TopicSpread;
		TopicInfo(double spread, double focus) {
			this.spread = spread;
			this.focus = focus;
		}
	}

	public static DistributionMap generateDistributionMap(String projectName,
			String[] documentIds, int[][] clusters) {
		DistributionMap distributionMap = new DistributionMap(projectName);
		for (int i = 0; i < clusters.length; i++) {
			for (int documentId : clusters[i]) {
				String document = documentIds[documentId];
				String packageName = document.substring(0,
						document.lastIndexOf(File.separatorChar)).replace(
						File.separatorChar, '.');
				String className = document;

				distributionMap.put(packageName, className, i);
			}
		}
		distributionMap = addSemanticClustersMetrics(distributionMap,
				clusters.length);
		distributionMap.organize();
		return distributionMap;
	}

	public static DistributionMap addSemanticClustersMetrics(
			DistributionMap distributionMap, int numClusters) {
		Map<String, Double> spread = new TopicSpread(distributionMap,
				numClusters).calculate();
// Path: modularitycheck/src/br/ufmg/dcc/labsoft/aserg/modularitycheck/distribution/control/metrics/TopicFocus.java
// public class TopicFocus extends AbstractSemanticTopicMetric {
// 	
// 	public TopicFocus(DistributionMap distributionMap, int numClusters) {
// 		super(distributionMap, numClusters);
// 	}
// 
// 	private double calculate(int topicIndex) {
// 		double focus = 0D;
// 		for (String packageName : this.distributionMap.getPackages())
// 			focus += this.calculateTopicTouch(topicIndex, packageName) * this.calculatePackageTouch(packageName, topicIndex);
// 		return focus;
// 	}
// 
// 	public Map<String, Double> calculate() {
// 		Map<String, Double> metricMapping = new HashMap<String, Double>();
// 		for (int topicIndex = 0; topicIndex < this.numClusters; topicIndex++)
// 			metricMapping.put(String.valueOf(topicIndex), calculate(topicIndex));
// 		return metricMapping;
// 	}
// }
// 
// Path: modularitycheck/src/br/ufmg/dcc/labsoft/aserg/modularitycheck/distribution/control/metrics/TopicSpread.java
// public class TopicSpread extends AbstractSemanticTopicMetric {
// 	
// 	public TopicSpread(DistributionMap distributionMap, int numClusters) {
// 		super(distributionMap, numClusters);
// 	}
// 	
// 	private double calculate(int topicIndex) {
// 		double spread = 0D;
// 		for (String packageName : this.distributionMap.getPackages())
// 			spread += (this.calculateTopicTouch(topicIndex, packageName) > 0) ? 1 : 0;
// 		return spread;
// 	}
// 
// 	public Map<String, Double> calculate() {
// 		Map<String, Double> metricMapping = new HashMap<String, Double>();
// 		for (int topicIndex = 0; topicIndex < this.numClusters; topicIndex++)
// 			metricMapping.put(String.valueOf(topicIndex), calculate(topicIndex));
// 		return metricMapping;
// 	}
// }


// Path: modularitycheck/src/br/ufmg/dcc/labsoft/aserg/modularitycheck/distribution/control/DistributionMap.java
import java.io.File;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import br.ufmg.dcc.labsoft.aserg.modularitycheck.distribution.control.metrics.TopicFocus;
import br.ufmg.dcc.labsoft.aserg.modularitycheck.distribution.control.metrics.TopicSpread;

		TopicInfo(double spread, double focus) {
			this.spread = spread;
			this.focus = focus;
		}
	}

	public static DistributionMap generateDistributionMap(String projectName,
			String[] documentIds, int[][] clusters) {
		DistributionMap distributionMap = new DistributionMap(projectName);
		for (int i = 0; i < clusters.length; i++) {
			for (int documentId : clusters[i]) {
				String document = documentIds[documentId];
				String packageName = document.substring(0,
						document.lastIndexOf(File.separatorChar)).replace(
						File.separatorChar, '.');
				String className = document;

				distributionMap.put(packageName, className, i);
			}
		}
		distributionMap = addSemanticClustersMetrics(distributionMap,
				clusters.length);
		distributionMap.organize();
		return distributionMap;
	}

	public static DistributionMap addSemanticClustersMetrics(
			DistributionMap distributionMap, int numClusters) {
		Map<String, Double> spread = new TopicSpread(distributionMap,
				numClusters).calculate();
		Map<String, Double> focus = new TopicFocus(distributionMap, numClusters)