1 package com.calipso.reportgenerator.reportcalculator; 2 3 import com.calipso.reportgenerator.common.ReportMetricSpec; 4 import com.calipso.reportgenerator.common.InfoException; 5 import com.calipso.reportgenerator.common.LanguageTraslator; 6 import com.calipso.reportgenerator.reportcalculator.expression.Expression; 7 8 import java.util.Map ; 9 import java.util.Collection ; 10 import java.util.Iterator ; 11 import java.util.HashMap ; 12 import java.io.Serializable ; 13 14 21 public class CalculatedStrategy extends MetricCalculationStrategy implements Serializable { 22 ReportMetricSpec metricSpec; 23 24 public CalculatedStrategy(ReportMetricSpec metricSpec){ 25 this.metricSpec = metricSpec; 26 } 27 28 public Object operate(Object [] node, int index, Object measure, Object [] aRow) { 29 Map map = metricSpec.getVariableIndexes(); 30 Map context = fillContext(node, map); 31 return SharedFloat.newFrom(metricSpec.getValue(context)); 32 } 33 34 public String getSQLFunction() throws InfoException { 35 throw new InfoException(LanguageTraslator.traslate("581") + "Calculated"); 36 } 37 38 private Map fillContext(Object [] node, Map map) { 39 Map context = new HashMap (); 40 Iterator iterator = map.entrySet().iterator(); 41 while (iterator.hasNext()) { 42 Map.Entry entry = (Map.Entry ) iterator.next(); 43 context.put(entry.getKey(), ((SharedFloat)node[((Integer ) entry.getValue()).intValue()]).getValue()); 44 } 45 return context; 46 } 47 48 } 49 | Popular Tags |