From 9e75b02f092d348d242930064a9a20da20574b8e Mon Sep 17 00:00:00 2001 From: qhng Date: Sat, 29 Oct 2016 16:59:51 +0800 Subject: [PATCH 1/4] Update UserGuide.md for recurring tasks --- docs/UserGuide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 7aaa71e72095..dada09ed4b5d 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -62,7 +62,7 @@ Format: `add TASK_NAME [s/START_DATE] [e/END_DATE] [l/LOCATION] [p/PRIORITY_LEVE > LOCATION | `Optional` Specifies the location where the task happens. > PRIORITY_LEVEL | `Optional` Specifies the priority level of the task.
`Accepts` values `low`, `medium`, `high`
`Defaults` to `???` > RECURRING_TYPE | `Optional` Specifies the recurring type of the task.
`Accepts` values `none`, `daily`, `weekly`, `monthly`, `yearly`
`Defaults` to `none` -> NUMBER_OF_RECURRENCE | `Optional` Specifies the number of times the task recurrs. A value of 0 specifies a never-ending recurrence.
`Defaults` to `0`
`Ignored` if RECURRING_TYPE is `none` +> NUMBER_OF_RECURRENCE | `Optional` Specifies the number of times the task recurrs.
`Defaults` to `1`
`Ignored` if RECURRING_TYPE is `none` > CATEGORY | `Optional` Specifies a custom category for the task. This can be used for keeping track of similar tasks. > DESCRIPTION | `Optional` Describes the task. From e00b4587dfadeb1ef50d1d05e50144caffd1fe06 Mon Sep 17 00:00:00 2001 From: qhng Date: Sat, 29 Oct 2016 17:28:04 +0800 Subject: [PATCH 2/4] Implement recurring tasks --- .../logic/commands/AddCommand.java | 53 +++++--- .../java/seedu/savvytasker/model/Model.java | 9 ++ .../seedu/savvytasker/model/ModelManager.java | 9 ++ .../seedu/savvytasker/model/SavvyTasker.java | 126 +++++++++++++++++- .../savvytasker/model/task/ReadOnlyTask.java | 7 +- .../seedu/savvytasker/model/task/Task.java | 38 ++++-- .../savvytasker/model/task/TaskList.java | 30 ++++- .../savvytasker/storage/XmlAdaptedTask.java | 16 +-- .../seedu/savvytasker/testutil/TestTask.java | 11 ++ 9 files changed, 253 insertions(+), 46 deletions(-) diff --git a/src/main/java/seedu/savvytasker/logic/commands/AddCommand.java b/src/main/java/seedu/savvytasker/logic/commands/AddCommand.java index 6aa20e6962f5..3ea4e5d69376 100644 --- a/src/main/java/seedu/savvytasker/logic/commands/AddCommand.java +++ b/src/main/java/seedu/savvytasker/logic/commands/AddCommand.java @@ -1,5 +1,8 @@ package seedu.savvytasker.logic.commands; +import java.util.Iterator; +import java.util.LinkedList; + import seedu.savvytasker.commons.core.EventsCenter; import seedu.savvytasker.commons.core.UnmodifiableObservableList; import seedu.savvytasker.commons.events.ui.JumpToListRequestEvent; @@ -40,6 +43,7 @@ public class AddCommand extends ModelRequiringCommand { private final String description; private Task toAdd; + private LinkedList tasksAdded; //@@author A0139915W /** @@ -57,16 +61,24 @@ public AddCommand(String taskName, InferredDate startDateTime, InferredDate endD this.numberOfRecurrence = numberOfRecurrence; this.category = category; this.description = description; + tasksAdded = new LinkedList(); } private void createTask() { final boolean isArchived = false; // all tasks are first added as active tasks final int taskId = 0; // taskId to be assigned by ModelManager, leave as 0 + final int groupId = 0; // groupId to be assigned by ModelManager, leave as 0 - this.toAdd = new Task(taskId, taskName, startDateTime, endDateTime, + this.toAdd = new Task(taskId, groupId, taskName, startDateTime, endDateTime, location, priority, recurringType, numberOfRecurrence, category, description, isArchived); } + + private void addToListOfTasksAdded(Task... tasks) { + for (Task t : tasks) { + tasksAdded.add(t); + } + } @Override public CommandResult execute() { @@ -74,7 +86,18 @@ public CommandResult execute() { createTask(); try { - Task taskAdded = model.addTask(toAdd); + Task taskAdded = null; + if (toAdd.getRecurringType() == RecurrenceType.None) { + // not a recurring task, add a single task + taskAdded = model.addTask(toAdd); + addToListOfTasksAdded(taskAdded); + } else { + // a recurring task, add a group of recurring tasks + LinkedList tasksAdded = model.addRecurringTask(toAdd); + taskAdded = tasksAdded.peekFirst(); + addToListOfTasksAdded(tasksAdded.toArray(new Task[tasksAdded.size()])); + } + int targetIndex = getIndexOfTask(taskAdded); if (targetIndex > 0) { EventsCenter.getInstance().post(new JumpToListRequestEvent(targetIndex)); @@ -119,7 +142,7 @@ public boolean canUndo() { @Override public boolean redo() { execute(); - return false; + return true; } /** @@ -128,20 +151,18 @@ public boolean redo() { */ @Override public boolean undo() { - - UnmodifiableObservableList lastShownList = model.getFilteredTaskListTask(); - - for (int i = 0; i < lastShownList.size(); i++) { - if (lastShownList.get(i) == toAdd){ - ReadOnlyTask taskToDelete = lastShownList.get(i); - try { - model.deleteTask(taskToDelete); - } catch (TaskNotFoundException e) { - e.printStackTrace(); - } + Iterator itr = tasksAdded.iterator(); + while (itr.hasNext()) { + try { + model.deleteTask(itr.next()); + } catch (TaskNotFoundException e) { + // do nothing. } - } - return false; + } + // clears the list of tasks added. + // if redo is performed, the list will be populated again. + tasksAdded.clear(); + return true; } /** diff --git a/src/main/java/seedu/savvytasker/model/Model.java b/src/main/java/seedu/savvytasker/model/Model.java index b2fadeba0fc2..6628f3ff1e80 100644 --- a/src/main/java/seedu/savvytasker/model/Model.java +++ b/src/main/java/seedu/savvytasker/model/Model.java @@ -1,5 +1,7 @@ package seedu.savvytasker.model; +import java.util.LinkedList; + import seedu.savvytasker.commons.core.UnmodifiableObservableList; import seedu.savvytasker.model.alias.AliasSymbol; import seedu.savvytasker.model.alias.DuplicateSymbolKeywordException; @@ -43,6 +45,13 @@ public interface Model { * @return Returns a Task if the add operation is successful, an exception is thrown otherwise. * */ Task addTask(Task task) throws DuplicateTaskException, InvalidDateException; + + /** Adds the given Task as a recurring task. The task's recurrence type must not be null. + * @throws {@link DuplicateTaskException} if a duplicate is found + * @throws {@link InvalidDateException} if the end date is earlier than the start date + * @return Returns the list of Tasks added if the add operation is successful, an exception is thrown otherwise. + * */ + LinkedList addRecurringTask(Task task) throws DuplicateTaskException, InvalidDateException; /** Returns the filtered task list as an {@code UnmodifiableObservableList} */ UnmodifiableObservableList getFilteredTaskList(); diff --git a/src/main/java/seedu/savvytasker/model/ModelManager.java b/src/main/java/seedu/savvytasker/model/ModelManager.java index a4c64eee41ce..bd5edac68632 100644 --- a/src/main/java/seedu/savvytasker/model/ModelManager.java +++ b/src/main/java/seedu/savvytasker/model/ModelManager.java @@ -4,6 +4,7 @@ import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.logging.Logger; @@ -115,6 +116,14 @@ public synchronized Task addTask(Task t) throws DuplicateTaskException, InvalidD indicateSavvyTaskerChanged(); return taskAdded; } + + @Override + public synchronized LinkedList addRecurringTask(Task recurringTask) throws DuplicateTaskException, InvalidDateException { + LinkedList recurringTasks = savvyTasker.addRecurringTasks(recurringTask); + updateFilteredListToShowActive(); + indicateSavvyTaskerChanged(); + return recurringTasks; + } //@@author //@@author A0139916U diff --git a/src/main/java/seedu/savvytasker/model/SavvyTasker.java b/src/main/java/seedu/savvytasker/model/SavvyTasker.java index 2fe1d703b6b3..9bfe2fbb39db 100644 --- a/src/main/java/seedu/savvytasker/model/SavvyTasker.java +++ b/src/main/java/seedu/savvytasker/model/SavvyTasker.java @@ -1,7 +1,11 @@ package seedu.savvytasker.model; +import java.util.Calendar; import java.util.Collection; import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -12,6 +16,7 @@ import seedu.savvytasker.model.alias.DuplicateSymbolKeywordException; import seedu.savvytasker.model.alias.SymbolKeywordNotFoundException; import seedu.savvytasker.model.task.ReadOnlyTask; +import seedu.savvytasker.model.task.RecurrenceType; import seedu.savvytasker.model.task.Task; import seedu.savvytasker.model.task.TaskList; import seedu.savvytasker.model.task.TaskList.DuplicateTaskException; @@ -70,13 +75,130 @@ public void resetData(ReadOnlySavvyTasker newData) { /** * Adds a task to savvy tasker. - * @throws DuplicateTaskException if an equivalent task already exists. - * @throws InvalidDateException if the end date is earlier than the start date. + * @throws {@link DuplicateTaskException} if a duplicate is found + * @throws {@link InvalidDateException} if the end date is earlier than the start date + * @return Returns the task added if the operation succeeds, an exception is thrown otherwise. */ public Task addTask(Task t) throws DuplicateTaskException, InvalidDateException { t.setId(tasks.getNextId()); return tasks.add(t); } + + /** + * Adds a group of recurring tasks to savvy tasker. + * @throws {@link DuplicateTaskException} if a duplicate is found + * @throws {@link InvalidDateException} if the end date is earlier than the start date + * @return Returns the list of recurring tasks if the operation succeeds, an exception is thrown otherwise + */ + public LinkedList addRecurringTasks(Task recurringTask) throws DuplicateTaskException, InvalidDateException { + LinkedList tasksToAdd = + createRecurringTasks(recurringTask, recurringTask.getRecurringType(), + recurringTask.getNumberOfRecurrence()); + Iterator itr = tasksToAdd.iterator(); + + while(itr.hasNext()) { + // this will be an atomic operation + // guaranteed no duplicates + // if the start/end dates are invalid, + // the first task to be added will fail immediately, + // subsequent tasks will not be added + tasks.add(itr.next()); + } + return tasksToAdd; + } + + /** + * Creates a list of recurring tasks to be added into savvy tasker. + * @param recurringTask the task that recurs + * @param recurringType the type of recurrence + * @param numberOfRecurrences the number of recurrences + * @return A list of tasks that represents a recurring task. + */ + private LinkedList createRecurringTasks(Task recurringTask, RecurrenceType recurringType, int numberOfRecurrences) { + assert recurringTask.getRecurringType() != null; + assert recurringTask.getNumberOfRecurrence() > 0; + + LinkedList listOfTasks = new LinkedList(); + recurringTask.setGroupId(tasks.getNextGroupId()); + + for (int i = 0; i < numberOfRecurrences; ++i) { + Task t = recurringTask.clone(); + t.setId(tasks.getNextId()); + listOfTasks.add(setDatesForRecurringType(t, recurringType, i)); + } + + return listOfTasks; + } + + /** + * Helper function for createRecurringTasks(). Sets the respective start/end datetime for the + * i-th recurring task to be added + * @param t The first recurring task + * @param recurringType the type of recurrence + * @param index the index of the loop + * @return A task with its respective datetime set. + */ + private Task setDatesForRecurringType(Task t, RecurrenceType recurringType, int index) { + Date startDate = t.getStartDateTime(); + Date endDate = t.getEndDateTime(); + Calendar calendar = Calendar.getInstance(); + switch (recurringType) { + case Daily: // add one day to the i-th task + if (startDate != null) { + calendar.setTime(startDate); + calendar.add(Calendar.DATE, 1 * index); + startDate = calendar.getTime(); + } + if (endDate != null) { + calendar.setTime(endDate); + calendar.add(Calendar.DATE, 1 * index); + endDate = calendar.getTime(); + } + break; + case Weekly: // add 7 days to the i-th task + if (startDate != null) { + calendar.setTime(startDate); + calendar.add(Calendar.DATE, 7 * index); + startDate = calendar.getTime(); + } + if (endDate != null) { + calendar.setTime(endDate); + calendar.add(Calendar.DATE, 7 * index); + endDate = calendar.getTime(); + } + break; + case Monthly: // add 1 month to the i-th task + if (startDate != null) { + calendar.setTime(startDate); + calendar.add(Calendar.MONTH, 1 * index); + startDate = calendar.getTime(); + } + if (endDate != null) { + calendar.setTime(endDate); + calendar.add(Calendar.MONTH, 1 * index); + endDate = calendar.getTime(); + } + break; + case Yearly: // add 1 year to the i-th task + if (startDate != null) { + calendar.setTime(startDate); + calendar.add(Calendar.YEAR, 1 * index); + startDate = calendar.getTime(); + } + if (endDate != null) { + calendar.setTime(endDate); + calendar.add(Calendar.YEAR, 1 * index); + endDate = calendar.getTime(); + } + break; + case None: + default: + assert false; // should not come here + } + t.setStartDateTime(startDate); + t.setEndDateTime(endDate); + return t; + } /** * Removes a task from savvy tasker. diff --git a/src/main/java/seedu/savvytasker/model/task/ReadOnlyTask.java b/src/main/java/seedu/savvytasker/model/task/ReadOnlyTask.java index 65253ee3875a..f1a256e8aace 100644 --- a/src/main/java/seedu/savvytasker/model/task/ReadOnlyTask.java +++ b/src/main/java/seedu/savvytasker/model/task/ReadOnlyTask.java @@ -10,6 +10,7 @@ public interface ReadOnlyTask { int getId(); + int getGroupId(); boolean isMarked(); boolean isArchived(); String getTaskName(); @@ -53,11 +54,7 @@ default String getAsText() { .append(getLocation()); } builder.append(" Priority: ") - .append(getPriority()) - .append(" Recurring Type: ") - .append(getRecurringType()) - .append(" Nr. Recurrence: ") - .append(getNumberOfRecurrence()); + .append(getPriority()); if (getCategory() != null && !getCategory().isEmpty()) { builder.append(" Category: ") .append(getCategory()); diff --git a/src/main/java/seedu/savvytasker/model/task/Task.java b/src/main/java/seedu/savvytasker/model/task/Task.java index e70d8763336c..593822c9bf31 100644 --- a/src/main/java/seedu/savvytasker/model/task/Task.java +++ b/src/main/java/seedu/savvytasker/model/task/Task.java @@ -13,6 +13,7 @@ public class Task implements ReadOnlyTask { private int id; + private int groupId; private String taskName; private Date startDateTime; private Date endDateTime; @@ -27,12 +28,13 @@ public class Task implements ReadOnlyTask { /** * Constructor with smart defaults */ - public Task(int id, String taskName, InferredDate startDateTime, InferredDate endDateTime, String location, + public Task(int id, int groupId, String taskName, InferredDate startDateTime, InferredDate endDateTime, String location, PriorityLevel priority, RecurrenceType recurringType, Integer numberOfRecurrence, String category, String description, boolean isArchived) { SmartDefaultDates sdd = new SmartDefaultDates(startDateTime, endDateTime); this.id = id; + this.groupId = groupId; this.taskName = taskName; this.startDateTime = sdd.getStartDate(); this.endDateTime = sdd.getEndDate(); @@ -48,7 +50,7 @@ public Task(int id, String taskName, InferredDate startDateTime, InferredDate en this.recurringType = recurringType; } if (numberOfRecurrence == null) { - this.numberOfRecurrence = 0; + this.numberOfRecurrence = 1; } else { this.numberOfRecurrence = numberOfRecurrence.intValue(); } @@ -60,11 +62,12 @@ public Task(int id, String taskName, InferredDate startDateTime, InferredDate en /** * Constructor without smart defaults */ - public Task(int id, String taskName, Date startDateTime, Date endDateTime, String location, + public Task(int id, int groupId, String taskName, Date startDateTime, Date endDateTime, String location, PriorityLevel priority, RecurrenceType recurringType, Integer numberOfRecurrence, String category, String description, boolean isArchived) { this.id = id; + this.groupId = groupId; this.taskName = taskName; this.startDateTime = startDateTime; this.endDateTime = endDateTime; @@ -80,7 +83,7 @@ public Task(int id, String taskName, Date startDateTime, Date endDateTime, Strin this.recurringType = recurringType; } if (numberOfRecurrence == null) { - this.numberOfRecurrence = 0; + this.numberOfRecurrence = 1; } else { this.numberOfRecurrence = numberOfRecurrence.intValue(); } @@ -93,15 +96,13 @@ public Task(String taskName) { this.taskName = taskName; // sets initial default values this.priority = PriorityLevel.Medium; - this.recurringType = RecurrenceType.None; - this.numberOfRecurrence = 0; } /** * Copy constructor. */ public Task(ReadOnlyTask source) { - this(source.getId(), source.getTaskName(), source.getStartDateTime(), + this(source.getId(), source.getGroupId(), source.getTaskName(), source.getStartDateTime(), source.getEndDateTime(), source.getLocation(), source.getPriority(), source.getRecurringType(), source.getNumberOfRecurrence(), source.getCategory(), source.getDescription(), source.isArchived()); @@ -113,12 +114,13 @@ public Task(ReadOnlyTask source) { public Task(ReadOnlyTask source, String taskName, InferredDate startDateTime, InferredDate endDateTime, String location, PriorityLevel priority, RecurrenceType recurringType, Integer numberOfRecurrence, String category, String description) { - this(source.getId(), source.getTaskName(), source.getStartDateTime(), + this(source.getId(), source.getGroupId(), source.getTaskName(), source.getStartDateTime(), source.getEndDateTime(), source.getLocation(), source.getPriority(), source.getRecurringType(), source.getNumberOfRecurrence(), source.getCategory(), source.getDescription(), source.isArchived()); //this.id should follow that of the source. + //this.groupId should follow that of the source. //this.isArchived should follow that of the source. this.taskName = taskName == null ? this.taskName : taskName; setStartDate(startDateTime); @@ -172,6 +174,11 @@ public int getId() { return this.id; } + @Override + public int getGroupId() { + return this.groupId; + } + @Override public boolean isMarked() { return isArchived(); // all marked tasks are archived @@ -231,6 +238,10 @@ public void setId(int id) { this.id = id; } + public void setGroupId(int groupId) { + this.groupId = groupId; + } + public void setTaskName(String taskName) { this.taskName = taskName; } @@ -309,6 +320,17 @@ public int hashCode() { public String toString() { return getAsText(); } + + /** + * Creates a deep copy of this object. + */ + public Task clone() { + Task t = new Task(id, groupId, taskName, + (Date)startDateTime.clone(), (Date)endDateTime.clone(), + location, priority, recurringType, numberOfRecurrence, + category, description, isArchived); + return t; + } } //@@author diff --git a/src/main/java/seedu/savvytasker/model/task/TaskList.java b/src/main/java/seedu/savvytasker/model/task/TaskList.java index 75ca93107d08..6c68eab70ae7 100644 --- a/src/main/java/seedu/savvytasker/model/task/TaskList.java +++ b/src/main/java/seedu/savvytasker/model/task/TaskList.java @@ -1,7 +1,6 @@ package seedu.savvytasker.model.task; import java.util.Iterator; -import java.util.LinkedList; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -63,6 +62,8 @@ public static class TaskNotFoundException extends Exception { private final ObservableList internalList = FXCollections.observableArrayList(); private int nextId = 0; private boolean isNextIdInitialized = false; + private int nextGroupId = 0; + private boolean isNextGroupIdInitialized = false; /** * Constructs empty TaskList. @@ -76,10 +77,8 @@ public TaskList() {} */ public int getNextId() { if (!isNextIdInitialized) { - int nextLowest = -1; // first id to be used is 0. Start finding with -1 - LinkedList usedIds = new LinkedList(); + int nextLowest = 0; // first id to be used is 1. Start finding with 0 for (Task t : internalList) { - usedIds.add(t.getId()); if (t.getId() > nextLowest) { nextLowest = t.getId(); } @@ -93,6 +92,29 @@ public int getNextId() { nextId++; return nextId; } + + /** + * Gets the next available group id for uniquely identifying a group of recurring tasks in + * Savvy Tasker. + * @return The next available group id; + */ + public int getNextGroupId() { + if (!isNextGroupIdInitialized) { + int nextLowest = 0; // first id to be used is 1. Start finding with 0 + for (Task t : internalList) { + if (t.getId() > nextLowest) { + nextLowest = t.getGroupId(); + } + } + // assumption that the number of tasks < 2^31 + // implementation will be buggy if nextId exceeds 2^31 + nextGroupId = nextLowest; + assert nextGroupId < Integer.MAX_VALUE; + isNextGroupIdInitialized = true; + } + nextGroupId++; + return nextGroupId; + } /** * Returns true if the list contains an equivalent task as the given argument. diff --git a/src/main/java/seedu/savvytasker/storage/XmlAdaptedTask.java b/src/main/java/seedu/savvytasker/storage/XmlAdaptedTask.java index 2598075ab531..7df5aab8cf31 100644 --- a/src/main/java/seedu/savvytasker/storage/XmlAdaptedTask.java +++ b/src/main/java/seedu/savvytasker/storage/XmlAdaptedTask.java @@ -7,7 +7,6 @@ import seedu.savvytasker.commons.exceptions.IllegalValueException; import seedu.savvytasker.model.task.PriorityLevel; import seedu.savvytasker.model.task.ReadOnlyTask; -import seedu.savvytasker.model.task.RecurrenceType; import seedu.savvytasker.model.task.Task; //@@author A0139915W @@ -18,6 +17,8 @@ public class XmlAdaptedTask { @XmlElement(required = true) private int id; + @XmlElement(required = false) + private int groupId; @XmlElement(required = true) private String taskName; @XmlElement(required = false) @@ -29,10 +30,6 @@ public class XmlAdaptedTask { @XmlElement(required = false) private PriorityLevel priority; @XmlElement(required = false) - private RecurrenceType recurringType; - @XmlElement(required = false) - private int numberOfRecurrence; - @XmlElement(required = false) private String category; @XmlElement(required = false) private String description; @@ -52,13 +49,12 @@ public XmlAdaptedTask() {} */ public XmlAdaptedTask(ReadOnlyTask source) { id = source.getId(); + groupId = source.getGroupId(); taskName = source.getTaskName(); startDateTime = source.getStartDateTime(); endDateTime = source.getEndDateTime(); location = source.getLocation(); priority = source.getPriority(); - recurringType = source.getRecurringType(); - numberOfRecurrence = source.getNumberOfRecurrence(); category = source.getCategory(); description = source.getDescription(); isArchived = source.isArchived(); @@ -76,13 +72,11 @@ public Task toModelType() throws IllegalValueException { final Date endDateTime = this.endDateTime; final String location = this.location; final PriorityLevel priority = this.priority; - final RecurrenceType recurringType = this.recurringType; - final int numberOfRecurrence = this.numberOfRecurrence; final String category = this.category; final String description = this.description; final boolean isArchived = this.isArchived; - return new Task(id, taskName, startDateTime, endDateTime, location, priority, - recurringType, numberOfRecurrence, category, description, isArchived); + return new Task(id, groupId, taskName, startDateTime, endDateTime, location, priority, + null, null, category, description, isArchived); } } //@@author diff --git a/src/test/java/seedu/savvytasker/testutil/TestTask.java b/src/test/java/seedu/savvytasker/testutil/TestTask.java index 56f03a4e97cb..baf28be569da 100644 --- a/src/test/java/seedu/savvytasker/testutil/TestTask.java +++ b/src/test/java/seedu/savvytasker/testutil/TestTask.java @@ -13,6 +13,7 @@ public class TestTask implements ReadOnlyTask { private int id; + private int groupId; private String taskName; private Date startDateTime; private Date endDateTime; @@ -31,10 +32,16 @@ public TestTask() { this.numberOfRecurrence = 0; } + @Override public int getId() { return id; } + @Override + public int getGroupId() { + return groupId; + } + @Override public String getTaskName() { return taskName; @@ -93,6 +100,10 @@ public boolean isArchived() { public void setId(int id) { this.id = id; } + + public void setGroupId(int groupId) { + this.groupId = groupId; + } public void setTaskName(String taskName) { this.taskName = taskName; From a73a3cc898537fcba0bc816e132e44cfdfdc1c9f Mon Sep 17 00:00:00 2001 From: qhng Date: Sat, 29 Oct 2016 17:28:46 +0800 Subject: [PATCH 3/4] Fix bug for add/modify not jumping to list item if the first item on the list is added/modified --- src/main/java/seedu/savvytasker/logic/commands/AddCommand.java | 2 +- .../java/seedu/savvytasker/logic/commands/ModifyCommand.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/savvytasker/logic/commands/AddCommand.java b/src/main/java/seedu/savvytasker/logic/commands/AddCommand.java index 3ea4e5d69376..9d4fbdd1a2b6 100644 --- a/src/main/java/seedu/savvytasker/logic/commands/AddCommand.java +++ b/src/main/java/seedu/savvytasker/logic/commands/AddCommand.java @@ -99,7 +99,7 @@ public CommandResult execute() { } int targetIndex = getIndexOfTask(taskAdded); - if (targetIndex > 0) { + if (targetIndex >= 0) { EventsCenter.getInstance().post(new JumpToListRequestEvent(targetIndex)); } else { // GUI should never ever get here diff --git a/src/main/java/seedu/savvytasker/logic/commands/ModifyCommand.java b/src/main/java/seedu/savvytasker/logic/commands/ModifyCommand.java index 34754a1b496e..02438849d7a4 100644 --- a/src/main/java/seedu/savvytasker/logic/commands/ModifyCommand.java +++ b/src/main/java/seedu/savvytasker/logic/commands/ModifyCommand.java @@ -82,7 +82,7 @@ public CommandResult execute() { originalTask = (Task)taskToModify; Task taskModified = model.modifyTask(taskToModify, replacement); int targetIndex = getIndexOfTask(taskModified); - if (targetIndex > 0) { + if (targetIndex >= 0) { EventsCenter.getInstance().post(new JumpToListRequestEvent(targetIndex)); } else { // GUI should never ever get here From 90e3a39c1b8b8af3fd7afc3027700659a98fb160 Mon Sep 17 00:00:00 2001 From: qhng Date: Sat, 29 Oct 2016 17:32:21 +0800 Subject: [PATCH 4/4] Update SUT to fit requirements for the task object. --- .../testutil/TypicalTestTasks.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/java/seedu/savvytasker/testutil/TypicalTestTasks.java b/src/test/java/seedu/savvytasker/testutil/TypicalTestTasks.java index da6b3a91cb1e..2b4569326b92 100644 --- a/src/test/java/seedu/savvytasker/testutil/TypicalTestTasks.java +++ b/src/test/java/seedu/savvytasker/testutil/TypicalTestTasks.java @@ -22,26 +22,26 @@ public class TypicalTestTasks { public TypicalTestTasks() { try { - highPriority = new TaskBuilder().withId(0).withTaskName("High Priority Task") + highPriority = new TaskBuilder().withId(1).withTaskName("High Priority Task") .withPriority(PriorityLevel.High).build(); - medPriority = new TaskBuilder().withId(1).withTaskName("Medium Priority Task") + medPriority = new TaskBuilder().withId(2).withTaskName("Medium Priority Task") .withPriority(PriorityLevel.Medium).build(); - lowPriority = new TaskBuilder().withId(2).withTaskName("Low Priority Task") + lowPriority = new TaskBuilder().withId(3).withTaskName("Low Priority Task") .withPriority(PriorityLevel.Low).build(); - furthestDue = new TaskBuilder().withId(3).withTaskName("Furthest Due Task") + furthestDue = new TaskBuilder().withId(4).withTaskName("Furthest Due Task") .withEndDateTime(getDate("01/12/2016")).build(); - nearerDue = new TaskBuilder().withId(4).withTaskName("Nearer Due Task") + nearerDue = new TaskBuilder().withId(5).withTaskName("Nearer Due Task") .withEndDateTime(getDate("01/11/2016")).build(); - notSoNearerDue = new TaskBuilder().withId(5).withTaskName("Not So Nearer Due Task") + notSoNearerDue = new TaskBuilder().withId(6).withTaskName("Not So Nearer Due Task") .withEndDateTime(getDate("02/11/2016")).build(); - earliestDue = new TaskBuilder().withId(6).withTaskName("Earliest Due Task") + earliestDue = new TaskBuilder().withId(7).withTaskName("Earliest Due Task") .withEndDateTime(getDate("01/10/2016")).build(); - longDue = new TaskBuilder().withId(7).withTaskName("Long Due Task") + longDue = new TaskBuilder().withId(8).withTaskName("Long Due Task") .withEndDateTime(getDate("01/1/2016")).withArchived(true).build(); //Manually added - happy = new TaskBuilder().withId(8).withTaskName("Happy Task").build(); - haloween = new TaskBuilder().withId(9).withTaskName("Haloween Task").build(); + happy = new TaskBuilder().withId(9).withTaskName("Happy Task").build(); + haloween = new TaskBuilder().withId(10).withTaskName("Haloween Task").build(); } catch (IllegalValueException e) { e.printStackTrace(); assert false : "not possible";