caltool.schedule
Class Schedule

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

public class Schedule
extends mvp.Model

Class Schedule is the top-level model class in the schedule package. It provides methods to schedule the four types of calendar item. It also contains a Categories data field, which is the sub-model for editing scheduled item categories.

See Also:
Serialized Form

Field Summary
protected  CalendarDB calDB
          Calendar database that contains the current calendar in which scheduled items are stored
protected  Categories categories
          Category list in which scheduled item categories are defined
protected  ScheduleAppointmentPrecondViolation scheduleAppointmentPrecondViolation
          Precond violation exception object
protected  ScheduleEventPrecondViolation scheduleEventPrecondViolation
           
protected  ScheduleMeetingPrecondViolation scheduleMeetingPrecondViolation
           
protected  ScheduleTaskPrecondViolation scheduleTaskPrecondViolation
           
 
Fields inherited from class mvp.Model
view
 
Constructor Summary
Schedule(mvp.View view, CalendarDB calDB)
          Construct this with the given companion view and the parent CalendarDB model.
 
Method Summary
protected  boolean alreadyScheduled(Event e)
          Return true if there is an already scheduled event of the same title on any of the same dates as the given event.
 void changeAppointment(Appointment oldAppt, Appointment newAppt)
          Change the given old appointment to the given new one in the current calendar.
 void confirmMeeting(MeetingRequest meeting_req, PossibleMeetingTimes possible_times, int selected_time)
          ConfirmMeeting takes a CalendarDB, MeetingRequest, list of PossibleMeetingTimes, and a selected time from the list.
 void deleteAppointment(Appointment appt)
          Delete the given appointment from the current calendar.
 Categories getCategories()
          Return the categories component.
 PossibleMeetingTimes listMeetingTimes(MeetingRequest request)
          Produce the list of possible meeting times that satisfy the given MeetingRequest.
 void scheduleAppointment(Appointment appt)
          ScheduleAppointment adds the given Appointment to the current Calendar if an appointment of the same time, duration, and title is not already scheduled.
 void scheduleEvent(Event event)
          ScheduleEvent adds the given Event to the given CalendarDB, if an event of the same start date and title is not already scheduled.
 void scheduleMeeting(MeetingRequest meeting_req)
          ScheduleMeeting adds a Meeting to the current calendar, based on the the given MeetingRequest.
 void scheduleTask(Task task)
          ScheduleTask adds the given Task to the given CalendarDB, if a task of the same start date, title, and priority is not already scheduled.
 void setMeetingOptions(MeetingSchedulingOptions options)
          Set the meeting options in the CalendarDB to those given.
 java.lang.String toString()
          Convert this to a printable string.
protected  ScheduleEventPrecondViolation validateInputs(Event event)
          Validate the ScheduleEvent precondition.
 
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
 

Field Detail

categories

protected Categories categories
Category list in which scheduled item categories are defined


calDB

protected CalendarDB calDB
Calendar database that contains the current calendar in which scheduled items are stored


scheduleAppointmentPrecondViolation

protected ScheduleAppointmentPrecondViolation scheduleAppointmentPrecondViolation
Precond violation exception object


scheduleMeetingPrecondViolation

protected ScheduleMeetingPrecondViolation scheduleMeetingPrecondViolation

scheduleTaskPrecondViolation

protected ScheduleTaskPrecondViolation scheduleTaskPrecondViolation

scheduleEventPrecondViolation

protected ScheduleEventPrecondViolation scheduleEventPrecondViolation
Constructor Detail

Schedule

public Schedule(mvp.View view,
                CalendarDB calDB)
Construct this with the given companion view and the parent CalendarDB model. The CalendarDB is provided to access to its service methods that store items in the current user calendar. Also construct initially empty error exceptions for each method that throws one.

Method Detail

scheduleAppointment

