monthlyCalendar
Class WeekActivities

java.lang.Object
  extended by monthlyCalendar.WeekActivities

public class WeekActivities
extends java.lang.Object

This class represents activities we have in a week. The class uses a map (Map<Day, MySortedLinkedList<Activity>>) to associate a day with a list of activities for that particular day. If a day has no activities then no entry for that day will exist in the map.

Notice that for this project you must use a MySortedLinkedList object to keep track of the activities associated with a particular day.

Author:
Dept of Computer Science, UMCP

Constructor Summary
WeekActivities()
          Creates a HashMap that maps days to list of activities.
 
Method Summary
 boolean addActivity(java.lang.String name, Day day, Time activityStartTime, int duration)
          Verifies whether the specified time period is available and if so, adds the activity to the list of activities for the day.
 boolean anyActivitiesOnDay(Day day)
          Returns true if there are any activities scheduled during the specified day and false otherwise.
 java.util.Iterator<Activity> dayActivitiesIterator(Day day)
          Returns an Activity iterator for the activities in the specified day
 java.util.Set<Day> daysWithActivities()
          Returns a set of days with activities.
 Activity getActivity(Day day, Time startTime)
          Returns a reference to the Activity that takes place at the specified day and that starts at the specified time.
 java.util.Map<Day,java.util.Map<Time,Activity>> getDayTimeActivityMap()
          This methods returns a map that allow us to tell what activity takes place at a particular day and at a particular start time.
 boolean isTimePeriodAvailable(Day day, Time activityStartTime, int duration)
          Returns true if it is possible to schedule an activity in the time period starting at activityStartTime and lasting for the specified duration (minutes).
 boolean removeActivity(Day day, Time startTime)
          Removes the activity taking place at the specified day and start time.
 java.lang.String toString()
          Returns a string representation for the week.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WeekActivities

public WeekActivities()
Creates a HashMap that maps days to list of activities.

Method Detail

isTimePeriodAvailable

public boolean isTimePeriodAvailable(Day day,
                                     Time activityStartTime,
                                     int duration)
Returns true if it is possible to schedule an activity 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. You can assume an activity will start and end on the same day. For example, you do not have to handle the case where the start time is 11:59 pm and the duration of the activity is 2 minutes. Any activity will have a duration of at least one minute.

Parameters:
day - day 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,
                           Day day,
                           Time activityStartTime,
                           int duration)
Verifies whether the specified time period is available and if so, adds the activity to the list of activities for the day. The list must be kept sorted in ascending order according to the start time of the activities. You can assume an activity will start and end on the same day. For example, you do not have to handle the case where the start time is 11:59 pm and the duration of the activity is 2 minutes. Any activity will have a duration of at least one minute.

Parameters:
name - activity name
day - day activity will take place
activityStartTime - start time
duration - duration of activity in minutes
Returns:
true if the activity was added and false otherwise

getActivity

public Activity getActivity(Day day,
                            Time startTime)
Returns a reference to the Activity that takes place at the specified day and that starts at the specified time.

Parameters:
day - day activity will take place
startTime - 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 day)

removeActivity

public boolean removeActivity(Day day,
                              Time startTime)
Removes the activity taking place at the specified day and start time. If after removing the activity there are no more activites left in the day, then the map entry associated with that day should be removed.

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

dayActivitiesIterator

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

Parameters:
day - target day
Returns:
Activities' iterator
Throws:
java.lang.IllegalArgumentException - Thrown if the specified day has no activities associated with it. The thrown exception must use the message "Invalid day"

anyActivitiesOnDay

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

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

daysWithActivities

public java.util.Set<Day> daysWithActivities()
Returns a set of days with activities.

Returns:
days set

getDayTimeActivityMap

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

Returns:
a map (which could be empty)

toString

public java.lang.String toString()
Returns a string representation for the week. We have implemented this method for you and you should not modify it.

Overrides:
toString in class java.lang.Object
Returns:
string representation for the week activities


Web Accessibility