Calculate start dates for a daily recurrence.

@param calendar current date
@param frequency frequency
@param dates array of start dates
426911
private void getDailyDates(Calendar calendar, int frequency, List<Date> dates)
   {
      while (moreDates(calendar, dates))
      {
         dates.add(calendar.getTime());
         calendar.add(Calendar.DAY_OF_YEAR, frequency);
      }
   }
118027
private static Calendar buildCalendar(final Date date) {

    Calendar calendar = buildCalendar();
    calendar.setTime(date);
    return calendar;
  }
568112
public function setRecurring($frequency, $unit, $start_date)
    {
        $this->_recurring_options = new AnConfig(array(
             'frequency' => $frequency, 'unit' => $unit, 'start_date' => $start_date,
        ));

        return $this;
    }
41975
static Generator byMonthDayGenerator(int[] dates, final DateValue dtStart) {
        final int[] udates = Util.uniquify(dates);

        return new Generator() {
            int year = dtStart.year();
            int month = dtStart.month();
            /** list of generated dates for the current month */
            int[] posDates;
            /** index of next date to return */
            int i = 0;

            {
                convertDatesToAbsolute();
            }

            private void convertDatesToAbsolute() {
                IntSet posDates = new IntSet();
                int nDays = TimeUtils.monthLength(year, month);
                for (int j = 0; j < udates.length; ++j) {
                    int date = udates[j];
                    if (date < 0) {
                        date += nDays + 1;
                    }
                    if (date >= 1 && date <= nDays) {
                        posDates.add(date);
                    }
                }
                this.posDates = posDates.toIntArray();
            }

            @Override
            boolean generate(DTBuilder builder) {
                if (year != builder.year || month != builder.month) {
                    year = builder.year;
                    month = builder.month;

                    convertDatesToAbsolute();

                    i = 0;
                }
                if (i >= posDates.length) {
                    return false;
                }
                builder.day = posDates[i++];
                return true;
            }

            @Override
            public String toString() {
                return "byMonthDayGenerator";
            }
        };
    }
270506
private void addException(ProjectCalendar mpxjCalendar, net.sf.mpxj.ganttproject.schema.Date date)
   {
      String year = date.getYear();
      if (year == null || year.isEmpty())
      {
         // In order to process recurring exceptions using MPXJ, we need a start and end date
         // to constrain the number of dates we generate.
         // May need to pre-process the tasks in order to calculate a start and finish date.
         // TODO: handle recurring exceptions
      }
      else
      {
         Calendar calendar = DateHelper.popCalendar();
         calendar.set(Calendar.YEAR, Integer.parseInt(year));
         calendar.set(Calendar.MONTH, NumberHelper.getInt(date.getMonth()));
         calendar.set(Calendar.DAY_OF_MONTH, NumberHelper.getInt(date.getDate()));
         Date exceptionDate = calendar.getTime();
         DateHelper.pushCalendar(calendar);
         ProjectCalendarException exception = mpxjCalendar.addCalendarException(exceptionDate, exceptionDate);

         // TODO: not sure how NEUTRAL should be handled
         if ("WORKING_DAY".equals(date.getType()))
         {
            exception.addRange(ProjectCalendarWeek.DEFAULT_WORKING_MORNING);
            exception.addRange(ProjectCalendarWeek.DEFAULT_WORKING_AFTERNOON);
         }
      }
   }
118891
public void setRecurringCharges(java.util.Collection<RecurringCharge> recurringCharges) {
        if (recurringCharges == null) {
            this.recurringCharges = null;
            return;
        }

        this.recurringCharges = new java.util.ArrayList<RecurringCharge>(recurringCharges);
    }
1160698
public static RecurrenceIterator createRecurrenceIterator(RDateList rdates) {
        DateValue[] dates = rdates.getDatesUtc();
        Arrays.sort(dates);
        int k = 0;
        for (int i = 1; i < dates.length; ++i) {
            if (!dates[i].equals(dates[k])) {
                dates[++k] = dates[i];
            }
        }
        if (++k < dates.length) {
            DateValue[] uniqueDates = new DateValue[k];
            System.arraycopy(dates, 0, uniqueDates, 0, k);
            dates = uniqueDates;
        }
        return new RDateIteratorImpl(dates);
    }
