com.ftlabs.fisa
Class DefaultHolidaySchedule

java.lang.Object
  extended by com.ftlabs.fisa.DefaultHolidaySchedule
All Implemented Interfaces:
HolidaySchedule, java.io.Serializable

public class DefaultHolidaySchedule
extends java.lang.Object
implements HolidaySchedule, java.io.Serializable

This is the default implementation of HolidaySchedule. For maximum efficiency, this implementation caches all provided holidays so that the isHoliday() method returns as quickly as possible.

See Also:
Serialized Form

Constructor Summary
DefaultHolidaySchedule()
          Creates a new instance of DefaultHolidaySchedule without any holidays.
DefaultHolidaySchedule(java.io.InputStream inputStream)
          Creates a new instance of DefaultHolidaySchedule populated with the dates provided by an InputStream.
DefaultHolidaySchedule(java.io.InputStream inputStream, java.text.Format format)
          Creates a new instance of DefaultHolidaySchedule populated with the dates provided by an InputStream.
DefaultHolidaySchedule(java.lang.String filePath)
          Creates a new instance of DefaultHolidaySchedule populated with dates contained in the provided file.
 
Method Summary
 void addHoliday(java.util.Date date)
          Add a holiday date to this schedule.
 void clear()
          Clear all holidays from this schedule.
 boolean isHoliday(java.util.Date date)
          Determines if the provided date is a holiday.
 void loadHolidays(java.io.InputStream inputStream)
          Adds dates provided by an InputStream to this DefaultHolidaySchedule.
 void loadHolidays(java.io.InputStream inputStream, java.text.Format format)
          Adds dates provided by an InputStream to this DefaultHolidaySchedule.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultHolidaySchedule

public DefaultHolidaySchedule()
Creates a new instance of DefaultHolidaySchedule without any holidays. The addHoliday(), or one of the load*() methods must be called to populate the schedule. Otherwise all calls to isHoliday() will return false.


DefaultHolidaySchedule

public DefaultHolidaySchedule(java.lang.String filePath)
                       throws java.io.IOException,
                              java.text.ParseException
Creates a new instance of DefaultHolidaySchedule populated with dates contained in the provided file. The dates in the file must be parsable using "M/d/yyyy" as a mask to SimpleDateFormat, and must be delimited with a carriage return and/or a linefeed.

Parameters:
filePath - The path to a file that contains the holiday dates.
Throws:
java.io.IOException
java.text.ParseException

DefaultHolidaySchedule

public DefaultHolidaySchedule(java.io.InputStream inputStream)
                       throws java.io.IOException,
                              java.text.ParseException
Creates a new instance of DefaultHolidaySchedule populated with the dates provided by an InputStream. The dates in the stream must be parsable using "M/d/yyyy" as a mask to SimpleDateFormat, and must be delimited with a carriage return and/or a linefeed.

Parameters:
inputStream - An InputStream that contains the holiday dates.
Throws:
java.io.IOException
java.text.ParseException

DefaultHolidaySchedule

public DefaultHolidaySchedule(java.io.InputStream inputStream,
                              java.text.Format format)
                       throws java.io.IOException,
                              java.text.ParseException
Creates a new instance of DefaultHolidaySchedule populated with the dates provided by an InputStream. The dates in the stream must be parsable using the provided format, and must be delimited with a carriage return and/or a linefeed.

Parameters:
inputStream - An InputStream that contains the holiday dates.
format - A Format object used to parse the holiday dates contained within the provided InputStream.
Throws:
java.io.IOException
java.text.ParseException
Method Detail

clear

public void clear()
Clear all holidays from this schedule.


loadHolidays

public void loadHolidays(java.io.InputStream inputStream)
                  throws java.io.IOException,
                         java.text.ParseException
Adds dates provided by an InputStream to this DefaultHolidaySchedule. The dates in the stream must be parsable using "M/d/yyyy" as a mask to SimpleDateFormat, and must be delimited with a carriage return and/or a linefeed.

Parameters:
inputStream - An InputStream that contains the holiday dates.
Throws:
java.io.IOException
java.text.ParseException

loadHolidays

public void loadHolidays(java.io.InputStream inputStream,
                         java.text.Format format)
                  throws java.io.IOException,
                         java.text.ParseException
Adds dates provided by an InputStream to this DefaultHolidaySchedule. The dates in the stream must be parsable using the provided Format object, and must be delimited with a carriage return and/or a linefeed.

Parameters:
inputStream - An InputStream that contains the holiday dates.
format - A Format object used to parse the holiday dates contained within the provided InputStream.
Throws:
java.io.IOException
java.text.ParseException

addHoliday

public void addHoliday(java.util.Date date)
Add a holiday date to this schedule. If the date already exists in this schedule, then nothing happens. If the date object also contains the time, the time will be stripped from the date before being added to the schedule.

Parameters:
date - A holiday date to be added to this schedule.

isHoliday

public boolean isHoliday(java.util.Date date)
Determines if the provided date is a holiday.

Specified by:
isHoliday in interface HolidaySchedule
Parameters:
date - Any date.
Returns:
true if the provided date is a holiday, otherwise false.