caltool.caldb
Class UserCalendar

java.lang.Object
  extended by java.util.Observable
      extended by mvp.Model
          extended by caltool.caldb.UserCalendar
All Implemented Interfaces:
java.io.Serializable

public class UserCalendar
extends mvp.Model

The main data components of a user UserCalendar are a collection of scheduled items and calendar-specific settings. Calendar bookkeeping components are the ID of the user who owns the calendar, the file it's stored on, the currently selected date, and a flag indicating if the calendar requires saving.

In the current design, the concrete representation of the scheduled item list is a TreeMap. UserCalendar provides a getItem method to look up a scheduled item by its unique key. Based on the specs, the unique key for each type of item is as follows:

     Item             Unique Key
     ====================================================================
     Appointment      {date, start time, duration, title}
     Meeting          {date, start time, duration, title}
     Task             {date, time, title, priority}
     Event            {date, title}
                                                                       
UserCalendar also provides an array-valued getItems method to retrieve all of the items that are scheduled in a specified interval of date/time. This method is used by the caltool viewing methods to access the scheduled items for a given day, week, or month.

UserCalendar provides general-purpose methods to support the higher-level model classes in the schedule and view packages. The general-purpose methods of UserCalendar do no input validity checking, assuming it has been performed by the higher-level model methods.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class mvp.Model
view
 
Constructor Summary
UserCalendar(java.lang.String uid)
          Construct this by constructing and initializing all components.
 
Method Summary
 void add(ScheduledItem item)
          Add the given item to this.items.
 void delete(ScheduledItem item)
          Delete the given item from this.items.
 ScheduledItem getItem(ItemKey key)
          Return the scheduled item of the given unique key.
 ScheduledItem[] getItems(Date startDate, Date endDate)
          Return an array of items in the given date range.
 ScheduledItem getNextItem(ItemKey key)
          Return the next item in item-key order after the item with the given key.
 ScheduledItem getPrev(ItemKey key)
          Return the previous item in item-key order after the item with the given key.
 Date getSelectedDate()
          Return the date most recently selected by the user via clicking in some view.
 ScheduledItem getSelectedItem()
          Return the item most recently selected by the user via clicking in some view.
 int numItems()
          Return the number of items in this.items, for testing purposes.
 void setSelectedDate(Date date)
          Set the currently selected date to the given date.
 void setSelectedItem(ScheduledItem item)
          Set the currently selected date to the given date.
 java.lang.String toString()
          Convert this to a printable string.
 
Methods inherited from class mvp.Model
dump, exit, getView, setView
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UserCalendar

public UserCalendar(java.lang.String uid)
Construct this by constructing and initializing all components.

Method Detail

add

public void add(ScheduledItem item)
Add the given item to this.items. Note that this method has no 1 * precondition. All the validity and no-duplication requirements for the given item are checked at the level of the Schedule model.
 pre: ;

 post: 
       //
       // The input item is added to items via items.put, which means
       // that item is added if an item of the same key is not already
       // there.  This is marked as changed via Observable.setChanged().
       //
       (items' == items.put(item.getKey(), item))

           &&

       this'.hasChanged();
                                                                   


delete

public void delete(ScheduledItem item)
Delete the given item from this.items. Note that this method has no precondition. All the validity and no-duplication requirements for the given item are checked at the level of the Schedule model.
 pre: ;

 post: 
       //
       // The input item is added to items via HashMap.put, which means
       // that item is added if an item of the same key is not already
       // there.  This is marked as changed via Observable.setChanged().
       //
       (items' == items.remove(item.getKey(), item))

           &&

       this'.hasChanged();
                                                                   


getItem

public ScheduledItem getItem(ItemKey key)
Return the scheduled item of the given unique key.
 pre: ;

 post: 
       //
       // If there is an item with the given key in this.items, then the
       // return value is that item, otherwise the return is null.
       //
       (exists (item in items) (item.getKey().equals(key)) &&
                               (return == item)
           ||

       (return == null);
                                                                   


getItems

public ScheduledItem[] getItems(Date startDate,
                                Date endDate)
Return an array of items in the given date range. The start date must be <= the end date.


getPrev

public ScheduledItem getPrev(ItemKey key)
Return the previous item in item-key order after the item with the given key. Return null if the given key is that of the first item


getNextItem

public ScheduledItem getNextItem(ItemKey key)
Return the next item in item-key order after the item with the given key. Return null if the given key is that of the last item


getSelectedDate

public Date getSelectedDate()
Return the date most recently selected by the user via clicking in some view.


setSelectedDate

public void setSelectedDate(Date date)
Set the currently selected date to the given date.


getSelectedItem

public ScheduledItem getSelectedItem()
Return the item most recently selected by the user via clicking in some view.


setSelectedItem

public void setSelectedItem(ScheduledItem item)
Set the currently selected date to the given date.


toString

public java.lang.String toString()
Convert this to a printable string. The items are dumped last, since there may be a lot of them. Note that the settings field is only printed shallow since no methods of this change the contents of settings.

Overrides:
toString in class java.lang.Object

numItems

public int numItems()
Return the number of items in this.items, for testing purposes.