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: StatisticsMonth.java,v 1.1 2005/11/04 10:44:41 indal Exp $
19   */
20  
21  package no.feide.moria.servlet;
22  
23  /***
24   * This class sorts the months in the correct order.
25   * 
26   * @author Eva Indal
27   * @version $Revision: 1.1 $
28   *
29   */
30  public class StatisticsMonth implements Comparable {
31      private String monthname;
32      private int monthnum;
33      
34      StatisticsMonth(final String name) {
35          this.monthname = name;
36          this.monthnum = findMonthNum(name);        
37      }
38      public int hashCode() {
39          return this.monthname.hashCode();
40      }
41  
42      public int compareTo(Object obj) {
43          StatisticsMonth in = (StatisticsMonth) obj;
44          return this.monthnum - in.monthnum;
45      }
46      public boolean equals(Object obj) {
47          StatisticsMonth in = (StatisticsMonth) obj;
48          return this.monthname.equals(in.monthname);
49      }
50      public int getMonthNum() {
51          return this.monthnum;
52      }
53      public String getMonthName() {
54          return this.monthname;
55      }
56      
57      private static int findMonthNum(final String name) {
58          if (name.equals("January")) return 1;
59          if (name.equals("February")) return 2;
60          if (name.equals("Mars")) return 3;
61          if (name.equals("March")) return 3;
62          if (name.equals("April")) return 4;
63          if (name.equals("May")) return 5;
64          if (name.equals("June")) return 6;
65          if (name.equals("July")) return 7;
66          if (name.equals("August")) return 8;
67          if (name.equals("September")) return 9;
68          if (name.equals("October")) return 10;
69          if (name.equals("November")) return 11;
70          if (name.equals("December")) return 12;
71          return 0;
72      }
73  }