Class ImmutableHolidayCalendar
- java.lang.Object
-
- com.opengamma.strata.basics.date.ImmutableHolidayCalendar
-
- All Implemented Interfaces:
HolidayCalendar,Named,Serializable,org.joda.beans.Bean,org.joda.beans.ImmutableBean
public final class ImmutableHolidayCalendar extends Object implements HolidayCalendar, org.joda.beans.ImmutableBean, Serializable
An immutable holiday calendar implementation.A standard immutable implementation of
HolidayCalendarthat 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 aHolidayCalendarbefore the holiday data methods can be accessed. SeeHolidayCalendarIdsfor a standard set of identifiers available inReferenceData.standard().- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classImmutableHolidayCalendar.MetaThe meta-bean forImmutableHolidayCalendar.
-
Field Summary
Fields Modifier and Type Field Description static org.joda.beans.ser.SerDeserializerDESERIALIZERThe deserializer, for compatibility.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ImmutableHolidayCalendarcombined(ImmutableHolidayCalendar cal1, ImmutableHolidayCalendar cal2)Obtains a combined holiday calendar instance.intdaysBetween(LocalDate startInclusive, LocalDate endExclusive)Calculates the number of business days between two dates.booleanequals(Object obj)HolidayCalendarIdgetId()Gets the identifier, such as 'GBLO'.inthashCode()booleanisHoliday(LocalDate date)Checks if the specified date is a holiday.booleanisLastBusinessDayOfMonth(LocalDate date)Checks if the specified date is the last business day of the month.LocalDatelastBusinessDayOfMonth(LocalDate date)Calculates the last business day of the month.static ImmutableHolidayCalendar.Metameta()The meta-bean forImmutableHolidayCalendar.ImmutableHolidayCalendar.MetametaBean()LocalDatenext(LocalDate date)Finds the next business day, always returning a later date.LocalDatenextSameOrLastInMonth(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 ImmutableHolidayCalendarof(HolidayCalendarId id, Iterable<LocalDate> holidays, Iterable<DayOfWeek> weekendDays)Obtains an instance from a set of holiday dates and weekend days.static ImmutableHolidayCalendarof(HolidayCalendarId id, Iterable<LocalDate> holidays, Iterable<DayOfWeek> weekendDays, Iterable<LocalDate> workingDays)Obtains an instance from a set of holiday dates and weekend days.static ImmutableHolidayCalendarof(HolidayCalendarId id, Iterable<LocalDate> holidays, DayOfWeek firstWeekendDay, DayOfWeek secondWeekendDay)Obtains an instance from a set of holiday dates and weekend days.LocalDateprevious(LocalDate date)Finds the previous business day, always returning an earlier date.LocalDateshift(LocalDate date, int amount)Shifts the date by the specified number of business days.StringtoString()Returns the name of the calendar.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.opengamma.strata.basics.date.HolidayCalendar
adjustBy, businessDays, combinedWith, getName, holidays, isBusinessDay, linkedWith, nextOrSame, previousOrSame
-
-
-
-
Method Detail
-
of
public static ImmutableHolidayCalendar of(HolidayCalendarId id, Iterable<LocalDate> holidays, DayOfWeek firstWeekendDay, DayOfWeek secondWeekendDay)
Obtains an instance from a set of holiday dates and weekend days.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.
- Parameters:
id- the identifierholidays- the set of holiday datesfirstWeekendDay- the first weekend daysecondWeekendDay- the second weekend day, may be same as first- Returns:
- the holiday calendar
-
of
public static ImmutableHolidayCalendar of(HolidayCalendarId id, Iterable<LocalDate> holidays, Iterable<DayOfWeek> weekendDays)
Obtains an instance from a set of holiday dates and weekend days.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.
- Parameters:
id- the identifierholidays- the set of holiday datesweekendDays- the days that define the weekend, if empty then weekends are treated as business days- Returns:
- the holiday calendar
-
of
public 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.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.
- Parameters:
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 weekends- Returns:
- the holiday calendar
-
combined
public static ImmutableHolidayCalendar combined(ImmutableHolidayCalendar cal1, ImmutableHolidayCalendar cal2)
Obtains a combined holiday calendar instance.This combines the two input calendars. It is intended for up-front occasional use rather than continuous use, as it can be relatively slow.
- Parameters:
cal1- the first calendarcal2- the second calendar- Returns:
- the combined calendar
-
isHoliday
public boolean isHoliday(LocalDate date)
Description copied from interface:HolidayCalendarChecks if the specified date is a holiday.This is the opposite of
HolidayCalendar.isBusinessDay(LocalDate). A weekend is treated as a holiday.- Specified by:
isHolidayin interfaceHolidayCalendar- Parameters:
date- the date to check- Returns:
- true if the specified date is a holiday
-
shift
public LocalDate shift(LocalDate date, int amount)
Description copied from interface:HolidayCalendarShifts the date by the specified number of business days.If 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.
- Specified by:
shiftin interfaceHolidayCalendar- Parameters:
date- the date to adjustamount- the number of business days to adjust by- Returns:
- the shifted date
-
next
public LocalDate next(LocalDate date)
Description copied from interface:HolidayCalendarFinds the next business day, always returning a later date.Given a date, this method returns the next business day.
- Specified by:
nextin interfaceHolidayCalendar- Parameters:
date- the date to adjust- Returns:
- the first business day after the input date
-
previous
public LocalDate previous(LocalDate date)
Description copied from interface:HolidayCalendarFinds the previous business day, always returning an earlier date.Given a date, this method returns the previous business day.
- Specified by:
previousin interfaceHolidayCalendar- Parameters:
date- the date to adjust- Returns:
- the first business day before the input date
-
nextSameOrLastInMonth
public LocalDate nextSameOrLastInMonth(LocalDate date)
Description copied from interface:HolidayCalendarFinds 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.Given 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.
- Specified by:
nextSameOrLastInMonthin interfaceHolidayCalendar- Parameters:
date- the date to adjust- Returns:
- the input date if it is a business day, the next business day if within the same month or the last business day of the month
-
isLastBusinessDayOfMonth
public boolean isLastBusinessDayOfMonth(LocalDate date)
Description copied from interface:HolidayCalendarChecks if the specified date is the last business day of the month.This returns true if the date specified is the last valid business day of the month.
- Specified by:
isLastBusinessDayOfMonthin interfaceHolidayCalendar- Parameters:
date- the date to check- Returns:
- true if the specified date is the last business day of the month
-
lastBusinessDayOfMonth
public LocalDate lastBusinessDayOfMonth(LocalDate date)
Description copied from interface:HolidayCalendarCalculates the last business day of the month.Given a date, this method returns the date of the last business day of the month.
- Specified by:
lastBusinessDayOfMonthin interfaceHolidayCalendar- Parameters:
date- the date to check- Returns:
- the date of the last business day of the month
-
daysBetween
public int daysBetween(LocalDate startInclusive, LocalDate endExclusive)
Description copied from interface:HolidayCalendarCalculates the number of business days between two dates.This 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.
- Specified by:
daysBetweenin interfaceHolidayCalendar- Parameters:
startInclusive- the start dateendExclusive- the end date- Returns:
- the total number of business days between the start and end date
-
toString
public String toString()
Returns the name of the calendar.
-
meta
public static ImmutableHolidayCalendar.Meta meta()
The meta-bean forImmutableHolidayCalendar.- Returns:
- the meta-bean, not null
-
metaBean
public ImmutableHolidayCalendar.Meta metaBean()
- Specified by:
metaBeanin interfaceorg.joda.beans.Bean
-
getId
public HolidayCalendarId getId()
Gets the identifier, such as 'GBLO'.- Specified by:
getIdin interfaceHolidayCalendar- Returns:
- the value of the property, not null
-
-