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
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 aHolidayCalendar
before the holiday data methods can be accessed. SeeHolidayCalendarIds
for a standard set of identifiers available inReferenceData.standard()
.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ImmutableHolidayCalendar.Meta
The meta-bean forImmutableHolidayCalendar
.
-
Field Summary
Fields Modifier and Type Field Description static org.joda.beans.ser.SerDeserializer
DESERIALIZER
The deserializer, for compatibility.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 forImmutableHolidayCalendar
.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, 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.static ImmutableHolidayCalendar
of(HolidayCalendarId id, Iterable<LocalDate> holidays, DayOfWeek firstWeekendDay, DayOfWeek secondWeekendDay)
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.-
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:HolidayCalendar
Checks if the specified date is a holiday.This is the opposite of
HolidayCalendar.isBusinessDay(LocalDate)
. A weekend is treated as a holiday.- Specified by:
isHoliday
in 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:HolidayCalendar
Shifts 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:
shift
in 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:HolidayCalendar
Finds the next business day, always returning a later date.Given a date, this method returns the next business day.
- Specified by:
next
in 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:HolidayCalendar
Finds the previous business day, always returning an earlier date.Given a date, this method returns the previous business day.
- Specified by:
previous
in 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:HolidayCalendar
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.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:
nextSameOrLastInMonth
in 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:HolidayCalendar
Checks 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:
isLastBusinessDayOfMonth
in 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:HolidayCalendar
Calculates 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:
lastBusinessDayOfMonth
in 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:HolidayCalendar
Calculates 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:
daysBetween
in 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:
metaBean
in interfaceorg.joda.beans.Bean
-
getId
public HolidayCalendarId getId()
Gets the identifier, such as 'GBLO'.- Specified by:
getId
in interfaceHolidayCalendar
- Returns:
- the value of the property, not null
-
-