// Path: src/main/java/org/dmfs/rfc5545/recur/RecurrenceRule.java
// public static class WeekdayNum
// {
//     /**
//      * The position of this weekday in the interval. This value is <code>0</code> if this instance means every occurrence of {@link #weekday} in the
//      * interval.
//      */
//     public final int pos;
// 
//     /**
//      * The {@link Weekday}.
//      */
//     public final Weekday weekday;
// 
// 
//     /**
//      * Create a new WeekdayNum instance.
//      * <p>
//      * TODO: update range check
//      *
//      * @param pos
//      *         The position of the weekday in the Interval or <code>0</code> for every occurrence of the weekday.
//      * @param weekday
//      *         The {@link Weekday}.
//      */
//     public WeekdayNum(int pos, Weekday weekday)
//     {
//         if (pos < -53 || pos > 53)
//         {
//             throw new IllegalArgumentException("position " + pos + " of week day out of range");
//         }
//         this.pos = pos;
//         this.weekday = weekday;
//     }
// 
// 
//     /**
//      * Parse a weekdaynum String as defined in <a href="http://tools.ietf.org/html/rfc5545#section-3.3.10">RFC 5545</a> (this definition equals the
//      * definition in RFC 2445).
//      *
//      * @param value
//      *         The weekdaynum String to parse.
//      * @param tolerant
//      *         Set to <code>true</code> to be tolerant and accept values outside of the allowed range.
//      *
//      * @return A new {@link WeekdayNum} instance.
//      *
//      * @throws InvalidRecurrenceRuleException
//      *         If the weekdaynum string is invalid.
//      */
//     public static WeekdayNum valueOf(String value, boolean tolerant) throws InvalidRecurrenceRuleException
//     {
//         try
//         {
//             int len = value.length();
//             if (len > 2)
//             {
//                 // includes a position
//                 int pos = Integer.parseInt(value.substring(value.charAt(0) == '+' ? 1 : 0, len - 2));
//                 if (!tolerant && (pos == 0 || pos < -53 || pos > 53))
//                 {
//                     throw new InvalidRecurrenceRuleException("invalid weeknum: '" + value + "'");
//                 }
//                 return new WeekdayNum(pos, Weekday.valueOf(value.substring(len - 2)));
//             }
//             else
//             {
//                 return new WeekdayNum(0, Weekday.valueOf(value));
//             }
//         }
//         catch (Exception e)
//         {
//             throw new InvalidRecurrenceRuleException("invalid weeknum: '" + value + "'", e);
//         }
//     }
// 
// 
//     /**
//      * Parse a weekdaynum String as defined in <a href="http://tools.ietf.org/html/rfc5545#section-3.3.10">RFC 5545</a> (this definition equals the
//      * definition in RFC 2445). In contrast to {@link #valueOf(String, boolean)} this method is always strict and throws on every invalid value.
//      *
//      * @param value
//      *         The weekdaynum String to parse.
//      *
//      * @return A new {@link WeekdayNum} instance.
//      *
//      * @throws InvalidRecurrenceRuleException
//      *         If the weekdaynum string is invalid.
//      */
//     public static WeekdayNum valueOf(String value) throws InvalidRecurrenceRuleException
//     {
//         return valueOf(value, false);
//     }
// 
// 
//     @Override
//     public String toString()
//     {
//         return pos == 0 ? weekday.name() : Integer.valueOf(pos) + weekday.name();
//     }
// }


import org.dmfs.rfc5545.calendarmetrics.CalendarMetrics;
import org.dmfs.rfc5545.recur.RecurrenceRule.WeekdayNum;
import java.util.List;
/*
 * Copyright 2018 Marten Gajda <marten@dmfs.org>
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.dmfs.rfc5545.recur;




/**
 * An expander that expands recurrence rules by day of week in a weekly scope.
 *
 * @author Marten Gajda
 */
final class ByDayWeeklyExpander extends ByExpander
{
    /**
     * The bitmap of week days to expand.
     */
    private final int mDayBitMap;


