if (mUntil != null) { if (mUntil.compareTo(rangeEndDate) < 0) rangeEndDate = mUntil.getDate(); }
    public List<java.util.Date> expandRecurrenceOverRange(ParsedDateTime dtStart, long rangeStart, long rangeEnd) throws ServiceException {        List<java.util.Date> toRet = new LinkedList<java.util.Date>();                java.util.Date earliestDate = new java.util.Date(rangeStart);        java.util.Date rangeEndDate = new java.util.Date(rangeEnd);        java.util.Date dtStartDate = new java.util.Date(dtStart.getUtcTime());                if (dtStartDate.after(earliestDate))            earliestDate = dtStartDate;                if (earliestDate.compareTo(rangeEndDate)>=0)            return toRet;                GregorianCalendar cur = dtStart.getCalendarCopy();                // until we hit rangeEnd, or we've SAVED count entries:        //        //     gather each set {        //                //                //                //        curDate forward one INTERVAL        //        //     }         //     check Set against BYSETPOS & ranges & count        //                int interval = mInterval;        if (interval <= 0)             interval = 1;                int count = mCount;        if (count <= 0 || count > MAXIMUM_INSTANCES_EXPANDED)            count = MAXIMUM_INSTANCES_EXPANDED;                        while (toRet.size() < count                 && (toRet.size() == 0 || (toRet.get(toRet.size()-1).before(rangeEndDate)))                && (cur.getTime().before(rangeEndDate)))        {            List<Calendar> addList = new LinkedList<Calendar>();                        switch (mFreq) {            case SECONDLY:            case MINUTELY:                // intentionally not supported (performance)                return toRet;            case HOURLY:                /*                 * BYSECOND - for each listed second                 * BYMINUTE - for each listed minute in hour                 * BYHOUR - match iff in hour list                 * BYDAY - for each day listed                 * BYMONTHDAY - only those monthdays                 * BYYEARDAY - only those yeardays                 * BYMONTH - only those months                 */                if (!checkMonthList(cur))                    continue;                                if (!checkYearDayList(cur))                    continue;                                if (!checkMonthDayList(cur))                    continue;                                if (!checkDayList(cur))                    continue;                                if (!checkHourList(cur))                    continue;                                addList.add((Calendar)(cur.clone()));                                cur.add(Calendar.HOUR_OF_DAY, interval);                                addList = expandHourList(addList);                addList = expandMinuteList(addList);                addList = expandSecondList(addList);                                                break;            case DAILY:                /*                 * BYSECOND - for each listed second in day                 * BYMINUTE - for each listed minute in day                  * BYHOUR - for each listed hour in day                 * BYDAY - no ordinal allowed, match iff in day list                 * BYMONTHDAY - only that day                 * BYYEARDAY - only that day                 * BYWEEKNO -- YEARLY ONLY                 * BYMONTH - only that month                 *                  * while (count check & until check & rangeEnd check) {                  *    if (byMonth && !month matches)                 *      curDay = set MONTH to matching month                 *                       *    if (byYearDay && !yearday matches)                 *      curDay = set DAY to next matching yearday                 *                       *    if (byMonthday && !monthday matches)                 *      curDay = skip to next matching monthday                 *                       *    if (byDay && !day in list)                 *      curDay = skip to next mathcing byDay                 *                       *    if (!byHour or FOR EACH HOUR IN HOURLIST)                 *      if (!byMinute or FOR EACH MINUTE IN MINLIST)                 *        if (!bySecond or FOR EACH SECOND IN LIST)                 *          ----add to list---                 *                      *     check against BYSETPOS                 *                                     *     curDay+=1 day                 * }                  *                  */                                if (!checkMonthList(cur))                    continue;                                if (!checkYearDayList(cur))                    continue;                                if (!checkMonthDayList(cur))                    continue;                                if (!checkDayList(cur))                    continue;                                addList.add((Calendar)(cur.clone()));                                cur.add(Calendar.DAY_OF_YEAR, interval);                                addList = expandHourList(addList);                addList = expandMinuteList(addList);                addList = expandSecondList(addList);                break;            case WEEKLY:                /*                 * BYSECOND - for every listed second                 * BYMINUTE - for every listed minute                 * BYHOUR - for every listed hour                 * BYDAY - for every listed day                 * BYMONTHDAY - MAYBE once a month                 * BYYEARDAY - MAYBE once a year                 * BYMONTH - iff month matches                 *                  *  for each (INTERVAL)WEEK{                  *    if (byMonth && !month matches)                 *      curDay = set MONTH to DtStart in next matching month                 *                       *    if (byYearDay && !yearday matches)                 *      curDay = set date to next matching yearday                 *                       *    if (byMonthDay && !monthday matches)                 *      curDay = skip to next matching monthday                 *                 *    if (!byDay or FOREACH day in list)                 *      if (!byHour or FOREACH hour in list)                 *        if (!byMinute or FOREACH minute in list)                 *          if (!bySecond or FOREACH second in list)                 *            ----add to list----                 *                          *    check against BYSETPOS                 *                     *    curDay += 1 week                 * } while (count check & until check & rangeEnd check)                 *                  */                if (!checkMonthList(cur))                    continue;                                if (!checkYearDayList(cur))                    continue;                if (!checkMonthDayList(cur))                    continue;                addList.add((Calendar)(cur.clone()));                                cur.add(Calendar.WEEK_OF_YEAR, interval);                                addList = expandDayListForWeekly(addList);                addList = expandHourList(addList);                addList = expandMinuteList(addList);                addList = expandSecondList(addList);                break;            case MONTHLY:                if (!checkMonthList(cur))                    continue;                                if (!checkYearDayList(cur))                    continue;                                addList.add((Calendar)(cur.clone()));                                cur.add(Calendar.MONTH, interval);                                addList = expandMonthDayList(addList);                addList = expandDayListForMonthlyYearly(addList);                addList = expandHourList(addList);                addList = expandMinuteList(addList);                addList = expandSecondList(addList);                                break;            case YEARLY:                /*                 * BYSECOND                 * BYMINUTE                 * BYHOUR                  * BYDAY                 * BYMONTHDAY                  * BYYEARDAY                  * BYWEEKNO - specified week                 * BYMONTH - once                 */                addList.add((Calendar)(cur.clone()));                                cur.add(Calendar.YEAR, interval);                                addList = expandMonthList(addList);                addList = expandYearDayList(addList);                                addList = expandMonthDayList(addList);                addList = expandDayListForMonthlyYearly(addList);                addList = expandHourList(addList);                addList = expandMinuteList(addList);                addList = expandSecondList(addList);                                break;            }                        addList = handleSetPos(addList);                        // add all the ones that match!            for (Calendar addCal : addList) {                Date toAdd = addCal.getTime();                if (toAdd.compareTo(earliestDate)>=0 && toAdd.compareTo(rangeEndDate)<0)                    toRet.add(toAdd);                if (toRet.size() > count)                    return toRet;            }        }                return toRet;    }