Class CalendricalMatchers


  • public final class CalendricalMatchers
    extends java.lang.Object
    Provides common implementations of CalendricalMatcher.

    These matchers are useful and common implementations of CalendricalMatcher. A matcher allows any type of matching to be performed against a calendrical. Examples might be checking of the calendrical represents Friday the Thirteenth, or the last day of the month, or one of the American continent time-zones.

    CalendricalMatchers is a utility class. All matchers returned are immutable and thread-safe.

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private CalendricalMatchers()
      Private constructor since this is a utility class.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static CalendricalMatcher dayOfWeekInMonth​(int ordinal, DayOfWeek dayOfWeek)
      Returns the day-of-week in month matcher, which returns true if the date is the ordinal occurrence of the day-of-week in the month.
      static CalendricalMatcher firstInMonth​(DayOfWeek dayOfWeek)
      Returns the first in month matcher, which returns true if the date is the first occurrence of day-of-week in the month.
      static CalendricalMatcher lastDayOfMonth()
      Returns the last day-of-month matcher, which returns true if the date is the last valid day of the month.
      static CalendricalMatcher lastDayOfYear()
      Returns the last day-of-year matcher, which returns true if the date is the last valid day of the year.
      static CalendricalMatcher leapDay()
      Returns the leap day matcher, which returns true if the date is February 29th in a leap year.
      static CalendricalMatcher leapYear()
      Returns the leap year matcher, which returns true if the date is in a leap year.
      static CalendricalMatcher nonWeekendDay()
      Returns the non weekend day matcher, which returns true if the date is between Monday and Friday inclusive.
      static CalendricalMatcher weekendDay()
      Returns the weekend day matcher, which returns true if the date is Saturday or Sunday.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CalendricalMatchers

        private CalendricalMatchers()
        Private constructor since this is a utility class.
    • Method Detail

      • leapYear

        public static CalendricalMatcher leapYear()
        Returns the leap year matcher, which returns true if the date is in a leap year.
        Returns:
        the leap year matcher, never null
      • leapDay

        public static CalendricalMatcher leapDay()
        Returns the leap day matcher, which returns true if the date is February 29th in a leap year.
        Returns:
        the leap day matcher, never null
      • lastDayOfMonth

        public static CalendricalMatcher lastDayOfMonth()
        Returns the last day-of-month matcher, which returns true if the date is the last valid day of the month.
        Returns:
        the last day-of-month matcher, never null
      • lastDayOfYear

        public static CalendricalMatcher lastDayOfYear()
        Returns the last day-of-year matcher, which returns true if the date is the last valid day of the year.
        Returns:
        the last day-of-year matcher, never null
      • weekendDay

        public static CalendricalMatcher weekendDay()
        Returns the weekend day matcher, which returns true if the date is Saturday or Sunday.

        Some territories have weekends that do not consist of Saturday and Sunday. No implementation is supplied to support this, however a DateMatcher can be easily written to do so.

        Returns:
        the non weekend day matcher, never null
      • nonWeekendDay

        public static CalendricalMatcher nonWeekendDay()
        Returns the non weekend day matcher, which returns true if the date is between Monday and Friday inclusive.

        Some territories have weekends that do not consist of Saturday and Sunday. No implementation is supplied to support this, however a DateMatcher can be easily written to do so.

        Returns:
        the non weekend day matcher, never null
      • firstInMonth

        public static CalendricalMatcher firstInMonth​(DayOfWeek dayOfWeek)
        Returns the first in month matcher, which returns true if the date is the first occurrence of day-of-week in the month.
        Parameters:
        dayOfWeek - the day-of-week, not null
        Returns:
        the first in month matcher, never null
      • dayOfWeekInMonth

        public static CalendricalMatcher dayOfWeekInMonth​(int ordinal,
                                                          DayOfWeek dayOfWeek)
        Returns the day-of-week in month matcher, which returns true if the date is the ordinal occurrence of the day-of-week in the month.
        Parameters:
        ordinal - ordinal, from 1 to 5
        dayOfWeek - the day-of-week, not null
        Returns:
        the day-of-week in month matcher, never null
        Throws:
        java.lang.IllegalArgumentException - if the ordinal is invalid