de.jaret.util.date.holidayenumerator
Class HolidayEnumeratorBase

java.lang.Object
  extended by de.jaret.util.date.holidayenumerator.HolidayEnumeratorBase
All Implemented Interfaces:
HolidayEnumerator
Direct Known Subclasses:
HolidayEnumerator_de_DE, HolidayEnumerator_en_US, HolidayEnumerator_fr_FR, HolidayEnumerator_pl_PL

public abstract class HolidayEnumeratorBase
extends Object
implements HolidayEnumerator

Base implementation for HolidayEnumerators. This abstract class contains a complete base implementation and some date calculation code (easter and other). Concrete HolidayEnumertaors have to implement the method fillMap(int year) to fill all hollidays (and special days). To add a day the method addNamedDate should be used. Attention has to be taken: all month values start with 0 (january = 0)

Version:
$Id: HolidayEnumeratorBase.java 297 2007-03-12 21:38:00Z olk $
Author:
Peter Kliem

Nested Class Summary
 class HolidayEnumeratorBase.EasyDate
          Simple holder class for a split date.
 class HolidayEnumeratorBase.NamedDateImpl
          Implementation of the NamedDate for use with holiday enumerators.
 
Field Summary
protected  Locale _locale
          locale.
protected  String _regionId
          region id.
protected  Map<Integer,Map<Integer,Map<Integer,NamedDate>>> _yearMap
          map containing the holidays and special days.
protected static Calendar CALENDAR
          calendar instance for calculations.
 
Constructor Summary
HolidayEnumeratorBase()
           
 
Method Summary
protected  void addNamedDate(HolidayEnumeratorBase.EasyDate ed, boolean isHoliday, String name)
           
protected  void addNamedDate(int year, int month, int day, boolean isHoliday, String name)
          Add a named date to the list of holidays.
protected  void addNamedDate(int year, int month, int day, int dayOffset, boolean isHoliday, String name)
           
 HolidayEnumeratorBase.EasyDate calcEaster(int year)
          Calculate the easter date (sunday) for a given year.
protected  int daysInMonth(int year, int month)
           
 boolean equals(Object obj)
          .
protected abstract  void fillMap(int year)
          Calculate the holidays for a given year.
 HolidayEnumeratorBase.EasyDate fridayOrMonday(HolidayEnumeratorBase.EasyDate ed)
          If the given Date is a saturday return the friday before, if it is a sunday return the monday after, in all other cases return null.
 String[] getAvailableRegionIds()
          Retrieve the available region identifiers of the holiday enumerator.
protected  Date getDate(int year, int month, int day, int dayOffset)
           
 String getDayName(Date date)
          Retrieve the name of a special day or holiday.
 HolidayEnumeratorBase.EasyDate getEasyDate(int year, int month, int day)
           
 Locale getLocale()
          Retrieve the Locale of this HolidayEnumerator.
 List<NamedDate> getNamedDays(int year, boolean includeSpecialDays)
          Retrieve a list of named days for a given year.
 List<NamedDate> getNamedDays(int year, int month, boolean includeSpecialDays)
          Retrieve a list of named days for a given year.
 String getRegionId()
          Retrieve the RegionId of this HolidayEnumerator.
protected  int getWeekday(Date date)
           
 int hashCode()
           
protected  void init()
          Do initializations.
 boolean isHoliday(Date date)
          Check whether a given day denotes a holiday.
 boolean isSpecialDay(Date date)
          Check whether a given day denotes a special (named) day.
 HolidayEnumeratorBase.EasyDate lastWeekdayInMonth(int year, int month, int weekday)
          Calculate the last weekday in a given month.
 HolidayEnumeratorBase.EasyDate nThWeekdayInMonth(int year, int month, int weekday, int nTh)
          Calculate the nTh weekday in a month (i.e. the 3rd Monday in october)
 void setLocale(Locale locale)
          
 void setRegionId(String regionId)
          
 String toString()
          toString delivers the region.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_yearMap

protected Map<Integer,Map<Integer,Map<Integer,NamedDate>>> _yearMap
map containing the holidays and special days.


CALENDAR

protected static final Calendar CALENDAR
calendar instance for calculations.


_locale

protected Locale _locale
locale.


_regionId

protected String _regionId
region id.

Constructor Detail

HolidayEnumeratorBase

public HolidayEnumeratorBase()
Method Detail

fillMap

protected abstract void fillMap(int year)
Calculate the holidays for a given year. This method has to be implemented by concrete implementations of HolidayEnumerators.

Parameters:
year - year to calculate the holidays for

getAvailableRegionIds

public String[] getAvailableRegionIds()
Retrieve the available region identifiers of the holiday enumerator. Default implementation returns en empty array.

