Class AbstractObservance

java.lang.Object
org.holiday.calendar.observance.AbstractObservance
All Implemented Interfaces:
Function<Integer,LocalDate>, Predicate<Integer>, Observance
Direct Known Subclasses:
AutumnalEquinoxDay, BankHoliday, ChineseNewYearDay, ChineseNewYearFirstDay, ChineseNewYearSecondDay, ComingOfAgeDay, CompositeObservance, DayAfterThanksgiving, Deepavali, DragonBoatFestival, EmperorsBirthday, HariRayaHaji, HariRayaPuasa, KingsBirthday, MarineDay, MidAutumnFestival, OrthodoxEaster, QingmingFestival, RespectForTheAgedDay, SportsDay, VernalEquinoxDay, VesakDay, VictoryInEuropeDay, WesternEaster

public abstract class AbstractObservance extends Object implements Observance
Abstract base class for Observance implementations, providing standard null-guard and year-validity logic.
Author:
Dave Joyce
  • Constructor Details

    • AbstractObservance

      public AbstractObservance()
  • Method Details

    • apply

      public final LocalDate apply(Integer year)
      Specified by:
      apply in interface Function<Integer,LocalDate>
    • test

      public final boolean test(Integer year)
      Description copied from interface: Observance
      Determines whether this observance applies to the specified year.
      Specified by:
      test in interface Observance
      Specified by:
      test in interface Predicate<Integer>
      Parameters:
      year - year of potential observance
      Returns:
      true if the input year applies for this observance, otherwise false
    • computeDate

      protected abstract LocalDate computeDate(int year)
      Compute the date for this observance in the given year. Only called when isValidYear(int) returns true.
      Parameters:
      year - the year for which to compute the date
      Returns:
      computed holiday date
    • isValidYear

      protected boolean isValidYear(int year)
      Determine whether this observance applies in the given year. Defaults to true (all years are valid).
      Parameters:
      year - the year to test
      Returns:
      true if this observance applies