monthlyCalendar
Class MonthlyCalendar

java.lang.Object
  extended by monthlyCalendar.MonthlyCalendar

public class MonthlyCalendar
extends java.lang.Object

This class provides the basic functionality associated with a monthly calendar. We have implemented this class for you and you should not modify it.

Author:
Dept of Computer Science, UMCP

Constructor Summary
MonthlyCalendar(Month month, int maxNumberDays, Day firstDay)
          Initializes the MonthlyCalendar object using the specified parameters.
 
Method Summary
 boolean addActivity(java.lang.String name, Date date, Time activityStartTime, int duration)
          Verifies whether the specified time period is available and if so, adds the activity to the list of activities for that date.
 boolean anyActivitiesOnDay(Date date)
          Returns true if there are any activities scheduled during the specified date and false otherwise.
 java.util.Iterator<Activity> dayActivitiesIterator(Date date)
          Returns an Activity iterator for the activities in the specified date
 Activity getActivity(Date date, Time activityStartTime)
          Returns a reference to the Activity that takes place at the specified date and that starts at the specified time.
 int getDaysInFirstWeek()
          Returns the number of days in the first week of the month.
 java.util.Map<Day,java.util.Map<Time,Activity>> getDayTimeActivityMap(int weekNumber)
          This methods returns a map that allow us to tell what activity takes place in a week, at a particular day and at a particular start time.
 Day getFirstDay()
          Returns the first day of the month.
 Month getMonth()
          Returns the calendar's month.
 int getNumberOfDays()
          Returns the number of days in the month.
 int getNumberOfWeeks()
          Returns the number of weeks associated with the month.
 boolean isTimePeriodAvailable(Date date, Time activityStartTime, int duration)
          Returns true if it is possible to schedule an activity on the specified date, in the time period starting at activityStartTime and lasting for the specified duration (minutes).
 boolean isValidDate(Date date)
          Returns true if the date is considered a valid date for the month associated with the calendar.
 boolean removeActivity(Date date, Time activityStartTime)
          Removes the activity taking place at the specified date and start time.
 java.lang.String toString()
          Returns a string representation for the calendar.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MonthlyCalendar

public MonthlyCalendar(Month month,
                       int maxNumberDays,
                       Day firstDay)
Initializes the MonthlyCalendar object using the specified parameters. The constructor computes the number of weeks associated with the month and creates the appropriate number of WeekActivities objects.

Parameters:
month -
maxNumberDays - maximum number of days in the month
firstDay - first day of the month
Method Detail

isTimePeriodAvailable

public boolean isTimePeriodAvailable(Date date,
                                     Time activityStartTime,
                                     int duration)
Returns true if it is possible to schedule an activity on the specified date, in the time period starting at activityStartTime and lasting for the specified duration (minutes). Keep in mind that you can schedule an activity that starts right after another ends, or right before another begins. For example, if you have an activity scheduled from 3:00 pm to 4:00 pm, you can schedule an activity starting at 4:00 pm. You could also schedule an activity that starts before 3:00 pm and ends exactly at 3:00 pm. It is assumed an activity will start and end on the same day. Any activity will have a duration of at least one minute.

Parameters:
date - date activity will take place
activityStartTime - start time
duration - duration of activity in minutes
Returns:
true if the time period is available and false otherwise

addActivity

public boolean addActivity(java.lang.String name,
                           Date date,
                           Time activityStartTime,
                           int duration)
Verifies whether the specified time period is available and if so, adds the activity to the list of activities for that date. The list must be kept sorted in ascending order according to the start time of the activities. It is assumed an activity will start and end on the same day. Any activity will have a duration of at least one minute.

Parameters:
name - activity's name
date - date to schedule activity
activityStartTime - start time
duration - duration in minutes
Returns:
true if activity is added and false otherwise

getActivity

public Activity getActivity(Date date,
                            Time activityStartTime)
Returns a reference to the Activity that takes place at the specified date and that starts at the specified time.

Parameters:
date - date activity will take place
activityStartTime - start time
Returns:
Reference to the activity or null otherwise (e.g., if activity not found, or if no activities are scheduled for the specified date)

removeActivity

public boolean removeActivity(Date date,
                              Time activityStartTime)
Removes the activity taking place at the specified date and start time.

Parameters:
date - date activity will take place
activityStartTime - start time
Returns:
true if the activity is removed and false otherwise (e.g., activity not found, or no activities scheduled for the specified date).

dayActivitiesIterator

public java.util.Iterator<Activity> dayActivitiesIterator(Date date)
Returns an Activity iterator for the activities in the specified date

Parameters:
date - target date
Returns:
Activities' iterator
Throws:
java.lang.IllegalArgumentException - Thrown if the specified date has no activities associated with it.

anyActivitiesOnDay

public boolean anyActivitiesOnDay(Date date)
Returns true if there are any activities scheduled during the specified date and false otherwise.

Parameters:
date - target date
Returns:
true if any activities are scheduled and false otherwise.

getDayTimeActivityMap

public java.util.Map<Day,java.util.Map<Time,Activity>> getDayTimeActivityMap(int weekNumber)
This methods returns a map that allow us to tell what activity takes place in a week, at a particular day and at a particular start time.

Parameters:
weekNumber - week number
Returns:
a map (which could be empty)

toString

public java.lang.String toString()
Returns a string representation for the calendar.

Overrides:
toString in class java.lang.Object
Returns:
string representation

getMonth

public Month getMonth()
Returns the calendar's month.

Returns:
Month value

getFirstDay

public Day getFirstDay()
Returns the first day of the month.

Returns:
Day value representing the first day of the month

getNumberOfDays

public int getNumberOfDays()
Returns the number of days in the month.

Returns:
maximum number of days

getDaysInFirstWeek

public int getDaysInFirstWeek()
Returns the number of days in the first week of the month.

Returns:
number of days in the first week

getNumberOfWeeks

public int getNumberOfWeeks()
Returns the number of weeks associated with the month.

Returns:
number of weeks

isValidDate

public boolean isValidDate(Date date)
Returns true if the date is considered a valid date for the month associated with the calendar.

Parameters:
date -
Returns:
true if valid date and false otherwise


Web Accessibility