Class ImmutableHolidayCalendar

  • All Implemented Interfaces:
    HolidayCalendar, Named, java.io.Serializable, Bean, ImmutableBean

    public final class ImmutableHolidayCalendar
    extends java.lang.Object
    implements HolidayCalendar, ImmutableBean, java.io.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 a HolidayCalendar before the holiday data methods can be accessed. See HolidayCalendarIds for a standard set of identifiers available in ReferenceData.standard().

    See Also:
    Serialized Form
    • Field Detail

      • DESERIALIZER

        public static final SerDeserializer DESERIALIZER
        The deserializer, for compatibility.
    • Method Detail

      • of

        public static ImmutableHolidayCalendar of​(HolidayCalendarId id,
                                                  java.lang.Iterable<java.time.LocalDate> holidays,
                                                  java.time.DayOfWeek firstWeekendDay,
                                                  java.time.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 identifier
        holidays - the set of holiday dates
        firstWeekendDay - the first weekend day
        secondWeekendDay - the second weekend day, may be same as first
        Returns:
        the holiday calendar
      • of

        public static ImmutableHolidayCalendar of​(HolidayCalendarId id,
                                                  java.lang.Iterable<java.time.LocalDate> holidays,
                                                  java.lang.Iterable<java.time.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 identifier
        holidays - the set of holiday dates
        weekendDays - the days that define the weekend, if empty then weekends are treated as business days
        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 calendar
        cal2 - the second calendar
        Returns:
        the combined calendar
      • isHoliday

        public boolean isHoliday​(java.time.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 interface HolidayCalendar
        Parameters:
        date - the date to check
        Returns:
        true if the specified date is a holiday
      • shift

        public java.time.LocalDate shift​(java.time.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 interface HolidayCalendar
        Parameters:
        date - the date to adjust
        amount - the number of business days to adjust by
        Returns:
        the shifted date
      • next

        public java.time.LocalDate next​(java.time.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 interface HolidayCalendar
        Parameters:
        date - the date to adjust
        Returns:
        the first business day after the input date
      • previous

        public java.time.LocalDate previous​(java.time.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 interface HolidayCalendar
        Parameters:
        date - the date to adjust
        Returns:
        the first business day before the input date
      • nextSameOrLastInMonth

        public java.time.LocalDate nextSameOrLastInMonth​(java.time.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 interface HolidayCalendar
        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​(java.time.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 interface HolidayCalendar
        Parameters:
        date - the date to check
        Returns:
        true if the specified date is the last business day of the month
      • lastBusinessDayOfMonth

        public java.time.LocalDate lastBusinessDayOfMonth​(java.time.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 interface HolidayCalendar
        Parameters:
        date - the date to check
        Returns:
        true if the specified date is the last business day of the month
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Returns the name of the calendar.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the descriptive string