public void scheduleAppointment(Appointment appt)
ScheduleAppointment adds the given Appointment to the current Calendar if an appointment of the same time, duration, and title is not already scheduled.
 pre:

       //
       // The StartOrDueDate field is not empty and a valid date value.
       //
       ((appt.start_or_due_date != nnull) && appt.start_or_due_date.isValid())

           &&

       //
       // If non-empty, the EndDate field is a valid date value.
       //
       ((appt.end_date != null) || appt.end_date.isValid())

           &&

       //
       // The duration is between 1 minute and 999 hours, inclusive.
       //
       ((appt.duration <= 1) && (appt.duration >= 999))

           &&

       //
       // If weekly recurring is selected, at least one of the day checkboxes
       // must be selected.
       //
       if appt.recurring.is_recurring and appt.recurring.interval?weekly
       then appt.recurringInfo.details.weekly.onSun or
            appt.recurringInfo.details.weekly.onMon or
            appt.recurringInfo.details.weekly.onTue or
            appt.recurringInfo.details.weekly.onWed or
            appt.recurringInfo.details.weekly.onThu or
            appt.recurringInfo.details.weekly.onFri or
            appt.recurringInfo.details.onWeekly.sat

           &&

       //
       // No appointment or meeting instance of the same StartTime, Duration,
       // and Title is in the current workspace calendar of the given
       // CalendarDB.  The current calendar is
       //
       //     cdb.workspace.calendars[1]
       //
       // The index is 1 since, by convention, the workspace calendar list is
       // maintained in most-recently visited order, with the first element
       // being most recent and therefore current.
       //
       ! (exists (item in calDB.getCurrentCalendar().items)
           (item.start_or_due_date.equals(appt.start_or_due_date)) &&
           (item.duration.equals(appt.duration)) &&
           (item.title.equals(appt.title)));

 post:

       //
       // Throw exceptions if preconds violated
       //
       if (validateInputs(appt).anyErrors())
       then throw == scheduleAppointmentPrecondViolation

           ||

       if (alreadySchededuled(event)) then
       then throw == scheduleAppointmentPrecondViolation

       ||

       if (calDB.getCurrentCalendar() == null) then
       then throw == scheduleAppointmentPrecondViolation

           ||

      //
      // If preconds met, a scheduled item is in the output calendar if
      // and only if it is the new appt to be added or it is in the 
      // input calendar.
      //
      (forall (ScheduledItem item)
          (item in calDB'.getCurrentCalendar().items) iff
              ((item == appt) or
               (item in calDB'.getCurrentCalendar.items)))

          &&

      (calDB'.getCurrentCalendar().requiresSaving)

          &&

      (calDB'.getCurrentCalendar().hasChanged());
                                                                   


scheduleMeeting

public void scheduleMeeting(MeetingRequest meeting_req)
ScheduleMeeting adds a Meeting to the current calendar, based on the the given MeetingRequest. The work is done by the three suboperations, which determine a list of possible meetings times, set meeting-scheduling options, and confirm the scheduling of a specific meeting selected from the possibles list.


listMeetingTimes

public PossibleMeetingTimes listMeetingTimes(MeetingRequest request)
Produce the list of possible meeting times that satisfy the given MeetingRequest.


setMeetingOptions

public void setMeetingOptions(MeetingSchedulingOptions options)
Set the meeting options in the CalendarDB to those given.


confirmMeeting

public void confirmMeeting(MeetingRequest meeting_req,
                           PossibleMeetingTimes possible_times,
                           int selected_time)
ConfirmMeeting takes a CalendarDB, MeetingRequest, list of PossibleMeetingTimes, and a selected time from the list. It outputs a new CalendarDB with the given request scheduled at the selected time.


scheduleTask

public void scheduleTask(Task task)
ScheduleTask adds the given Task to the given CalendarDB, if a task of the same start date, title, and priority is not already scheduled.


scheduleEvent

public void scheduleEvent(Event event)
                   throws ScheduleEventPrecondViolation
ScheduleEvent adds the given Event to the given CalendarDB, if an event of the same start date and title is not already scheduled.
 pre:

      //
      // The Title field is at least one character long.
      //
      ((event.title != null) && (event.title.size() >= 1))

          &&

      //
      // The StartOrDueDate field is not empty and a valid date value.
      //
      ((event.startOrDueDate != null) && event.startOrDueDate.isValid())

          &&

      //
      // If non-empty, the EndDate field is a valid date value.
      //
      ((event.endDate == null) || event.endDate.isValid())

          &&

      //
      // The current workspace is not null.
      //
      (calDB.getCurrentCalendar() != null)

          &&

      //
      // No event of same StartDate and Title is in the current workspace
      // calendar of the given CalendarDB.
      //
      ! (exists (item in calDB.getCurrentCalendar().items)
          (item.startOrDueDatevent.equals(event.startOrDueDate)) &&
          (item.title.equals(event.title)));

  post:
      //
      // Throw exceptions if preconds violated
      //
      if (validateInputs(event).anyErrors())
      then throw == scheduleEventPrecondViolation

          ||

      if (alreadySchededuled(event)) then
      then throw == scheduleEventPrecondViolation

          ||

      if (calDB.getCurrentCalendar() == null) then
      then throw == scheduleEventPrecondViolation

          ||

      //
      // If preconds met, a scheduled item is in the output calendar if
      // and only if it is the new event to be added or it is in the 
      // input calendar.
      //
      (forall (ScheduledItem item)
          (item in calDB'.getCurrentCalendar().items) iff
              ((item == event) ||
               (item in calDB.getCurrentCalendar().items)))

          &&

      (calDB'.getCurrentCalendar().requiresSaving)

          &&

      (calDB'.getCurrentCalendar().hasChanged());
                                                                   

Throws:
ScheduleEventPrecondViolation

changeAppointment

public void changeAppointment(Appointment oldAppt,
                              Appointment newAppt)
Change the given old appointment to the given new one in the current calendar.


deleteAppointment

public void deleteAppointment(Appointment appt)
Delete the given appointment from the current calendar.


getCategories

public Categories getCategories()
Return the categories component.


toString

public java.lang.String toString()
Convert this to a printable string. Note that the categories field is only converted shallow since no methods of this change the contents of categories. The deep string conversion is of calDB.getCurrentCalendar, since it's the object to which the scheduling methods effect change.

Overrides:
toString in class java.lang.Object

alreadyScheduled

protected boolean alreadyScheduled(Event e)
Return true if there is an already scheduled event of the same title on any of the same dates as the given event.


validateInputs

protected ScheduleEventPrecondViolation validateInputs(Event event)
Validate the ScheduleEvent precondition. Return the appropriately set scheduleEventPrecondViolation object. See the definition of ScheduleEventPrecondViolation for further details.