View Javadoc

1   /*
2    * Copyright (c) 2004 UNINETT FAS
3    *
4    * This program is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU General Public License as published by the Free
6    * Software Foundation; either version 2 of the License, or (at your option)
7    * any later version.
8    *
9    * This program is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12   * more details.
13   *
14   * You should have received a copy of the GNU General Public License along with
15   * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16   * Place - Suite 330, Boston, MA 02111-1307, USA.
17   *
18   * $Id: StatisticsCollection.java,v 1.2 2005/11/10 10:40:37 indal Exp $
19   */
20  
21  package no.feide.moria.servlet;
22  
23  import java.util.Vector;
24  
25  /***
26   * @author Eva Indal
27   * @version $Revision: 1.2 $
28   *
29   */
30  public class StatisticsCollection {
31      private String orgname = "";
32      private Vector stats = new Vector(); 
33      private Vector allmonths = new Vector();
34      
35      public StatisticsCollection(final String orgname_in) {
36          this.orgname = orgname_in;
37      }
38      public String getOrgName() {
39          return this.orgname;
40      }
41      public int getNumMonths() {
42          return this.allmonths.size();
43      }
44      public String getMonthName(final int idx) {
45          StatisticsMonth month = (StatisticsMonth) this.allmonths.get(idx);
46          return month.getMonthName();
47      }
48      public int getNumStatisticsData() {
49          return this.stats.size();
50      }
51      public StatisticsData getStatisticsData(final int idx) {
52          return (StatisticsData) this.stats.get(idx);
53      }
54      public void addMonth(final String name, final String month, final int count) {
55          this.addUniqueMonth(month);
56          for (int i = 0; i < this.stats.size(); i++) {
57              StatisticsData data = (StatisticsData) this.stats.get(i);
58              if (data.getName().equals(name)) {
59                  data.addMonth(month, count);
60                  return;
61              }
62          }
63          StatisticsData data = new StatisticsData();
64          data.setName(name);
65          data.addMonth(month, count);
66          this.stats.add(data);
67      }
68      
69      /***
70       * Adds a month to the list of unique months (if not already in list)
71       * 
72       * @param monthname
73       */
74      private void addUniqueMonth(final String monthname) {
75          StatisticsMonth month = new StatisticsMonth(monthname);
76          final int n = this.allmonths.size();
77          
78          // first check if month is already in Vector
79          for (int i = 0; i < n; i++) {
80              StatisticsMonth tmp = (StatisticsMonth) this.allmonths.get(i);
81              if (month.equals(tmp)) return;
82          }
83          // insert the month in sorted order
84          for (int i = 0; i < n; i++) {
85              StatisticsMonth tmp = (StatisticsMonth) this.allmonths.get(i);
86              if (month.getMonthNum() <= tmp.getMonthNum()) {
87                  this.allmonths.add(i, month);
88                  return;
89              }
90          }
91          // just add at end of Vector if we get here
92          this.allmonths.add(month);
93      }
94  }