net.objectlab.kit.datecalc.common
Class AbstractDateCalculator<E>

Package class diagram package AbstractDateCalculator
java.lang.Object
  extended by net.objectlab.kit.datecalc.common.AbstractDateCalculator<E>
Type Parameters:
E - a representation of a date, typically JDK: Date, Calendar; Joda:LocalDate, YearMonthDay
All Implemented Interfaces:
DateCalculator<E>

public abstract class AbstractDateCalculator<E>
extends Object
implements DateCalculator<E>

Abstract implementation in order to encapsulate all the common functionality between Jdk and Joda implementations. It is parametrized on but basically Date and LocalDate are the only viable values for it for now.

Version:
$Revision: 309 $ $Date: 2010-03-23 17:01:49 -0400 (Tue, 23 Mar 2010) $
Author:
Marcin Jekot and Benoit Xhenseval, $LastChangedBy: marchy $

Field Summary
protected static int DAYS_IN_WEEK
           
 
Constructor Summary
protected AbstractDateCalculator(String name, HolidayCalendar<E> holidayCalendar, HolidayHandler<E> holidayHandler)
           
 
Method Summary
 List<E> calculateTenorDates(List<Tenor> tenors)
          Calculate a series of Tenor codes in one go based on current day, this does NOT change the current business date.
 List<E> calculateTenorDates(List<Tenor> tenors, int spotLag)
          Calculate a series of Tenor codes in one go based on SPOT day (calculated with the spot lag), this does NOT change the current business date.
protected abstract  void checkBoundary(E date)
          This may throw an IndexOutOfBoundsException if the date is not within the boundaries.
protected abstract  E clone(E date)
           
 DateCalculator<E> combine(DateCalculator<E> calculator)
          Allows DateCalculators to be combined into a new one, the startDate and currentBusinessDate will be the ones from the existing calendar (not the parameter one).
protected abstract  E compareDate(E date1, E date2, boolean returnEarliest)
           
protected abstract  DateCalculator<E> createNewCalculator(String calcName, E theStartDate, HolidayCalendar<E> holidays, HolidayHandler<E> handler)
           
 E getCurrentBusinessDate()
          Gives the current business date held by the calculator.
 int getCurrentIncrement()
          return the current increment in the calculator, this is used by the handler.
 HolidayCalendar<E> getHolidayCalendar()
          Returns an immutable version of the HolidayCalendar.
 HolidayHandler<E> getHolidayHandler()
           
 String getHolidayHandlerType()
          Gives the name of the holiday handler algorithm, see HolidayHandlerType for some standard values.
 String getName()
          This is typically the name of the associated set of holidays.
 E getStartDate()
          Gives the startDate of this calculator (immutable once set via setStartDate).
protected abstract  E getToday()
           
 boolean isCurrentDateNonWorking()
          Is the current business day a non-working day, this is useful if the calculator does not have any algorithm to change the date when it falls on a non-working day.
 boolean isNonWorkingDay(E date)
          is the given date a non working day?
 DateCalculator<E> moveByBusinessDays(int businessDays)
          This changes the current business date held in the calculator, it moves the current date by a number of business days, this means that if a date is either a 'weekend' or holiday along the way, it will be skipped acording to the holiday handler and not count towards the number of days to move.
protected abstract  DateCalculator<E> moveByMonths(int months)
           
 DateCalculator<E> moveByTenor(Tenor tenor)
          Move the current date by a given tenor, please note that all tenors are relative to the CURRENT day (and NOT from spot).
 DateCalculator<E> moveByTenor(Tenor tenor, int spotLag)
          move the current date by a given tenor, this means that if a date is either a 'weekend' or holiday, it will be skipped acording to the holiday handler and not count towards the number of days to move.
 E setCurrentBusinessDate(E date)
          Gives a current business date, it may be moved acording to the HolidayHandler algorithm if it falls on a non-working day.
 void setCurrentIncrement(int currentIncrement)
          This would be used by delegate methods to detect if the increment if positive or negative (this will allow us to define a Handler that can act as Forward if positive and Backward if negative).
 void setHolidayCalendar(HolidayCalendar<E> calendar)
          This is typically used at the construction of a DateCalculator to give a reference to a Holiday Calendar, if not the case, the calculator will make an immutable copy of the HolidayCalendar.
 void setHolidayHandler(HolidayHandler<E> holidayHandler)
           
 void setName(String name)
           
 void setStartDate(E startDate)
          Set both start date and current date
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.objectlab.kit.datecalc.common.DateCalculator
isWeekend, moveByDays, setWorkingWeek
 