275755
public void scheduleRecurring(Runnable runnable, Date firstTime, long period)
   {
	timer.scheduleAtFixedRate(toTimerTask(runnable), firstTime, period);
	
   }
1321794
private void getMonthlyAbsoluteDates(Calendar calendar, int frequency, List<Date> dates)
   {
      int currentDayNumber = calendar.get(Calendar.DAY_OF_MONTH);
      calendar.set(Calendar.DAY_OF_MONTH, 1);
      int requiredDayNumber = NumberHelper.getInt(m_dayNumber);
      if (requiredDayNumber < currentDayNumber)
      {
         calendar.add(Calendar.MONTH, 1);
      }

      while (moreDates(calendar, dates))
      {
         int useDayNumber = requiredDayNumber;
         int maxDayNumber = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
         if (useDayNumber > maxDayNumber)
         {
            useDayNumber = maxDayNumber;
         }
         calendar.set(Calendar.DAY_OF_MONTH, useDayNumber);
         dates.add(calendar.getTime());
         calendar.set(Calendar.DAY_OF_MONTH, 1);
         calendar.add(Calendar.MONTH, frequency);
      }
   }
684566
public static RecurrenceIterator createRecurrenceIterator(Recurrence rrule, DateValue dtStart, TimeZone tzid) {
		Frequency freq = rrule.getFrequency();

		/*
		 * If the given RRULE is malformed and does not have a frequency
		 * specified, default to "yearly".
		 */
		if (freq == null) {
			freq = Frequency.YEARLY;
		}

		DayOfWeek wkst = rrule.getWorkweekStarts();

		ICalDate until = rrule.getUntil();

		DateValue untilUtc = (until == null) ? null : Google2445Utils.convert(until, tzid);

		int count = toInt(rrule.getCount());
		int interval = toInt(rrule.getInterval());
		ByDay[] byDay = rrule.getByDay().toArray(new ByDay[0]);
		int[] byMonth = toIntArray(rrule.getByMonth());
		int[] byMonthDay = toIntArray(rrule.getByMonthDay());
		int[] byWeekNo = toIntArray(rrule.getByWeekNo());
		int[] byYearDay = toIntArray(rrule.getByYearDay());
		int[] bySetPos = toIntArray(rrule.getBySetPos());
		int[] byHour = toIntArray(rrule.getByHour());
		int[] byMinute = toIntArray(rrule.getByMinute());
		int[] bySecond = toIntArray(rrule.getBySecond());

		if (interval <= 0) {
			interval = 1;
		}

		if (wkst == null) {
			wkst = DayOfWeek.MONDAY;
		}

		//optimize out BYSETPOS where possible
		if (bySetPos.length > 0) {
			switch (freq) {
			case HOURLY:
				if (byHour.length > 0 && byMinute.length <= 1 && bySecond.length <= 1) {
					byHour = filterBySetPos(byHour, bySetPos);
				}

				/*
				 * Handling bySetPos for rules that are more frequent than daily
				 * tends to lead to large amounts of processor being used before
				 * other work limiting features can kick in since there many
				 * seconds between dtStart and where the year limit kicks in.
				 * There are no known use cases for the use of bySetPos with
				 * hourly minutely and secondly rules so we just ignore it.
				 */
				bySetPos = NO_INTS;
				break;
			case MINUTELY:
				if (byMinute.length > 0 && bySecond.length <= 1) {
					byMinute = filterBySetPos(byMinute, bySetPos);
				}
				//see bySetPos handling comment above
				bySetPos = NO_INTS;
				break;
			case SECONDLY:
				if (bySecond.length > 0) {
					bySecond = filterBySetPos(bySecond, bySetPos);
				}
				//see bySetPos handling comment above
				bySetPos = NO_INTS;
				break;
			default:
			}
		}

		DateValue start = dtStart;
		if (bySetPos.length > 0) {
			/*
			 * Roll back until the beginning of the period to make sure that any
			 * positive indices are indexed properly. The actual iterator
			 * implementation is responsible for anything < dtStart.
			 */
			switch (freq) {
			case YEARLY:
				start = (dtStart instanceof TimeValue) ? new DateTimeValueImpl(start.year(), 1, 1, 0, 0, 0) : new DateValueImpl(start.year(), 1, 1);
				break;
			case MONTHLY:
				start = (dtStart instanceof TimeValue) ? new DateTimeValueImpl(start.year(), start.month(), 1, 0, 0, 0) : new DateValueImpl(start.year(), start.month(), 1);
				break;
			case WEEKLY:
				int d = (7 + wkst.ordinal() - TimeUtils.dayOfWeek(dtStart).getCalendarConstant()) % 7;
				start = TimeUtils.add(dtStart, new DateValueImpl(0, 0, -d));
				break;
			default:
				break;
			}
		}

		/*
		 * Recurrences are implemented as a sequence of periodic generators.
		 * First a year is generated, and then months, and within months, days.
		 */
		ThrottledGenerator yearGenerator = Generators.serialYearGenerator(freq == Frequency.YEARLY ? interval : 1, dtStart);
		Generator monthGenerator = null;
		Generator dayGenerator = null;
		Generator secondGenerator = null;
		Generator minuteGenerator = null;
		Generator hourGenerator = null;

		/*
		 * When multiple generators are specified for a period, they act as a
		 * union operator. We could have multiple generators (say, for day) and
		 * then run each and merge the results, but some generators are more
		 * efficient than others. So to avoid generating 53 Sundays and throwing
		 * away all but 1 for RRULE:FREQ=YEARLY;BYDAY=TU;BYWEEKNO=1, we
		 * reimplement some of the more prolific generators as filters.
		 */
		// TODO(msamuel): don't need a list here
		List<Predicate<? super DateValue>> filters = new ArrayList<Predicate<? super DateValue>>();

		switch (freq) {
		case SECONDLY:
			if (bySecond.length == 0 || interval != 1) {
				secondGenerator = Generators.serialSecondGenerator(interval, dtStart);
				if (bySecond.length > 0) {
					filters.add(Filters.bySecondFilter(bySecond));
				}
			}
			break;
		case MINUTELY:
			if (byMinute.length == 0 || interval != 1) {
				minuteGenerator = Generators.serialMinuteGenerator(interval, dtStart);
				if (byMinute.length > 0) {
					filters.add(Filters.byMinuteFilter(byMinute));
				}
			}
			break;
		case HOURLY:
			if (byHour.length == 0 || interval != 1) {
				hourGenerator = Generators.serialHourGenerator(interval, dtStart);
				if (byHour.length > 0) {
					filters.add(Filters.byHourFilter(bySecond));
				}
			}
			break;
		case DAILY:
			break;
		case WEEKLY:
			/*
			 * Week is not considered a period because a week may span multiple
			 * months and/or years. There are no week generators, so a filter is
			 * used to make sure that FREQ=WEEKLY;INTERVAL=2 only generates
			 * dates within the proper week.
			 */
			if (byDay.length > 0) {
				dayGenerator = Generators.byDayGenerator(byDay, false, start);
				byDay = NO_DAYS;
				if (interval > 1) {
					filters.add(Filters.weekIntervalFilter(interval, wkst, dtStart));
				}
			} else {
				dayGenerator = Generators.serialDayGenerator(interval * 7, dtStart);
			}
			break;
		case YEARLY:
			if (byYearDay.length > 0) {
				/*
				 * The BYYEARDAY rule part specifies a COMMA separated list of
				 * days of the year. Valid values are 1 to 366 or -366 to -1.
				 * For example, -1 represents the last day of the year (December
				 * 31st) and -306 represents the 306th to the last day of the
				 * year (March 1st).
				 */
				dayGenerator = Generators.byYearDayGenerator(byYearDay, start);
				break;
			}
			// $FALL-THROUGH$
		case MONTHLY:
			if (byMonthDay.length > 0) {
				/*
				 * The BYMONTHDAY rule part specifies a COMMA separated list of
				 * days of the month. Valid values are 1 to 31 or -31 to -1. For
				 * example, -10 represents the tenth to the last day of the
				 * month.
				 */
				dayGenerator = Generators.byMonthDayGenerator(byMonthDay, start);
				byMonthDay = NO_INTS;
			} else if (byWeekNo.length > 0 && Frequency.YEARLY == freq) {
				/*
				 * The BYWEEKNO rule part specifies a COMMA separated list of
				 * ordinals specifying weeks of the year. This rule part is only
				 * valid for YEARLY rules.
				 */
				dayGenerator = Generators.byWeekNoGenerator(byWeekNo, wkst, start);
				byWeekNo = NO_INTS;
			} else if (byDay.length > 0) {
				/*
				 * Each BYDAY value can also be preceded by a positive (n) or
				 * negative (-n) integer. If present, this indicates the nth
				 * occurrence of the specific day within the MONTHLY or YEARLY
				 * RRULE. For example, within a MONTHLY rule, +1MO (or simply
				 * 1MO) represents the first Monday within the month, whereas
				 * -1MO represents the last Monday of the month. If an integer
				 * modifier is not present, it means all days of this type
				 * within the specified frequency. For example, within a MONTHLY
				 * rule, MO represents all Mondays within the month.
				 */
				dayGenerator = Generators.byDayGenerator(byDay, Frequency.YEARLY == freq && byMonth.length == 0, start);
				byDay = NO_DAYS;
			} else {
				if (Frequency.YEARLY == freq) {
					monthGenerator = Generators.byMonthGenerator(new int[] { dtStart.month() }, start);
				}
				dayGenerator = Generators.byMonthDayGenerator(new int[] { dtStart.day() }, start);
			}
			break;
		}

		if (secondGenerator == null) {
			secondGenerator = Generators.bySecondGenerator(bySecond, start);
		}
		if (minuteGenerator == null) {
			if (byMinute.length == 0 && freq.compareTo(Frequency.MINUTELY) < 0) {
				minuteGenerator = Generators.serialMinuteGenerator(1, dtStart);
			} else {
				minuteGenerator = Generators.byMinuteGenerator(byMinute, start);
			}
		}
		if (hourGenerator == null) {
			if (byHour.length == 0 && freq.compareTo(Frequency.HOURLY) < 0) {
				hourGenerator = Generators.serialHourGenerator(1, dtStart);
			} else {
				hourGenerator = Generators.byHourGenerator(byHour, start);
			}
		}

		if (dayGenerator == null) {
			boolean dailyOrMoreOften = freq.compareTo(Frequency.DAILY) <= 0;
			if (byMonthDay.length > 0) {
				dayGenerator = Generators.byMonthDayGenerator(byMonthDay, start);
				byMonthDay = NO_INTS;
			} else if (byDay.length > 0) {
				dayGenerator = Generators.byDayGenerator(byDay, Frequency.YEARLY == freq, start);
				byDay = NO_DAYS;
			} else if (dailyOrMoreOften) {
				dayGenerator = Generators.serialDayGenerator(Frequency.DAILY == freq ? interval : 1, dtStart);
			} else {
				dayGenerator = Generators.byMonthDayGenerator(new int[] { dtStart.day() }, start);
			}
		}

		if (byDay.length > 0) {
			filters.add(Filters.byDayFilter(byDay, Frequency.YEARLY == freq, wkst));
			byDay = NO_DAYS;
		}

		if (byMonthDay.length > 0) {
			filters.add(Filters.byMonthDayFilter(byMonthDay));
		}

		//generator inference common to all periods
		if (byMonth.length > 0) {
			monthGenerator = Generators.byMonthGenerator(byMonth, start);
		} else if (monthGenerator == null) {
			monthGenerator = Generators.serialMonthGenerator(freq == Frequency.MONTHLY ? interval : 1, dtStart);
		}

		/*
		 * The condition tells the iterator when to halt. The condition is
		 * exclusive, so the date that triggers it will not be included.
		 */
		Predicate<DateValue> condition;
		boolean canShortcutAdvance = true;
		if (count != 0) {
			condition = Conditions.countCondition(count);

			/*
			 * We can't shortcut because the countCondition must see every
			 * generated instance.
			 * 
			 * TODO(msamuel): If count is large, we might try predicting the end
			 * date so that we can convert the COUNT condition to an UNTIL
			 * condition.
			 */
			canShortcutAdvance = false;
		} else if (untilUtc != null) {
			if ((untilUtc instanceof TimeValue) != (dtStart instanceof TimeValue)) {
				// TODO(msamuel): warn
				if (dtStart instanceof TimeValue) {
					untilUtc = TimeUtils.dayStart(untilUtc);
				} else {
					untilUtc = TimeUtils.toDateValue(untilUtc);
				}
			}
			condition = Conditions.untilCondition(untilUtc);
		} else {
			condition = Predicates.<DateValue> alwaysTrue();
		}

		//combine filters into a single function
		Predicate<? super DateValue> filter;
		switch (filters.size()) {
		case 0:
			filter = Predicates.<DateValue> alwaysTrue();
			break;
		case 1:
			filter = filters.get(0);
			break;
		default:
			filter = Predicates.and(filters);
			break;
		}

		Generator instanceGenerator;
		if (bySetPos.length > 0) {
			instanceGenerator = InstanceGenerators.bySetPosInstanceGenerator(bySetPos, freq, wkst, filter, yearGenerator, monthGenerator, dayGenerator, hourGenerator, minuteGenerator, secondGenerator);
		} else {
			instanceGenerator = InstanceGenerators.serialInstanceGenerator(filter, yearGenerator, monthGenerator, dayGenerator, hourGenerator, minuteGenerator, secondGenerator);
		}

		return new RRuleIteratorImpl(dtStart, tzid, condition, instanceGenerator, yearGenerator, monthGenerator, dayGenerator, hourGenerator, minuteGenerator, secondGenerator, canShortcutAdvance);
	}
