01: /*
02: * @(#)Month.java 1.6 06/10/10
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package sun.tools.javazic;
28:
29: import java.util.HashMap;
30:
31: /**
32: * Month class handles month related manipulation.
33: *
34: * @since 1.4
35: */
36: class Month {
37: private static HashMap months = new HashMap();
38: static {
39: months.put("Jan", new Integer(0));
40: months.put("Feb", new Integer(1));
41: months.put("Mar", new Integer(2));
42: months.put("Apr", new Integer(3));
43: months.put("May", new Integer(4));
44: months.put("Jun", new Integer(5));
45: months.put("Jul", new Integer(6));
46: months.put("Aug", new Integer(7));
47: months.put("Sep", new Integer(8));
48: months.put("Oct", new Integer(9));
49: months.put("Nov", new Integer(10));
50: months.put("Dec", new Integer(11));
51: }
52:
53: /**
54: * Parses the specified string as a month abbreviation.
55: * @param name the month abbreviation
56: * @return the month value
57: */
58: static int parse(String name) {
59: Integer m = (Integer) months.get(name);
60: if (m != null) {
61: return m.intValue();
62: }
63: throw new IllegalArgumentException("wrong month name: " + name);
64: }
65:
66: private static String upper_months[] = { "JANUARY", "FEBRUARY",
67: "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST",
68: "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER" };
69:
70: /**
71: * @param month the numth number
72: * @return the month name in uppercase of the specified month
73: */
74: static String toString(int month) {
75: if (month >= 0 && month <= 11) {
76: return "Calendar." + upper_months[month];
77: }
78: throw new IllegalArgumentException("wrong month number: "
79: + month);
80: }
81: }
|