KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > reportcalculator > MetricCalculationStrategy


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 /**
8  *
9  * User: jbassino
10  * Date: 03/11/2004
11  * Time: 14:30:43
12  *
13  */

14 public abstract class MetricCalculationStrategy {
15
16
17
18   public abstract Object JavaDoc operate(Object JavaDoc[] node, int index, Object JavaDoc measure, Object JavaDoc[] 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   /**
31    * Obtiene una estrategia de calculo según corresponda al valor del tipo de calculo especificado en el
32    * ReportSourceDefinition para cada metrica. Los tipos existentes pueden verse en CalculationType.
33    * @param metricSpec
34    * @return metricCalculationStrategy
35    */

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 JavaDoc getSQLFunction() throws InfoException;
61 }
62
Popular Tags