package pete.metrics.adaptability;

import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

class AdaptabilityMetric {

	private Map<String, AdaptableElement> elements;

	private final static int REFERENCE_SCORE = 6;

	private AtomicInteger sum;

	private AtomicInteger maxDegree;

	public AdaptabilityMetric() {
		elements = new AdaptableElements().getElementsByName();
	}

	public double computeAdaptability(Map<String, AtomicInteger> processElements) {
		sum = new AtomicInteger(0);
		maxDegree = new AtomicInteger(0);
		processElements.keySet().forEach(
				elementName -> addElementAdaptability(processElements,
						elementName));
		if (maxDegree.get() == 0) {
			return 0;
		} else {
			return sum.doubleValue() / maxDegree.doubleValue();
		}
	}

	private void addElementAdaptability(
			Map<String, AtomicInteger> processElements, String elementName) {
		int number = processElements.get(elementName).get();
		int elementScore = elements.get(elementName).getAdaptabilityScore();
		sum.addAndGet(number * elementScore);
		maxDegree.addAndGet(number * REFERENCE_SCORE);
	}
}

@@ -193,44 +193,26 @@
 ate 
-f
 in
-al static int REFERENCE_SCORE = 6
+t referenceScore
 ;%0A%0A%09
@@ -363,16 +363,150 @@
 Name();%0A
+%09%09referenceScore = elements.values().parallelStream()%0A%09%09%09%09.mapToInt(element -%3E element.getAdaptabilityScore()).max()%0A%09%09%09%09.getAsInt();%0A
 %09%7D%0A%0A%09pub
@@ -1189,23 +1189,22 @@
 r * 
-REFERENCE_SCORE
+referenceScore
 );%0A%09

Compute reference score dynamically