forked from nus-cs2103-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from AY2122S1-CS2103T-F13-2/add-recurring-tasks
Add recurring tasks
- Loading branch information
Showing
27 changed files
with
491 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package seedu.address.model.task; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Represents if a task is a recurring task in NurseyBook. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidRecurrence(String)} | ||
*/ | ||
public class Recurrence { | ||
public static final String MESSAGE_CONSTRAINTS = "Recurrence can only be of type day, week or month and " | ||
+ "is case-insensitive. It cannot be null."; | ||
|
||
/** | ||
* The first character of the Description must not be a whitespace, | ||
* otherwise " " (a blank string) becomes a valid input. | ||
*/ | ||
public static final String VALIDATION_REGEX = "\\bNONE|DAY|WEEK|MONTH\\b"; | ||
|
||
private boolean isRecurring; | ||
|
||
private RecurrenceType recurrenceType; | ||
|
||
public enum RecurrenceType { | ||
NONE, DAY, WEEK, MONTH | ||
} | ||
|
||
/** | ||
* Constructs an {@code Recurrence}. | ||
* | ||
* @param recurrenceTypeStr A valid recurrence type. | ||
*/ | ||
public Recurrence(String recurrenceTypeStr) { | ||
requireNonNull(recurrenceTypeStr); | ||
recurrenceTypeStr = recurrenceTypeStr.toUpperCase(); | ||
checkArgument(isValidRecurrence(recurrenceTypeStr), MESSAGE_CONSTRAINTS); | ||
this.isRecurring = !recurrenceTypeStr.equals(RecurrenceType.NONE.name()); | ||
this.recurrenceType = RecurrenceType.valueOf(recurrenceTypeStr); | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid recurrence type. | ||
*/ | ||
public static boolean isValidRecurrence(String test) { | ||
return test.matches(VALIDATION_REGEX); | ||
} | ||
|
||
public boolean isRecurring() { | ||
return isRecurring; | ||
} | ||
|
||
public RecurrenceType getRecurrenceType() { | ||
return recurrenceType; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return recurrenceType.name(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof Recurrence // instanceof handles nulls | ||
&& isRecurring == ((Recurrence) other).isRecurring) // both booleans are the same | ||
&& recurrenceType.equals(((Recurrence) other).recurrenceType); // state check | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(isRecurring, recurrenceType); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.