Methods Summary |
---|
public boolean | addEvent(java.lang.String eventName, java.util.Date eventTime)
This will add the requested event.
// Add this event to the list of events
if (!events.contains(eventName)) {
events.addElement(eventName);
eventDetails.put(eventName, eventTime);
eventsSorted = false;
// Start thread on server sorting
SortEventsThread sorter = new SortEventsThread();
sorter.start();
}
return true;
|
public java.util.Vector | getListOfEvents()
This returns the current listing of events.
Vector list = new Vector();
// Create a Date Formatter
SimpleDateFormat fmt =
new SimpleDateFormat("hh:mm a MM/dd/yyyy");
// Add each event to the list
for (int i=0; i<events.size(); i++) {
String eventName = (String)events.elementAt(i);
list.addElement("Event \"" + eventName +
"\" scheduled for " +
fmt.format(
(Date)eventDetails.get(eventName)));
}
return list;
|
public synchronized boolean | removeEvent(java.lang.String eventName)
This will remove the requested event.
events.remove(eventName);
eventDetails.remove(eventName);
return true;
|
private synchronized void | sortEvents()
Sort the events in the current list.
if (eventsSorted) {
return;
}
// Create array of events as they are (unsorted)
String[] eventNames = new String[events.size()];
events.copyInto(eventNames);
// Bubble sort these
String tmpName;
Date date1, date2;
for (int i=0; i<eventNames.length - 1; i++) {
for (int j=0; j<eventNames.length - i - 1; j++) {
// Compare the dates for these events
date1 = (Date)eventDetails.get(eventNames[j]);
date2 = (Date)eventDetails.get(eventNames[j+1]);
if (date1.compareTo(date2) > 0) {
// Swap if needed
tmpName = eventNames[j];
eventNames[j] = eventNames[j+1];
eventNames[j+1] = tmpName;
}
}
}
// Put into new Vector (ordered)
Vector sortedEvents = new Vector();
for (int i=0; i<eventNames.length; i++) {
sortedEvents.addElement(eventNames[i]);
}
// Update the global events
events = sortedEvents;
eventsSorted = true;
|