KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.calipso.reportgenerator.reportcalculator;
2
3 import com.calipso.reportgenerator.common.ReportMetricSpec;
4 import com.calipso.reportgenerator.common.InfoException;
5
6 import java.util.Set JavaDoc;
7 import java.util.HashSet JavaDoc;
8
9 /**
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(metricSpec.getAggregateFunction()).intValue();
22   }
23
24   public Object JavaDoc operate(Object JavaDoc[] node, int index, Object JavaDoc measure, Object JavaDoc[] row) {
25     if(node[index]!=null){
26       if(node[index] instanceof SharedFloat && ((Float JavaDoc)((SharedFloat)node[index]).getValue()).isNaN()){
27         node[index] = new HashSet JavaDoc();
28       }
29       ((Set JavaDoc)node[index]).add(row[dimensionIndex]);
30       return node[index];//SharedFloat.newFrom(((Set)measure).size());
31
}else{
32       measure = new HashSet JavaDoc();
33       ((Set JavaDoc)measure).add(row[dimensionIndex]);
34       return measure;
35     }
36   }
37
38   public String JavaDoc getSQLFunction() throws InfoException {
39     return BasicSQLConstants.COUNT_DISTINCT;
40   }
41
42 }
43
Popular Tags