01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/calendar/tags/sakai_2-4-1/calendar-tool/tool/src/java/org/sakaiproject/calendar/tool/CalendarDB.java $
03: * $Id: CalendarDB.java 8050 2006-04-20 17:39:55Z ggolden@umich.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.calendar.tool;
21:
22: //import java.util.Enumeration;
23: import java.util.Hashtable;
24:
25: public class CalendarDB {
26:
27: private Hashtable events;
28: private static final String[] time = { "8:00 am", "9:00 am",
29: "10:00 am", "11:00 am", "12:00 pm", "1:00 pm", "2:00 pm",
30: "3:00 pm", "4:00 pm", "5:00 pm", "6:00 pm", "7:00 pm",
31: "8:00 pm" };
32: public static final int rows = 12;
33:
34: // Event class
35:
36: public class Event {
37:
38: String hour;
39: String description;
40:
41: public Event(String hourx) {
42: hour = hourx;
43: description = "";
44:
45: }
46:
47: public String getHour() {
48: return hour;
49: }
50:
51: public String getDescription() {
52: if (description.equals(""))
53: return "";
54: else
55: return description;
56: }
57:
58: public void setDescription(String descr) {
59: description = descr;
60: }
61:
62: }
63:
64: // End of event class
65:
66: public CalendarDB() {
67: events = new Hashtable(rows);
68: for (int i = 0; i < rows; i++) {
69: events.put(time[i], new Event(time[i]));
70: }
71: }
72:
73: public int getRows() {
74: return rows;
75: }
76:
77: public Event getEvent(int index) {
78: return (Event) events.get(time[index]);
79: }
80:
81: public int getIndex(String tm) {
82: for (int i = 0; i < rows; i++)
83: if (tm.equals(time[i]))
84: return i;
85: return -1;
86: }
87:
88: public void addEvent(String tm, String desc) {
89: int index = getIndex(tm);
90: if (index >= 0) {
91: String descr = desc;
92: Event e = (Event) events.get(time[index]);
93: e.setDescription(descr);
94: }
95: }
96:
97: }
|