net.sf.mpxj
Class ProjectCalendar

java.lang.Object
  extended by net.sf.mpxj.ProjectCalendarWeek
      extended by net.sf.mpxj.ProjectCalendar

public final class ProjectCalendar
extends ProjectCalendarWeek

This class represents the a Calendar Definition record. Both base calendars and calendars derived from base calendars are represented by instances of this class. The class is used to define the working and non-working days of the week. The default calendar defines Monday to Friday as working days.


Field Summary
static String DEFAULT_BASE_CALENDAR_NAME
          Default base calendar name to use when none is supplied.
 
Fields inherited from class net.sf.mpxj.ProjectCalendarWeek
DEFAULT_WORKING_AFTERNOON, DEFAULT_WORKING_MORNING
 
Constructor Summary
ProjectCalendar(ProjectFile file)
          Default constructor.
ProjectCalendar(ProjectFile file, ProjectCalendar taskCalendar, ProjectCalendar resourceCalendar)
          Create a calendar based on the intersection of a task calendar and a resource calendar.
 
Method Summary
 ProjectCalendarException addCalendarException(Date fromDate, Date toDate)
          Used to add exceptions to the calendar.
 ProjectCalendarHours addCalendarHours(Day day)
          Used to add working hours to the calendar.
protected  void addDerivedCalendar(ProjectCalendar calendar)
          Add a reference to a calendar derived from this one.
 ProjectCalendarWeek addWorkWeek()
          Add an empty work week.
 void attachHoursToDay(ProjectCalendarHours hours)
          Attaches a pre-existing set of hours to the correct day within the calendar.
 void copy(ProjectCalendar cal)
          Copy the settings from another calendar to this calendar.
 List<ProjectCalendarException> getCalendarExceptions()
          This method retrieves a list of exceptions to the current calendar.
 Date getDate(Date startDate, Duration duration, boolean returnNextWorkStart)
          Given a start date and a duration, this method calculates the end date.
 List<ProjectCalendar> getDerivedCalendars()
          Retrieve a list of derived calendars.
 Duration getDuration(Date startDate, Date endDate)
          This method is provided to allow an absolute period of time represented by start and end dates into a duration in working days based on this calendar instance.
 ProjectCalendarException getException(Date date)
          Retrieve a calendar calendar exception which applies to this date.
 Date getFinishTime(Date date)
          Retrieves the time at which work finishes on the given date, or returns null if this is a non-working day.
 Date getNextWorkStart(Date date)
          Utility method to retrieve the next working date start time, given a date and time as a starting point.
 ProjectCalendar getParent()
          If this week is derived from a another week, this method will return the parent week.
 ProjectFile getParentFile()
          Accessor method allowing retrieval of ProjectFile reference.
 Date getPreviousWorkFinish(Date date)
          Utility method to retrieve the previous working date finish time, given a date and time as a starting point.
 Resource getResource()
          Retrieve the resource to which this calendar is linked.
 Date getStartDate(Date finishDate, Duration duration)
          Given a finish date and a duration, this method calculates backwards to the start date.
 Date getStartTime(Date date)
          Retrieves the time at which work starts on the given date, or returns null if this is a non-working day.
 Integer getUniqueID()
          Accessor method to retrieve the unique ID of this calendar.
 Duration getWork(Date startDate, Date endDate, TimeUnit format)
          This method retrieves a Duration instance representing the amount of work between two dates based on this calendar.
 Duration getWork(Date date, TimeUnit format)
          Retrieves the amount of work on a given day, and returns it in the specified format.
 List<ProjectCalendarWeek> getWorkWeeks()
          Retrieve the work weeks associated with this calendar.
 boolean isWorkingDate(Date date)
          This method allows the caller to determine if a given date is a working day.
 boolean isWorkingDay(Day day)
          Method indicating whether a day is a working or non-working day.
 void remove()
          Removes this calendar from the project.
