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.reportdefinitions.types.CalculationType; 6 7 14 public abstract class MetricCalculationStrategy { 15 16 17 18 public abstract Object operate(Object [] node, int index, Object measure, Object [] aRow); 19 20 public static MetricCalculationStrategy getMetricStrategyFor(ReportMetricSpec reportMetricSpec) { 21 CalculationType type = reportMetricSpec.getAggregateType(); 22 return doGetStrategyFor(reportMetricSpec, type); 23 } 24 25 public static MetricCalculationStrategy getFooterStrategyFor(ReportMetricSpec reportMetricSpec) { 26 CalculationType type = reportMetricSpec.getGroupFooterType(); 27 return doGetStrategyFor(reportMetricSpec, type); 28 } 29 30 36 private static MetricCalculationStrategy doGetStrategyFor(ReportMetricSpec metricSpec, CalculationType type) { 37 if(type==null){ 38 return new SumStrategy(); 39 } 40 switch(type.getType()){ 41 case CalculationType.AVERAGE_TYPE: 42 return new AverageStrategy(); 43 case CalculationType.COUNT_TYPE: 44 return new CountStrategy(); 45 case CalculationType.MAX_TYPE: 46 return new MaxStrategy(); 47 case CalculationType.MIN_TYPE: 48 return new MinStrategy(); 49 case CalculationType.SUM_TYPE: 50 return new SumStrategy(); 51 case CalculationType.CALCULATED_TYPE: 52 return new CalculatedStrategy(metricSpec); 53 case CalculationType.COUNT_DISTINCT_TYPE: 54 return new CountDistinctStrategy(metricSpec); 55 default: 56 return new SumStrategy(); 57 } 58 } 59 60 public abstract String getSQLFunction() throws InfoException; 61 } 62 | Popular Tags |