KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.calipso.reportgenerator.reportcalculator;
2
3 import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionOrderType;
4 import com.calipso.reportgenerator.common.*;
5
6 import java.util.Collection JavaDoc;
7 import java.util.Vector JavaDoc;
8 import java.util.Iterator JavaDoc;
9 import java.util.Map JavaDoc;
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 JavaDoc values;
22
23   public TopOperation(ReportResult result, ReportQuery reportQuery, ReportFilterSpec filter, int value) {
24     super();
25     ReportDimensionSpec dimension = reportQuery.getReportSpec().getDimensionFromName(filter.getDimensionName());
26     Collection JavaDoc values = result.getValuesCollection(dimension.getOrder()==DimensionDefinitionOrderType.A);
27     this.values = new Vector JavaDoc();
28     Iterator JavaDoc it = values.iterator();
29     this.upToValue = value;
30     for(int i=0; i < upToValue && it.hasNext(); i++){
31       Object JavaDoc ob = it.next();
32       if(ob instanceof DimensionValueNode){
33         this.values.add(((DimensionValueNode)ob).getValue());
34       }else if(ob instanceof Map.Entry JavaDoc){
35         this.values.add(((Map.Entry JavaDoc)((Map.Entry JavaDoc)ob).getValue()).getKey());
36       }
37     }
38   }
39
40   /**
41    * Np entra en este metodo porque se redefine el metodo operate(result) de la clase padre
42    * @param value
43    * @return
44    */

45   protected boolean accept(SharedFloat value) {
46     /*accum++;
47     return accum <= upToValue;*/

48     return false;
49   }
50
51   public Collection JavaDoc operate(ReportResult result) {
52     return values;
53   }
54
55 }
56
Popular Tags