View Javadoc

1   /*
2    * Copyright (C) 2007 Alf Mikula
3    * 
4    * This file is part of PromoteGo.
5    *
6    * PromoteGo is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * PromoteGo is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with PromoteGo.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.promotego.logic.storehours;
20  
21  import java.util.Calendar;
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  /***
26   * @author alf
27   *
28   */
29  public enum Day
30  {
31  	SUNDAY(Calendar.SUNDAY, "SUN"), MONDAY(Calendar.MONDAY, "MON"), TUESDAY(Calendar.TUESDAY, "TUE"),
32  	WEDNESDAY(Calendar.WEDNESDAY, "WED"), THURSDAY(Calendar.THURSDAY, "THU"), FRIDAY(Calendar.FRIDAY, "FRI"),
33  	SATURDAY(Calendar.SATURDAY, "SAT");
34  
35  	private static Map<String,Day> s_dayMapping;
36  
37  	static {
38  		s_dayMapping = new HashMap<String,Day>();
39  		for (Day curDay : values())
40  		{
41  			s_dayMapping.put(curDay.getAbbreviation(), curDay);
42  		}
43  	}
44  	
45  	public static Day mapAbbreviation(String abbrev)
46  	{
47  		Day retval = s_dayMapping.get(abbrev);
48  		if (retval == null)
49  		{
50  			throw new IllegalArgumentException("Illegal abbreviation: " + abbrev);
51  		}
52  		else
53  		{
54  			return retval;
55  		}
56  	}
57  	
58  	private String m_abbreviation;
59  	
60  	/***
61  	 * The corresponding int used by <code>java.util.Calendar</code> for this day.
62  	 */
63  	private int m_javaCalendarInt;
64  	
65  	private Day(int javaCalendarInt, String abbrev)
66  	{
67  		m_javaCalendarInt = javaCalendarInt;
68  		m_abbreviation = abbrev;
69  	}
70  	
71  	public int getJavaCalendarInt()
72  	{
73  		return m_javaCalendarInt;
74  	}
75  	
76  	public String getAbbreviation()
77  	{
78  		return m_abbreviation;
79  	}
80  }