public final class ImmutableHolidayCalendar extends Object implements HolidayCalendar, org.joda.beans.ImmutableBean, Serializable
A standard immutable implementation of HolidayCalendar that stores all
dates that are holidays, plus a list of weekend days.
Internally, the class uses a range to determine the range of known holiday dates. Beyond the range of known holiday dates, weekend days are used to determine business days. Dates may be queried from year zero to year 10,000.
Applications should refer to holidays using HolidayCalendarId.
The identifier must be resolved
to a HolidayCalendar before the holiday data methods can be accessed.
See HolidayCalendarIds for a standard set of identifiers available in ReferenceData.standard().
| Modifier and Type | Class and Description |
|---|---|
static class |
ImmutableHolidayCalendar.Meta
The meta-bean for
ImmutableHolidayCalendar. |
| Modifier and Type | Field and Description |
|---|---|
static org.joda.beans.ser.SerDeserializer |
DESERIALIZER
The deserializer, for compatibility.
|
| Modifier and Type | Method and Description |
|---|---|
static ImmutableHolidayCalendar |
combined(ImmutableHolidayCalendar cal1,
ImmutableHolidayCalendar cal2)
Obtains a combined holiday calendar instance.
|
int |
daysBetween(LocalDate startInclusive,
LocalDate endExclusive)
Calculates the number of business days between two dates.
|
boolean |
equals(Object obj) |
HolidayCalendarId |
getId()
Gets the identifier, such as 'GBLO'.
|
int |
hashCode() |
boolean |
isHoliday(LocalDate date)
Checks if the specified date is a holiday.
|
boolean |
isLastBusinessDayOfMonth(LocalDate date)
Checks if the specified date is the last business day of the month.
|
LocalDate |
lastBusinessDayOfMonth(LocalDate date)
Calculates the last business day of the month.
|
static ImmutableHolidayCalendar.Meta |
meta()
The meta-bean for
ImmutableHolidayCalendar. |
ImmutableHolidayCalendar.Meta |
metaBean() |
LocalDate |
next(LocalDate date)
Finds the next business day, always returning a later date.
|
LocalDate |
nextSameOrLastInMonth(LocalDate date)
Finds the next business day within the month, returning the input date if it is a business day,
or the last business day of the month if the next business day is in a different month.
|
static ImmutableHolidayCalendar |
of(HolidayCalendarId id,
Iterable<LocalDate> holidays,
DayOfWeek firstWeekendDay,
DayOfWeek secondWeekendDay)
Obtains an instance from a set of holiday dates and weekend days.
|
static ImmutableHolidayCalendar |
of(HolidayCalendarId id,
Iterable<LocalDate> holidays,
Iterable<DayOfWeek> weekendDays)
Obtains an instance from a set of holiday dates and weekend days.
|
static ImmutableHolidayCalendar |
of(HolidayCalendarId id,
Iterable<LocalDate> holidays,
Iterable<DayOfWeek> weekendDays,
Iterable<LocalDate> workingDays)
Obtains an instance from a set of holiday dates and weekend days.
|
LocalDate |
previous(LocalDate date)
Finds the previous business day, always returning an earlier date.
|
LocalDate |
shift(LocalDate date,
int amount)
Shifts the date by the specified number of business days.
|
String |
toString()
Returns the name of the calendar.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitadjustBy, businessDays, combinedWith, getName, holidays, isBusinessDay, linkedWith, nextOrSame, previousOrSamepublic static final org.joda.beans.ser.SerDeserializer DESERIALIZER
public static ImmutableHolidayCalendar of(HolidayCalendarId id, Iterable<LocalDate> holidays, DayOfWeek firstWeekendDay, DayOfWeek secondWeekendDay)
The holiday dates will be extracted into a set with duplicates ignored. The minimum supported date for query is the start of the year of the earliest holiday. The maximum supported date for query is the end of the year of the latest holiday.
The weekend days may both be the same.
id - the identifierholidays - the set of holiday datesfirstWeekendDay - the first weekend daysecondWeekendDay - the second weekend day, may be same as firstpublic static ImmutableHolidayCalendar of(HolidayCalendarId id, Iterable<LocalDate> holidays, Iterable<DayOfWeek> weekendDays)
The holiday dates will be extracted into a set with duplicates ignored. The minimum supported date for query is the start of the year of the earliest holiday. The maximum supported date for query is the end of the year of the latest holiday.
The weekend days may be empty, in which case the holiday dates should contain any weekends.
id - the identifierholidays - the set of holiday datesweekendDays - the days that define the weekend, if empty then weekends are treated as business dayspublic static ImmutableHolidayCalendar of(HolidayCalendarId id, Iterable<LocalDate> holidays, Iterable<DayOfWeek> weekendDays, Iterable<LocalDate> workingDays)
The holiday dates will be extracted into a set with duplicates ignored. The minimum supported date for query is the start of the year of the earliest holiday. The maximum supported date for query is the end of the year of the latest holiday.
The weekend days may be empty, in which case the holiday dates should contain any weekends. The working days are processed last, changing holidays and weekends back to business days, but only within the range of supported years.
id - the identifierholidays - the set of holiday datesweekendDays - the days that define the weekend, if empty then weekends are treated as business daysworkingDays - the working days that override holidays and weekendspublic static ImmutableHolidayCalendar combined(ImmutableHolidayCalendar cal1, ImmutableHolidayCalendar cal2)
This combines the two input calendars. It is intended for up-front occasional use rather than continuous use, as it can be relatively slow.
cal1 - the first calendarcal2 - the second calendarpublic boolean isHoliday(LocalDate date)
HolidayCalendar
This is the opposite of HolidayCalendar.isBusinessDay(LocalDate).
A weekend is treated as a holiday.
isHoliday in interface HolidayCalendardate - the date to checkpublic LocalDate shift(LocalDate date, int amount)
HolidayCalendarIf the amount is zero, the input date is returned. If the amount is positive, later business days are chosen. If the amount is negative, earlier business days are chosen.
shift in interface HolidayCalendardate - the date to adjustamount - the number of business days to adjust bypublic LocalDate next(LocalDate date)
HolidayCalendarGiven a date, this method returns the next business day.
next in interface HolidayCalendardate - the date to adjustpublic LocalDate previous(LocalDate date)
HolidayCalendarGiven a date, this method returns the previous business day.
previous in interface HolidayCalendardate - the date to adjustpublic LocalDate nextSameOrLastInMonth(LocalDate date)
HolidayCalendarGiven a date, this method returns a business day. If the input date is a business day, it is returned. If the next business day is within the same month, it is returned. Otherwise, the last business day of the month is returned.
Note that the result of this method may be earlier than the input date.
This corresponds to the modified following business day convention.
nextSameOrLastInMonth in interface HolidayCalendardate - the date to adjustpublic boolean isLastBusinessDayOfMonth(LocalDate date)
HolidayCalendarThis returns true if the date specified is the last valid business day of the month.
isLastBusinessDayOfMonth in interface HolidayCalendardate - the date to checkpublic LocalDate lastBusinessDayOfMonth(LocalDate date)
HolidayCalendarGiven a date, this method returns the date of the last business day of the month.
lastBusinessDayOfMonth in interface HolidayCalendardate - the date to checkpublic int daysBetween(LocalDate startInclusive, LocalDate endExclusive)
HolidayCalendarThis calculates the number of business days within the range. If the dates are equal, zero is returned. If the end is before the start, an exception is thrown.
daysBetween in interface HolidayCalendarstartInclusive - the start dateendExclusive - the end datepublic String toString()
public static ImmutableHolidayCalendar.Meta meta()
ImmutableHolidayCalendar.public ImmutableHolidayCalendar.Meta metaBean()
metaBean in interface org.joda.beans.Beanpublic HolidayCalendarId getId()
getId in interface HolidayCalendarCopyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.