code: private int getNextLastDayOfWeekInMonth(int day, int lastDay, int dayOfWeek)
      {
          for (;;)
          {
              if (lastDay - day < 7 && contains(lastDaysOfWeekInMonth, dayOfWeek))
              {
                  return day;
              }
  
              day++;
              if (day > lastDay)
              {
                  return ADVANCE_TO_NEXT_MONTH;
              }
  
              dayOfWeek = (dayOfWeek + 1) % 7;
          }
      }
docs: Returns the next day of the month after <tt>day</tt> that satisfies
  the lastDaysOfWeekInMonth constraint.
  
  @param day the current 0-based day of the month
  @param lastDay the current 0-based last day of the month
  @param dayOfWeek the current 0-based day of the week
  @return a value greater than or equal to <tt>day</tt>