225712
public void setStartTimes(java.util.Collection<DateTimeRange> startTimes) {
        if (startTimes == null) {
            this.startTimes = null;
            return;
        }

        this.startTimes = new java.util.ArrayList<DateTimeRange>(startTimes);
    }
607489
static void rollToNextWeekStart(DTBuilder builder, Weekday wkst) {
        DateValue bd = builder.toDate();
        builder.day += (7 - ((7 + (Weekday.valueOf(bd).javaDayNum
                - wkst.javaDayNum))
                % 7)) % 7;
        builder.normalize();
    }
1245270
@Override
    public <B extends Appendable> B format(Calendar calendar, final B buf) {
        // do not pass in calendar directly, this will cause TimeZone of FastDatePrinter to be ignored
        if(!calendar.getTimeZone().equals(mTimeZone)) {
            calendar = (Calendar)calendar.clone();
            calendar.setTimeZone(mTimeZone);
        }
        return applyRules(calendar, buf);
    }
11394
public void setWeekDays(SortedSet<WeekDay> weekDays) {

        final SortedSet<WeekDay> newWeekDays = null == weekDays ? new TreeSet<WeekDay>() : weekDays;
        SortedSet<WeekDay> currentWeekDays = m_model.getWeekDays();
        if (!currentWeekDays.equals(newWeekDays)) {
            conditionallyRemoveExceptionsOnChange(new Command() {

                public void execute() {

                    m_model.setWeekDays(newWeekDays);
                    onValueChange();
                }
            }, !newWeekDays.containsAll(m_model.getWeekDays()));
        }
    }
78243
public void setRecurringCharges(java.util.Collection<RecurringCharge> recurringCharges) {
        if (recurringCharges == null) {
            this.recurringCharges = null;
            return;
        }

        this.recurringCharges = new com.amazonaws.internal.SdkInternalList<RecurringCharge>(recurringCharges);
    }
1192248
protected final void beginOfMonth(final Calendar c) {
        c.set(Calendar.DAY_OF_MONTH,
                c.getActualMinimum(Calendar.DAY_OF_MONTH));
    }
669286
private void setDatesInternal(SortedSet<Date> dates) {

        if (!m_dates.equals(dates)) {
            m_dates = new TreeSet<>(dates);
            fireValueChange();
        }
    }