protected  void removeDerivedCalendar(ProjectCalendar calendar)
          Remove a reference to a derived calendar.
 void removeHoursFromDay(ProjectCalendarHours hours)
          Removes a set of calendar hours from the day to which they are currently attached.
 void setParent(ProjectCalendar calendar)
          Sets the ProjectCalendar instance from which this calendar is derived.
 void setResource(Resource resource)
          Sets the resource to which this calendar is linked.
 void setUniqueID(Integer uniqueID)
          Modifier method to set the unique ID of this calendar.
 String toString()
          
 
Methods inherited from class net.sf.mpxj.ProjectCalendarWeek
addCalendarHours, addDefaultCalendarHours, addDefaultCalendarHours, getCalendarHours, getDateRange, getDays, getHours, getHours, getName, getWorkingDay, isDerived, setDateRange, setName, setWorkingDay, setWorkingDay
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_BASE_CALENDAR_NAME

public static final String DEFAULT_BASE_CALENDAR_NAME
Default base calendar name to use when none is supplied.

See Also:
Constant Field Values
Constructor Detail

ProjectCalendar

public ProjectCalendar(ProjectFile file)
Default constructor.

Parameters:
file - the parent file to which this record belongs.

ProjectCalendar

public ProjectCalendar(ProjectFile file,
                       ProjectCalendar taskCalendar,
                       ProjectCalendar resourceCalendar)
Create a calendar based on the intersection of a task calendar and a resource calendar.

Parameters:
file - the parent file to which this record belongs.
taskCalendar - task calendar to merge
resourceCalendar - resource calendar to merge
Method Detail

addWorkWeek

public ProjectCalendarWeek addWorkWeek()
Add an empty work week.

Returns:
new work week

getWorkWeeks

public List<ProjectCalendarWeek> getWorkWeeks()
Retrieve the work weeks associated with this calendar.

Returns:
list of work weeks

addCalendarException

public ProjectCalendarException addCalendarException(Date fromDate,
                                                     Date toDate)
Used to add exceptions to the calendar. The MPX standard defines a limit of 250 exceptions per calendar.

Parameters:
fromDate - exception start date
toDate - exception end date
Returns:
ProjectCalendarException instance

getCalendarExceptions

public List<ProjectCalendarException> getCalendarExceptions()
This method retrieves a list of exceptions to the current calendar.

Returns:
List of calendar exceptions

addCalendarHours

public ProjectCalendarHours addCalendarHours(Day day)
Used to add working hours to the calendar. Note that the MPX file definition allows a maximum of 7 calendar hours records to be added to a single calendar.

Overrides:
addCalendarHours in class ProjectCalendarWeek
Parameters:
day - day number
Returns:
new ProjectCalendarHours instance

attachHoursToDay

public void attachHoursToDay(ProjectCalendarHours hours)
Attaches a pre-existing set of hours to the correct day within the calendar.

Overrides:
attachHoursToDay in class ProjectCalendarWeek
Parameters:
hours - calendar hours instance

removeHoursFromDay

public void removeHoursFromDay(ProjectCalendarHours hours)
Removes a set of calendar hours from the day to which they are currently attached.

Overrides:
removeHoursFromDay in class ProjectCalendarWeek
Parameters:
hours - calendar hours instance

setParent

public void setParent(ProjectCalendar calendar)
Sets the ProjectCalendar instance from which this calendar is derived.

Parameters:
calendar - base calendar instance

getParent

public ProjectCalendar getParent()
Description copied from class: ProjectCalendarWeek
If this week is derived from a another week, this method will return the parent week.

Overrides:
getParent in class ProjectCalendarWeek
Returns:
parent week

isWorkingDay

public boolean isWorkingDay(Day day)
Method indicating whether a day is a working or non-working day.

Parameters:
day - required day
Returns:
true if this is a working day

getDuration

public Duration getDuration(Date startDate,
                            Date endDate)
This method is provided to allow an absolute period of time represented by start and end dates into a duration in working days based on this calendar instance. This method takes account of any exceptions defined for this calendar.

Parameters:
startDate - start of the period
endDate - end of the period
Returns:
new Duration object

getStartTime