Field Detail

DAYS_IN_WEEK

protected static final int DAYS_IN_WEEK
See Also:
Constant Field Values
Constructor Detail

AbstractDateCalculator

protected AbstractDateCalculator(String name,
                                 HolidayCalendar<E> holidayCalendar,
                                 HolidayHandler<E> holidayHandler)
Method Detail

setHolidayCalendar

public void setHolidayCalendar(HolidayCalendar<E> calendar)
Description copied from interface: DateCalculator
This is typically used at the construction of a DateCalculator to give a reference to a Holiday Calendar, if not the case, the calculator will make an immutable copy of the HolidayCalendar.

Specified by:
setHolidayCalendar in interface DateCalculator<E>
Parameters:
calendar - the holiday calendar (if null, no holidays taken into account)

getName

public String getName()
Description copied from interface: DateCalculator
This is typically the name of the associated set of holidays.

Specified by:
getName in interface DateCalculator<E>
Returns:
calculator name (Typically the name associated with the holiday set).

setName

public void setName(String name)

getStartDate

public E getStartDate()
Description copied from interface: DateCalculator
Gives the startDate of this calculator (immutable once set via setStartDate).

Specified by:
getStartDate in interface DateCalculator<E>
Returns:
startDate the reference date for this calculator.

setStartDate

public void setStartDate(E startDate)
Set both start date and current date

Specified by:
setStartDate in interface DateCalculator<E>
Parameters:
startDate - the reference date for this calculator, the current business date is also updated and may be moved if it falls on a non working day (holiday/weekend).

getCurrentBusinessDate

public E getCurrentBusinessDate()
Description copied from interface: DateCalculator
Gives the current business date held by the calculator.

Specified by:
getCurrentBusinessDate in interface DateCalculator<E>
Returns:
a date.

moveByTenor

public DateCalculator<E> moveByTenor(Tenor tenor,
                                     int spotLag)
move the current date by a given tenor, this means that if a date is either a 'weekend' or holiday, it will be skipped acording to the holiday handler and not count towards the number of days to move.

Specified by:
moveByTenor in interface DateCalculator<E>
Parameters:
tenor - the tenor.
spotLag - number of days to "spot" days, this can vary from one market to the other.
Returns:
the current businessCalendar (so one can do calendar.moveByTenor(StandardTenor.T_2M).getCurrentBusinessDate();)

moveByTenor

public DateCalculator<E> moveByTenor(Tenor tenor)
Move the current date by a given tenor, please note that all tenors are relative to the CURRENT day (and NOT from spot).

Specified by:
moveByTenor in interface DateCalculator<E>
Parameters:
tenor - the Tenor to reach.
Returns:
the current DateCalculator
Since:
1.1.0

calculateTenorDates

public List<E> calculateTenorDates(List<Tenor> tenors)
Calculate a series of Tenor codes in one go based on current day, this does NOT change the current business date.

Specified by:
calculateTenorDates in interface DateCalculator<E>
Returns:
list of dates in same order as tenors.
Since:
1.1.0

calculateTenorDates

public List<E> calculateTenorDates(List<Tenor> tenors,
                                   int spotLag)
Calculate a series of Tenor codes in one go based on SPOT day (calculated with the spot lag), this does NOT change the current business date.

Specified by:
calculateTenorDates in interface DateCalculator<E>
Returns:
list of dates in same order as tenors.
Since:
1.1.0

moveByMonths

protected abstract DateCalculator<E> moveByMonths(int months)

setHolidayHandler

