java.lang.Object
org.holiday.calendar.HolidayCalendar
A named collection of
holidays observed within a single
calendar year. An instance of this class defines the days on which
activities may not occur.- Author:
- Dave Joyce
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DateRollDefault 'empty'date rollingbehavior.Defaultdays of weekthat constitute the 'standard' weekend worldwide. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuilder()calculate(int year) Calculate the dates of the holidays on this calendar for the specified year.calculate(int fromYear, int toYear) Calculate the dates of the holidays on this calendar for each year in the specified range, returning all results as a single chronologically- sorted list.calculateByYear(int fromYear, int toYear) Calculate the dates of the holidays on this calendar for each year in the specified range, returning results grouped by year.getCode()Get holidays observed on this calendar.getName()Get weekend days recognized by this calendar.booleanDetermine if the given instant, in the specified time zone, falls on the weekend as defined by this holiday calendar.booleanDetermine if the given date, in the specified time zone, falls on the weekend as defined by this holiday calendar.booleanisWeekendUTC(Instant instant) Determine if the given instant, in UTC standard time, falls on the weekend as defined by this holiday calendar.booleanisWeekendUTC(Date date) Determine if the given date, in UTC standard time, falls on the weekend as defined by this holiday calendar.merge(HolidayCalendar other) Merge the givenHolidayCalendarobject with this one.toString()
-
Field Details
-
NO_ROLL
Default 'empty'date rollingbehavior. -
STANDARD_WEEKEND
Defaultdays of weekthat constitute the 'standard' weekend worldwide.
-
-
Constructor Details
-
HolidayCalendar
public HolidayCalendar(String code, String name, DateRoll dateRoll, Set<DayOfWeek> weekendDays, Set<Holiday> holidays) Construct a new holiday calendar object.- Parameters:
code- short text code symbol by which this calendar may be locatedname- name of this holiday calendar objectdateRoll- date rolling behavior to be employed by this holiday calendarweekendDays- days of the week to be treated as the weekendholidays- set ofHolidayobjects to be observed
-
-
Method Details
-
builder
-
getCode
-
getName
-
getDateRoll
-
getHolidays
Get holidays observed on this calendar.- Returns:
- unmodifiable set of
Holidayobjects
-
getWeekendDays
Get weekend days recognized by this calendar.- Returns:
- unmodifiable set of weekend
days
-
isWeekend
Determine if the given instant, in the specified time zone, falls on the weekend as defined by this holiday calendar. -
isWeekendUTC
Determine if the given instant, in UTC standard time, falls on the weekend as defined by this holiday calendar. -
isWeekend
Determine if the given date, in the specified time zone, falls on the weekend as defined by this holiday calendar. -
isWeekendUTC
Determine if the given date, in UTC standard time, falls on the weekend as defined by this holiday calendar. -
calculate
Calculate the dates of the holidays on this calendar for the specified year. Thedatesreturned by this method are adjusted according to the date rolling behavior of this calendar.- Parameters:
year- Common Era (CE) year for which to obtain holiday dates- Returns:
- chronologically-sorted list of observed holiday dates
-
calculate
Calculate the dates of the holidays on this calendar for each year in the specified range, returning all results as a single chronologically- sorted list.The
datesreturned are adjusted according to the date rolling behavior of this calendar. Note that a rolled date may fall outside the nominal year range (e.g. a Dec 31 holiday rolled forward to Jan 1 of the following year).Passing
fromYear == toYearis legal and returns the same result ascalculate(int).- Parameters:
fromYear- first Common Era (CE) year in the range (inclusive)toYear- last Common Era (CE) year in the range (inclusive)- Returns:
- chronologically-sorted list of observed holiday dates across all
years in
[fromYear, toYear] - Throws:
IllegalArgumentException- iffromYear > toYear- See Also:
-
calculateByYear
Calculate the dates of the holidays on this calendar for each year in the specified range, returning results grouped by year.The map contains an entry for every year in
[fromYear, toYear]inclusive — years with no holidays map to an empty list (dense representation). Each list is chronologically sorted. The map itself is ordered by ascending year.Note: the year key is the nominal year used for calculation. A rolled date may have a
HolidayDate.getDate()whose year differs from the map key.Passing
fromYear == toYearis legal.- Parameters:
fromYear- first Common Era (CE) year in the range (inclusive)toYear- last Common Era (CE) year in the range (inclusive)- Returns:
- map of nominal year to chronologically-sorted observed holiday dates, ordered by ascending year; all years in the range are present as keys
- Throws:
IllegalArgumentException- iffromYear > toYear- See Also:
-
merge
Merge the givenHolidayCalendarobject with this one.- Parameters:
other- holiday calendar to be merged- Returns:
- union of this holiday calendar and the specified calendar
-
toString
-