public class UserCalendar
extends mvp.Model
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.
| Modifier and Type | Field and Description |
|---|---|
(package private) java.io.File |
file
File this calendar is stored on
|
(package private) java.util.TreeMap |
items
The collection of all scheduled items for this calendar
|
(package private) boolean |
requiresSaving
True if this requires saving
|
(package private) Date |
selectedDate
Currently selected date, if any
|
(package private) ScheduledItem |
selectedItem
Currently selected item, if any
|
(package private) CalendarSpecificSettings |
settings
Calendar-specific settings for this calendar
|
(package private) java.lang.String |
uid
Id of user who owns this calendar
|
| Constructor and Description |
|---|
UserCalendar(java.lang.String uid)
Construct this by constructing and initializing all components.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(ScheduledItem item)
Add the given item to this.items.
|
void |
delete(ScheduledItem item)
Delete the given item from this.items.
|
(package private) java.io.File |
getFile()
Return the file on which this calendar was most recently stored.
|
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.
|
(package private) CalendarSpecificSettings |
getSettings()
Get the calendar-specific settings for this calendar.
|
(package private) java.lang.String |
getUid()
Return the user id of this calendar.
|
int |
numItems()
Return the number of items in this.items, for testing purposes.
|
(package private) void |
setFile(java.io.File file)
Set the file on which this calendar is currently stored.
|
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.
|
java.util.TreeMap items
CalendarSpecificSettings settings
java.lang.String uid
java.io.File file
Date selectedDate
boolean requiresSaving
ScheduledItem selectedItem
public UserCalendar(java.lang.String uid)
public void add(ScheduledItem item)
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();
public void delete(ScheduledItem item)
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();
public ScheduledItem getItem(ItemKey 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);
public ScheduledItem[] getItems(Date startDate, Date endDate)
public ScheduledItem getPrev(ItemKey key)
public ScheduledItem getNextItem(ItemKey key)
java.lang.String getUid()
java.io.File getFile()
void setFile(java.io.File file)
CalendarSpecificSettings getSettings()
public Date getSelectedDate()
public void setSelectedDate(Date date)
public ScheduledItem getSelectedItem()
public void setSelectedItem(ScheduledItem item)
public java.lang.String toString()
toString in class java.lang.Objectpublic int numItems()