/* 
 * Mutability Detector
 *
 * Copyright 2009 Graham Allan
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * 		http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.mutabilitydetector.checkers;

import static java.lang.Integer.valueOf;
import static org.mutabilitydetector.IAnalysisSession.IsImmutable.DEFINITELY;
import static org.mutabilitydetector.IAnalysisSession.IsImmutable.DEFINITELY_NOT;
import static org.mutabilitydetector.IAnalysisSession.IsImmutable.MAYBE;
import static org.mutabilitydetector.IAnalysisSession.IsImmutable.PROBABLY;

import java.util.Map;

import org.mutabilitydetector.IAnalysisSession.IsImmutable;


public final class ResultCalculator {
	public IsImmutable calculateImmutableStatus(Map<IsImmutable, Integer> results) {
		IsImmutable isImmutable;
		int numDefinitely = getNumOfResult(results, DEFINITELY);
		int numProbably = getNumOfResult(results, PROBABLY);
		int numMaybe = getNumOfResult(results, MAYBE);
		int numDefinitelyNot = getNumOfResult(results, DEFINITELY_NOT);
		
		if(numDefinitelyNot > 0) {
			isImmutable = DEFINITELY_NOT; 
		} else if(numMaybe > 0) {
			isImmutable = MAYBE;
		} else if(numProbably > 0) {
			isImmutable = PROBABLY;
		} else if(numDefinitely > 0) {
			isImmutable = DEFINITELY;
		} else {
			isImmutable = numProbably > numMaybe ? PROBABLY : MAYBE;
		}
		
		return isImmutable;
	}

	private int getNumOfResult(Map<IsImmutable, Integer> results, IsImmutable resultType) {
		if(! results.containsKey(resultType)) { return valueOf(0); }
		
		Integer numOfResultType = valueOf(results.get(resultType));
		if(numOfResultType != null) {
			return numOfResultType.intValue();
		} else {
			return valueOf(0);
		}
	}
}

@@ -936,84 +936,8 @@
 YBE;
-%0Aimport static org.mutabilitydetector.IAnalysisSession.IsImmutable.PROBABLY;
 %0A%0Aim
@@ -1229,63 +1229,8 @@
 Y);%0A
-%09%09int numProbably = getNumOfResult(results, PROBABLY);%0A
 %09%09in
@@ -1462,66 +1462,8 @@
 BE;%0A
-%09%09%7D else if(numProbably %3E 0) %7B%0A%09%09%09isImmutable = PROBABLY;%0A
 %09%09%7D 
@@ -1531,16 +1531,16 @@
  else %7B%0A
+
 %09%09%09isImm
@@ -1551,44 +1551,8 @@
 le =
- numProbably %3E numMaybe ? PROBABLY :
  MAY

Begin rework of 'spectrum of immutability' to be a bit more meaningful. First step is to get rid of the 'PROBABLY' immutable result.