Source:
protected void updateAggregateStatistics(List<HostState> hosts) { aggregateStatisticsLock.lock(); try { updateActiveJobIDs(); double maxMeanActive = -1; double maxDiskPercentUsed = -1; double minDiskPercentUsed = 0; double sumDiskPercentUsed = 0; double maxTaskPercent = 0; double minTaskPercent = 1; double sumTaskPercent = 0; for (HostState host : hosts) { maxMeanActive = Math.max(maxMeanActive, host.getMeanActiveTasks()); double diskPercentUsed = getUsedDiskPercent(host); sumDiskPercentUsed += diskPercentUsed; maxDiskPercentUsed = Math.max(diskPercentUsed, maxDiskPercentUsed); minDiskPercentUsed = Math.min(diskPercentUsed, minDiskPercentUsed); double taskPercent = host.getMeanActiveTasks(); sumTaskPercent += taskPercent; maxTaskPercent = Math.max(taskPercent, maxTaskPercent); minTaskPercent = Math.min(taskPercent, minTaskPercent); } int numScores = hosts.size(); double avgDiskPercentUsed = sumDiskPercentUsed / (double) numScores; double sumDiskPercentUsedDiff = 0; double avgTaskPercent = sumTaskPercent / (double) numScores; double sumTaskPercentDiff = 0; for (HostState host : hosts) { HostScore score = calculateHostScore(host, maxMeanActive, maxDiskPercentUsed); cachedHostScores.put(host.getHostUuid(), score); double diskDiff = Math.abs(avgDiskPercentUsed - getUsedDiskPercent(host)); sumDiskPercentUsedDiff += diskDiff; double taskDiff = cachedHostScores.get(host.getHostUuid()).getScoreValue(false); sumTaskPercentDiff += Math.abs(avgTaskPercent - taskDiff); } avgDiskPercentUsedDiff = sumDiskPercentUsedDiff / (double) numScores; avgTaskPercentDiff = sumTaskPercentDiff / (double) numScores; minDiskPercentUsedDiff = avgDiskPercentUsed - minDiskPercentUsed; maxDiskPercentUsedDiff = maxDiskPercentUsed - avgDiskPercentUsed; minTaskPercentDiff = avgTaskPercent - minTaskPercent; maxTaskPercentDiff = maxTaskPercent - avgTaskPercent; } finally { aggregateStatisticsLock.unlock(); } }

Target:
protected void updateAggregateStatistics(List<HostState> hosts) { aggregateStatisticsLock.lock(); try { updateActiveJobIDs(); double maxMeanActive = -1; double maxDiskPercentUsed = -1; double minDiskPercentUsed = 0; double sumDiskPercentUsed = 0; double maxTaskPercent = 0; double minTaskPercent = 1; double sumTaskPercent = 0; for (HostState host : hosts) { maxMeanActive = Math.max(maxMeanActive, host.getMeanActiveTasks()); double diskPercentUsed = getUsedDiskPercent(host); sumDiskPercentUsed += diskPercentUsed; maxDiskPercentUsed = Math.max(diskPercentUsed, maxDiskPercentUsed); minDiskPercentUsed = Math.min(diskPercentUsed, minDiskPercentUsed); double taskPercent = host.getMeanActiveTasks(); sumTaskPercent += taskPercent; maxTaskPercent = Math.max(taskPercent, maxTaskPercent); minTaskPercent = Math.min(taskPercent, minTaskPercent); } int numScores = hosts.size(); double avgDiskPercentUsed = sumDiskPercentUsed / (double) numScores; double sumDiskPercentUsedDiff = 0; double avgTaskPercent = sumTaskPercent / (double) numScores; double sumTaskPercentDiff = 0; for (HostState host : hosts) { HostScore score = calculateHostScore(host, maxMeanActive, maxDiskPercentUsed); cachedHostScores.put(host.getHostUuid(), score); double diskDiff = Math.abs(avgDiskPercentUsed - getUsedDiskPercent(host)); sumDiskPercentUsedDiff += diskDiff; double taskDiff = score.getScoreValue(false); sumTaskPercentDiff += Math.abs(avgTaskPercent - taskDiff); } avgDiskPercentUsedDiff = sumDiskPercentUsedDiff / (double) numScores; avgTaskPercentDiff = sumTaskPercentDiff / (double) numScores; minDiskPercentUsedDiff = avgDiskPercentUsed - minDiskPercentUsed; maxDiskPercentUsedDiff = maxDiskPercentUsed - avgDiskPercentUsed; minTaskPercentDiff = avgTaskPercent - minTaskPercent; maxTaskPercentDiff = maxTaskPercent - avgTaskPercent; } finally { aggregateStatisticsLock.unlock(); } }