package caltool.model.caldb; import caltool.model.schedule.*; import caltool.model.options.*; import mvp.*; import java.util.*; /**** * * 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. * */ public class UserCalendar extends Model { /*-* * Public methods. */ /** * Construct this by constructing and initializing all components. */ public UserCalendar(String uid) { items = new TreeMap(); settings = null; this.uid = uid; file = null; selectedDate = null; requiresSaving = false; selectedItem = null; /* * For initial testing purposes, construct a fixed item to use as the * currently selected item. */ selectedItem = new Appointment( "Dentist", // Title new caltool.model.schedule.Date( // Date "September 25, 2015"), null, // End Date new Time("8 AM"), // Time new Duration(1, 30), // Duration null, // Recurring info new Category("personal"), // Category "1342 Sycamore Dr", // Location Security.PublicTitle, // Security Priority.Must, // Priority new RemindInfo(true, // Remind info new RemindWhen(1, ReminderTimeUnit.DaysBefore), RemindWhere.OnScreen), "" // Details ); } /** * Add the given item to 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 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 add(ScheduledItem item) {
/*
* Put the given item into the items map with its generated unique key.
*/
items.put(item.getKey(), item);
requiresSaving = true;
/*
* Indicate that this has changed in case anyone is observing. The
* setChanged method is inherited from Model, which in turn inherits
* them from Observable.
*/
setChanged();
//p("size after add = " + items.values().size());
}
/**
* 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();
*
*/
public void delete(ScheduledItem item) {
items.remove(item);
requiresSaving = true;
/*
* Indicate that this has changed in case anyone is observing. The
* setChanged method is inherited from Model, which in turn inherits
* them from Observable.
*/
setChanged();
}
/**
* 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);
*
*/
public ScheduledItem getItem(ItemKey key) {
return (ScheduledItem) items.get((Object) key);
}
/**
* Return an array of items in the given date range. The start date must
* be <= the end date. The items in the array are sorted from earlierests
* schedcule date to latest.
*/
public ScheduledItem[] getItems(caltool.model.schedule.Date startDate,
caltool.model.schedule.Date endDate) {
/*
* Implementation forthcoming.
*/
return null;
}
/**
* Return a raw Collection of all the items in this. "Raw" means
* that the order of the items in the returned collection is TreeMap order,
* not sorted by calendar date.
*/
public Collection