01: package com.calipso.reportgenerator.reportcalculator;
02:
03: import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionOrderType;
04: import com.calipso.reportgenerator.common.*;
05:
06: import java.util.Collection;
07: import java.util.Vector;
08: import java.util.Iterator;
09: import java.util.Map;
10:
11: /**
12: *
13: * User: jbassino
14: * Date: 12-may-2005
15: * Time: 16:32:32
16: * Calipso Software
17: */
18: public class TopOperation extends FilterOperation {
19: private float upToValue;
20: private int accum = 0;
21: private Collection values;
22:
23: public TopOperation(ReportResult result, ReportQuery reportQuery,
24: ReportFilterSpec filter, int value) {
25: super ();
26: ReportDimensionSpec dimension = reportQuery.getReportSpec()
27: .getDimensionFromName(filter.getDimensionName());
28: Collection values = result.getValuesCollection(dimension
29: .getOrder() == DimensionDefinitionOrderType.A);
30: this .values = new Vector();
31: Iterator it = values.iterator();
32: this .upToValue = value;
33: for (int i = 0; i < upToValue && it.hasNext(); i++) {
34: Object ob = it.next();
35: if (ob instanceof DimensionValueNode) {
36: this .values.add(((DimensionValueNode) ob).getValue());
37: } else if (ob instanceof Map.Entry) {
38: this .values.add(((Map.Entry) ((Map.Entry) ob)
39: .getValue()).getKey());
40: }
41: }
42: }
43:
44: /**
45: * Np entra en este metodo porque se redefine el metodo operate(result) de la clase padre
46: * @param value
47: * @return
48: */
49: protected boolean accept(SharedFloat value) {
50: /*accum++;
51: return accum <= upToValue;*/
52: return false;
53: }
54:
55: public Collection operate(ReportResult result) {
56: return values;
57: }
58:
59: }
|