01: package com.calipso.reportgenerator.reportcalculator;
02:
03: import com.calipso.reportgenerator.common.ReportMetricSpec;
04: import com.calipso.reportgenerator.common.InfoException;
05:
06: import java.util.Set;
07: import java.util.HashSet;
08:
09: /**
10: *
11: * User: jbassino
12: * Date: 24-oct-2005
13: * Time: 16:00:52
14: */
15: public class CountDistinctStrategy extends MetricCalculationStrategy {
16: private ReportMetricSpec metricSpec;
17: int dimensionIndex;
18:
19: public CountDistinctStrategy(ReportMetricSpec metricSpec) {
20: this .metricSpec = metricSpec;
21: dimensionIndex = Integer.valueOf(
22: metricSpec.getAggregateFunction()).intValue();
23: }
24:
25: public Object operate(Object[] node, int index, Object measure,
26: Object[] row) {
27: if (node[index] != null) {
28: if (node[index] instanceof SharedFloat
29: && ((Float) ((SharedFloat) node[index]).getValue())
30: .isNaN()) {
31: node[index] = new HashSet();
32: }
33: ((Set) node[index]).add(row[dimensionIndex]);
34: return node[index];//SharedFloat.newFrom(((Set)measure).size());
35: } else {
36: measure = new HashSet();
37: ((Set) measure).add(row[dimensionIndex]);
38: return measure;
39: }
40: }
41:
42: public String getSQLFunction() throws InfoException {
43: return BasicSQLConstants.COUNT_DISTINCT;
44: }
45:
46: }
|