public void setHolidayHandler(HolidayHandler<E> holidayHandler)

getHolidayHandlerType

public String getHolidayHandlerType()
Description copied from interface: DateCalculator
Gives the name of the holiday handler algorithm, see HolidayHandlerType for some standard values.

Specified by:
getHolidayHandlerType in interface DateCalculator<E>
Returns:
the holiday handler type, can be null

isNonWorkingDay

public boolean isNonWorkingDay(E date)
is the given date a non working day?

Specified by:
isNonWorkingDay in interface DateCalculator<E>
Returns:
true if the given date is non-working.

checkBoundary

protected abstract void checkBoundary(E date)
This may throw an IndexOutOfBoundsException if the date is not within the boundaries.

Parameters:
date -

isCurrentDateNonWorking

public boolean isCurrentDateNonWorking()
Description copied from interface: DateCalculator
Is the current business day a non-working day, this is useful if the calculator does not have any algorithm to change the date when it falls on a non-working day. This method can then be used to show a warning to the user.

Specified by:
isCurrentDateNonWorking in interface DateCalculator<E>
Returns:
true if the current date is either a weekend or a holiday.

setCurrentBusinessDate

public E setCurrentBusinessDate(E date)
Description copied from interface: DateCalculator
Gives a current business date, it may be moved acording to the HolidayHandler algorithm if it falls on a non-working day.

Specified by:
setCurrentBusinessDate in interface DateCalculator<E>
Returns:
new current business date if moved.

getHolidayHandler

public HolidayHandler<E> getHolidayHandler()

moveByBusinessDays

public DateCalculator<E> moveByBusinessDays(int businessDays)
Description copied from interface: DateCalculator
This changes the current business date held in the calculator, it moves the current date by a number of business days, this means that if a date is either a 'weekend' or holiday along the way, it will be skipped acording to the holiday handler and not count towards the number of days to move.

Specified by:
moveByBusinessDays in interface DateCalculator<E>
Parameters:
businessDays - (can be <0 or >0)
Returns:
the current DateCalculator (so one can do calendar.moveByBusinessDays(2).getCurrentBusinessDate();)

combine

public DateCalculator<E> combine(DateCalculator<E> calculator)
Allows DateCalculators to be combined into a new one, the startDate and currentBusinessDate will be the ones from the existing calendar (not the parameter one). The name will be combined name1+"/"+calendar.getName().

Specified by:
combine in interface DateCalculator<E>
Parameters:
calculator - return the same DateCalculator if calender is null or the original calendar (but why would you want to do that?)
Throws:
IllegalArgumentException - if both calendars have different types of HolidayHandlers or WorkingWeek;

getToday

protected abstract E getToday()

compareDate

protected abstract E compareDate(E date1,
                                 E date2,
                                 boolean returnEarliest)

createNewCalculator

protected abstract DateCalculator<E> createNewCalculator(String calcName,
                                                         E theStartDate,
                                                         HolidayCalendar<E> holidays,
                                                         HolidayHandler<E> handler)

getCurrentIncrement

public int getCurrentIncrement()
Description copied from interface: DateCalculator
return the current increment in the calculator, this is used by the handler.

Specified by:
getCurrentIncrement in interface DateCalculator<E>
Returns:
Returns the currentIncrement.

setCurrentIncrement

public void setCurrentIncrement(int currentIncrement)
Description copied from interface: DateCalculator
This would be used by delegate methods to detect if the increment if positive or negative (this will allow us to define a Handler that can act as Forward if positive and Backward if negative).

Specified by:
setCurrentIncrement in interface DateCalculator<E>
Parameters:
currentIncrement - The currentIncrement to set.

getHolidayCalendar

public HolidayCalendar<E> getHolidayCalendar()
Description copied from interface: DateCalculator
Returns an immutable version of the HolidayCalendar.

Specified by:
getHolidayCalendar in interface DateCalculator<E>
Returns:
Returns the holidayCalendar.

clone

protected abstract E clone(E date)


Copyright © 2006-2010 Appendium - Portfolio Financing Platform. All Rights Reserved.