public Date getStartTime(Date date)
Retrieves the time at which work starts on the given date, or returns null if this is a non-working day.

Parameters:
date - Date instance
Returns:
start time, or null for non-working day

getFinishTime

public Date getFinishTime(Date date)
Retrieves the time at which work finishes on the given date, or returns null if this is a non-working day.

Parameters:
date - Date instance
Returns:
finish time, or null for non-working day

getDate

public Date getDate(Date startDate,
                    Duration duration,
                    boolean returnNextWorkStart)
Given a start date and a duration, this method calculates the end date. It takes account of working hours in each day, non working days and calendar exceptions. If the returnNextWorkStart parameter is set to true, the method will return the start date and time of the next working period if the end date is at the end of a working period.

Parameters:
startDate - start date
duration - duration
returnNextWorkStart - if set to true will return start of next working period
Returns:
end date

getStartDate

public Date getStartDate(Date finishDate,
                         Duration duration)
Given a finish date and a duration, this method calculates backwards to the start date. It takes account of working hours in each day, non working days and calendar exceptions.

Parameters:
finishDate - finish date
duration - duration
Returns:
start date

getNextWorkStart

public Date getNextWorkStart(Date date)
Utility method to retrieve the next working date start time, given a date and time as a starting point.

Parameters:
date - date and time start point
Returns:
date and time of next work start

getPreviousWorkFinish

public Date getPreviousWorkFinish(Date date)
Utility method to retrieve the previous working date finish time, given a date and time as a starting point.

Parameters:
date - date and time start point
Returns:
date and time of previous work finish

isWorkingDate

public boolean isWorkingDate(Date date)
This method allows the caller to determine if a given date is a working day. This method takes account of calendar exceptions.

Parameters:
date - Date to be tested
Returns:
boolean value

setUniqueID

public void setUniqueID(Integer uniqueID)
Modifier method to set the unique ID of this calendar.

Parameters:
uniqueID - unique identifier

getUniqueID

public Integer getUniqueID()
Accessor method to retrieve the unique ID of this calendar.

Returns:
calendar unique identifier

getResource

public Resource getResource()
Retrieve the resource to which this calendar is linked.

Returns:
resource instance

setResource

public void setResource(Resource resource)
Sets the resource to which this calendar is linked. Note that this method updates the calendar's name to be the same as the resource name. If the resource does not yet have a name, then the calendar is given a default name.

Parameters:
resource - resource instance

remove

public void remove()
Removes this calendar from the project.


getException

public ProjectCalendarException getException(Date date)
Retrieve a calendar calendar exception which applies to this date.

Parameters:
date - target date
Returns:
calendar exception, or null if none match this date

getWork

public Duration getWork(Date date,
                        TimeUnit format)
Retrieves the amount of work on a given day, and returns it in the specified format.

Parameters:
date - target date
format - required format
Returns:
work duration

getWork

public Duration getWork(Date startDate,
                        Date endDate,
                        TimeUnit format)
This method retrieves a Duration instance representing the amount of work between two dates based on this calendar.

Parameters:
startDate - start date
endDate - end date
format - required duration format
Returns:
amount of work

addDerivedCalendar

protected void addDerivedCalendar(ProjectCalendar calendar)
Add a reference to a calendar derived from this one.

Parameters:
calendar - derived calendar instance

removeDerivedCalendar

protected void removeDerivedCalendar(ProjectCalendar calendar)
Remove a reference to a derived calendar.

Parameters:
calendar - derived calendar instance

getDerivedCalendars

public List<ProjectCalendar> getDerivedCalendars()
Retrieve a list of derived calendars.

Returns:
list of derived calendars

toString

public String toString()

Overrides:
toString in class Object

copy

public void copy(ProjectCalendar cal)
Copy the settings from another calendar to this calendar.

Parameters:
cal - calendar data source

getParentFile

public final ProjectFile getParentFile()
Accessor method allowing retrieval of ProjectFile reference.

Returns:
reference to this the parent ProjectFile instance


Copyright © 2012. All Rights Reserved.