summaryrefslogtreecommitdiff
path: root/java/src/org/singinst/uf/model/MultiplicationCalculation.java
blob: bc956cf481fc7e40da5a2decacbbcd1558753d52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package org.singinst.uf.model;

import java.util.ArrayList;
import java.util.List;

import org.singinst.uf.common.StringUtil;
import org.singinst.uf.presenter.HtmlUtil;

public class MultiplicationCalculation extends Calculation {

	private final Evaluable[] calculationArray;

	public MultiplicationCalculation(String description,
			Evaluable... calculationArray) {
		super(description, false);
		this.calculationArray = calculationArray;
	}

	@Override
	public double rawEvaluate(StringBuilder htmlConsole) {
		double retVal = 1;
		List<String> readableSubCalculationResultList = new ArrayList<String>();
		for (Evaluable subCalculation : calculationArray) {
			double subCalculationResult = subCalculation.evaluate(htmlConsole);
			retVal *= subCalculationResult;
//			String percentage = MathUtil.round(subCalculationResult * 100, 2) + "%"; //FIXME
//			String str = HtmlUtil.htmlcolorFromColor(((Calculation)subCalculation).getColor(), percentage);
			String str = HtmlUtil.htmlcolorFromColor(((Calculation)subCalculation).getColor(), 
					StringUtil.formatProbability(subCalculationResult));
			readableSubCalculationResultList.add(str);
		}
		htmlConsole.append(getDescription() + " = " + StringUtil.join(" * ", readableSubCalculationResultList));
		return retVal;
	}

	
}