Specified by:
getAvailableRegionIds in interface HolidayEnumerator
Returns:
the availbale ids or an empty array for no regions

toString

public String toString()
toString delivers the region.

Overrides:
toString in class Object

equals

public boolean equals(Object obj)
. Two hes are qual if loale and region match.

Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

init

protected void init()
Do initializations.


addNamedDate

protected void addNamedDate(int year,
                            int month,
                            int day,
                            boolean isHoliday,
                            String name)
Add a named date to the list of holidays.

Parameters:
year - year
month - (0= January!)
day - day
isHoliday - true for holiday, false = special day
name - name of the date

addNamedDate

protected void addNamedDate(int year,
                            int month,
                            int day,
                            int dayOffset,
                            boolean isHoliday,
                            String name)

addNamedDate

protected void addNamedDate(HolidayEnumeratorBase.EasyDate ed,
                            boolean isHoliday,
                            String name)

getDate

protected Date getDate(int year,
                       int month,
                       int day,
                       int dayOffset)

getWeekday

protected int getWeekday(Date date)

isHoliday

public boolean isHoliday(Date date)
Check whether a given day denotes a holiday.

Specified by:
isHoliday in interface HolidayEnumerator
Parameters:
date - date to be checked
Returns:
true if the date denotes a holiday

isSpecialDay

public boolean isSpecialDay(Date date)
Check whether a given day denotes a special (named) day.

Specified by:
isSpecialDay in interface HolidayEnumerator
Parameters:
date - The date to be checked
Returns:
true if the date denotes a named day.

getDayName

public String getDayName(Date date)
Retrieve the name of a special day or holiday.

Specified by:
getDayName in interface HolidayEnumerator
Parameters:
date - date for which the name is to be retrieved
Returns:
the name of the day or null if no name is found.

getLocale

public Locale getLocale()
Retrieve the Locale of this HolidayEnumerator.

Specified by:
getLocale in interface HolidayEnumerator
Returns:
configured Locale

setLocale

public void setLocale(Locale locale)


getRegionId

public String getRegionId()
Retrieve the RegionId of this HolidayEnumerator.

Specified by:
getRegionId in interface HolidayEnumerator
Returns:
the regionid

setRegionId

public void setRegionId(String regionId)


getNamedDays

public List<NamedDate> getNamedDays(int year,
                                    boolean includeSpecialDays)
Retrieve a list of named days for a given year.

Specified by:
getNamedDays in interface HolidayEnumerator
Parameters:
year - year to be questioned
includeSpecialDays - if true, special days are includes, otherwise the list will only contain holidays
Returns:
an ordered list of named dates

getNamedDays

public List<NamedDate> getNamedDays(int year,
                                    int month,
                                    boolean includeSpecialDays)
Retrieve a list of named days for a given year.

Specified by:
getNamedDays in interface HolidayEnumerator
Parameters:
year - year to be questioned
month - month to be questioned
includeSpecialDays - if true, special days are includes, otherwise the list will only contain holidays
Returns:
an ordered list of named dates

calcEaster

public HolidayEnumeratorBase.EasyDate calcEaster(int year)
Calculate the easter date (sunday) for a given year. This method was supplied by Marita Gierlings.

Parameters:
year - year (valid input from 1583 to 2499)
Returns:
an Easydate indicating easter sunday.

nThWeekdayInMonth

public HolidayEnumeratorBase.EasyDate nThWeekdayInMonth(int year,
                                                        int month,
                                                        int weekday,
                                                        int nTh)
Calculate the nTh weekday in a month (i.e. the 3rd Monday in october)

Parameters:
year - year
month - month (starting with january = 0)
weekday - weekday as constant from java.util.Calendar
nTh - first=1, ... max 5
Returns:
date as EasyDate or null if not found

lastWeekdayInMonth

public HolidayEnumeratorBase.EasyDate lastWeekdayInMonth(int year,
                                                         int month,
                                                         int weekday)
Calculate the last weekday in a given month.

Parameters:
year - year
month - (January=0!)
weekday - constant from java.util.Calendar
Returns:
EasyDate

fridayOrMonday

public HolidayEnumeratorBase.EasyDate fridayOrMonday(HolidayEnumeratorBase.EasyDate ed)
If the given Date is a saturday return the friday before, if it is a sunday return the monday after, in all other cases return null. Used for correction of US holidays.

Parameters:
ed - date to go from
Returns:
shifted date or null

daysInMonth

protected int daysInMonth(int year,
                          int month)

getEasyDate

public HolidayEnumeratorBase.EasyDate getEasyDate(int year,
                                                  int month,
                                                  int day)


Copyright © 2013. All Rights Reserved.