package org.teamstbf.yats.model.item;

import org.teamstbf.yats.commons.exceptions.IllegalValueException;

/**
 * Represents a Task's Periodicity in the Task Manager.
 * Guarantees: immutable; is valid as declared in {@link #isValidPeriod(String)}
 */

public class Periodic {

    public static final String MESSAGE_PERIODIC_CONSTRAINTS =
            "Periodicity must be none, daily, weekly or monthly";
    public static final String PERIODIC_VALIDATION_REGEX = ".*(none|daily|monthly|weekly).*";

    public final String value;

    /**
     * Validates given period.
     *
     * @throws IllegalValueException if given period string is invalid.
     */
    public Periodic(String period) throws IllegalValueException {
        assert period != null;
        String trimmedPeriod = period.trim();
        if (!isValidPeriod(trimmedPeriod)) {
            throw new IllegalValueException(MESSAGE_PERIODIC_CONSTRAINTS);
        }
        this.value = trimmedPeriod;
    }

    /**
     * Returns if a given string is a valid period.
     */
    public static boolean isValidPeriod(String test) {
        return test.matches(PERIODIC_VALIDATION_REGEX);
    }

    @Override
    public String toString() {
        return value;
    }

    @Override
    public boolean equals(Object other) {
        return other == this // short circuit if same object
                || (other instanceof Periodic // instanceof handles nulls
                && this.value.equals(((Periodic) other).value)); // state check
    }

    @Override
    public int hashCode() {
        return value.hashCode();
    }

}

@@ -32,16 +32,45 @@
 .item;%0A%0A
+import java.util.ArrayList;%0A%0A
 import o
@@ -128,16 +128,16 @@
 eption;%0A
-
 %0A/**%0A * 
@@ -298,16 +298,408 @@
 riodic %7B
+%0A%09%0A%09private ArrayList%3CSchedule%3E scheduleArray;%0A%09private final String PERIODIC_DAILY = %22daily%22;%0A%09private final String PERIODIC_WEEKLY = %22weekly%22;%0A%09private final String PERIODIC_MONTHLY = %22monthly%22;%0A%09private final int REPEAT_FREQUENCY_NONE = 1;%0A%09private final int REPEAT_FREQUENCY_DAILY = 365;%0A%09private final int REPEAT_FREQUENCY_WEEKLY = 52;%0A%09private final int REPEAT_FREQUENCY_MONTHLY = 12;%0A%09
 %0A%0A    pu
@@ -898,20 +898,20 @@
 ily%7C
-monthly%7Cweek
+weekly%7Cmonth
 ly).
@@ -1346,16 +1346,16 @@
       %7D%0A
-
         
@@ -1382,16 +1382,813 @@
 Period;%0A
+        int repeatFrequency = parsePeriod(trimmedPeriod);%0A        setupScheduleArray(scheduleArray, repeatFrequency);%0A    %7D%0A    %0A    public int parsePeriod(String value) %7B%0A    %09int repeatFrequency = REPEAT_FREQUENCY_NONE;%0A    %09switch(value) %7B%0A    %09case(PERIODIC_DAILY):%0A    %09%09repeatFrequency = REPEAT_FREQUENCY_DAILY;%0A    %09case(PERIODIC_WEEKLY):%0A    %09%09repeatFrequency = REPEAT_FREQUENCY_WEEKLY;%0A    %09case(PERIODIC_MONTHLY):%0A    %09%09repeatFrequency = REPEAT_FREQUENCY_MONTHLY;%0A    %09%7D%0A    %09return repeatFrequency;%0A    %7D%0A    %0A    public ArrayList%3CSchedule%3E getScheduleArray() %7B%0A    %09return scheduleArray;%0A    %7D%0A    %0A    private void setupScheduleArray(ArrayList%3CSchedule%3E scheduleArray, int repeatFrequency) %7B%0A    %09for(int i=0; i%3CrepeatFrequency; i++) %7B%0A    %09%09scheduleArray.add(new Schedule());%0A    %09%7D%0A
     %7D%0A%0A 

Update Periodic to include ArrayList of schedules