01: package com.calipso.reportgenerator.reportcalculator;
02:
03: import com.calipso.reportgenerator.common.ReportMetricSpec;
04: import com.calipso.reportgenerator.common.InfoException;
05: import com.calipso.reportgenerator.reportdefinitions.types.CalculationType;
06:
07: /**
08: *
09: * User: jbassino
10: * Date: 03/11/2004
11: * Time: 14:30:43
12: *
13: */
14: public abstract class MetricCalculationStrategy {
15:
16: public abstract Object operate(Object[] node, int index,
17: Object measure, Object[] aRow);
18:
19: public static MetricCalculationStrategy getMetricStrategyFor(
20: ReportMetricSpec reportMetricSpec) {
21: CalculationType type = reportMetricSpec.getAggregateType();
22: return doGetStrategyFor(reportMetricSpec, type);
23: }
24:
25: public static MetricCalculationStrategy getFooterStrategyFor(
26: ReportMetricSpec reportMetricSpec) {
27: CalculationType type = reportMetricSpec.getGroupFooterType();
28: return doGetStrategyFor(reportMetricSpec, type);
29: }
30:
31: /**
32: * Obtiene una estrategia de calculo según corresponda al valor del tipo de calculo especificado en el
33: * ReportSourceDefinition para cada metrica. Los tipos existentes pueden verse en CalculationType.
34: * @param metricSpec
35: * @return metricCalculationStrategy
36: */
37: private static MetricCalculationStrategy doGetStrategyFor(
38: ReportMetricSpec metricSpec, CalculationType type) {
39: if (type == null) {
40: return new SumStrategy();
41: }
42: switch (type.getType()) {
43: case CalculationType.AVERAGE_TYPE:
44: return new AverageStrategy();
45: case CalculationType.COUNT_TYPE:
46: return new CountStrategy();
47: case CalculationType.MAX_TYPE:
48: return new MaxStrategy();
49: case CalculationType.MIN_TYPE:
50: return new MinStrategy();
51: case CalculationType.SUM_TYPE:
52: return new SumStrategy();
53: case CalculationType.CALCULATED_TYPE:
54: return new CalculatedStrategy(metricSpec);
55: case CalculationType.COUNT_DISTINCT_TYPE:
56: return new CountDistinctStrategy(metricSpec);
57: default:
58: return new SumStrategy();
59: }
60: }
61:
62: public abstract String getSQLFunction() throws InfoException;
63: }
|