Interface CalendricalMatcher

All Known Implementing Classes:
CalendricalMatchers.DayOfWeekInMonth, CalendricalMatchers.Impl, DateTimeFields, LocalDate, LocalDateTime, LocalTime, MonthDay, OffsetDate, OffsetDateTime, OffsetTime, Year, YearMonth, ZonedDateTime

public interface CalendricalMatcher
Strategy for matching against a calendrical.

Matchers can be used to query the calendrical in unusual ways. Examples might be a matcher that checks if the date is a weekend or holiday, or Friday the Thirteenth.

CalendricalMatcher is an interface and must be implemented with care to ensure other classes in the framework operate correctly. All instantiable implementations must be final, immutable and thread-safe.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks if the input calendrical matches the rules of the implementation.
  • Method Details

    • matchesCalendrical

      boolean matchesCalendrical(Calendrical calendrical)
      Checks if the input calendrical matches the rules of the implementation.

      This is a strategy pattern that allows a range of matches to be made against a calendrical. A typical implementation will query the calendrical to extract one of more values, and compare or check them in some way.

      For example, an implementation to check if the calendrical represents a Saturday or Sunday:

        public boolean matchesCalendrical(Calendrical calendrical) {
          DayOfWeek dow = calendrical.get(ISOChronology.dayOfWeekRule());
          return dow != null && (dow == DayOfWeek.SATURDAY || dow == DayOfWeek.SUNDAY);
        }
       
      Parameters:
      calendrical - the calendrical to match against, not null
      Returns:
      true if the date matches, false otherwise