    public ByDayWeeklyExpander(RecurrenceRule rule, RuleIterator previous, CalendarMetrics calendarTools, long start)
    {
        super(previous, calendarTools, start);

        // get the list of WeekDayNums and convert it into an array
        List<WeekdayNum> byDay = rule.getByDayPart();

        int dayBitMap = 0;

// Path: src/main/java/org/dmfs/rfc5545/recur/RecurrenceRule.java
// public static class WeekdayNum
// {
//     /**
//      * The position of this weekday in the interval. This value is <code>0</code> if this instance means every occurrence of {@link #weekday} in the
//      * interval.
//      */
//     public final int pos;
// 
//     /**
//      * The {@link Weekday}.
//      */
//     public final Weekday weekday;
// 
// 
//     /**
//      * Create a new WeekdayNum instance.
//      * <p>
//      * TODO: update range check
//      *
//      * @param pos
//      *         The position of the weekday in the Interval or <code>0</code> for every occurrence of the weekday.
//      * @param weekday
//      *         The {@link Weekday}.
//      */
//     public WeekdayNum(int pos, Weekday weekday)
//     {
//         if (pos < -53 || pos > 53)
//         {
//             throw new IllegalArgumentException("position " + pos + " of week day out of range");
//         }
//         this.pos = pos;
//         this.weekday = weekday;
//     }
// 
// 
//     /**
//      * Parse a weekdaynum String as defined in <a href="http://tools.ietf.org/html/rfc5545#section-3.3.10">RFC 5545</a> (this definition equals the
//      * definition in RFC 2445).
//      *
//      * @param value
//      *         The weekdaynum String to parse.
//      * @param tolerant
//      *         Set to <code>true</code> to be tolerant and accept values outside of the allowed range.
//      *
//      * @return A new {@link WeekdayNum} instance.
//      *
//      * @throws InvalidRecurrenceRuleException
//      *         If the weekdaynum string is invalid.
//      */
//     public static WeekdayNum valueOf(String value, boolean tolerant) throws InvalidRecurrenceRuleException
//     {
//         try
//         {
//             int len = value.length();
//             if (len > 2)
//             {
//                 // includes a position
//                 int pos = Integer.parseInt(value.substring(value.charAt(0) == '+' ? 1 : 0, len - 2));
//                 if (!tolerant && (pos == 0 || pos < -53 || pos > 53))
//                 {
//                     throw new InvalidRecurrenceRuleException("invalid weeknum: '" + value + "'");
//                 }
//                 return new WeekdayNum(pos, Weekday.valueOf(value.substring(len - 2)));
//             }
//             else
//             {
//                 return new WeekdayNum(0, Weekday.valueOf(value));
//             }
//         }
//         catch (Exception e)
//         {
//             throw new InvalidRecurrenceRuleException("invalid weeknum: '" + value + "'", e);
//         }
//     }
// 
// 
//     /**
//      * Parse a weekdaynum String as defined in <a href="http://tools.ietf.org/html/rfc5545#section-3.3.10">RFC 5545</a> (this definition equals the
//      * definition in RFC 2445). In contrast to {@link #valueOf(String, boolean)} this method is always strict and throws on every invalid value.
//      *
//      * @param value
//      *         The weekdaynum String to parse.
//      *
//      * @return A new {@link WeekdayNum} instance.
//      *
//      * @throws InvalidRecurrenceRuleException
//      *         If the weekdaynum string is invalid.
//      */
//     public static WeekdayNum valueOf(String value) throws InvalidRecurrenceRuleException
//     {
//         return valueOf(value, false);
//     }
// 
// 
//     @Override
//     public String toString()
//     {
//         return pos == 0 ? weekday.name() : Integer.valueOf(pos) + weekday.name();
//     }
// }


// Path: src/main/java/org/dmfs/rfc5545/recur/ByDayWeeklyExpander.java
import org.dmfs.rfc5545.calendarmetrics.CalendarMetrics;
import org.dmfs.rfc5545.recur.RecurrenceRule.WeekdayNum;
import java.util.List;

/*
 * Copyright 2018 Marten Gajda <marten@dmfs.org>
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.dmfs.rfc5545.recur;




/**
 * An expander that expands recurrence rules by day of week in a weekly scope.
 *
 * @author Marten Gajda
 */
final class ByDayWeeklyExpander extends ByExpander
{
    /**
     * The bitmap of week days to expand.
     */
    private final int mDayBitMap;


    public ByDayWeeklyExpander(RecurrenceRule rule, RuleIterator previous, CalendarMetrics calendarTools, long start)
    {
        super(previous, calendarTools, start);

        // get the list of WeekDayNums and convert it into an array
        List<WeekdayNum> byDay = rule.getByDayPart();

        int dayBitMap = 0;

        for (WeekdayNum weekdayNum : byDay)