001 /*
002 * Created on Sep 21, 2007
003 */
004 package com.x8ing.mc.web;
005
006 import java.text.DecimalFormat;
007
008 import javax.servlet.http.HttpServletRequest;
009
010 import org.apache.struts.action.ActionErrors;
011 import org.apache.struts.action.ActionForm;
012 import org.apache.struts.action.ActionMapping;
013 import org.apache.struts.action.ActionMessage;
014
015 import com.x8ing.mc.Configuration;
016 import com.x8ing.mc.MonteCarloControler;
017 import com.x8ing.mc.Statistic;
018 import com.x8ing.mc.bp.Constants;
019
020 /**
021 *
022 * @author Patrick Heusser
023 */
024 public class MCForm extends ActionForm {
025
026 private static final long serialVersionUID = -3131385288285080580L;
027
028 private Configuration configuration = new Configuration();
029
030 private MonteCarloControler monteCarloControlerResult = null;
031
032 public String getEarningAverage() {
033
034 if (monteCarloControlerResult != null) {
035 Statistic statistic = new Statistic(monteCarloControlerResult.getBalanceValues());
036 DecimalFormat df = Constants.createCurrencyFormater();
037
038 return df.format(statistic.getAverage());
039 }
040 return "n/a";
041 }
042
043 public String getEarningMaximum() {
044 if (monteCarloControlerResult != null) {
045 Statistic statistic = new Statistic(monteCarloControlerResult.getBalanceValues());
046 DecimalFormat df = Constants.createCurrencyFormater();
047
048 return df.format(statistic.getMinimumAndMaximum()[1]);
049 }
050 return "n/a";
051 }
052
053 public String getEarningMinimum() {
054 if (monteCarloControlerResult != null) {
055 Statistic statistic = new Statistic(monteCarloControlerResult.getBalanceValues());
056 DecimalFormat df = Constants.createCurrencyFormater();
057 return df.format(statistic.getMinimumAndMaximum()[0]);
058 }
059 return "n/a";
060 }
061
062 public Configuration getConfiguration() {
063 return configuration;
064 }
065
066 public void setConfiguration(Configuration configuration) {
067 this.configuration = configuration;
068 }
069
070 public MonteCarloControler getMonteCarloControlerResult() {
071 return monteCarloControlerResult;
072 }
073
074 public void setMonteCarloControlerResult(MonteCarloControler monteCarloControlerResult) {
075 this.monteCarloControlerResult = monteCarloControlerResult;
076 }
077
078 public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {
079
080 ActionErrors actionErrors = new ActionErrors();
081
082 final int maxCompleteSimulationLoops = 10000;
083 final int maxCollectMaxNumberOfBusinessContext = 20;
084 final int maxNumberOfSimulationDays = 180;
085
086 if (configuration.getNumberCompleteSimulationLoops() > maxCompleteSimulationLoops) {
087
088 actionErrors.add("configuration.numberCompleteSimulationLoops", new ActionMessage("validation.simloops", String
089 .valueOf(maxCompleteSimulationLoops)));
090 }
091
092 if (configuration.getCollectMaxNumberOfBusinessContext() > maxCollectMaxNumberOfBusinessContext) {
093
094 actionErrors.add("configuration.collectMaxNumberOfBusinessContext", new ActionMessage(
095 "validation.collectMaxNumberOfBusinessContext", String.valueOf(maxCollectMaxNumberOfBusinessContext)));
096 }
097
098 if (configuration.getNumberOfSimulationDays() > maxNumberOfSimulationDays) {
099
100 actionErrors.add("configuration.numberOfSimulationDays", new ActionMessage("validation.maxNumberSimulationDays",
101 String.valueOf(maxNumberOfSimulationDays)));
102 }
103
104 return actionErrors;
105 }
106
107 }
|