diff --git a/collated/docs/A0139257X.md b/collated/docs/A0139257X.md index 45e5f60dbc96..ac72fd592115 100644 --- a/collated/docs/A0139257X.md +++ b/collated/docs/A0139257X.md @@ -1,6 +1,28 @@ # A0139257X +###### \AboutUs.md +``` md +#### [Marcus Ng Wen Jian](https://github.com/marcusngwj)
+
+ +Role: Team Leader +* Components in charge of: [Logic](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/DeveloperGuide.md#logic-component) +* Aspects/tools in charge of: Overall Project Management, Code Quality +* Features implemented: + * [Add Command](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/UserGuide.md#adding-a-task-add) +* Code written: +[[functional code](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/collated/main/A0139257X.md)] +[[test code](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/collated/test/A0139257X.md)] +[[docs](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/collated/docs/A0139257X.md)] +* Other major contributions: + * Contributed to first round refactoring from AddressBook Level 4 to TaskManager [[#11](https://github.com/CS2103AUG2016-W15-C3/main/pull/11)] + * Contributed to second round refactoring from AddressBook Level 4 to Taskell [[#64](https://github.com/CS2103AUG2016-W15-C3/main/pull/64)] + * Set up Codacy [[#113](https://github.com/CS2103AUG2016-W15-C3/main/pull/113)] + +----- +``` ###### \DeveloperGuide.md ``` md + ## Appendix B : Use Cases #### Use case: Add task @@ -8,7 +30,6 @@ **MSS** 1. User requests to add tasks - 2. Taskell adds the task
Use case ends @@ -59,7 +80,7 @@ Use case ends 4a. User tries to mark a completed task as completed -#### Use case: Help task +#### Use case: Help command **MSS** @@ -74,7 +95,7 @@ Use case ends > 3a1. Taskell stil displays the help message
-#### Use case: Find task +#### Use case: Find tasks **MSS** @@ -110,97 +131,10 @@ Use case ends > 3a1, 3b1 and 3c1. Taskell shows an error message
Use case resumes at step 2 -#### Use case: Undo task - -**MSS** - -1. User enters a command -2. Taskell executes it -<<<<<<< HEAD -3. User requests to list commands history -4. User requests to undo command at specific index -5. Taskell undoes the previous command
-======= -3. User requests to list undo commands history -4. User requests to undo command at specific index -5. Taskell revert the command
->>>>>>> 9d3e940bc97dc4a324dca16582e28cdbfc8c5ebc -Use case ends - -**Extensions** - -3a. The user did not enter any previous command - -> 3a1. Taskell shows a message indicating no commands available for undo
- -4a. The user enters invalid index - -> 4a1. Taskell shows error message indicating index is invalid
- -#### Use case: List task - -**MSS** - -1. User requests to list either all tasks, incomplete tasks, completed tasks, task with specific start date or task with specific priority -2. Taskell shows a list of tasks accordingly -Use case ends - -**Extensions** - -2a. The list is empty - -> 2a1. Taskell shows an error message
- Use case resumes at step 2 - -#### Use case: View calendar for the week - -**MSS** - -1. User requests to view calendar -2. Taskell displays calendar - -#### Use case: Save data to specified folder - -**MSS** - -1. User requests to save all tasks -2. Taskell saves all tasks in the requested folder
-Use case ends - -**Extensions** - -2a. Data cannot be written to the requested folder (invalid directory or access prohibited) - -> 2a1. Taskell shows an error message and still saves data in previous old location.
- -#### Use case: Clear task - -**MSS** - -1. User requests to clear all tasks -2. Taskell deletes all tasks -Use case ends - -**Extensions** - -2a. The list is empty - -> 2a1. Taskell shows an error message
- -#### Use case: Exit task - -**MSS** - -1. User requests to exit Taskell -2. Taskell saves all the data and stops -Use case ends - -**Extensions** - -NIL ``` ###### \UserGuide.md ``` md + #### Adding a task: `add` To add a floating task
Format: @@ -239,4 +173,5 @@ Example: `add ` concert by 2am band startat 7pm
- `add ` TASK endat [TIME]
Example: `add ` netball training endat 7pm
+ ``` diff --git a/collated/docs/A0142073R.md b/collated/docs/A0142073R.md index 2999f290780e..0b3ee61fd2a2 100644 --- a/collated/docs/A0142073R.md +++ b/collated/docs/A0142073R.md @@ -1,14 +1,41 @@ # A0142073R +###### \AboutUs.md +``` md +#### [Madasamy Ravi Nadar Mamtha](https://github.com/Mamtha3005) +
+ +Role: Developer +* Components in charge of: [Logic](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/DeveloperGuide.md#logic-component) +* Aspects/tools in charge of: Documentation, Scheduling +* Features implemented: + * [Edit Command](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/UserGuide.md#editing-a-task--edit) + * [List-date Command] + (https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/UserGuide.md#listing-a-task--list) + * [List-priority Command] + (https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/UserGuide.md#listing-a-task--list) +* Code Written: +[[functional code](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/collated/main/A0142073R.md)] +[[test code](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/collated/test/A0142073R.md)] +[[docs](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/collated/docs/A0142073R.md)] +* Other major contributions: + * Contributed to second round refactoring from AddressBook Level 4 to Taskell [[#64](https://github.com/CS2103AUG2016-W15-C3/main/pull/64)] + * Copy, editing and revising of documentation + +----- +``` ###### \DeveloperGuide.md ``` md + ##Introduction Taskell is a simple software for users to keep track of their daily tasks and manage their busy schedule. Keyboard lovers will be able to experience the full benefit of Taskell as it implements a command-line interface. This developer guide will help you understand the design and implementation of Taskell. It helps you understand how Taskell works and how you can contribute for further development. This guide follows a top-down approach by giving an overview of the essential components first, followed by thorough explanation subsequently. + ``` ###### \DeveloperGuide.md ``` md + ## Appendix A : User Stories Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unlikely to have) - `*` @@ -37,40 +64,32 @@ Priority | As a ... | I want to ... | So that I can... `*` | user | edit my notification time period | customise if I wanted to be reminded earlier or later. `*` | user | use the history command | saves time typing repeated commands. `*` | user | view the task in either calendar form or list form | switch between the two display format. + ``` ###### \UserGuide.md ``` md + ## Introduction Are you having a hard time remembering all the work you have to do? Do you have trouble finding a task manager that suits your preference for keyboard input? Well, worry no more, Taskell is here for you!
Taskell will be your personal secretary. It will keep track of your daily tasks and remind you of any important dates and deadlines. What distinguishes Taskell from other task managers is that Taskell only requires a single line of command for every task input. This means that you can record each one of your tasks with just a single statement. You will no longer have to use a mouse if you do not wish to.
-Ready to begin life anew with a more efficient task manager? Read on to find out more! +Ready to begin life anew with a more efficient task manager? Read on to find out more! + ``` ###### \UserGuide.md ``` md + #### Editing a task : `edit` -To edit the description of a task
+To edit a task
Formats: -- `edit-desc` INDEX NEWDESCRIPTION
-- `edit-name` INDEX NEWDESCRIPTION
+- `edit ` INDEX `st: `[NEWSTARTTIME] `et: `[NEWENDTIME] `desc: `[NEWDESCRIPTION] `sd: `[NEWSTARTDATE] `ed: `[NEWENDDATE] `p: `[NEWPRIORITY]


-Diagram 5: Edits the 2nd task on the list
+Diagram 5: Edits the 1st task on the list.
+Entering "edit 1 desc: send all emails sd: 11-11-2016 ed: 12-11-2016 st: 3pm et: 4pm p: 3", will update description to "send all emails", start date to 11-11-2016, end date to 12-11-2016, start time to 3pm end time to 4pm and priority to 3.
-To edit the time of a task
-Formats: -- `edit-startTime` INDEX NEWTIME
-- `edit-endTime` INDEX NEWTIME
- -To edit the date of a task
-Formats: -- `edit-startDate` INDEX NEWDATE
-- `edit-endDate` INDEX NEWDATE
- -To edit the priority of a task
-Formats: -- `edit-priority` INDEX NEWDATE
``` ###### \UserGuide.md ``` md + ## Command Summary Command | Format @@ -87,13 +106,12 @@ Edit | `edit` INDEX NEWTASK Find | `find` KEYWORD [MORE_KEYWORDS] Find Tag | `find-tag` KEYWORD [MORE_KEYWORDS] Help | `help` +History | `history` or `hist` List Incomplete Tasks| `list` List All Tasks | `list-all` List Given Day | `list-date` [DATE] List Tasks Done | `list-done` [DONE] -List Undo | `list-undo` -Undo | `undo INDEX` -Calendar View | `calendar` or `cal` +Undo | `undo` or `undo` INDEX ## Appendix A @@ -119,5 +137,6 @@ Supported Time Format | Example -------- | :-------- 12hour |1pm 12hour |12am -12hour |111.45pm +12hour |11.45pm + ``` diff --git a/collated/docs/A0142130A.md b/collated/docs/A0142130A.md index 8705d1423f06..d96e7412b286 100644 --- a/collated/docs/A0142130A.md +++ b/collated/docs/A0142130A.md @@ -1,6 +1,97 @@ # A0142130A +###### \AboutUs.md +``` md +#### [Jazlyn Ang Chue Ching](https://github.com/turtle96) +
+ +Role: Developer +* Components in charge of: [Storage](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/DeveloperGuide.md#storage-component), +[UI](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/DeveloperGuide.md#ui-component) +* Aspects/tools in charge of: Testing, Integration, Git +* Features implemented: + * [Save Location](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/UserGuide.md#saving-the-information-in-taskell--save) + * [Undo Command & Command History](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/UserGuide.md#reverting-previous-action--undo) + * [Find Command](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/UserGuide.md#finding-tasks-find) + * [Calendar View](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/UserGuide.md#showing-calendar-view--calendar-or-cal) +* Code written: [[functional code](https://github.com/CS2103AUG2016-W15-C3/main/tree/master/collated/main/A0142130A.md)][[test code](https://github.com/CS2103AUG2016-W15-C3/main/tree/master/collated/test/A0142130A.md)][[docs](https://github.com/CS2103AUG2016-W15-C3/main/tree/master/collated/docs/A0142130A.md)] +* Other major contributions: + * Contributed to second round refactoring from AddressBook Level 4 to Taskell [[#64](https://github.com/CS2103AUG2016-W15-C3/main/pull/64) ] + * Set up Travis and Coveralls + * Designed UI theme + +----- +``` +###### \DeveloperGuide.md +``` md + +#### Use case: Undo command + +**MSS** + +1. User enters a command +2. Taskell executes it +3. User requests to view undo commands history +4. User requests to undo command at specific index +5. Taskell revert the command
+Use case ends + +**Extensions** + +3a. The user did not enter any previous command + +> 3a1. Taskell shows a message indicating no commands available for undo
+ +4a. The user enters invalid index + +> 4a1. Taskell shows error message indicating index is invalid
+ +``` +###### \DeveloperGuide.md +``` md + +#### Use case: View calendar for the week + +**MSS** + +1. User requests to view calendar +2. Taskell displays calendar + +#### Use case: Save data to specified folder + +**MSS** + +1. User requests to save all tasks +2. Taskell saves all tasks in the requested folder
+Use case ends + +**Extensions** + +2a. Data cannot be written to the requested folder (invalid directory or access prohibited) + +> 2a1. Taskell shows an error message and still saves data in previous old location.
+ +``` +###### \DeveloperGuide.md +``` md + +#### Remember the Milk +**Pros:**
+1. Can be used offline and tasks are synced once internet connection is established
+2. Can handle some natural language processing by saving deadlines from task information itself (e.g. Do math homework tomorrow: Saves task with deadline set to tomorrow)
+3. Can undo when marking tasks as done (recover from accidentally marking a task as done)
+4. Can set priority, and list tasks by priority
+5. Can set recursive tasks
+ +**Cons:**
+1. Need to click frequently to enter or edit a task
+2. Need to remember lots of shortcuts, so user is less likely to use them
+3. Has a cluttered interface, which is not intuitive
+4. Does not support calendar view in-house
+ +``` ###### \UserGuide.md ``` md + #### Finding tasks: `find` You can use the find command to view tasks with specific keywords.
Formats:
@@ -20,19 +111,39 @@ This returns any task with either tag `homework`, `essay`, or `cs2103`.
###### \UserGuide.md ``` md +#### Showing history : `history` or `hist` +You can view the command history available for undo on the right panel to refer to when undoing previous commands.
+To save your time, Taskell has a short form command `hist`.
+Format: `history`
+ +> Take Note!
+> * Only commands available for undo are shown here. +> * Refer to undo section for more information about what commands undo supports. + #### Reverting previous action : `undo` -If you wish to undo your previous actions, Enter list-undo to see a list of +If you wish to undo your most recent action, you can do so by using the undo command.
+You can also undo previous commands, Enter `hist` to see a list of previous commands that can be undone.
-Then use undo command at the specified INDEX in the list.
-Format: `undo INDEX`
-Example: `list-undo`, then `undo 3`, will undo third command in command history. +Then use undo command with specified INDEX from the list of command history.
+Formats:
+-`undo`
+Undo most recent command executed.
+-`undo INDEX`
+Undo by index of command history.
+Example: `hist`, then `undo 3`, will undo third command in command history.
+ +> Take Note!
+> * Undo command only supports add, edit, delete, and undo commands. +> * Clear commands are irreversible! ``` ###### \UserGuide.md ``` md + #### Showing calendar view : `calendar` or `cal` -You can view the calendar for the week on right panel to refer to the dates when adding tasks and scheduling events.
-To save time, Taskell has a short form command `cal`.
+You can view the calendar for the week on the right panel to refer to the dates and any events scheduled +when adding tasks and scheduling events.
+To save your time, Taskell has a short form command `cal`.
Format: `calendar`
#### Saving the information in Taskell : `save` diff --git a/collated/docs/A0148004R.md b/collated/docs/A0148004R.md index 395f1e9a5f46..286fc57c3e8d 100644 --- a/collated/docs/A0148004R.md +++ b/collated/docs/A0148004R.md @@ -1,6 +1,43 @@ -# A0148004Rz +# A0148004R +###### \AboutUs.md +``` md +#### [Zuo ZhuoLin](https://github.com/ZuoZhuolin) +
+Role: Developer +* Components in charge of: [Model](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/DeveloperGuide.md#model-component) +* Aspects/tools in charge of: Testing, Scheduling +* Features implemented: + * [Done Command](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/UserGuide.md#marking-a-task-as-completed-done + * [List Command](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/UserGuide.md#listing-tasks--list) + * [List-all Command](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/UserGuide.md#listing-tasks--list) + * [List-done Command](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/docs/UserGuide.md#listing-tasks--list) + * [Recurring Task] +* Code written: +[[functional code](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/collated/main/A0148004R.md)] +[[test code](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/collated/test/A0148004R.md)] +[[docs](https://github.com/CS2103AUG2016-W15-C3/main/blob/master/collated/docs/A0148004R.md)] +* Other major contributions: + * Contributed to second round refactoring from AddressBook Level 4 to Taskell + + +----- + +# Contributors + +We welcome contributions. See [Contact Us](ContactUs.md) page for more info. + +* [Damith C. Rajapakse](http://www.comp.nus.edu.sg/~damithch/) +* [Joshua Lee](https://github.com/lejolly) +* [Leow Yijin](https://github.com/yijinl) +* [Martin Choo](https://github.com/m133225) +* [Thien Nguyen](https://github.com/ndt93) +* [You Liang](https://github.com/yl-coder) +* [Akshay Narayan](https://github.com/se-edu/addressbook-level4/pulls?q=is%3Apr+author%3Aokkhoy) +* [Sam Yong](https://github.com/se-edu/addressbook-level4/pulls?q=is%3Apr+author%3Amauris) +``` ###### \UserGuide.md ``` md + #### Listing tasks : `list` Formats: - `list`
@@ -15,11 +52,14 @@ Displays a list of completed tasks.
Displays a list of tasks with given priority.


Diagram 2: Displays all the tasks to be done by today after typing list-date. + ``` ###### \UserGuide.md ``` md + #### Marking a task as completed: `done` Format: `done` INDEX
Example: `done` 1
This adds the 1st task as completed and moves it to the completed list.
+ ``` diff --git a/collated/main/A0139257X.md b/collated/main/A0139257X.md index 29c50de0678c..1279eca93958 100644 --- a/collated/main/A0139257X.md +++ b/collated/main/A0139257X.md @@ -9,9 +9,9 @@ public class AddCommand extends Command { public static final String COMMAND_WORD = "add"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a task to the task manager. " - + "Parameters: DESCRIPTION by/on[DATE] from[START_TIME] to[END_TIME] [p/PRIORITY] [#TAG]...\n" + + "Parameters: DESCRIPTION by/on[DATE] from[START_TIME] to[END_TIME] [p/PRIORITY] [r/daily] [#TAG]...\n" + "Example: " + COMMAND_WORD - + " go for meeting on 1-1-2100 from 12.30AM to 12.45AM p/3 #work"; + + " go for meeting on 1-1-2100 from 12.30AM to 12.45AM p/3 r/daily #work"; public static final String MESSAGE_SUCCESS = "New task added: %1$s"; public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task manager"; @@ -24,8 +24,10 @@ public class AddCommand extends Command { * @throws IllegalValueException if any of the raw values are invalid */ - public AddCommand(String description, String taskType, String startDate, String endDate, String startTime, String endTime, String taskPriority, Set tags) - throws IllegalValueException { + public AddCommand(String description, String taskType, String startDate, String endDate, + String startTime, String endTime, String taskPriority, + String recurringType, Set tags) throws IllegalValueException { + final Set tagSet = new HashSet<>(); for (String tagName : tags) { tagSet.add(new Tag(tagName)); @@ -33,10 +35,10 @@ public class AddCommand extends Command { switch (taskType) { case Task.FLOATING_TASK: - this.toAdd = new FloatingTask(description, taskPriority, TaskStatus.INCOMPLETE, new UniqueTagList(tagSet)); + this.toAdd = new FloatingTask(description, taskPriority, recurringType, TaskStatus.INCOMPLETE, new UniqueTagList(tagSet)); break; case Task.EVENT_TASK: - this.toAdd = new EventTask(description, startDate, endDate, startTime, endTime, taskPriority, TaskStatus.INCOMPLETE, new UniqueTagList(tagSet)); + this.toAdd = new EventTask(description, startDate, endDate, startTime, endTime, taskPriority, recurringType, TaskStatus.INCOMPLETE, new UniqueTagList(tagSet)); break; default: toAdd = null; @@ -56,7 +58,6 @@ public class AddCommand extends Command { */ private Command prepareAdd(String args) { if (args.isEmpty()) { - UndoCommand.deletePreviousCommand(); return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } @@ -76,22 +77,23 @@ public class AddCommand extends Command { String endTime = TaskTime.DEFAULT_END_TIME; String token = ""; String taskPriority = TaskPriority.DEFAULT_PRIORITY; + String recurringType = RecurringType.DEFAULT_RECURRING; String tagString = ""; int priorityCount = 0; - + int recurrenceCount = 0; boolean hasStartDate = false; boolean hasEndDate = false; boolean hasStartTime = false; boolean hasEndTime = false; - + boolean hasRecurring = false; while (!initialQueue.isEmpty()) { token = initialQueue.poll().trim(); String tempToken = ""; if (!token.equals(BY) && !token.equals(ON) && !token.equals(AT) && !token.equals(FROM) && !token.equals(TO) && !TaskDate.isValidDate(token) && !TaskTime.isValidTime(token) && !token.startsWith(Tag.PREFIX) - && !token.startsWith(TaskPriority.PREFIX)) { + && !token.startsWith(TaskPriority.PREFIX) && !token.startsWith(RecurringType.PREFIX)) { tempToken = flushQueue(byQueue, onQueue, atQueue, fromQueue, toQueue); if (!tempToken.isEmpty()) { descriptionQueue.offer(tempToken); @@ -153,6 +155,21 @@ public class AddCommand extends Command { priorityCount++; } continue; + } else if (token.startsWith(RecurringType.PREFIX)) { + tempToken = flushQueue(byQueue, onQueue, atQueue, fromQueue, toQueue); + if (!tempToken.isEmpty()) { + descriptionQueue.offer(tempToken); + } + if (recurrenceCount > 0) { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); + } else { + + recurringType = token.substring(token.indexOf(RecurringType.PREFIX) + 2); + hasRecurring = true; + recurrenceCount++; + } + } else if (TaskDate.isValidDate(token)) { if (byQueue.isEmpty() && onQueue.isEmpty() && atQueue.isEmpty() && fromQueue.isEmpty() && toQueue.isEmpty()) { @@ -257,29 +274,32 @@ public class AddCommand extends Command { if (!hasEndDate) { endDate = startDate; } - - if ((TaskDate.isValidToday(startDate) && !hasStartTime) || startDate.equals(TaskDate.DEFAULT_DATE) && !hasStartTime) { + + if ((TaskDate.isValidToday(startDate) && !hasStartTime) + || startDate.equals(TaskDate.DEFAULT_DATE) && !hasStartTime) { startTime = TaskTime.getTimeNow().toString(); } if (hasStartDate || hasEndDate || hasStartTime || hasEndTime) { try { return new AddCommand(description, Task.EVENT_TASK, startDate, endDate, startTime, endTime, - taskPriority, getTagsFromArgs(tagString)); + taskPriority, recurringType, getTagsFromArgs(tagString)); } catch (IllegalValueException ive) { - UndoCommand.deletePreviousCommand(); return new IncorrectCommand(ive.getMessage()); } } else { - try { - return new AddCommand(description, Task.FLOATING_TASK, startDate, endDate, startTime, endTime, - taskPriority, getTagsFromArgs(tagString)); - } catch (IllegalValueException ive) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand(ive.getMessage()); + + if (hasRecurring) { + return new IncorrectCommand(FloatingTask.RECURRING_TYPE_NOT_ALLOWED); + } else { + try { + return new AddCommand(description, Task.FLOATING_TASK, startDate, endDate, startTime, endTime, + taskPriority, recurringType, getTagsFromArgs(tagString)); + } catch (IllegalValueException ive) { + return new IncorrectCommand(ive.getMessage()); + } } } - } private String flushQueue(Queue byQueue, Queue onQueue, Queue atQueue, @@ -384,7 +404,10 @@ public class EventTask extends Task { public static final String MESSAGE_EVENT_CONSTRAINTS = "Start date and time must be before end date and time" + "\nAll date and time should not before current time"; - public EventTask(String description, String startDate, String endDate, String startTime, String endTime, String taskPriority, String taskStatus, UniqueTagList tags) throws IllegalValueException { + public EventTask(String description, String startDate, String endDate, String startTime, + String endTime, String taskPriority, String recurringType, String taskStatus, + UniqueTagList tags) throws IllegalValueException { + this(new Description(description), EVENT_TASK, new TaskDate(startDate), @@ -392,20 +415,29 @@ public class EventTask extends Task { new TaskTime(startTime), new TaskTime(endTime), new TaskPriority(taskPriority), - new TaskStatus(taskStatus), + new RecurringType(recurringType), + new TaskStatus(taskStatus), tags); } + /** * Every field must be present and not null. * @throws IllegalValueException */ - public EventTask(Description description, String taskType, TaskDate startDate, TaskDate endDate, TaskTime startTime, TaskTime endTime, TaskPriority taskPriority, TaskStatus taskStatus, UniqueTagList tags) throws IllegalValueException { + public EventTask(Description description, String taskType, TaskDate startDate, + TaskDate endDate, TaskTime startTime, TaskTime endTime, TaskPriority taskPriority, + RecurringType recurringType, TaskStatus taskStatus, UniqueTagList tags) throws IllegalValueException { + endDate = autoAdjustEndDate(startDate, endDate, startTime, endTime); if (!isValidEventDuration(startDate, endDate, startTime, endTime)) { throw new IllegalValueException(MESSAGE_EVENT_CONSTRAINTS); } + if(!isValidRecurringEvent(startDate, endDate, recurringType)){ + throw new IllegalValueException(RecurringType.MESSAGE_INVALID_RECURRING_DURATION); + } + this.description = description; this.taskType = EVENT_TASK; this.startDate = startDate; @@ -413,10 +445,14 @@ public class EventTask extends Task { this.startTime = startTime; this.endTime = endTime; this.taskPriority = taskPriority; + this.recurringType = recurringType; this.taskStatus = taskStatus; this.tags = tags; } +``` +###### \java\seedu\taskell\model\task\EventTask.java +``` java private boolean isValidEventDuration(TaskDate startDate, TaskDate endDate, TaskTime startTime, TaskTime endTime) { TaskDate today = TaskDate.getTodayDate(); TaskTime currentTime = TaskTime.getTimeNow(); @@ -440,8 +476,8 @@ public class EventTask extends Task { TaskDate today = TaskDate.getTodayDate(); if (startDate.equals(endDate) && startTime.isAfter(endTime)) { endDate = endDate.getNextDay(); - } else if (startDate.getDayNameInWeek().equals(today.getDayNameInWeek()) - && !endDate.getDayNameInWeek().equals(today.getDayNameInWeek())) { + } else if((TaskDate.between(startDate, endDate) > -TaskDate.NUM_DAYS_IN_A_WEEK)&& (TaskDate.between(startDate, endDate) < 0)) { + System.out.println(TaskDate.between(startDate, endDate)); endDate = endDate.getNextWeek(); } return endDate; @@ -462,8 +498,13 @@ public class EventTask extends Task { * Guarantees: details are present and not null, field values are validated. */ public class FloatingTask extends Task { - - public FloatingTask(String description, String taskPriority, String taskStatus, UniqueTagList tags) throws IllegalValueException { + + public static final String RECURRING_TYPE_NOT_ALLOWED = "Floating task cannot be recurring"; + public static final String EDIT_FLOATING_NOT_ALLOWED = "Floating task does not have date and time."; + + public FloatingTask(String description, String taskPriority, String recurringType, + String taskStatus, UniqueTagList tags) throws IllegalValueException { + this(new Description(description), FLOATING_TASK, new TaskDate(TaskDate.DEFAULT_DATE), @@ -471,12 +512,17 @@ public class FloatingTask extends Task { new TaskTime(TaskTime.DEFAULT_START_TIME), new TaskTime(TaskTime.DEFAULT_END_TIME), new TaskPriority(taskPriority), + new RecurringType(recurringType), new TaskStatus(taskStatus), tags); } - public FloatingTask(Description description, String taskType, TaskDate startDate, TaskDate endDate, TaskTime startTime, TaskTime endTime, TaskPriority taskPriority, TaskStatus taskStatus, UniqueTagList tags) { - super(description, taskType, startDate, endDate, startTime, endTime, taskPriority, taskStatus, tags); + public FloatingTask(Description description, String taskType, TaskDate startDate, + TaskDate endDate, TaskTime startTime, TaskTime endTime, TaskPriority taskPriority, + RecurringType recurringType, TaskStatus taskStatus, UniqueTagList tags) { + + super(description, taskType, startDate, endDate, startTime, endTime, + taskPriority, recurringType, taskStatus, tags); } @Override @@ -516,7 +562,9 @@ public class TaskDate { public static final int SATURDAY = 6; public static final int SUNDAY = 7; + public static final int NUM_DAYS_PER_DAY = 1; public static final int NUM_DAYS_IN_A_WEEK = 7; + public static final int NUM_DAYS_IN_A_MONTH = 30; public static final int NUM_MONTHS_IN_A_YEAR = 12; public static final int NOT_A_VALID_MONTH = 0; @@ -718,6 +766,9 @@ public class TaskDate { || isValidTomorrow(dateToValidate) || isValidDayOfWeek(dateToValidate); } + /** + * Returns true if given string is the same as a name of the week + */ public static boolean isValidDayOfWeek(String dateToValidate) { if (convertDayOfWeekIntoInteger(dateToValidate) == NOT_A_VALID_DAY_OF_THE_WEEK) { return false; @@ -780,6 +831,9 @@ public class TaskDate { return true; } + /** + * Returns true if given string contains a word that suggest today + */ public static boolean isValidToday(String dateToValidate) { assert (dateToValidate != null); dateToValidate = dateToValidate.toLowerCase(); @@ -794,6 +848,9 @@ public class TaskDate { } } + /** + * Returns true if given string contains a word that suggest tomorrow + */ public static boolean isValidTomorrow(String dateToValidate) { assert (dateToValidate != null); dateToValidate = dateToValidate.toLowerCase(); @@ -808,6 +865,9 @@ public class TaskDate { } } + /** + * Returns true if the given string has the same name as a month in the year + */ public static boolean isValidMonth(String month) { if (convertMonthIntoInteger(month) == NOT_A_VALID_MONTH) { return false; @@ -952,7 +1012,7 @@ public class TaskDate { public TaskDate getNextDay() throws IllegalValueException { try { - LocalDate localDate = LocalDate.of(Integer.valueOf(getYear()), Integer.valueOf(getMonth()), Integer.valueOf(getDay())); + LocalDate localDate = this.getLocalDate(); LocalDate nextDay = localDate.plusDays(1); return new TaskDate(nextDay.format(standardFormat)); } catch (IllegalValueException e) { @@ -962,14 +1022,17 @@ public class TaskDate { public TaskDate getNextWeek() throws IllegalValueException { try { - LocalDate localDate = LocalDate.of(Integer.valueOf(getYear()), Integer.valueOf(getMonth()), Integer.valueOf(getDay())); + LocalDate localDate = this.getLocalDate(); LocalDate nextWeek = localDate.plusWeeks(1); return new TaskDate(nextWeek.format(standardFormat)); } catch (IllegalValueException e) { throw new IllegalValueException(MESSAGE_TASK_DATE_CONSTRAINTS); } } - + +``` +###### \java\seedu\taskell\model\task\TaskDate.java +``` java /** * Returns a string representing the integer value of this year */ @@ -1011,23 +1074,15 @@ public class TaskDate { } public String getDayNameInWeek() throws IllegalValueException { - try { - LocalDate localDate = LocalDate.of(Integer.valueOf(getYear()), Integer.valueOf(getMonth()), Integer.valueOf(getDay())); - String dayNameInWeek = localDate.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.US); - return dayNameInWeek; - } catch (IllegalValueException ive) { - throw ive; - } + LocalDate localDate = this.getLocalDate(); + String dayNameInWeek = localDate.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.US); + return dayNameInWeek; } - public String getMonthName() throws IllegalValueException { - try { - LocalDate localDate = LocalDate.of(Integer.valueOf(getYear()), Integer.valueOf(getMonth()), Integer.valueOf(getDay())); - String month = localDate.getMonth().getDisplayName(TextStyle.FULL, Locale.US); - return month; - } catch (IllegalValueException ive) { - throw ive; - } + public String getMonthName() { + LocalDate localDate = this.getLocalDate(); + String month = localDate.getMonth().getDisplayName(TextStyle.FULL, Locale.US); + return month; } public String getDisplayDate() { @@ -1037,6 +1092,14 @@ public class TaskDate { return ""; } } + + public LocalDate getLocalDate() { + try { + return LocalDate.of(Integer.valueOf(getYear()), Integer.valueOf(getMonth()), Integer.valueOf(getDay())); + } catch (NumberFormatException | IllegalValueException e) { + return null; + } + } public static String getDefaultDate() { int day = LocalDate.now().getDayOfMonth(); @@ -1045,26 +1108,43 @@ public class TaskDate { return convertToStandardFormat(day, month, year); } + /** + * Returns true if the given date is before this date + */ public boolean isBefore(TaskDate date) { try { - LocalDate thisDate = LocalDate.of(Integer.valueOf(this.getYear()), Integer.valueOf(this.getMonth()), Integer.valueOf(this.getDay())); - LocalDate dateToComapare = LocalDate.of(Integer.valueOf(date.getYear()), Integer.valueOf(date.getMonth()), Integer.valueOf(date.getDay())); + LocalDate thisDate = this.getLocalDate(); + LocalDate dateToComapare = date.getLocalDate(); return thisDate.isBefore(dateToComapare); } catch (Exception e) { return false; } } + /** + * Returns true if the given date is after this date + */ public boolean isAfter(TaskDate date) { try { - LocalDate thisDate = LocalDate.of(Integer.valueOf(this.getYear()), Integer.valueOf(this.getMonth()), Integer.valueOf(this.getDay())); - LocalDate dateToComapare = LocalDate.of(Integer.valueOf(date.getYear()), Integer.valueOf(date.getMonth()), Integer.valueOf(date.getDay())); + LocalDate thisDate = this.getLocalDate(); + LocalDate dateToComapare = date.getLocalDate(); return thisDate.isAfter(dateToComapare); } catch (Exception e) { return false; } } + /** + * Calculates the number of days from the first date to the second date + */ + public static long between(TaskDate first, TaskDate second) { + return ChronoUnit.DAYS.between(first.getLocalDate(), second.getLocalDate()); + } + + public LocalDateTime toLocalDateTime(TaskTime time) { + return LocalDateTime.of(this.getLocalDate(), time.getLocalTime()); + } + /** * Returns a string with the format of * DAY-MONTH-YEAR @@ -1109,9 +1189,9 @@ public class TaskPriority { public static final String DEFAULT_PRIORITY = NO_PRIORITY; - public static final String LOW_PRIORITY_BACKGROUND = "-fx-background-color:#4ca64c"; - public static final String MEDIUM_PRIORITY_BACKGROUND = "-fx-background-color:#ffff4c"; - public static final String HIGH_PRIORITY_BACKGROUND = "-fx-background-color:#ff4c4c"; + public static final String LOW_PRIORITY_BACKGROUND = "-fx-background-color: #4CAF50"; + public static final String MEDIUM_PRIORITY_BACKGROUND = "-fx-background-color: #FFEB3B"; + public static final String HIGH_PRIORITY_BACKGROUND = "-fx-background-color: #F44336"; public final String taskPriority; @@ -1129,7 +1209,7 @@ public class TaskPriority { } /** - * Returns true if a given string is a valid task taskTime. + * Returns true if a given string is a valid task taskPriority. */ public static boolean isValidPriority(String priority) { return priority.equals(NO_PRIORITY) @@ -1200,6 +1280,9 @@ public class TaskTime { } } + /** + * Returns true if given string is a valid 12-hour time in the real world + */ public static boolean isValidTime(String time) { assert time != null; if (time.isEmpty()) { @@ -1221,12 +1304,7 @@ public class TaskTime { private static boolean isValidNow(String time) { time = time.toLowerCase(); - switch (time) { - case "now": - return true; - default: - return false; - } + return "now".equals(time); } private static boolean isValidNoon(String time) { @@ -1270,22 +1348,8 @@ public class TaskTime { * Checks if this time is before the specified time */ public boolean isBefore(TaskTime time) { - int timeHour = Integer.valueOf(time.getHour()); - if (time.getAntePost().equals(PM) && (timeHour != TIME_OFFSET)) { - timeHour += TIME_OFFSET; - } else if (time.getAntePost().equals(AM) && (timeHour == TIME_OFFSET)) { - timeHour -= TIME_OFFSET; - } - LocalTime timeToCompare = LocalTime.of(timeHour, Integer.valueOf(time.getMinute())); - - //TaskTime thisTimeTaskTime = new TaskTime(this.taskTime); - int thisTimeHour = Integer.valueOf(this.getHour()); - if (this.getAntePost().equals(PM) && (thisTimeHour != TIME_OFFSET)) { - thisTimeHour += TIME_OFFSET; - } else if (this.getAntePost().equals(AM) && (thisTimeHour == TIME_OFFSET)) { - thisTimeHour -= TIME_OFFSET; - } - LocalTime thisTimeLocalTime = LocalTime.of(thisTimeHour, Integer.valueOf(this.getMinute())); + LocalTime timeToCompare = time.getLocalTime(); + LocalTime thisTimeLocalTime = this.getLocalTime(); return thisTimeLocalTime.isBefore(timeToCompare); } @@ -1293,22 +1357,8 @@ public class TaskTime { * Checks if this time is after the specified time */ public boolean isAfter(TaskTime time) { - int timeHour = Integer.valueOf(time.getHour()); - if (time.getAntePost().equals(PM) && (timeHour != TIME_OFFSET)) { - timeHour += TIME_OFFSET; - } else if (time.getAntePost().equals(AM) && (timeHour == TIME_OFFSET)) { - timeHour -= TIME_OFFSET; - } - LocalTime timeToCompare = LocalTime.of(timeHour, Integer.valueOf(time.getMinute())); - - //TaskTime thisTimeTaskTime = new TaskTime(this.taskTime); - int thisTimeHour = Integer.valueOf(this.getHour()); - if (this.getAntePost().equals(PM) && (thisTimeHour != TIME_OFFSET)) { - thisTimeHour += TIME_OFFSET; - } else if (this.getAntePost().equals(AM) && (thisTimeHour == TIME_OFFSET)) { - thisTimeHour -= TIME_OFFSET; - } - LocalTime thisTimeLocalTime = LocalTime.of(thisTimeHour, Integer.valueOf(this.getMinute())); + LocalTime timeToCompare = time.getLocalTime(); + LocalTime thisTimeLocalTime = this.getLocalTime(); return thisTimeLocalTime.isAfter(timeToCompare); } @@ -1316,9 +1366,13 @@ public class TaskTime { final Matcher matcherFullArg = TASK_TIME_ARGS_FORMAT.matcher(time.trim()); final Matcher matcherHourOnly = TASK_TIME_HOUR_ONLY_FORMAT.matcher(time.trim()); if (matcherFullArg.matches()) { - this.taskTime = setTime(matcherFullArg.group("hour"), matcherFullArg.group("minute"), matcherFullArg.group("antePost")); + this.taskTime = setTime(matcherFullArg.group("hour"), + matcherFullArg.group("minute"), + matcherFullArg.group("antePost")); } else if (matcherHourOnly.matches()) { - this.taskTime = setTime(matcherHourOnly.group("hour"), ZERO_MINUTE, matcherHourOnly.group("antePost")); + this.taskTime = setTime(matcherHourOnly.group("hour"), + ZERO_MINUTE, + matcherHourOnly.group("antePost")); } else if (isValidNow(time)) { this.taskTime = getTimeNow().toString(); } else if (isValidNoon(time)) { @@ -1377,6 +1431,20 @@ public class TaskTime { return ""; } + public LocalTime getLocalTime() { + int timeHour = Integer.valueOf(this.getHour()); + if (this.getAntePost().equals(PM) && (timeHour != TIME_OFFSET)) { + timeHour += TIME_OFFSET; + } else if (this.getAntePost().equals(AM) && (timeHour == TIME_OFFSET)) { + timeHour -= TIME_OFFSET; + } + return LocalTime.of(timeHour, Integer.valueOf(this.getMinute())); + } + + public LocalDateTime toLocalDateTime(TaskDate date) { + return LocalDateTime.of(date.getLocalDate(), this.getLocalTime()); + } + @Override public String toString() { return taskTime; @@ -1402,6 +1470,7 @@ public class TaskTime { id.setText(displayedIndex + ". "); description.setText(task.getDescription().description); tags.setText(task.tagsString()); + recurringType.setText(task.getRecurringType().recurringType); taskStatus.setText(task.getTaskStatus().taskStatus); setDateTime(); @@ -1414,7 +1483,6 @@ public class TaskTime { endDate.setText(task.getEndDate().getDisplayDate()); startTime.setText(task.getStartTime().taskTime); endTime.setText(task.getEndTime().taskTime); - } private void setDateTimeVisibility() { @@ -1425,15 +1493,18 @@ public class TaskTime { endTime.setVisible(false); } + if (task.getRecurringType().recurringType.equals(RecurringType.NO_RECURRING)) { + recurringType.setVisible(false); + } } private void setCardPaneBackground() { if (task.getTaskPriority().taskPriority.equals(TaskPriority.HIGH_PRIORITY)) { - cardPane.setStyle(TaskPriority.HIGH_PRIORITY_BACKGROUND); + priorityColour.setStyle(TaskPriority.HIGH_PRIORITY_BACKGROUND); } else if (task.getTaskPriority().taskPriority.equals(TaskPriority.MEDIUM_PRIORITY)) { - cardPane.setStyle(TaskPriority.MEDIUM_PRIORITY_BACKGROUND); + priorityColour.setStyle(TaskPriority.MEDIUM_PRIORITY_BACKGROUND); } else if (task.getTaskPriority().taskPriority.equals(TaskPriority.LOW_PRIORITY)) { - cardPane.setStyle(TaskPriority.LOW_PRIORITY_BACKGROUND); + priorityColour.setStyle(TaskPriority.LOW_PRIORITY_BACKGROUND); } } ``` diff --git a/collated/main/A0139257Xreused.md b/collated/main/A0139257Xreused.md index 74cc608b5bd6..6a36730bc1d6 100644 --- a/collated/main/A0139257Xreused.md +++ b/collated/main/A0139257Xreused.md @@ -6,14 +6,28 @@ assert model != null; try { model.addTask(toAdd); - UndoCommand.addTaskToCommandHistory(toAdd); + HistoryManager.getInstance().addTask(toAdd); + jumpToNewTaskIndex(); return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); } catch (UniqueTaskList.DuplicateTaskException e) { - UndoCommand.deletePreviousCommand(); + HistoryManager.getInstance().deleteLatestCommand(); return new CommandResult(MESSAGE_DUPLICATE_TASK); } - + } + + private void jumpToNewTaskIndex() { + int indexOfNewTask = model.getFilteredTaskList().size()-1; + jumpToIndex(indexOfNewTask); } } ``` +###### \java\seedu\taskell\logic\commands\Command.java +``` java + /** + * Raises an event to jump to the given index + */ + protected void jumpToIndex(int index) { + EventsCenter.getInstance().post(new JumpToListRequestEvent(index)); + } +``` diff --git a/collated/main/A0142073R.md b/collated/main/A0142073R.md index 7dc0c2bf33e5..0f60ee7f172d 100644 --- a/collated/main/A0142073R.md +++ b/collated/main/A0142073R.md @@ -1,254 +1,108 @@ # A0142073R -###### \java\seedu\taskell\logic\commands\EditDescriptionCommand.java +###### \java\seedu\taskell\logic\commands\EditCommand.java ``` java + package seedu.taskell.logic.commands; import seedu.taskell.commons.core.Messages; import seedu.taskell.commons.core.UnmodifiableObservableList; import seedu.taskell.commons.exceptions.IllegalValueException; -import seedu.taskell.model.tag.Tag; -import seedu.taskell.model.tag.UniqueTagList; +import seedu.taskell.logic.commands.Command; +import seedu.taskell.logic.commands.CommandResult; +import seedu.taskell.logic.commands.UndoCommand; import seedu.taskell.model.task.Description; +import seedu.taskell.model.task.FloatingTask; import seedu.taskell.model.task.ReadOnlyTask; import seedu.taskell.model.task.Task; import seedu.taskell.model.task.TaskDate; import seedu.taskell.model.task.TaskPriority; import seedu.taskell.model.task.TaskTime; -import seedu.taskell.model.task.UniqueTaskList; +import seedu.taskell.model.task.UniqueTaskList.DuplicateTaskException; import seedu.taskell.model.task.UniqueTaskList.TaskNotFoundException; /** - * Edits a task identified using it's last displayed index from the task manager. + * Edits a task identified using it's last displayed index from the task + * manager. Supports to edit different parameters of a task including description, + * time, date and priority of a task. */ -public class EditDescriptionCommand extends Command { - public static final String COMMAND_WORD_1 = "edit-desc"; - public static final String COMMAND_WORD_2 = "edit-name"; +public class EditCommand extends Command { + public static final String COMMAND_WORD = "edit"; - public static final String MESSAGE_USAGE = COMMAND_WORD_1 - + "/"+ COMMAND_WORD_2 - + ": Edits the description task identified by the index number used in the last task listing.\n" - + "Parameters: INDEX (must be a positive integer) NEW_DESCRIPTION\n" - + "Example: " + COMMAND_WORD_1 + " 1 buy cake\n" - + "Example: " + COMMAND_WORD_2 + " 2 do 2103t\n"; + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Edits the different parts of a task identified by the index number used in the last task listing.\n" + + "Parameters: INDEX (must be a positive integer) RESPECTIVE TASK PARAMETERS\n" + "Example: " + COMMAND_WORD + + " 1 desc: buy cake st: 7am et: 8am sd: 11-12-2016 ed: 12-12-2016 p: 2\n"; public static final String MESSAGE_EDIT_TASK_SUCCESS = "Original Task: %1$s \n\nUpdated Task: %2$s"; - - public final int targetIndex; - public final Description description; - - public EditDescriptionCommand(int targetIndex, String newDescription) throws IllegalValueException { + public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task manager"; + public static final String TASK_NOT_FOUND = "The target task is missing"; + public static final String MESSAGE_TIME_CONSTRAINTS = "Start time must be before end time"; + public static final String MESSAGE_DATE_CONSTRAINTS = "Start date must be before end date"; + + private final int targetIndex; + + private Description description; + private TaskDate startDate; + private TaskDate endDate; + private TaskTime startTime; + private TaskTime endTime; + private TaskPriority taskPriority; + + private boolean hasChangedDescription; + private boolean hasChangedStartDate; + private boolean hasChangedEndDate; + private boolean hasChangedStartTime; + private boolean hasChangedEndTime; + private boolean hasChangedPriority; + + public EditCommand(int targetIndex, Description newDescription, boolean hasChangedDescription, + TaskDate newStartDate, boolean hasChangedStartDate, TaskDate newEndDate, boolean hasChangedEndDate, + TaskTime newStartTime, boolean hasChangedStartTime, TaskTime newEndTime, boolean hasChangedEndTime, + TaskPriority newPriority, boolean hasChangedPriority) throws IllegalValueException { + this.targetIndex = targetIndex; - this.description = new Description(newDescription); + + description = newDescription; + this.hasChangedDescription = hasChangedDescription; + + startTime = newStartTime; + this.hasChangedStartTime = hasChangedStartTime; + + endTime = newEndTime; + this.hasChangedEndTime = hasChangedEndTime; + + startDate = newStartDate; + this.hasChangedStartDate = hasChangedStartDate; + + endDate = newEndDate; + this.hasChangedEndDate = hasChangedEndDate; + + taskPriority = newPriority; + this.hasChangedPriority = hasChangedPriority; } - - @Override - public CommandResult execute() { - - UnmodifiableObservableList lastShownList = model.getFilteredTaskList(); - - if (lastShownList.size() < targetIndex) { - indicateAttemptToExecuteIncorrectCommand(); - return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); - } - ReadOnlyTask taskToEdit = lastShownList.get(targetIndex - 1); + public void getEditInformation(ReadOnlyTask taskToEdit) { - Task newTask = new Task(description,taskToEdit.getTaskType(),taskToEdit.getStartDate(), taskToEdit.getEndDate(), taskToEdit.getStartTime(),taskToEdit.getEndTime(), - taskToEdit.getTaskPriority(),taskToEdit.getTaskStatus(), taskToEdit.getTags() - ); - try { - model.editTask(taskToEdit,newTask); - UndoCommand.addTaskToCommandHistory(newTask); - UndoCommand.addOldTaskToCommandHistory((Task) taskToEdit); - } catch (TaskNotFoundException pnfe) { - assert false : "The target task cannot be missing"; - } catch (UniqueTaskList.DuplicateTaskException e) { - UndoCommand.deletePreviousCommand(); - return new CommandResult(AddCommand.MESSAGE_DUPLICATE_TASK); + if (hasChangedDescription == false) { + description = taskToEdit.getDescription(); } - - return new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToEdit, newTask)); - } -} -``` -###### \java\seedu\taskell\logic\commands\EditEndDateCommand.java -``` java -package seedu.taskell.logic.commands; - -import seedu.taskell.commons.core.Messages; -import seedu.taskell.commons.core.UnmodifiableObservableList; -import seedu.taskell.commons.exceptions.IllegalValueException; -import seedu.taskell.model.tag.Tag; -import seedu.taskell.model.tag.UniqueTagList; -import seedu.taskell.model.task.ReadOnlyTask; -import seedu.taskell.model.task.Task; -import seedu.taskell.model.task.TaskDate; -import seedu.taskell.model.task.TaskPriority; -import seedu.taskell.model.task.TaskTime; -import seedu.taskell.model.task.UniqueTaskList; -import seedu.taskell.model.task.UniqueTaskList.TaskNotFoundException; - -/** - * Edits a task EndDate identified using it's last displayed index from the task - * manager. - */ -public class EditEndDateCommand extends Command { - public static final String COMMAND_WORD = "edit-endDate"; - - public static final String MESSAGE_USAGE = COMMAND_WORD - + ": Edits the EndDate of a task identified by the index number used in the last task listing.\n" - + "Parameters: INDEX (must be a positive integer) NEW_DATE\n" + "Example: " + COMMAND_WORD + " 1 8-8-2016 "; - - public static final String MESSAGE_EDIT_TASK_SUCCESS = "Original Task: %1$s \n\nUpdatedTask: %2$s"; - - public final int targetIndex; - public final TaskDate endDate; - - public EditEndDateCommand(int targetIndex, String EndDate) throws IllegalValueException { - this.targetIndex = targetIndex; - this.endDate = new TaskDate(EndDate); - } - - @Override - public CommandResult execute() { - - UnmodifiableObservableList lastShownList = model.getFilteredTaskList(); - - if (lastShownList.size() < targetIndex) { - indicateAttemptToExecuteIncorrectCommand(); - return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + if (hasChangedStartTime == false) { + startTime = taskToEdit.getStartTime(); } - - ReadOnlyTask taskToEdit = lastShownList.get(targetIndex - 1); - if (taskToEdit.getTaskType().equals("FLOATING")) { - return new CommandResult("Unable to edit date of floating task"); + if (hasChangedEndTime == false) { + endTime = taskToEdit.getEndTime(); } - Task newTask = new Task(taskToEdit.getDescription(), taskToEdit.getTaskType(), taskToEdit.getStartDate(), - - endDate, taskToEdit.getStartTime(), taskToEdit.getEndTime(), taskToEdit.getTaskPriority(), taskToEdit.getTaskStatus(), - - taskToEdit.getTags()); - try { - model.editTask(taskToEdit, newTask); - } catch (TaskNotFoundException pnfe) { - assert false : "The target task cannot be missing"; - } catch (UniqueTaskList.DuplicateTaskException e) { - return new CommandResult(AddCommand.MESSAGE_DUPLICATE_TASK); + if (hasChangedStartDate == false) { + startDate = taskToEdit.getStartDate(); } - - return new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToEdit, newTask)); - } -} -``` -###### \java\seedu\taskell\logic\commands\EditEndTimeCommand.java -``` java -package seedu.taskell.logic.commands; - -import seedu.taskell.commons.core.Messages; -import seedu.taskell.commons.core.UnmodifiableObservableList; -import seedu.taskell.commons.exceptions.IllegalValueException; -import seedu.taskell.model.tag.Tag; -import seedu.taskell.model.tag.UniqueTagList; -import seedu.taskell.model.task.ReadOnlyTask; -import seedu.taskell.model.task.Task; -import seedu.taskell.model.task.TaskDate; -import seedu.taskell.model.task.TaskPriority; -import seedu.taskell.model.task.TaskTime; -import seedu.taskell.model.task.UniqueTaskList; -import seedu.taskell.model.task.UniqueTaskList.TaskNotFoundException; - -/** - * Edits a task end time identified using it's last displayed index from the task manager. - */ -public class EditEndTimeCommand extends Command { - public static final String COMMAND_WORD = "edit-endTime"; - - public static final String MESSAGE_USAGE = COMMAND_WORD - + ": Edits the end time of a task identified by the index number used in the last task listing.\n" - + "Parameters: INDEX (must be a positive integer) NEW_END_TIME\n" - + "Example: " + COMMAND_WORD + " 1 9pm "; - - public static final String MESSAGE_EDIT_TASK_SUCCESS = "Original Task: %1$s \n\nUpdatedTask: %2$s"; - - public final int targetIndex; - public final TaskTime endTime; - - public EditEndTimeCommand(int targetIndex, String newTime) throws IllegalValueException { - this.targetIndex = targetIndex; - this.endTime = new TaskTime(newTime); - } - - @Override - public CommandResult execute() { - - UnmodifiableObservableList lastShownList = model.getFilteredTaskList(); - - if (lastShownList.size() < targetIndex) { - indicateAttemptToExecuteIncorrectCommand(); - return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); - } - - ReadOnlyTask taskToEdit = lastShownList.get(targetIndex - 1); - if (taskToEdit.getTaskType().equals("FLOATING")) { - return new CommandResult("Unable to edit time of floating task"); + if (hasChangedEndDate == false) { + endDate = taskToEdit.getEndDate(); } - Task newTask = new Task(taskToEdit.getDescription(),taskToEdit.getTaskType(),taskToEdit.getStartDate(), taskToEdit.getEndDate(), taskToEdit.getStartTime(),endTime, - taskToEdit.getTaskPriority(),taskToEdit.getTaskStatus(), taskToEdit.getTags() - ); - try { - model.editTask(taskToEdit,newTask); - UndoCommand.addTaskToCommandHistory(newTask); - UndoCommand.addOldTaskToCommandHistory((Task) taskToEdit); - } catch (TaskNotFoundException pnfe) { - assert false : "The target task cannot be missing"; - } catch (UniqueTaskList.DuplicateTaskException e) { - UndoCommand.deletePreviousCommand(); - return new CommandResult(AddCommand.MESSAGE_DUPLICATE_TASK); + if (hasChangedPriority == false) { + taskPriority = taskToEdit.getTaskPriority(); } - - return new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToEdit, newTask)); } -} -``` -###### \java\seedu\taskell\logic\commands\EditPriorityCommand.java -``` java -package seedu.taskell.logic.commands; - -import seedu.taskell.commons.core.Messages; -import seedu.taskell.commons.core.UnmodifiableObservableList; -import seedu.taskell.commons.exceptions.IllegalValueException; -import seedu.taskell.model.tag.Tag; -import seedu.taskell.model.tag.UniqueTagList; -import seedu.taskell.model.task.Description; -import seedu.taskell.model.task.ReadOnlyTask; -import seedu.taskell.model.task.Task; -import seedu.taskell.model.task.TaskDate; -import seedu.taskell.model.task.TaskPriority; -import seedu.taskell.model.task.TaskTime; -import seedu.taskell.model.task.UniqueTaskList; -import seedu.taskell.model.task.UniqueTaskList.TaskNotFoundException; - -/** - * Edits the priority of a task identified using it's last displayed index from the task manager. - */ -public class EditPriorityCommand extends Command { - public static final String COMMAND_WORD = "edit-priority"; - - public static final String MESSAGE_USAGE = COMMAND_WORD - + ": Edits the priority of a task identified by the index number used in the last task listing.\n" - + "Parameters: INDEX (must be a positive integer) NEW_PRIORITY(must be between 0 to 3)\n" - + "Example: " + COMMAND_WORD + " 1 3 "; - - public static final String MESSAGE_EDIT_TASK_SUCCESS = "Original Task: %1$s \n\nUpdatedTask: %2$s"; - public final int targetIndex; - public final TaskPriority taskPriority; - - public EditPriorityCommand(int targetIndex, String taskPriority) throws IllegalValueException { - this.targetIndex = targetIndex; - this.taskPriority = new TaskPriority(taskPriority); - } - @Override public CommandResult execute() { @@ -260,172 +114,59 @@ public class EditPriorityCommand extends Command { } ReadOnlyTask taskToEdit = lastShownList.get(targetIndex - 1); - Task newTask = new Task(taskToEdit.getDescription(),taskToEdit.getTaskType(),taskToEdit.getStartDate(), taskToEdit.getEndDate(), taskToEdit.getStartTime(),taskToEdit.getEndTime(), - taskPriority,taskToEdit.getTaskStatus(), taskToEdit.getTags() - ); - try { - model.editTask(taskToEdit,newTask); - UndoCommand.addTaskToCommandHistory(newTask); - UndoCommand.addOldTaskToCommandHistory((Task) taskToEdit); - } catch (TaskNotFoundException pnfe) { - assert false : "The target task cannot be missing"; - } catch (UniqueTaskList.DuplicateTaskException e) { - UndoCommand.deletePreviousCommand(); - return new CommandResult(AddCommand.MESSAGE_DUPLICATE_TASK); - } + getEditInformation(taskToEdit); - return new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToEdit, newTask)); - } -} -``` -###### \java\seedu\taskell\logic\commands\EditStartDateCommand.java -``` java -package seedu.taskell.logic.commands; - -import seedu.taskell.commons.core.Messages; -import seedu.taskell.commons.core.UnmodifiableObservableList; -import seedu.taskell.commons.exceptions.IllegalValueException; -import seedu.taskell.model.tag.Tag; -import seedu.taskell.model.tag.UniqueTagList; -import seedu.taskell.model.task.ReadOnlyTask; -import seedu.taskell.model.task.Task; -import seedu.taskell.model.task.TaskDate; -import seedu.taskell.model.task.TaskPriority; -import seedu.taskell.model.task.TaskTime; -import seedu.taskell.model.task.UniqueTaskList; -import seedu.taskell.model.task.UniqueTaskList.TaskNotFoundException; - -/** - * Edits a task startDate identified using it's last displayed index from the task - * manager. - */ -public class EditStartDateCommand extends Command { - public static final String COMMAND_WORD = "edit-startDate"; - - public static final String MESSAGE_USAGE = COMMAND_WORD - + ": Edits the startDate of a task identified by the index number used in the last task listing.\n" - + "Parameters: INDEX (must be a positive integer) NEW_DATE\n" + "Example: " + COMMAND_WORD + " 1 8-8-2016 "; - - public static final String MESSAGE_EDIT_TASK_SUCCESS = "Original Task: %1$s \n\nUpdatedTask: %2$s"; - - public final int targetIndex; - public final TaskDate startDate; - - public EditStartDateCommand(int targetIndex, String startDate) throws IllegalValueException { - this.targetIndex = targetIndex; - this.startDate = new TaskDate(startDate); - } - - @Override - public CommandResult execute() { - - UnmodifiableObservableList lastShownList = model.getFilteredTaskList(); - - if (lastShownList.size() < targetIndex) { - indicateAttemptToExecuteIncorrectCommand(); - return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + if (taskToEdit.getTaskType().equals(Task.FLOATING_TASK) && (hasChangedStartTime == true + || hasChangedEndTime == true || hasChangedStartDate == true || hasChangedEndDate == true)) { + return new CommandResult(FloatingTask.EDIT_FLOATING_NOT_ALLOWED); } - ReadOnlyTask taskToEdit = lastShownList.get(targetIndex - 1); - if (taskToEdit.getTaskType().equals("FLOATING")) { - return new CommandResult("Unable to edit date of floating task"); + TaskDate today = TaskDate.getTodayDate(); + TaskTime currentTime = TaskTime.getTimeNow(); + if (taskToEdit.getTaskType().equals(Task.EVENT_TASK)) { + if (startDate.isBefore(today) || endDate.isBefore(today)) { + return new CommandResult(MESSAGE_DATE_CONSTRAINTS); + } else if (startDate.isAfter(endDate)) { + return new CommandResult(MESSAGE_DATE_CONSTRAINTS); + } else if (startDate.equals(today) && startTime.isBefore(currentTime)) { + return new CommandResult(MESSAGE_TIME_CONSTRAINTS); + } else if (startDate.equals(endDate) && startTime.isAfter(endTime)) { + return new CommandResult(MESSAGE_TIME_CONSTRAINTS); + } } - Task newTask = new Task(taskToEdit.getDescription(), taskToEdit.getTaskType(), startDate, taskToEdit.getEndDate(), - taskToEdit.getStartTime(), taskToEdit.getEndTime(), taskToEdit.getTaskPriority(), taskToEdit.getTaskStatus(), taskToEdit.getTags()); + + Task newTask = new Task(description, taskToEdit.getTaskType(), startDate, endDate, startTime, endTime, + taskPriority, taskToEdit.getRecurringType(), taskToEdit.getTaskStatus(), taskToEdit.getTags()); + try { model.editTask(taskToEdit, newTask); - UndoCommand.addTaskToCommandHistory(newTask); - UndoCommand.addOldTaskToCommandHistory((Task) taskToEdit); + jumpToUpdatedTaskIndex(); + } catch (DuplicateTaskException pnfe) { + return new CommandResult(MESSAGE_DUPLICATE_TASK); } catch (TaskNotFoundException pnfe) { - assert false : "The target task cannot be missing"; - } catch (UniqueTaskList.DuplicateTaskException e) { - UndoCommand.deletePreviousCommand(); - return new CommandResult(AddCommand.MESSAGE_DUPLICATE_TASK); + return new CommandResult(TASK_NOT_FOUND); } return new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToEdit, newTask)); } -} -``` -###### \java\seedu\taskell\logic\commands\EditStartTimeCommand.java -``` java -package seedu.taskell.logic.commands; - -import seedu.taskell.commons.core.Messages; -import seedu.taskell.commons.core.UnmodifiableObservableList; -import seedu.taskell.commons.exceptions.IllegalValueException; -import seedu.taskell.model.tag.Tag; -import seedu.taskell.model.tag.UniqueTagList; -import seedu.taskell.model.task.ReadOnlyTask; -import seedu.taskell.model.task.Task; -import seedu.taskell.model.task.TaskDate; -import seedu.taskell.model.task.TaskPriority; -import seedu.taskell.model.task.TaskTime; -import seedu.taskell.model.task.UniqueTaskList; -import seedu.taskell.model.task.UniqueTaskList.TaskNotFoundException; - -/** - * Edits a task start time identified using it's last displayed index from the task manager. - */ -public class EditStartTimeCommand extends Command { - public static final String COMMAND_WORD = "edit-startTime"; - - public static final String MESSAGE_USAGE = COMMAND_WORD - + ": Edits the start time of a task identified by the index number used in the last task listing.\n" - + "Parameters: INDEX (must be a positive integer) NEW_START_TIME\n" - + "Example: " + COMMAND_WORD + " 1 2pm "; - - public static final String MESSAGE_EDIT_TASK_SUCCESS = "Original Task: %1$s \n\nUpdatedTask: %2$s"; - - public final int targetIndex; - public final TaskTime startTime; - - public EditStartTimeCommand(int targetIndex, String newTime) throws IllegalValueException { - this.targetIndex = targetIndex; - this.startTime = new TaskTime(newTime); - } - @Override - public CommandResult execute() { - - UnmodifiableObservableList lastShownList = model.getFilteredTaskList(); - - if (lastShownList.size() < targetIndex) { - indicateAttemptToExecuteIncorrectCommand(); - return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); - } - - ReadOnlyTask taskToEdit = lastShownList.get(targetIndex - 1); - - if (taskToEdit.getTaskType().equals("FLOATING")) { - return new CommandResult("Unable to edit time of floating task"); - } - Task newTask = new Task(taskToEdit.getDescription(),taskToEdit.getTaskType(),taskToEdit.getStartDate(), taskToEdit.getEndDate(), startTime,taskToEdit.getEndTime(), - taskToEdit.getTaskPriority(),taskToEdit.getTaskStatus(), taskToEdit.getTags() - ); - try { - model.editTask(taskToEdit,newTask); - UndoCommand.addTaskToCommandHistory(newTask); - UndoCommand.addOldTaskToCommandHistory((Task) taskToEdit); - } catch (TaskNotFoundException pnfe) { - assert false : "The target task cannot be missing"; - } catch (UniqueTaskList.DuplicateTaskException e) { - UndoCommand.deletePreviousCommand(); - return new CommandResult(AddCommand.MESSAGE_DUPLICATE_TASK); - } - - return new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToEdit, newTask)); + private void jumpToUpdatedTaskIndex() { + jumpToIndex(targetIndex-1); //index start from 0 } } + ``` -###### \java\seedu\taskell\logic\commands\ListDateCommand.java +###### \java\seedu\taskell\logic\commands\list\ListDateCommand.java ``` java -package seedu.taskell.logic.commands; + +package seedu.taskell.logic.commands.list; import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import seedu.taskell.logic.commands.Command; +import seedu.taskell.logic.commands.CommandResult; import seedu.taskell.model.task.Task; public class ListDateCommand extends Command { @@ -435,7 +176,7 @@ public class ListDateCommand extends Command { public static final String MESSAGE_SUCCESS = "Listed all tasks on a given date"; public static final String MESSAGE_USAGE = COMMAND_WORD - + ": Lists tasks on a specific date.\n" + + ": Lists tasks on 1 specific date only.\n" + "Parameters: DATE (must be a positive integer)\n" + "Example: " + COMMAND_WORD + " 8-8-2016 "; private Set keywordSet; @@ -451,14 +192,17 @@ public class ListDateCommand extends Command { } } ``` -###### \java\seedu\taskell\logic\commands\ListPriorityCommand.java +###### \java\seedu\taskell\logic\commands\list\ListPriorityCommand.java ``` java -package seedu.taskell.logic.commands; + +package seedu.taskell.logic.commands.list; import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import seedu.taskell.logic.commands.Command; +import seedu.taskell.logic.commands.CommandResult; import seedu.taskell.model.task.TaskPriority; public class ListPriorityCommand extends Command { @@ -467,299 +211,282 @@ public class ListPriorityCommand extends Command { public static final String MESSAGE_SUCCESS = "Listed all completed tasks in descending priority"; - public static final String MESSAGE_USAGE = COMMAND_WORD - + ": List the task with the specified priority. " - + "Parameters: INDEX (must be between 0 and 3 inclusive).\n" - + "Example: " + COMMAND_WORD + " 1"; + public static final String MESSAGE_USAGE = COMMAND_WORD + ": List the task with the specified priority. " + + "Parameters: INDEX (must be between 0 and 3 inclusive).\n" + "Example: " + COMMAND_WORD + " 1"; private Set mostImportant = new HashSet<>(Arrays.asList(TaskPriority.HIGH_PRIORITY)); private Set important = new HashSet<>(Arrays.asList(TaskPriority.MEDIUM_PRIORITY)); private Set lessImportant = new HashSet<>(Arrays.asList(TaskPriority.LOW_PRIORITY)); private Set leastImportant = new HashSet<>(Arrays.asList(TaskPriority.NO_PRIORITY)); - + private Set keyword; + public ListPriorityCommand(String priority) { - if(priority.equals(TaskPriority.HIGH_PRIORITY)) + + if (priority.equals(TaskPriority.HIGH_PRIORITY)) { keyword = mostImportant; - else if(priority.equals(TaskPriority.MEDIUM_PRIORITY)) + } else if (priority.equals(TaskPriority.MEDIUM_PRIORITY)) { keyword = important; - else if(priority.equals(TaskPriority.LOW_PRIORITY)) + } else if (priority.equals(TaskPriority.LOW_PRIORITY)) { keyword = lessImportant; - else + } else { keyword = leastImportant; + } + } @Override public CommandResult execute() { + model.updateFilteredTaskListPriority(keyword); return new CommandResult(getMessageForTaskListShownSummary(model.getFilteredTaskList().size())); + } } + ``` ###### \java\seedu\taskell\logic\parser\Parser.java ``` java + private Command prepareListDate(String arguments) { + if (arguments.isEmpty()) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListDateCommand.MESSAGE_USAGE)); } + StringTokenizer st = new StringTokenizer(arguments.trim(), " "); String date = st.nextToken(); + + if (st.hasMoreTokens()) { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListDateCommand.MESSAGE_USAGE)); + } if (!TaskDate.isValidDate(date)) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListDateCommand.MESSAGE_USAGE)); } - return new ListDateCommand(date); } - private Command prepareListPriority(String args) { + if (args.isEmpty()) { return new IncorrectCommand( String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListPriorityCommand.MESSAGE_USAGE)); } + StringTokenizer st = new StringTokenizer(args.trim(), " "); String intValue = st.nextToken(); + if (st.hasMoreTokens()) { return new IncorrectCommand( String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListPriorityCommand.MESSAGE_USAGE)); } if (!isInt(intValue)) { return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditEndDateCommand.MESSAGE_USAGE)); + String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListPriorityCommand.MESSAGE_USAGE)); } + int targetIdx = Integer.valueOf(intValue); - if (targetIdx < 0 || targetIdx > 3) { + if (targetIdx < Integer.valueOf(TaskPriority.DEFAULT_PRIORITY) || targetIdx > Integer.valueOf(TaskPriority.HIGH_PRIORITY)) { return new IncorrectCommand( - String.format(MESSAGE_INVALID_TASK_DISPLAYED_INDEX, ListPriorityCommand.MESSAGE_USAGE)); + String.format(TaskPriority.MESSAGE_TASK_PRIORITY_CONSTRAINTS, ListPriorityCommand.MESSAGE_USAGE)); } else return new ListPriorityCommand(intValue); + } /** - * Parses arguments in the context of the edit task startDate command. - * - * @param args - * full command args string - * @return the prepared command - */ - private Command prepareEditStartDate(String args) { - String arguments = ""; - if (args.isEmpty()) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditStartDateCommand.MESSAGE_USAGE)); - } - StringTokenizer st = new StringTokenizer(args.trim(), " "); - String intValue = st.nextToken(); - if (!isInt(intValue)) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_TASK_DISPLAYED_INDEX, EditEndDateCommand.MESSAGE_USAGE)); - } - int targetIdx = Integer.valueOf(intValue); - arguments = st.nextToken(); - if (st.hasMoreTokens()) { - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditStartDateCommand.MESSAGE_USAGE)); - } - if (!TaskDate.isValidDate(arguments)) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditStartDateCommand.MESSAGE_USAGE)); - } - - try { - return new EditStartDateCommand(targetIdx, arguments); - } catch (IllegalValueException ive) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand(ive.getMessage()); - } - } - - - /** - * Parses arguments in the context of the edit task description command. - * - * @param args - * full command args string - * @return the prepared command - */ - private Command prepareEditDescription(String args) { - String arguments = ""; - if (args.isEmpty()) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditDescriptionCommand.MESSAGE_USAGE)); - } - StringTokenizer st = new StringTokenizer(args.trim(), " "); - String intValue = st.nextToken(); - if (!isInt(intValue)) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_TASK_DISPLAYED_INDEX, EditDescriptionCommand.MESSAGE_USAGE)); - } - int targetIdx = Integer.valueOf(intValue); - while (st.hasMoreTokens()) { - arguments += st.nextToken() + " "; - } - arguments = arguments.trim(); - try { - return new EditDescriptionCommand(targetIdx, arguments); - } catch (IllegalValueException ive) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand(ive.getMessage()); - } - } - - - /** - * Parses arguments in the context of the edit start time command. + * Parses arguments in the context of the edit command. * * @param args * full command args string * @return the prepared command */ - private Command prepareEditStartTime(String args) { - String arguments = ""; - if (args.isEmpty()) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditStartTimeCommand.MESSAGE_USAGE)); - } - StringTokenizer st = new StringTokenizer(args.trim(), " "); - String intValue = st.nextToken(); - if (!isInt(intValue)) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_TASK_DISPLAYED_INDEX, EditStartTimeCommand.MESSAGE_USAGE)); - } - - int targetIdx = Integer.valueOf(intValue); - arguments = st.nextToken(); - if (st.hasMoreTokens()) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditStartTimeCommand.MESSAGE_USAGE)); - } - - if (!TaskTime.isValidTime(arguments)) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditStartTimeCommand.MESSAGE_USAGE)); - } - - try { - return new EditStartTimeCommand(targetIdx, arguments); - } catch (IllegalValueException ive) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand(ive.getMessage()); - } - } + private Command prepareEdit(String args) { + String description = "default"; + String startDate = TaskDate.DEFAULT_DATE; + String endDate = TaskDate.DEFAULT_DATE; + String startTime = TaskTime.DEFAULT_START_TIME; + String endTime = TaskTime.DEFAULT_END_TIME; + String taskPriority = TaskPriority.DEFAULT_PRIORITY; - /** - * Parses arguments in the context of the edit task endDate command. - * - * @param args - * full command args string - * @return the prepared command - */ - private Command prepareEditEndDate(String args) { - String arguments = ""; if (args.isEmpty()) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditEndDateCommand.MESSAGE_USAGE)); - } - StringTokenizer st = new StringTokenizer(args.trim(), " "); - String intValue = st.nextToken(); - if (!isInt(intValue)) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditEndDateCommand.MESSAGE_USAGE)); - } - int targetIdx = Integer.valueOf(intValue); - arguments = st.nextToken(); - if (st.hasMoreTokens() || !TaskDate.isValidDate(arguments)) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditEndDateCommand.MESSAGE_USAGE)); - } - - try { - return new EditEndDateCommand(targetIdx, arguments); - } catch (IllegalValueException ive) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand(ive.getMessage()); - } - } - - - /** - * Parses arguments in the context of the edit task end time command. - * - * @param args - * full command args string - * @return the prepared command - */ - private Command prepareEditEndTime(String args) { - String arguments = ""; - if (args.isEmpty()) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditEndTimeCommand.MESSAGE_USAGE)); + // UndoCommand.deletePreviousCommand(); + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); } + StringTokenizer st = new StringTokenizer(args.trim(), " "); String intValue = st.nextToken(); if (!isInt(intValue)) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditEndTimeCommand.MESSAGE_USAGE)); + return new IncorrectCommand(String.format(MESSAGE_INVALID_TASK_DISPLAYED_INDEX, EditCommand.MESSAGE_USAGE)); } + int targetIdx = Integer.valueOf(intValue); - arguments = st.nextToken(); - if (st.hasMoreTokens() || !TaskTime.isValidTime(arguments)) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditEndTimeCommand.MESSAGE_USAGE)); - } - - try { - return new EditEndTimeCommand(targetIdx, arguments); - } catch (IllegalValueException ive) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand(ive.getMessage()); - } - } - - - /** - * Parses arguments in the context of the edit task priority command. - * - * @param args - * full command args string - * @return the prepared command - */ - private Command prepareEditPriority(String args) { - String arguments = ""; - if (args.isEmpty()) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditPriorityCommand.MESSAGE_USAGE)); - } - StringTokenizer st = new StringTokenizer(args.trim(), " "); - int targetIdx = Integer.valueOf(st.nextToken()); - arguments = st.nextToken(); - if (st.hasMoreTokens() || !TaskPriority.isValidPriority(arguments)) { - UndoCommand.deletePreviousCommand(); - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditPriorityCommand.MESSAGE_USAGE)); + hasChangedDescription = false; + hasChangedStartDate = false; + hasChangedEndDate = false; + hasChangedStartTime = false; + hasChangedEndTime = false; + hasChangedPriority = false; + boolean lastChar = false; + + if (!st.hasMoreTokens()) { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); } + while (st.hasMoreTokens()) { + String parts = st.nextToken(); + // System.out.println("Parts is " + parts); + if (parts.equals(DESC)) { + if (hasChangedDescription == true) { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); + } + // System.out.println("I am inside desc"); + String desc = " "; + while (!(parts.equals(ST) || parts.equals(ET) || parts.equals(SD) + || parts.equals("ed") | parts.equals(P)) && st.hasMoreTokens()) { + desc += (parts + " "); + parts = st.nextToken(); + hasChangedDescription = true; + } + if (!(parts.equals(ST) || parts.equals(ET) || parts.equals(SD) + || parts.equals("ed") | parts.equals(P))) { + // System.out.println("I am here to add the last is + // "+parts); + desc += parts; + lastChar = true; + } + desc = desc.trim(); + if (Description.isValidDescription(desc)) { + System.out.println("The new desc is valid"); + description = desc.substring(5); + hasChangedDescription = true; + } + // System.out.println("Description End: " + desc); + } + if (parts.equals(ST)) { + if (hasChangedStartTime == true) { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); + } + // System.out.println("I am inside start time"); + if (st.hasMoreTokens()) { + String startT = st.nextToken(); + if (TaskTime.isValidTime(startT)) { + startTime = startT.trim(); + hasChangedStartTime = true; + } else { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, TaskTime.MESSAGE_TASK_TIME_CONSTRAINTS)); + } + } else { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); + } + // System.out.println("Start time is " + startTime); + } + if (parts.equals(ET)) { + if (hasChangedEndTime == true) { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); + } + if (st.hasMoreTokens()) { + String endT = st.nextToken(); + if (TaskTime.isValidTime(endT)) { + endTime = endT.trim(); + hasChangedEndTime = true; + } else { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, TaskTime.MESSAGE_TASK_TIME_CONSTRAINTS)); + } + } else { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); + } + // System.out.println("End time is " + endTime); + } + if (parts.equals(SD)) { + if (hasChangedStartDate == true) { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); + } + if (st.hasMoreTokens()) { + String startD = st.nextToken(); + if (TaskDate.isValidDate(startD)) { + startDate = startD.trim(); + hasChangedStartDate = true; + } else { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, TaskDate.MESSAGE_TASK_DATE_CONSTRAINTS)); + } + } else { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); + } + // System.out.println("Start Date is " + startDate); + } + if (parts.equals(ED)) { + if (hasChangedEndDate == true) { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); + } + if (st.hasMoreTokens()) { + String endD = st.nextToken(); + if (TaskDate.isValidDate(endD)) { + endDate = endD.trim(); + hasChangedEndDate = true; + } else { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, TaskDate.MESSAGE_TASK_DATE_CONSTRAINTS)); + } + } else { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); + } + // System.out.println("End Date is " + endDate); + } + if (parts.equals(P)) { + if (hasChangedPriority == true) { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); + } + if (st.hasMoreTokens()) { + String p = st.nextToken(); + if (TaskPriority.isValidPriority(p)) { + taskPriority = p.trim(); + hasChangedPriority = true; + } else { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + TaskPriority.MESSAGE_TASK_PRIORITY_CONSTRAINTS)); + } + } else { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); + } + // System.out.println("Priority is " + taskPriority); + } + if (!(parts.equals(DESC) || parts.equals(ST) || parts.equals(ET) || parts.equals(SD) || parts.equals(ED) + || parts.equals(P)) && lastChar == false) { + // System.out.println("I am here as incrct because of parts + // "+parts); + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE)); + } + + } + // System.out + // .println("Desc: " + hasChangedDescription + " st: " + + // hasChangedStartTime + " et: " + hasChangedEndTime + // + " sd: " + hasChangedStartDate + " ed: " + hasChangedEndDate + " p: + // " + hasChangedPriority); try { - return new EditPriorityCommand(targetIdx, arguments); + // System.out.println("I am here to exectue edit command"); + return new EditCommand(targetIdx, new Description(description), hasChangedDescription, + new TaskDate(startDate), hasChangedStartDate, new TaskDate(endDate), hasChangedEndDate, + new TaskTime(startTime), hasChangedStartTime, new TaskTime(endTime), hasChangedEndTime, + new TaskPriority(taskPriority), hasChangedPriority); } catch (IllegalValueException ive) { - UndoCommand.deletePreviousCommand(); return new IncorrectCommand(ive.getMessage()); } + } ``` diff --git a/collated/main/A0142130A.md b/collated/main/A0142130A.md index 10c24c4092bb..9be6d154e0d1 100644 --- a/collated/main/A0142130A.md +++ b/collated/main/A0142130A.md @@ -6,6 +6,9 @@ package seedu.taskell.commons.events.storage; import seedu.taskell.commons.core.Config; import seedu.taskell.commons.events.BaseEvent; +/** + * Indicates storage location has changed. + */ public class StorageLocationChangedEvent extends BaseEvent { private Config config; @@ -23,6 +26,24 @@ public class StorageLocationChangedEvent extends BaseEvent { return this.getClass().getSimpleName(); } +} +``` +###### \java\seedu\taskell\commons\events\ui\ClearCommandInputEvent.java +``` java +package seedu.taskell.commons.events.ui; + +import seedu.taskell.commons.events.BaseEvent; + +/** indicates ClearCommand is being executed + * */ + +public class ClearCommandInputEvent extends BaseEvent { + + @Override + public String toString() { + return this.getClass().getSimpleName(); + } + } ``` ###### \java\seedu\taskell\commons\events\ui\DisplayCalendarViewEvent.java @@ -69,6 +90,99 @@ public class DisplayListChangedEvent extends BaseEvent { return list; } +} +``` +###### \java\seedu\taskell\commons\events\undo\ExecutedIncorrectCommandEvent.java +``` java +package seedu.taskell.commons.events.undo; + +import seedu.taskell.commons.events.BaseEvent; + +/** Indicates a Command has been entered incorrectly, to feedback to History + * NOTE: this is different from IncorrectCommandAttemptedEvent (which is meant for UI) + */ + +public class ExecutedIncorrectCommandEvent extends BaseEvent { + + private boolean isUndoableCommand; + + public ExecutedIncorrectCommandEvent(boolean isUndoableCommand) { + this.isUndoableCommand = isUndoableCommand; + } + + public boolean isUndoableCommand() { + return isUndoableCommand; + } + + @Override + public String toString() { + return this.getClass().getSimpleName(); + } +} +``` +###### \java\seedu\taskell\logic\commands\ClearCommand.java +``` java +package seedu.taskell.logic.commands; + +import seedu.taskell.commons.core.EventsCenter; +import seedu.taskell.commons.events.ui.ClearCommandInputEvent; +import seedu.taskell.model.TaskManager; + +/** + * Clears the task manager. Will show confirm dialog before clearing. + */ +public class ClearCommand extends Command { + + public static final String COMMAND_WORD = "clear"; + public static final String MESSAGE_SUCCESS = "Clear command executed."; + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Clears all tasks.\n" + + "Example: " + COMMAND_WORD; + + private static ClearCommand self; + private static boolean isUnderTesting; //for testing ONLY + + public ClearCommand() {} + + public static ClearCommand getInstance() { + if (self == null) { + self = new ClearCommand(); + } + + return self; + } + + /** if set to true, ClearCommand bypasses confirm dialog + * for running test cases ONLY + * */ + public static void setIsUnderTesting(boolean value) { + isUnderTesting = value; + } + + @Override + public CommandResult execute() { + assert model != null; + + if (isUnderTesting) { + executeClear(); + } else { + raiseClearCommandInputEvent(); + } + + return new CommandResult(MESSAGE_SUCCESS); + } + + /** executes reset data + * will be called from UiManager after confirmation of clear + * */ + public void executeClear() { + model.resetData(TaskManager.getEmptyTaskManager()); + } + + private void raiseClearCommandInputEvent() { + EventsCenter.getInstance().post(new ClearCommandInputEvent()); + } + } ``` ###### \java\seedu\taskell\logic\commands\FindCommand.java @@ -137,43 +251,25 @@ public class FindTagCommand extends Command { } } ``` -###### \java\seedu\taskell\logic\commands\ListUndoCommand.java +###### \java\seedu\taskell\logic\commands\IncorrectCommand.java ``` java -package seedu.taskell.logic.commands; - -import seedu.taskell.commons.core.EventsCenter; -import seedu.taskell.commons.events.ui.DisplayListChangedEvent; - -/** Lists a list of previous commands available for Undo operation - * */ -public class ListUndoCommand extends Command { - - public static final String COMMAND_WORD = "list-undo"; - - public static final String MESSAGE_SUCCESS = "Listed all commands available for undo."; - - private static ListUndoCommand self; - public static ListUndoCommand getInstance() { - if (self == null) { - self = new ListUndoCommand(); - } - - return self; + /** for setting latest command as an undoable command + * */ + public static void setIsUndoableCommand(boolean value) { + isAddEditDeleteCommand = value; } - - @Override - public CommandResult execute() { - indicateDisplayListChanged(); - return new CommandResult(MESSAGE_SUCCESS); + + public static boolean isUndoableCommand() { + return isAddEditDeleteCommand; } - - public void indicateDisplayListChanged() { - EventsCenter.getInstance().post( - new DisplayListChangedEvent(UndoCommand.getListOfCommandHistoryText())); + + /** if latest command is an undoable command, need to delete its command history + * */ + private void indicateExecutedIncorrectCommand() { + EventsCenter.getInstance().post(new ExecutedIncorrectCommandEvent(isAddEditDeleteCommand)); } -} ``` ###### \java\seedu\taskell\logic\commands\SaveStorageLocationCommand.java ``` java @@ -202,7 +298,7 @@ public class SaveStorageLocationCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Saves data file to new location specified. " + "New files can be auto-created as long as given directory is valid.\n" + "Parameters: FILEPATH (must be valid)\n" - + "Example: " + COMMAND_WORD + " C:/Users/chicken/Desktop/cat"; + + "Example: " + COMMAND_WORD + " C:\\Users\\chicken\\Desktop\\cat"; private static final String MESSAGE_SUCCESS = "Data successfully saved to new location."; private static final String MESSAGE_INVALID_PATH = "Filepath given is invalid. Filepath will be reset to old path."; @@ -293,13 +389,15 @@ import seedu.taskell.commons.core.EventsCenter; import seedu.taskell.commons.core.LogsCenter; import seedu.taskell.commons.events.ui.DisplayListChangedEvent; import seedu.taskell.model.CommandHistory; +import seedu.taskell.model.History; +import seedu.taskell.model.HistoryManager; import seedu.taskell.model.Model; import seedu.taskell.model.task.Task; import seedu.taskell.model.task.UniqueTaskList.DuplicateTaskException; import seedu.taskell.model.task.UniqueTaskList.TaskNotFoundException; /** - * Undo previously executed command (add or delete only for now) + * Undo previously executed commands (add, delete, edit) * Note: only for current session only (meaning after app is closed, history will be cleared) */ public class UndoCommand extends Command { @@ -320,65 +418,26 @@ public class UndoCommand extends Command { private static final String MESSAGE_COMMAND_HISTORY_EMPTY = "No command history available for undo."; private static final String MESSAGE_INVALID_INDEX = "Index is invalid"; - private static ArrayList commandHistoryList; - private static UndoCommand self; + private ArrayList commandHistoryList; + private History history; private int index; private CommandHistory commandHistory; public UndoCommand(int index) { logger.info("Creating UndoCommand with index: " + index); - this.index = index; - } - - public static UndoCommand getInstance() { - if (self == null) { - self = new UndoCommand(0); - } - return self; - } - - public static ArrayList getListOfCommandHistoryText() { - assert commandHistoryList != null; - - UndoCommand.getInstance().updateCommandList(); - - ArrayList list = new ArrayList<>(); - for (CommandHistory history: commandHistoryList) { - list.add(history.getCommandText()); - } - - return list; + history = HistoryManager.getInstance(); + commandHistoryList = history.getList(); + this.index = index; } - //removes commandHistory with tasks not present in system - private void updateCommandList() { - if (model == null) { - logger.severe("model is null"); - return; - } - for (CommandHistory commandHistory: commandHistoryList) { - if (isCommandTypeAddOrEdit(commandHistory) - && !model.isTaskPresent(commandHistory.getTask())) { - commandHistoryList.remove(commandHistory); - } else if (isUndoEditCommand(commandHistory) - && !model.isTaskPresent(commandHistory.getOldTask())) { - commandHistoryList.remove(commandHistory); - } - } + public UndoCommand() { + logger.info("Creating UndoCommand without index"); - } - - private boolean isCommandTypeAddOrEdit(CommandHistory commandHistory) { - return (commandHistory.getCommandType().contains(AddCommand.COMMAND_WORD) - || commandHistory.getCommandType().contains(EDIT)) - && !commandHistory.isRedoTrue(); - } - - private boolean isUndoEditCommand(CommandHistory commandHistory) { - return commandHistory.isRedoTrue() - && commandHistory.getCommandType().contains(EDIT); + history = HistoryManager.getInstance(); + commandHistoryList = history.getList(); + this.index = commandHistoryList.size(); //offset will be done in execute() } @Override @@ -396,61 +455,40 @@ public class UndoCommand extends Command { return redoUndo(); } - switch (commandHistory.getCommandType()) { - case AddCommand.COMMAND_WORD: + String commandType = commandHistory.getCommandType(); + if (commandType.equals(AddCommand.COMMAND_WORD)) { return undoAdd(); - case DeleteCommand.COMMAND_WORD: + } else if (commandType.equals(DeleteCommand.COMMAND_WORD)) { return undoDelete(); - case EditStartDateCommand.COMMAND_WORD: - return undoEdit(); - case EditEndDateCommand.COMMAND_WORD: - return undoEdit(); - case EditDescriptionCommand.COMMAND_WORD_1: - return undoEdit(); - case EditDescriptionCommand.COMMAND_WORD_2: - return undoEdit(); - case EditStartTimeCommand.COMMAND_WORD: - return undoEdit(); - case EditEndTimeCommand.COMMAND_WORD: + } else if (commandType.contains(EDIT)) { return undoEdit(); - case EditPriorityCommand.COMMAND_WORD: - return undoEdit(); - default: + } else { logger.severe("CommandHistory is invalid"); return new CommandResult(String.format(MESSAGE_NO_TASK_TO_UNDO)); } + } private CommandResult redoUndo() { - switch (commandHistory.getCommandType()) { - case AddCommand.COMMAND_WORD: + + String commandType = commandHistory.getCommandType(); + if (commandType.equals(AddCommand.COMMAND_WORD)) { return undoDelete(); - case DeleteCommand.COMMAND_WORD: + } else if (commandType.equals(DeleteCommand.COMMAND_WORD)) { return undoAdd(); - case EditStartDateCommand.COMMAND_WORD: - return redoEdit(); - case EditEndDateCommand.COMMAND_WORD: - return redoEdit(); - case EditDescriptionCommand.COMMAND_WORD_1: - return redoEdit(); - case EditDescriptionCommand.COMMAND_WORD_2: + } else if (commandType.contains(EDIT)) { return redoEdit(); - case EditStartTimeCommand.COMMAND_WORD: - return redoEdit(); - case EditEndTimeCommand.COMMAND_WORD: - return redoEdit(); - case EditPriorityCommand.COMMAND_WORD: - return redoEdit(); - default: + } else { logger.severe("CommandHistory is invalid"); return new CommandResult(String.format(MESSAGE_NO_TASK_TO_UNDO)); } + } private CommandResult undoEdit() { try { model.editTask(commandHistory.getTask(), commandHistory.getOldTask()); - deleteCommandHistory(); + history.deleteCommandHistory(commandHistory); addUndoCommand(commandHistory); indicateDisplayListChanged(); return new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, commandHistory.getOldTask())); @@ -467,7 +505,7 @@ public class UndoCommand extends Command { private CommandResult redoEdit() { try { model.editTask(commandHistory.getOldTask(), commandHistory.getTask()); - deleteCommandHistory(); + history.deleteCommandHistory(commandHistory); indicateDisplayListChanged(); return new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, commandHistory.getTask())); } catch (DuplicateTaskException e) { @@ -483,7 +521,7 @@ public class UndoCommand extends Command { private CommandResult undoDelete() { try { model.addTask(commandHistory.getTask()); - deleteCommandHistory(); + history.deleteCommandHistory(commandHistory); addUndoCommand(commandHistory); indicateDisplayListChanged(); return new CommandResult(String.format(MESSAGE_ADD_TASK_SUCCESS, commandHistory.getTask())); @@ -495,7 +533,7 @@ public class UndoCommand extends Command { private CommandResult undoAdd() { try { model.deleteTask(commandHistory.getTask()); - deleteCommandHistory(); + history.deleteCommandHistory(commandHistory); addUndoCommand(commandHistory); indicateDisplayListChanged(); } catch (TaskNotFoundException e) { @@ -503,10 +541,6 @@ public class UndoCommand extends Command { } return new CommandResult(String.format(MESSAGE_DELETE_TASK_SUCCESS, commandHistory.getTask())); } - - private void deleteCommandHistory() { - commandHistoryList.remove(commandHistory); - } private void addUndoCommand(CommandHistory commandHistory) { if (commandHistory.isRedoTrue()) { @@ -519,59 +553,14 @@ public class UndoCommand extends Command { /******** static methods *********/ - public static void initializeCommandHistory() { - if (commandHistoryList == null) { - commandHistoryList = new ArrayList<>(); - } - } - - public static void clearCommandHistory() { - commandHistoryList.clear(); - } - private static int getOffset(int index) { return index - 1; } - - public static void addCommandToHistory(String commandText, - String commandType) { - assert commandHistoryList != null; - commandHistoryList.add(new CommandHistory(commandText, commandType)); - } - - public static void addTaskToCommandHistory(Task task) { - logger.info("Adding task to history"); - if (commandHistoryList.isEmpty()) { - logger.warning("No command history to add task to"); - return; - } - - commandHistoryList.get(getOffset(commandHistoryList.size())).setTask(task); - } - - public static void addOldTaskToCommandHistory(Task task) { - logger.info("Adding old task to history"); - if (commandHistoryList.isEmpty()) { - logger.warning("No command history to add task to"); - return; - } - - commandHistoryList.get(getOffset(commandHistoryList.size())).setOldTask(task); - } - - public static void deletePreviousCommand() { - logger.info("Command unsuccessfully executed. Deleting command history."); - if (commandHistoryList.isEmpty()) { - logger.warning("No command history to delete"); - return; - } - commandHistoryList.remove(getOffset(commandHistoryList.size())); - } /****** Event ******/ public void indicateDisplayListChanged() { EventsCenter.getInstance().post( - new DisplayListChangedEvent(getListOfCommandHistoryText())); + new DisplayListChangedEvent(history.getListCommandText())); } } ``` @@ -589,7 +578,7 @@ public class ViewCalendarCommand extends Command { public static final String COMMAND_WORD_1 = "calendar"; public static final String COMMAND_WORD_2 = "cal"; - private static final String MESSAGE_SUCCESS = "Displayed calendar."; + public static final String MESSAGE_SUCCESS = "Displayed calendar."; @Override public CommandResult execute() { @@ -601,7 +590,83 @@ public class ViewCalendarCommand extends Command { EventsCenter.getInstance().post(new DisplayCalendarViewEvent()); } +} +``` +###### \java\seedu\taskell\logic\commands\ViewHistoryCommand.java +``` java +package seedu.taskell.logic.commands; + +import seedu.taskell.commons.core.EventsCenter; +import seedu.taskell.commons.events.ui.DisplayListChangedEvent; +import seedu.taskell.model.History; +import seedu.taskell.model.HistoryManager; + +/** Lists a list of previous commands available for Undo operation + * */ +public class ViewHistoryCommand extends Command { + + public static final String COMMAND_WORD_1 = "history"; + public static final String COMMAND_WORD_2 = "hist"; + + public static final String MESSAGE_SUCCESS = "Listed all commands available for undo."; + + private static ViewHistoryCommand self; + private History history; + + public ViewHistoryCommand() { + history = HistoryManager.getInstance(); + } + + public static ViewHistoryCommand getInstance() { + if (self == null) { + self = new ViewHistoryCommand(); + } + + return self; + } + + @Override + public CommandResult execute() { + indicateDisplayListChanged(); + return new CommandResult(MESSAGE_SUCCESS); + } + + public void indicateDisplayListChanged() { + EventsCenter.getInstance().post( + new DisplayListChangedEvent(history.getListCommandText())); + } + } +``` +###### \java\seedu\taskell\logic\parser\Parser.java +``` java + + private Command prepareClear(String arguments) { + if (arguments.isEmpty()) { + return new ClearCommand(); + } else { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ClearCommand.MESSAGE_USAGE)); + } + + } + +``` +###### \java\seedu\taskell\logic\parser\Parser.java +``` java + + /** + * if type of command is undoable, saves to history for undoing + */ + private void saveToHistory(String userInput, final String commandWord) { + if (commandWord.equals(AddCommand.COMMAND_WORD) || commandWord.equals(DeleteCommand.COMMAND_WORD) + || commandWord.contains(UndoCommand.EDIT)) { + IncorrectCommand.setIsUndoableCommand(true); + history.addCommand(userInput, commandWord); + } else { + IncorrectCommand.setIsUndoableCommand(false); + } + } + ``` ###### \java\seedu\taskell\logic\parser\Parser.java ``` java @@ -611,6 +676,10 @@ public class ViewCalendarCommand extends Command { * */ private Command prepareUndo(String args) { + if (args.isEmpty()) { + return new UndoCommand(); + } + Optional index = parseIndex(args); if (!index.isPresent()) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, UndoCommand.MESSAGE_USAGE)); @@ -675,13 +744,13 @@ public class CommandHistory { private String commandText, commandType; private Task task; //relevent task to be added, deleted or edited private Task oldTask; //oldTask needed for EditCommands - private boolean toRedo; + private boolean isRedoCommand; public CommandHistory() { commandText = "default command text"; commandType = "default command type"; task = null; - toRedo = false; + isRedoCommand = false; } public CommandHistory(String commandText, String commandType) { @@ -693,7 +762,7 @@ public class CommandHistory { this.commandText = commandText.trim(); this.commandType = commandType.trim(); this.task = null; - toRedo = false; + isRedoCommand = false; } public String getCommandText() { @@ -713,7 +782,7 @@ public class CommandHistory { } public boolean isRedoTrue() { - return toRedo; + return isRedoCommand; } /**** Setter methods ****/ @@ -735,9 +804,214 @@ public class CommandHistory { } public void setToRedoToTrue() { - toRedo = true; + isRedoCommand = true; + } + +} +``` +###### \java\seedu\taskell\model\History.java +``` java +package seedu.taskell.model; + +import java.util.ArrayList; + +import seedu.taskell.model.task.Task; + +/** API of History, holds command history available for undo + */ +public interface History { + + /** Returns list of command history */ + ArrayList getList(); + + /** Returns list of command history text form*/ + ArrayList getListCommandText(); + + /** Clears internal history */ + void clear(); + + /** Adds new command to history */ + void addCommand(String commandText, String commandType); + + /** Updates most recent command history with the relevant Task created */ + void addTask(Task task); + + /** Updates most recent command history with the relevant old Task (for edit commands only)*/ + void addOldTask(Task task); + + /** Checks if task is present in internal model */ + boolean isTaskPresent(Task task); + + /** Most recent command is incorrect, needs to be deleted */ + void deleteLatestCommand(); + + /** Deletes a given CommandHistory */ + void deleteCommandHistory(CommandHistory commandHistory); + + /** removes Tasks no longer in system (i.e. manually deleted/cleared) */ + void updateList(); + +} +``` +###### \java\seedu\taskell\model\HistoryManager.java +``` java +package seedu.taskell.model; + +import java.util.ArrayList; +import java.util.logging.Logger; + +import com.google.common.eventbus.Subscribe; + +import seedu.taskell.commons.core.LogsCenter; +import seedu.taskell.commons.events.undo.ExecutedIncorrectCommandEvent; +import seedu.taskell.logic.commands.AddCommand; +import seedu.taskell.model.task.Task; + +/** Implementation of History API, manages command history available for undo + */ +public class HistoryManager implements History { + + private static final Logger logger = LogsCenter.getLogger(HistoryManager.class.getName()); + private static final String EDIT = "edit"; + + private static ArrayList historyList; + private static Model model; + private static HistoryManager self; + + public HistoryManager() { + historyList = new ArrayList<>(); + } + + public static History getInstance() { + if (self == null) { + self = new HistoryManager(); + } + return self; + } + + public static void setModel(Model m) { + model = m; + } + + @Override + public ArrayList getList() { + return historyList; + } + + @Override + /** returns list of command history's user input strings + * */ + public ArrayList getListCommandText() { + assert historyList != null; + + updateList(); + + ArrayList list = new ArrayList<>(); + for (CommandHistory history: historyList) { + list.add(history.getCommandText()); + } + + return list; + } + + @Override + /** should be called whenever DeleteCommand is executed + * deletes history of the task deleted + * */ + public synchronized void updateList() { + if (model == null) { + logger.severe("Model is null"); + return; + } + + for (CommandHistory commandHistory: historyList) { + if (isCommandTypeAddOrEdit(commandHistory) + && !isTaskPresent(commandHistory.getTask())) { + historyList.remove(commandHistory); + } else if (isUndoEditCommand(commandHistory) + && !isTaskPresent(commandHistory.getTask())) { + historyList.remove(commandHistory); + } + } + } + + private boolean isCommandTypeAddOrEdit(CommandHistory commandHistory) { + return (commandHistory.getCommandType().contains(AddCommand.COMMAND_WORD) + || commandHistory.getCommandType().contains(EDIT)) + && !commandHistory.isRedoTrue(); } + private boolean isUndoEditCommand(CommandHistory commandHistory) { + return commandHistory.isRedoTrue() + && commandHistory.getCommandType().contains(EDIT); + } + + @Override + public void clear() { + logger.info("Clearing history..."); + historyList.clear(); + } + + @Override + public void addCommand(String commandText, String commandType) { + assert historyList != null; + historyList.add(new CommandHistory(commandText, commandType)); + } + + @Override + public void addTask(Task task) { + logger.info("Adding task to history"); + if (historyList.isEmpty()) { + logger.warning("No command history to add task to"); + return; + } + + historyList.get(getOffset(historyList.size())).setTask(task); + } + + @Override + public void addOldTask(Task task) { + logger.info("Adding old task to history"); + if (historyList.isEmpty()) { + logger.warning("No command history to add task to"); + return; + } + + historyList.get(getOffset(historyList.size())).setOldTask(task); + } + + @Override + public boolean isTaskPresent(Task task) { + return model.isTaskPresent(task); + } + + @Override + public void deleteLatestCommand() { + logger.info("Command unsuccessfully executed. Deleting command history."); + if (historyList.isEmpty()) { + logger.warning("No command history to delete"); + return; + } + historyList.remove(getOffset(historyList.size())); + } + + @Override + public void deleteCommandHistory(CommandHistory commandHistory) { + historyList.remove(commandHistory); + } + + private static int getOffset(int index) { + return index - 1; + } + + @Subscribe + private void handleExecuteIncorrectCommandEvent(ExecutedIncorrectCommandEvent event) { + if (event.isUndoableCommand()) { + deleteLatestCommand(); + } + } + + } ``` ###### \java\seedu\taskell\model\ModelManager.java @@ -863,22 +1137,83 @@ public class JsonConfigStorage implements ConfigStorage { ``` java package seedu.taskell.ui; +import java.time.LocalDateTime; +import java.util.ArrayList; + import jfxtras.scene.control.agenda.Agenda; +import jfxtras.scene.control.agenda.Agenda.Appointment; +import seedu.taskell.model.Model; +import seedu.taskell.model.ReadOnlyTaskManager; +import seedu.taskell.model.task.ReadOnlyTask; +import seedu.taskell.model.task.Task; +import seedu.taskell.model.task.TaskStatus; +import seedu.taskell.model.task.UniqueTaskList; /** This class holds the necessary elements to display calendar UI via Agenda API from jfxtras * */ public class CalendarView { + private static Model model; + private Agenda agenda; public CalendarView() { agenda = new Agenda(); + setAgendaProperties(); + loadTasks(); + } + + public static void setData(Model m) { + model = m; } public Agenda getAgenda() { + agenda.appointments().clear(); + loadTasks(); return agenda; } + + private void setAgendaProperties() { + agenda.setAllowDragging(false); + agenda.setAllowResize(false); + agenda.setFocusTraversable(false); + + agenda.setStyle("-fx-font-size: 12pt"); + } + + public void loadTasks() { + agenda.appointments().clear(); + + ReadOnlyTaskManager taskManager = model.getTaskManager(); + UniqueTaskList taskList = taskManager.getUniqueTaskList(); + + ArrayList appointments = new ArrayList<>(); + int i=1; + + for (ReadOnlyTask task: taskList) { + + if (isValidEventTask(task)) { + appointments.add(new Agenda.AppointmentImplLocal() + .withStartLocalDateTime(task.getStartDate().toLocalDateTime(task.getStartTime())) + .withEndLocalDateTime(task.getEndDate().toLocalDateTime(task.getEndTime())) + .withSummary(task.getDescription().description) + .withAppointmentGroup( + new Agenda.AppointmentGroupImpl().withStyleClass("group"+i))); + } + + i++; + } + + agenda.appointments().addAll(appointments); + + //"-fx-background-color: #EC407A; -fx-fill: #EC407A;" + } + + private boolean isValidEventTask(ReadOnlyTask task) { + return task.getTaskStatus().toString().equals(TaskStatus.INCOMPLETE) + && task.getTaskType().equals(Task.EVENT_TASK); + } } ``` @@ -892,29 +1227,46 @@ import javafx.scene.layout.AnchorPane; import jfxtras.scene.control.agenda.Agenda; import seedu.taskell.commons.core.LogsCenter; import seedu.taskell.commons.util.FxViewUtil; +import seedu.taskell.logic.commands.AddCommand; +import seedu.taskell.logic.commands.HelpCommand; +import seedu.taskell.logic.commands.ViewCalendarCommand; +import seedu.taskell.logic.commands.ViewHistoryCommand; import java.util.ArrayList; import java.util.logging.Logger; /** - * The Display Panel of the App. + * The Display Panel of the App, on right side of screen + * shows history or calendar view + * calendar view is default view */ -public class DisplayPanel extends UiPart{ +public class DisplayPanel extends UiPart { + + public static final String MESSAGE_NO_HISTORY = "No commands available for undo."; + public static final String MESSAGE_DISPLAY_HISTORY = "List of command history available for undo:\n"; + + private static final String WELCOME_MESSAGE = "Welcome to Taskell!\n" + + "Enter '" + AddCommand.COMMAND_WORD + "' in command box to add a task.\n" + + "Enter '" + ViewHistoryCommand.COMMAND_WORD_1 + "' for a list of commands to undo.\n" + + "Enter '" + ViewCalendarCommand.COMMAND_WORD_1 + "' to view calendar.\n" + + "Enter '" + HelpCommand.COMMAND_WORD + "' for more information about commands."; private static Logger logger = LogsCenter.getLogger(DisplayPanel.class); - public static final String RESULT_DISPLAY_ID = "resultDisplay"; + public static final String DISPLAY_PANEL_ID = "displayPanel"; private static final String STATUS_BAR_STYLE_SHEET = "result-display"; - private TextArea display; + private TextArea displayTextArea; private CalendarView calendarView; + private Agenda agenda; /** * Constructor is kept private as {@link #load(AnchorPane)} is the only way to create a DisplayPanel. */ private DisplayPanel() { calendarView = new CalendarView(); - display = new TextArea(); + displayTextArea = new TextArea(); + agenda = calendarView.getAgenda(); } @Override @@ -932,51 +1284,52 @@ public class DisplayPanel extends UiPart{ * @param placeholder The AnchorPane where the DisplayPanel must be inserted */ public static DisplayPanel load(AnchorPane placeholder){ - logger.info("Initializing display panel"); + logger.info("Initializing displayTextArea panel"); DisplayPanel displayPanel = new DisplayPanel(); - //displayPanel.display = new TextArea(); - displayPanel.display.setEditable(false); - displayPanel.display.setId(RESULT_DISPLAY_ID); - displayPanel.display.getStyleClass().removeAll(); - displayPanel.display.getStyleClass().add(STATUS_BAR_STYLE_SHEET); + displayPanel.displayTextArea.setEditable(false); + displayPanel.displayTextArea.setId(DISPLAY_PANEL_ID); + displayPanel.displayTextArea.getStyleClass().removeAll(); + displayPanel.displayTextArea.getStyleClass().add(STATUS_BAR_STYLE_SHEET); - FxViewUtil.applyAnchorBoundaryParameters(displayPanel.display, 0.0, 0.0, 0.0, 0.0); - placeholder.getChildren().add(displayPanel.display); + FxViewUtil.applyAnchorBoundaryParameters(displayPanel.displayTextArea, 0.0, 0.0, 0.0, 0.0); + placeholder.getChildren().add(displayPanel.displayTextArea); - displayPanel.display.setText("Welcome to Taskell!\n" - + "Enter 'add' in command box to add a task.\n" - + "Enter 'list-undo' for list of commands to undo.\n" - + "Enter 'help' for more information about commands.\n" - + "Enter 'calendar' to view calendar."); + displayPanel.displayTextArea.setText(WELCOME_MESSAGE); return displayPanel; } + /** called whenever history list needs to be shown on display panel + * */ public void loadList(AnchorPane placeholder, ArrayList list) { placeholder.getChildren().clear(); - placeholder.getChildren().add(display); + placeholder.getChildren().add(displayTextArea); - display.setText(""); + displayTextArea.setText(""); if (list.isEmpty()) { - display.setText("No commands available for undo."); + displayTextArea.setText(MESSAGE_NO_HISTORY); } else { + displayTextArea.setText(MESSAGE_DISPLAY_HISTORY); for (int i=0; i lastShownList = model.getFilteredTaskList(); + + if (lastShownList.size() < targetIndex) { + indicateAttemptToExecuteIncorrectCommand(); + return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + } + + TaskStatus incompleteStatus = new TaskStatus(TaskStatus.INCOMPLETE); + + ReadOnlyTask taskToBeUndone = lastShownList.get(targetIndex - 1); + Task newTask = null; + if(taskToBeUndone.getTaskStatus().taskStatus().equals(TaskStatus.INCOMPLETE)){ + return new CommandResult(MESSAGE_UNDONE_UNSUCCESSFUL); + } else { + newTask = new Task(taskToBeUndone.getDescription(), taskToBeUndone.getTaskType(), taskToBeUndone.getStartDate(), taskToBeUndone.getEndDate(), + taskToBeUndone.getStartTime(), taskToBeUndone.getEndTime(), taskToBeUndone.getTaskPriority(), taskToBeUndone.getRecurringType(), incompleteStatus, taskToBeUndone.getTags()); + } + + try { + model.editTask(taskToBeUndone, newTask); + } catch (TaskNotFoundException pnfe) { + assert false : "The target task cannot be missing"; + } catch (UniqueTaskList.DuplicateTaskException e) { + return new CommandResult(AddCommand.MESSAGE_DUPLICATE_TASK); + } + + return new CommandResult(String.format(MESSAGE_UNDONE_TASK_SUCCESS, taskToBeUndone)); + } +} +``` ###### \java\seedu\taskell\logic\parser\Parser.java ``` java /** @@ -156,6 +252,22 @@ public class ListDoneCommand extends Command { return new DoneCommand(index.get()); } + + /** + * Parses arguments in the context of the Undone task command. + * + * @param args + * full command args string + * @return the prepared command + */ + private Command prepareUndone(String args) { + Optional index = parseIndex(args); + if (!index.isPresent()) { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, UndoneCommand.MESSAGE_USAGE)); + } + + return new UndoneCommand(index.get()); + } ``` ###### \java\seedu\taskell\model\ModelManager.java ``` java @@ -178,8 +290,92 @@ public class ListDoneCommand extends Command { } } ``` +###### \java\seedu\taskell\model\task\EventTask.java +``` java + private boolean isValidRecurringEvent(TaskDate startDate, TaskDate endDate, RecurringType recurringType){ + + if(recurringType.recurringType.equals(RecurringType.DAILY_RECURRING)){ + return Math.abs(TaskDate.between(startDate, endDate)) <= TaskDate.NUM_DAYS_PER_DAY; + } else if(recurringType.recurringType.equals(RecurringType.WEEKLY_RECURRING)){ + return Math.abs(TaskDate.between(startDate, endDate)) <= TaskDate.NUM_DAYS_IN_A_WEEK; + } else if(recurringType.recurringType.equals(RecurringType.MONTHLY_RECURRING)){ + return Math.abs(TaskDate.between(startDate, endDate)) <= TaskDate.NUM_DAYS_IN_A_MONTH; + } else { + return true; + } + } + +``` +###### \java\seedu\taskell\model\task\RecurringType.java +``` java +public class RecurringType { + + public static final String MESSAGE_TASK_RECURRING_CONSTRAINTS = "Task recurrence should be daily, weekly or monthly" + + "\nThere should not be more than 1 recurring class for a task"; + + public static final String MESSAGE_INVALID_RECURRING_DURATION = "Invalid duration!" + + "\nTask with recurring type as daily shoud not have a difference of more than a day" + + "\nTask with recurring type as weekly should not have a difference of more than a week" + + "\nTask with recurring type as monthly should not have a difference of more than a month"; + + public static final String PREFIX = "r/"; + + public static final String NO_RECURRING = "neverRecur"; + public static final String DAILY_RECURRING = "daily"; + public static final String WEEKLY_RECURRING = "weekly"; + public static final String MONTHLY_RECURRING = "monthly"; + + public static final String DEFAULT_RECURRING = NO_RECURRING; + + public final String recurringType; + + /** + * Validates given recurring. + * + * @throws IllegalValueException if given recurring string is invalid. + */ + public RecurringType(String recurring) throws IllegalValueException { + assert recurring != null; + if (!isValidRecurring(recurring)) { + throw new IllegalValueException(MESSAGE_TASK_RECURRING_CONSTRAINTS); + } + this.recurringType = recurring; + } + + /** + * Returns true if a given string is a valid task taskTime. + */ + public static boolean isValidRecurring(String recurring) { + return recurring.equals(NO_RECURRING) + || recurring.equals(DAILY_RECURRING) + || recurring.equals(WEEKLY_RECURRING) + || recurring.equals(MONTHLY_RECURRING); + } + + @Override + public String toString() { + return recurringType; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof RecurringType // instanceof handles nulls + && this.recurringType.equals(((RecurringType) other).recurringType)); // state check + } + + @Override + public int hashCode() { + return recurringType.hashCode(); + } +} +``` ###### \java\seedu\taskell\model\task\TaskStatus.java ``` java +/** + * Represents a Task's status in the task manager. + * Guarantees: immutable; is valid as declared in {@link #isValidTaskComplete(String)} + */ package seedu.taskell.model.task; import java.util.Objects; diff --git a/collated/main/A0148004Rreused.md b/collated/main/A0148004Rreused.md new file mode 100644 index 000000000000..0a0881b7b06f --- /dev/null +++ b/collated/main/A0148004Rreused.md @@ -0,0 +1,13 @@ +# A0148004Rreused +###### \java\seedu\taskell\model\task\TaskDate.java +``` java + public TaskDate getNextMonth() throws IllegalValueException { + try { + LocalDate localDate = LocalDate.of(Integer.valueOf(getYear()), Integer.valueOf(getMonth()), Integer.valueOf(getDay())); + LocalDate nextMonth = localDate.plusMonths(1); + return new TaskDate(nextMonth.format(standardFormat)); + } catch (IllegalValueException e) { + throw new IllegalValueException(MESSAGE_TASK_DATE_CONSTRAINTS); + } + } +``` diff --git a/collated/test/A0139257X.md b/collated/test/A0139257X.md index b914520540f0..1ce20b98a150 100644 --- a/collated/test/A0139257X.md +++ b/collated/test/A0139257X.md @@ -2,10 +2,10 @@ ###### \java\seedu\taskell\logic\LogicManagerTest.java ``` java @Test - public void execute_add_ValidFloatingTaskWithKeywords() throws Exception { + public void execute_add_ValidFloatingTaskWithKeywords_success() throws Exception { // setup expectations TestDataHelper helper = new TestDataHelper(); - Task toBeAdded = helper.generateFloatingTask("on by on at from to", "0"); + Task toBeAdded = helper.generateFloatingTask("on by on at from to", "0", "neverRecur"); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); @@ -17,10 +17,10 @@ } @Test - public void execute_add_ValidFloatingTaskWithKeywordsButNoValidDateTime() throws Exception { + public void execute_add_ValidFloatingTaskWithKeywordsButNoValidDateTime_success() throws Exception { // setup expectations TestDataHelper helper = new TestDataHelper(); - Task toBeAdded = helper.generateFloatingTask("sleep by the seaside", "0"); + Task toBeAdded = helper.generateFloatingTask("sleep by the seaside", "0", "neverRecur"); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); @@ -32,10 +32,10 @@ } @Test - public void execute_add_ValidTaskWithImproperUsageOfAt() throws Exception { + public void execute_add_ValidTaskWithImproperUsageOfAt_success() throws Exception { // setup expectations TestDataHelper helper = new TestDataHelper(); - Task toBeAdded = helper.generateFloatingTask("go shopping at monday", "0"); + Task toBeAdded = helper.generateFloatingTask("go shopping at monday", "0", "neverRecur"); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); @@ -47,10 +47,10 @@ } @Test - public void execute_add_ValidTaskWithValidDateButNoPreFix() throws Exception { + public void execute_add_ValidTaskWithValidDateButNoPreFix_success() throws Exception { // setup expectations TestDataHelper helper = new TestDataHelper(); - Task toBeAdded = helper.generateFloatingTask("go shopping today", "0"); + Task toBeAdded = helper.generateFloatingTask("go shopping today", "0", "neverRecur"); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); @@ -62,10 +62,10 @@ } @Test - public void execute_add_ValidTaskWithValidTimeButNoPreFix() throws Exception { + public void execute_add_ValidTaskWithValidTimeButNoPreFix_success() throws Exception { // setup expectations TestDataHelper helper = new TestDataHelper(); - Task toBeAdded = helper.generateFloatingTask("go shopping 7pm", "0"); + Task toBeAdded = helper.generateFloatingTask("go shopping 7pm", "0", "neverRecur"); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); @@ -77,10 +77,10 @@ } @Test - public void execute_add_ValidTaskWithImproperUsageOfOn() throws Exception { + public void execute_add_ValidTaskWithImproperUsageOfOn_success() throws Exception { // setup expectations TestDataHelper helper = new TestDataHelper(); - Task toBeAdded = helper.generateFloatingTask("go shopping on 7pm", "0"); + Task toBeAdded = helper.generateFloatingTask("go shopping on 7pm", "0", "neverRecur"); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); @@ -92,9 +92,9 @@ } @Test - public void execute_add_ValidTaskWithMultipleOn() throws Exception { + public void execute_add_ValidTaskWithMultipleOn_success() throws Exception { String description = "add go shopping on 2-2-2222 on 3-3-3333"; - Task toBeAdded = new EventTask("go shopping on 3-3-3333", "2-2-2222", "2-2-2222", TaskTime.DEFAULT_START_TIME, TaskTime.DEFAULT_END_TIME, "0", TaskStatus.INCOMPLETE, new UniqueTagList()); + Task toBeAdded = new EventTask("go shopping on 3-3-3333", "2-2-2222", "2-2-2222", TaskTime.DEFAULT_START_TIME, TaskTime.DEFAULT_END_TIME, TaskPriority.DEFAULT_PRIORITY, RecurringType.NO_RECURRING, TaskStatus.INCOMPLETE, new UniqueTagList()); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); // execute command and verify result @@ -105,9 +105,9 @@ } @Test - public void execute_add_ValidTaskWithMultipleAt() throws Exception { + public void execute_add_ValidTaskWithMultipleAt_success() throws Exception { String description = "add go shopping at 11.58pm at 11.59pm"; - Task toBeAdded = new EventTask("go shopping at 11.59pm", TaskDate.DEFAULT_DATE, TaskDate.DEFAULT_DATE, "11.58pm", TaskTime.DEFAULT_END_TIME, "0", TaskStatus.INCOMPLETE, new UniqueTagList()); + Task toBeAdded = new EventTask("go shopping at 11.59pm", TaskDate.DEFAULT_DATE, TaskDate.DEFAULT_DATE, "11.58pm", TaskTime.DEFAULT_END_TIME, TaskPriority.DEFAULT_PRIORITY, RecurringType.NO_RECURRING, TaskStatus.INCOMPLETE, new UniqueTagList()); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); // execute command and verify result @@ -118,9 +118,9 @@ } @Test - public void execute_add_ValidTaskWithMultipleByDate() throws Exception { + public void execute_add_ValidTaskWithMultipleByDate_success() throws Exception { String description = "add go shopping by 2-2-2222 by 3-3-3333"; - Task toBeAdded = new EventTask("go shopping by 3-3-3333", TaskDate.DEFAULT_DATE, "2-2-2222", TaskTime.getTimeNow().toString(), TaskTime.DEFAULT_END_TIME, TaskPriority.DEFAULT_PRIORITY, TaskStatus.INCOMPLETE, new UniqueTagList()); + Task toBeAdded = new EventTask("go shopping by 3-3-3333", TaskDate.DEFAULT_DATE, "2-2-2222", TaskTime.getTimeNow().toString(), TaskTime.DEFAULT_END_TIME, TaskPriority.DEFAULT_PRIORITY, RecurringType.NO_RECURRING, TaskStatus.INCOMPLETE, new UniqueTagList()); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); // execute command and verify result @@ -131,9 +131,9 @@ } @Test - public void execute_add_ValidTaskWithMultipleByTime() throws Exception { + public void execute_add_ValidTaskWithMultipleByTime_success() throws Exception { String description = "add go shopping by 11.58pm by 11.59pm"; - Task toBeAdded = new EventTask("go shopping by 11.59pm", TaskDate.DEFAULT_DATE, TaskDate.DEFAULT_DATE, TaskTime.getTimeNow().toString(), "11.58pm", TaskPriority.DEFAULT_PRIORITY, TaskStatus.INCOMPLETE, new UniqueTagList()); + Task toBeAdded = new EventTask("go shopping by 11.59pm", TaskDate.DEFAULT_DATE, TaskDate.DEFAULT_DATE, TaskTime.getTimeNow().toString(), "11.58pm", TaskPriority.DEFAULT_PRIORITY, RecurringType.NO_RECURRING, TaskStatus.INCOMPLETE, new UniqueTagList()); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); // execute command and verify result @@ -144,9 +144,9 @@ } @Test - public void execute_add_ValidTaskWithMultipleFromDate() throws Exception { + public void execute_add_ValidTaskWithMultipleFromDate_success() throws Exception { String description = "add go shopping from 2-2-2222 from 3-3-3333"; - Task toBeAdded = new EventTask("go shopping from 3-3-3333", "2-2-2222", "2-2-2222", TaskTime.DEFAULT_START_TIME, TaskTime.DEFAULT_END_TIME, "0", TaskStatus.INCOMPLETE, new UniqueTagList()); + Task toBeAdded = new EventTask("go shopping from 3-3-3333", "2-2-2222", "2-2-2222", TaskTime.DEFAULT_START_TIME, TaskTime.DEFAULT_END_TIME, TaskPriority.DEFAULT_PRIORITY, RecurringType.NO_RECURRING, TaskStatus.INCOMPLETE, new UniqueTagList()); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); // execute command and verify result @@ -157,9 +157,9 @@ } @Test - public void execute_add_ValidTaskWithMultipleFromTime() throws Exception { + public void execute_add_ValidTaskWithMultipleFromTime_success() throws Exception { String description = "add go shopping from 11.58pm from 11.59pm"; - Task toBeAdded = new EventTask("go shopping from 11.59pm", TaskDate.DEFAULT_DATE, TaskDate.DEFAULT_DATE, "11.58pm", TaskTime.DEFAULT_END_TIME, "0", TaskStatus.INCOMPLETE, new UniqueTagList()); + Task toBeAdded = new EventTask("go shopping from 11.59pm", TaskDate.DEFAULT_DATE, TaskDate.DEFAULT_DATE, "11.58pm", TaskTime.DEFAULT_END_TIME, TaskPriority.DEFAULT_PRIORITY, RecurringType.NO_RECURRING, TaskStatus.INCOMPLETE, new UniqueTagList()); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); // execute command and verify result @@ -170,9 +170,9 @@ } @Test - public void execute_add_ValidTaskWithMultipleToDate() throws Exception { + public void execute_add_ValidTaskWithMultipleToDate_success() throws Exception { String description = "add go shopping to 2-2-2222 to 3-3-3333"; - Task toBeAdded = new EventTask("go shopping to 3-3-3333", TaskDate.DEFAULT_DATE, "2-2-2222", TaskTime.getTimeNow().toString(), TaskTime.DEFAULT_END_TIME, TaskPriority.DEFAULT_PRIORITY, TaskStatus.INCOMPLETE, new UniqueTagList()); + Task toBeAdded = new EventTask("go shopping to 3-3-3333", TaskDate.DEFAULT_DATE, "2-2-2222", TaskTime.getTimeNow().toString(), TaskTime.DEFAULT_END_TIME, TaskPriority.DEFAULT_PRIORITY, RecurringType.NO_RECURRING, TaskStatus.INCOMPLETE, new UniqueTagList()); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); // execute command and verify result @@ -183,9 +183,9 @@ } @Test - public void execute_add_ValidTaskWithMultipleToTime() throws Exception { + public void execute_add_ValidTaskWithMultipleToTime_success() throws Exception { String description = "add go shopping to 11.58pm to 11.59pm"; - Task toBeAdded = new EventTask("go shopping to 11.59pm", TaskDate.DEFAULT_DATE, TaskDate.DEFAULT_DATE, TaskTime.getTimeNow().toString(), "11.58pm", TaskPriority.DEFAULT_PRIORITY, TaskStatus.INCOMPLETE, new UniqueTagList()); + Task toBeAdded = new EventTask("go shopping to 11.59pm", TaskDate.DEFAULT_DATE, TaskDate.DEFAULT_DATE, TaskTime.getTimeNow().toString(), "11.58pm", TaskPriority.DEFAULT_PRIORITY, RecurringType.NO_RECURRING, TaskStatus.INCOMPLETE, new UniqueTagList()); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); // execute command and verify result @@ -196,9 +196,9 @@ } @Test - public void execute_add_ValidEventWithByTime() throws Exception { + public void execute_add_ValidEventWithByTime_success() throws Exception { String description = "add go shopping by 11:59pm"; - Task toBeAdded = new EventTask("go shopping", TaskDate.getTodayDate().toString(), TaskDate.getTodayDate().toString(), TaskTime.getTimeNow().toString(), "11:59pm", TaskPriority.DEFAULT_PRIORITY, TaskStatus.INCOMPLETE, new UniqueTagList()); + Task toBeAdded = new EventTask("go shopping", TaskDate.getTodayDate().toString(), TaskDate.getTodayDate().toString(), TaskTime.getTimeNow().toString(), "11:59pm", TaskPriority.DEFAULT_PRIORITY, RecurringType.NO_RECURRING, TaskStatus.INCOMPLETE, new UniqueTagList()); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); // execute command and verify result @@ -209,9 +209,9 @@ } @Test - public void execute_add_ValidEventWithAtTime() throws Exception { + public void execute_add_ValidEventWithAtTime_success() throws Exception { String description = "add go shopping at 11:59pm"; - Task toBeAdded = new EventTask("go shopping", TaskDate.getTodayDate().toString(), TaskDate.getTodayDate().toString(), "11:59pm", TaskTime.DEFAULT_END_TIME, "0", TaskStatus.INCOMPLETE, new UniqueTagList()); + Task toBeAdded = new EventTask("go shopping", TaskDate.getTodayDate().toString(), TaskDate.getTodayDate().toString(), "11:59pm", TaskTime.DEFAULT_END_TIME, TaskPriority.DEFAULT_PRIORITY, RecurringType.NO_RECURRING, TaskStatus.INCOMPLETE, new UniqueTagList()); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); // execute command and verify result @@ -222,9 +222,9 @@ } @Test - public void execute_add_ValidEventWithTagNotAtTheEnd() throws Exception { + public void execute_add_ValidEventWithTagNotAtTheEnd_success() throws Exception { String description = "add go to #girlfriend Mavis's house at 11:58pm"; - Task toBeAdded = new EventTask("go to Mavis's house", TaskDate.getTodayDate().toString(), TaskDate.getTodayDate().toString(), "11:58pm", TaskTime.DEFAULT_END_TIME, TaskPriority.DEFAULT_PRIORITY, TaskStatus.INCOMPLETE, new UniqueTagList(new Tag("girlfriend"))); + Task toBeAdded = new EventTask("go to Mavis's house", TaskDate.getTodayDate().toString(), TaskDate.getTodayDate().toString(), "11:58pm", TaskTime.DEFAULT_END_TIME, TaskPriority.DEFAULT_PRIORITY, RecurringType.NO_RECURRING, TaskStatus.INCOMPLETE, new UniqueTagList(new Tag("girlfriend"))); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); // execute command and verify result @@ -235,9 +235,9 @@ } @Test - public void execute_add_ValidEventWithEndTimeBeforeStartTime() throws Exception { + public void execute_add_ValidEventWithEndTimeBeforeStartTime_success() throws Exception { String description = "add stayover at Juliet's house from 11.58pm to 10am"; - Task toBeAdded = new EventTask("stayover at Juliet's house", TaskDate.getTodayDate().toString(), TaskDate.getTodayDate().toString(), "11:58pm", "10:00am", TaskPriority.DEFAULT_PRIORITY, TaskStatus.INCOMPLETE, new UniqueTagList()); + Task toBeAdded = new EventTask("stayover at Juliet's house", TaskDate.getTodayDate().toString(), TaskDate.getTodayDate().toString(), "11:58pm", "10:00am", TaskPriority.DEFAULT_PRIORITY, RecurringType.NO_RECURRING, TaskStatus.INCOMPLETE, new UniqueTagList()); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); // execute command and verify result @@ -248,13 +248,13 @@ } @Test - public void execute_add_ValidEventWithSameDayNameInWeekAsToday() throws Exception { + public void execute_add_ValidEventWithSameDayNameInWeekAsToday_success() throws Exception { TaskDate today = new TaskDate(TaskDate.getTodayDate().toString()); TaskDate tomorrow = new TaskDate(TaskDate.getTomorrowDate().toString()); String todayNameInWeek = today.getDayNameInWeek(); String tomorrowNameInWeek = tomorrow.getDayNameInWeek(); String description = "add go school from " + todayNameInWeek + " to " + tomorrowNameInWeek ; - Task toBeAdded = new EventTask("go school", today.getNextWeek().toString(), tomorrow.toString(), TaskTime.DEFAULT_START_TIME, TaskTime.DEFAULT_END_TIME, "0", TaskStatus.INCOMPLETE, new UniqueTagList()); + Task toBeAdded = new EventTask("go school", today.getNextWeek().toString(), tomorrow.toString(), TaskTime.DEFAULT_START_TIME, TaskTime.DEFAULT_END_TIME, TaskPriority.DEFAULT_PRIORITY, RecurringType.NO_RECURRING, TaskStatus.INCOMPLETE, new UniqueTagList()); TaskManager expectedAB = new TaskManager(); expectedAB.addTask(toBeAdded); // execute command and verify result @@ -265,7 +265,7 @@ } @Test - public void execute_add_ValidEventDuration_successful() throws Exception { + public void execute_add_ValidEventDuration_successful_success() throws Exception { // setup expectations TestDataHelper helper = new TestDataHelper(); Task toBeAdded = helper.validEventDuration(); @@ -285,8 +285,7 @@ public class TaskDateTest { @Test - public void assertValidFormatBehaviourForDate() { - //Valid Day of the Week + public void isValidDate_dayOfTheWeek_returnTrue() { assertTrue(TaskDate.isValidDate("mon")); assertTrue(TaskDate.isValidDate("tue")); assertTrue(TaskDate.isValidDate("WED")); @@ -294,8 +293,10 @@ public class TaskDateTest { assertTrue(TaskDate.isValidDate("fRi")); assertTrue(TaskDate.isValidDate("saturday")); assertTrue(TaskDate.isValidDate("sun")); - - //Valid Month + } + + @Test + public void isValidDate_month_returnTrue() { assertTrue(TaskDate.isValidDate("jan")); assertTrue(TaskDate.isValidDate("fEb")); assertTrue(TaskDate.isValidDate("march")); @@ -308,20 +309,26 @@ public class TaskDateTest { assertTrue(TaskDate.isValidDate("oct")); assertTrue(TaskDate.isValidDate("November")); assertTrue(TaskDate.isValidDate("December")); + } - //Valid Month and Year + @Test + public void isValidDate_monthAndYear_returnTrue() { assertTrue(TaskDate.isValidDate("may 2016")); assertTrue(TaskDate.isValidDate("may-2016")); assertTrue(TaskDate.isValidDate("may.2016")); assertTrue(TaskDate.isValidDate("may/2016")); - - //Valid Day and Month + } + + @Test + public void isValidDate_dayAndMonth_returnTrue() { assertTrue(TaskDate.isValidDate("1 jan")); assertTrue(TaskDate.isValidDate("1-jan")); assertTrue(TaskDate.isValidDate("1.jan")); assertTrue(TaskDate.isValidDate("1/jan")); - - //Valid full Date + } + + @Test + public void isValidDate_fullDate_returnTrue() { assertTrue(TaskDate.isValidDate(TaskDate.DEFAULT_DATE)); assertTrue(TaskDate.isValidDate("1 1 2016")); assertTrue(TaskDate.isValidDate("1 jan 2016")); @@ -343,19 +350,22 @@ public class TaskDateTest { assertTrue(TaskDate.isValidDate("1.jan/2016")); assertTrue(TaskDate.isValidDate("1.1-2016")); assertTrue(TaskDate.isValidDate("1.jan-2016")); - - //Valid Today + } + + @Test + public void isValidDate_today_returnTrue() { assertTrue(TaskDate.isValidDate("Today")); assertTrue(TaskDate.isValidDate("tdy")); - - //Valid Tomorrow + } + + @Test + public void isValidDate_returnTrue() { assertTrue(TaskDate.isValidDate("Tomorrow")); assertTrue(TaskDate.isValidDate("tmr")); - } @Test - public void assertInvalidFormatBehaviourForDate() { + public void isValidDate_returnFalse() { assertFalse(TaskDate.isValidDate("")); assertFalse(TaskDate.isValidDate(null)); assertFalse(TaskDate.isValidDate("1st January")); @@ -366,7 +376,7 @@ public class TaskDateTest { } @Test - public void assertNewTaskDateBehaviour() throws IllegalValueException { + public void constructor_validDate_newObjectCreated() throws IllegalValueException { TaskDate today = TaskDate.getTodayDate(); TaskDate validDayOfWeek = new TaskDate(today.getDayNameInWeek()); assertEquals(today.getNextWeek(), validDayOfWeek); @@ -390,7 +400,10 @@ public class TaskDateTest { TaskDate validTomorrow = new TaskDate("tmr"); standardFormat = DateTimeFormatter.ofPattern("d-MM-yyyy"); assertEquals(LocalDate.now().plusDays(1).format(standardFormat), validTomorrow.toString()); - + } + + @Test + public void constructor_invalidDate_ExceptionThrown() { try { TaskDate invalidDate = new TaskDate("NOT-A-VALID-DATE"); } catch (IllegalValueException ive) { @@ -399,88 +412,146 @@ public class TaskDateTest { } @Test - public void assertCorrectTodayDate() { + public void getTodayDate_returnTodayDateAsString_success() { DateTimeFormatter standardFormat = DateTimeFormatter.ofPattern("d-MM-yyyy"); assertEquals(LocalDate.now().format(standardFormat), TaskDate.getTodayDate().toString()); } @Test - public void assertCorrectTomorrowDate() { + public void getTomorrowDate_returnTomorrowDateAsString_success() { DateTimeFormatter standardFormat = DateTimeFormatter.ofPattern("d-MM-yyyy"); assertEquals(LocalDate.now().plusDays(1).format(standardFormat), TaskDate.getTomorrowDate().toString()); } @Test - public void assertCorrectThisYear() { + public void getYear_returnYearAsString_success() { assertEquals(LocalDate.now().getYear() + "", TaskDate.getThisYear()); } @Test - public void assertCorrectGetNextDay() throws IllegalValueException { + public void getNextDay_returnNextDay_success() throws IllegalValueException { TaskDate today = new TaskDate("1-1-2016"); TaskDate nextDay = new TaskDate("2-1-2016"); assertEquals(nextDay, today.getNextDay()); } @Test - public void assertCorrectGetNextWeek() throws IllegalValueException { + public void getNextWeek_returnNextWeek_success() throws IllegalValueException { TaskDate today = new TaskDate("1-1-2016"); TaskDate nextWeek = new TaskDate("8-1-2016"); assertEquals(nextWeek, today.getNextWeek()); } @Test - public void assertDateisBeforeBehaviour() throws IllegalValueException { - TaskDate startDate = new TaskDate("1-1-2100"); - TaskDate endDateDiffDaySameMonthSameYear = new TaskDate("10-1-2100"); - TaskDate endDateSameDayDiffMonthSameYear = new TaskDate("1-2-2100"); - TaskDate endDateSameDaySameMonthDiffYear = new TaskDate("1-1-2200"); - - assertTrue(startDate.isBefore(endDateDiffDaySameMonthSameYear)); - assertTrue(startDate.isBefore(endDateSameDayDiffMonthSameYear)); - assertTrue(startDate.isBefore(endDateSameDaySameMonthDiffYear)); - - assertFalse(endDateDiffDaySameMonthSameYear.isBefore(startDate)); - assertFalse(endDateSameDayDiffMonthSameYear.isBefore(startDate)); - assertFalse(endDateSameDaySameMonthDiffYear.isBefore(startDate)); + public void getLocalDate_returnLocalDate_success() throws IllegalValueException { + TaskDate date = new TaskDate("1-1-2100"); + LocalDate actual = date.getLocalDate(); + LocalDate expected = LocalDate.of(2100, 1, 1); + assertEquals(expected, actual); } @Test - public void assertDateisAfterBehaviour() throws IllegalValueException { - TaskDate startDate = new TaskDate("1-1-2100"); - TaskDate endDateDiffDaySameMonthSameYear = new TaskDate("10-1-2100"); - TaskDate endDateSameDayDiffMonthSameYear = new TaskDate("1-2-2100"); - TaskDate endDateSameDaySameMonthDiffYear = new TaskDate("1-1-2200"); - - assertTrue(endDateDiffDaySameMonthSameYear.isAfter(startDate)); - assertTrue(endDateSameDayDiffMonthSameYear.isAfter(startDate)); - assertTrue(endDateSameDaySameMonthDiffYear.isAfter(startDate)); - - assertFalse(startDate.isAfter(endDateDiffDaySameMonthSameYear)); - assertFalse(startDate.isAfter(endDateSameDayDiffMonthSameYear)); - assertFalse(startDate.isAfter(endDateSameDaySameMonthDiffYear)); + public void isBefore_thisDateBeforeGivenDate_success() throws IllegalValueException { + TaskDate startDate = new TaskDate("1-1-2100"); + TaskDate endDateDiffDaySameMonthSameYear = new TaskDate("10-1-2100"); + TaskDate endDateSameDayDiffMonthSameYear = new TaskDate("1-2-2100"); + TaskDate endDateSameDaySameMonthDiffYear = new TaskDate("1-1-2200"); + + assertTrue(startDate.isBefore(endDateDiffDaySameMonthSameYear)); + assertTrue(startDate.isBefore(endDateSameDayDiffMonthSameYear)); + assertTrue(startDate.isBefore(endDateSameDaySameMonthDiffYear)); + } + + @Test + public void isBefore_thisDateBeforeGivenDate_failure() throws IllegalValueException { + TaskDate startDate = new TaskDate("1-1-2100"); + TaskDate endDateDiffDaySameMonthSameYear = new TaskDate("10-1-2100"); + TaskDate endDateSameDayDiffMonthSameYear = new TaskDate("1-2-2100"); + TaskDate endDateSameDaySameMonthDiffYear = new TaskDate("1-1-2200"); + + assertFalse(endDateDiffDaySameMonthSameYear.isBefore(startDate)); + assertFalse(endDateSameDayDiffMonthSameYear.isBefore(startDate)); + assertFalse(endDateSameDaySameMonthDiffYear.isBefore(startDate)); + } + + @Test + public void isAfter_thisDateAfterGivenDate_success() throws IllegalValueException { + TaskDate startDate = new TaskDate("1-1-2100"); + TaskDate endDateDiffDaySameMonthSameYear = new TaskDate("10-1-2100"); + TaskDate endDateSameDayDiffMonthSameYear = new TaskDate("1-2-2100"); + TaskDate endDateSameDaySameMonthDiffYear = new TaskDate("1-1-2200"); + + assertTrue(endDateDiffDaySameMonthSameYear.isAfter(startDate)); + assertTrue(endDateSameDayDiffMonthSameYear.isAfter(startDate)); + assertTrue(endDateSameDaySameMonthDiffYear.isAfter(startDate)); + } + + @Test + public void isAfter_thisDateAfterGivenDate_failure() throws IllegalValueException { + TaskDate startDate = new TaskDate("1-1-2100"); + TaskDate endDateDiffDaySameMonthSameYear = new TaskDate("10-1-2100"); + TaskDate endDateSameDayDiffMonthSameYear = new TaskDate("1-2-2100"); + TaskDate endDateSameDaySameMonthDiffYear = new TaskDate("1-1-2200"); + + assertFalse(startDate.isAfter(endDateDiffDaySameMonthSameYear)); + assertFalse(startDate.isAfter(endDateSameDayDiffMonthSameYear)); + assertFalse(startDate.isAfter(endDateSameDaySameMonthDiffYear)); + } + + @Test + public void between_firstDateBeforeSecondDate_returnPositiveDifference() throws IllegalValueException { + TaskDate first = new TaskDate("1-11-2016"); + TaskDate second = new TaskDate("20-11-2016"); + + long positiveDayDifference = TaskDate.between(first, second); + assertEquals(19, positiveDayDifference); + } + + @Test + public void between_firstDateAfterSecondDate_returnNegativeDifference() throws IllegalValueException { + TaskDate first = new TaskDate("1-11-2016"); + TaskDate second = new TaskDate("20-11-2016"); + + long negativeDayDifference = TaskDate.between(second, first); + assertEquals(-19, negativeDayDifference); } @Test - public void assertCorrectDisplayDate() throws IllegalValueException { + public void getDisplayDate_success() throws IllegalValueException { TaskDate date = new TaskDate("22-10-2016"); assertEquals("Saturday, 22 October 2016", date.getDisplayDate()); } @Test - public void assertCorrectToString() throws IllegalValueException { + public void getLocalDateTime_success() throws IllegalValueException { + TaskTime givenTime = new TaskTime("3am"); + TaskDate date = new TaskDate("1-1-2100"); + + LocalDateTime actual = date.toLocalDateTime(givenTime); + LocalDateTime expected = LocalDateTime.of(2100, 1, 1, 3, 0); + + assertEquals(expected, actual); + } + + @Test + public void toString_success() throws IllegalValueException { TaskDate date = new TaskDate("1-1-2015"); assertEquals("1-1-2015", date.toString()); } @Test - public void assertEqualsBehaviour() throws IllegalValueException { + public void equals_success() throws IllegalValueException { TaskDate date = new TaskDate("1-1-2015"); TaskDate sameDate = new TaskDate("1-1-2015"); - TaskDate differentDate = new TaskDate("2-2-2016"); assertEquals(date, date); assertEquals(date, sameDate); + } + + @Test + public void equals_failure() throws IllegalValueException { + TaskDate date = new TaskDate("1-1-2015"); + TaskDate differentDate = new TaskDate("2-2-2016"); assertNotSame(date, differentDate); assertNotSame(date, "1-1-2015"); @@ -493,7 +564,17 @@ public class TaskDateTest { ``` java public class TaskTimeTest { @Test - public void assertValidFormatBehaviourForTime() { + public void isValidTime_invalidTime_returnFalse() { + assertFalse(TaskTime.isValidTime("1.3am")); + assertFalse(TaskTime.isValidTime("2")); + assertFalse(TaskTime.isValidTime("13pm")); + assertFalse(TaskTime.isValidTime("2359")); + assertFalse(TaskTime.isValidTime("NotAValidTime")); + assertFalse(TaskTime.isValidTime("")); + } + + @Test + public void isValidTime_validTime_returnTrue() { assertTrue(TaskTime.isValidTime(TaskTime.DEFAULT_START_TIME)); assertTrue(TaskTime.isValidTime(TaskTime.DEFAULT_END_TIME)); assertTrue(TaskTime.isValidTime("12am")); @@ -502,14 +583,18 @@ public class TaskTimeTest { assertTrue(TaskTime.isValidTime("1-30am")); assertTrue(TaskTime.isValidTime("2:30Am")); assertTrue(TaskTime.isValidTime("noW")); - - //Valid Noon + } + + @Test + public void isValidTime_validNoon_returnTrue() { assertTrue(TaskTime.isValidTime("noon")); assertTrue(TaskTime.isValidTime("afterNoon")); assertTrue(TaskTime.isValidTime("12noon")); assertTrue(TaskTime.isValidTime("12-noon")); - - //Valid Midnight + } + + @Test + public void isValidTime_validMidnight_returnTrue(){ assertTrue(TaskTime.isValidTime("midnight")); assertTrue(TaskTime.isValidTime("Mid-Night")); assertTrue(TaskTime.isValidTime("12MidnIght")); @@ -519,17 +604,7 @@ public class TaskTimeTest { } @Test - public void assertInvalidFormatBehaviourForTime() { - assertFalse(TaskTime.isValidTime("1.3am")); - assertFalse(TaskTime.isValidTime("2")); - assertFalse(TaskTime.isValidTime("13pm")); - assertFalse(TaskTime.isValidTime("2359")); - assertFalse(TaskTime.isValidTime("NotAValidTime")); - assertFalse(TaskTime.isValidTime("")); - } - - @Test - public void assertValidNewTaskTimeBehaviour() { + public void constructor_validTime_success() { try { TaskTime time = new TaskTime("now"); TaskTime expected = new TaskTime(TaskTime.getTimeNow().toString()); @@ -548,7 +623,7 @@ public class TaskTimeTest { } @Test - public void assertInvalidNewTaskTimeBehaviour() { + public void constructor_invalidTime_failure() { try { TaskTime time = new TaskTime("NOT A VALID TIME"); } catch (IllegalValueException ive) { @@ -557,39 +632,49 @@ public class TaskTimeTest { } @Test - public void assertTimeIsBeforeBehaviour() throws IllegalValueException { - TaskTime timeIs12Am = new TaskTime("12am"); - TaskTime timeIs12Pm = new TaskTime("12pm"); - TaskTime timeNot12Am = new TaskTime("3am"); - TaskTime timeNot12Pm = new TaskTime("3pm"); - TaskTime time = new TaskTime(TaskTime.DEFAULT_END_TIME); - - //Correct Behaviour - assertTrue(timeIs12Am.isBefore(timeIs12Pm)); - assertTrue(timeIs12Am.isBefore(timeNot12Am)); - assertTrue(timeNot12Am.isBefore(timeIs12Pm)); - assertTrue(timeNot12Pm.isBefore(time)); - assertTrue(timeIs12Am.isBefore(time)); - - //Incorrect Behaviour - assertFalse(timeIs12Am.isBefore(timeIs12Am)); - assertFalse(timeIs12Pm.isBefore(timeIs12Am)); - assertFalse(timeIs12Pm.isBefore(timeNot12Am)); + public void isBefore_thisTimeBeforeGivenTime_success() throws IllegalValueException { + TaskTime timeIs12Am = new TaskTime("12am"); + TaskTime timeIs12Pm = new TaskTime("12pm"); + TaskTime timeNot12Am = new TaskTime("3am"); + TaskTime timeNot12Pm = new TaskTime("3pm"); + TaskTime time = new TaskTime(TaskTime.DEFAULT_END_TIME); + + assertTrue(timeIs12Am.isBefore(timeIs12Pm)); + assertTrue(timeIs12Am.isBefore(timeNot12Am)); + assertTrue(timeNot12Am.isBefore(timeIs12Pm)); + assertTrue(timeNot12Pm.isBefore(time)); + assertTrue(timeIs12Am.isBefore(time)); } @Test - public void assertTimeIsAfterBehaviour() throws IllegalValueException { + public void isBefore_thisTimeBeforeGivenTime_failure() throws IllegalValueException { + TaskTime timeIs12Am = new TaskTime("12am"); + TaskTime timeIs12Pm = new TaskTime("12pm"); + TaskTime timeNot12Am = new TaskTime("3am"); + + assertFalse(timeIs12Am.isBefore(timeIs12Am)); + assertFalse(timeIs12Pm.isBefore(timeIs12Am)); + assertFalse(timeIs12Pm.isBefore(timeNot12Am)); + } + + @Test + public void isAfter_thisTimeAfterGivenTime_success() throws IllegalValueException { TaskTime timeIs12Am = new TaskTime("12am"); TaskTime timeIs12Pm = new TaskTime("12pm"); TaskTime timeNot12Am = new TaskTime("3am"); - TaskTime timeNot12Pm = new TaskTime("3pm"); - TaskTime time = new TaskTime(TaskTime.DEFAULT_END_TIME); - //Correct Behaviour assertTrue(timeIs12Pm.isAfter(timeIs12Am)); assertTrue(timeIs12Pm.isAfter(timeNot12Am)); + } + + @Test + public void isAfter_thisTimeAfterGivenTime_failure() throws IllegalValueException { + TaskTime timeIs12Am = new TaskTime("12am"); + TaskTime timeIs12Pm = new TaskTime("12pm"); + TaskTime timeNot12Am = new TaskTime("3am"); + TaskTime timeNot12Pm = new TaskTime("3pm"); + TaskTime time = new TaskTime(TaskTime.DEFAULT_END_TIME); - //Incorrect Behaviour assertFalse(timeIs12Am.isAfter(timeIs12Am)); assertFalse(timeIs12Am.isAfter(timeIs12Pm)); assertFalse(timeIs12Am.isAfter(timeNot12Am)); @@ -598,7 +683,7 @@ public class TaskTimeTest { } @Test - public void assertCorrectExtractionOfTime() throws IllegalValueException { + public void getPartOfTime_success() throws IllegalValueException { TaskTime validTime = new TaskTime("4.35pm"); assertEquals("4", validTime.getHour()); @@ -607,26 +692,69 @@ public class TaskTimeTest { } @Test - public void assertCorrectCurrentTime() { + public void getCurrentTime_success() { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("h:mma"); LocalTime currTime = LocalTime.now(); assertEquals(LocalTime.of(currTime.getHour(), currTime.getMinute()).format(dtf), TaskTime.getTimeNow().toString()); } @Test - public void assertCorrectToString() throws IllegalValueException { + public void getLocalTime_success() throws IllegalValueException { + //Valid hour in the morning + TaskTime time = new TaskTime("3am"); + LocalTime actual = time.getLocalTime(); + LocalTime expected = LocalTime.of(3, 0); + assertEquals(expected, actual); + + //Valid time in the morning + time = new TaskTime("5.23am"); + actual = time.getLocalTime(); + expected = LocalTime.of(5, 23); + assertEquals(expected, actual); + + //Valid hour in the afternoon + time = new TaskTime("3pm"); + actual = time.getLocalTime(); + expected = LocalTime.of(15, 0); + assertEquals(expected, actual); + + //Valid time in the afternoon + time = new TaskTime("5.23pm"); + actual = time.getLocalTime(); + expected = LocalTime.of(17, 23); + assertEquals(expected, actual); + } + + @Test + public void getLocalDateTime_success() throws IllegalValueException { + TaskDate givenDate = new TaskDate("1-1-2100"); + TaskTime time = new TaskTime("3am"); + + LocalDateTime actual = time.toLocalDateTime(givenDate); + LocalDateTime expected = LocalDateTime.of(2100, 1, 1, 3, 0); + + assertEquals(expected, actual); + } + + @Test + public void toString_success() throws IllegalValueException { TaskTime time = new TaskTime("5pm"); assertEquals("5:00PM", time.toString()); } @Test - public void assertEqualsBehaviour() throws IllegalValueException { + public void equals_returnTrue() throws IllegalValueException { TaskTime time = new TaskTime("12.30am"); TaskTime sameTime= new TaskTime("12.30am"); - TaskTime differentTime= new TaskTime("3pm"); assertEquals(time, time); assertEquals(time, sameTime); + } + + @Test + public void equals_returnFalse() throws IllegalValueException { + TaskTime time = new TaskTime("12.30am"); + TaskTime differentTime= new TaskTime("3pm"); assertNotSame(time, differentTime); assertNotSame(time, "3am"); @@ -650,44 +778,44 @@ public class TypicalTestTasks { try { archivePastEmails = new TaskBuilder().withDescription("Archieve past emails").withTaskType(Task.EVENT_TASK) .withTaskPriority("1").withStartTime("12:30AM").withEndTime("12:45AM").withStartDate("1-1-2100") - .withEndDate("1-12-2100").withTags("friends").withTaskComplete(TaskStatus.INCOMPLETE).build(); + .withEndDate("1-12-2100").withTags("friends").withRecurringType(RecurringType.NO_RECURRING).withTaskComplete(TaskStatus.INCOMPLETE).build(); borrowBooks = new TaskBuilder().withDescription("Borrow books").withTaskType(Task.EVENT_TASK) .withTaskPriority("1").withStartTime("12:30AM").withEndTime("12:45AM").withStartDate("1-1-2100") - .withEndDate("1-12-2100").withTags("owesMoney", "friends").withTaskComplete(TaskStatus.INCOMPLETE) + .withEndDate("1-12-2100").withTags("owesMoney", "friends").withRecurringType(RecurringType.NO_RECURRING).withTaskComplete(TaskStatus.INCOMPLETE) .build(); collectParcel = new TaskBuilder().withDescription("Collect parcel").withTaskType(Task.EVENT_TASK) .withStartDate("1-1-2100").withEndDate("1-12-2100").withStartTime("12:30AM").withEndTime("12:45AM") - .withTaskPriority("1").withTags("owesMoney").withTaskComplete(TaskStatus.INCOMPLETE).build(); + .withTaskPriority("1").withTags("owesMoney").withRecurringType(RecurringType.NO_RECURRING).withTaskComplete(TaskStatus.INCOMPLETE).build(); discardBooks = new TaskBuilder().withDescription("Discard books").withTaskType(Task.EVENT_TASK) .withStartDate("1-1-2100").withEndDate("1-12-2100").withStartTime("12:30AM").withEndTime("12:45AM") - .withTaskPriority("1").withTaskComplete(TaskStatus.INCOMPLETE).build(); + .withTaskPriority("1").withRecurringType(RecurringType.NO_RECURRING).withTaskComplete(TaskStatus.INCOMPLETE).build(); editPowerpoint = new TaskBuilder().withDescription("Edit powerpoint").withTaskType(Task.EVENT_TASK) .withStartDate("1-1-2100").withEndDate("1-12-2100").withStartTime("12:30AM").withEndTime("12:45AM") - .withTaskPriority("1").withTaskComplete(TaskStatus.INCOMPLETE).build(); + .withTaskPriority("1").withRecurringType(RecurringType.NO_RECURRING).withTaskComplete(TaskStatus.INCOMPLETE).build(); fixbugs = new TaskBuilder().withDescription("Fix bugs").withTaskType(Task.EVENT_TASK) .withStartDate("1-1-2100").withEndDate("1-12-2100").withStartTime("12:30AM").withEndTime("12:45AM") - .withTaskPriority("1").withTaskComplete(TaskStatus.INCOMPLETE).build(); + .withTaskPriority("1").withRecurringType(RecurringType.NO_RECURRING).withTaskComplete(TaskStatus.INCOMPLETE).build(); getNewUniform = new TaskBuilder().withDescription("Get new uniform").withTaskType(Task.EVENT_TASK) .withStartDate("1-1-2100").withEndDate("1-12-2100").withStartTime("12:30AM").withEndTime("12:45AM") - .withTaskPriority("1").withTaskComplete(TaskStatus.INCOMPLETE).build(); + .withTaskPriority("1").withRecurringType(RecurringType.NO_RECURRING).withTaskComplete(TaskStatus.INCOMPLETE).build(); // Manually added holdMeeting = new TaskBuilder().withDescription("Hold meeting").withTaskType(Task.EVENT_TASK) .withStartDate("11-1-2100").withEndDate("1-12-2100").withStartTime("12:30AM").withEndTime("12:45AM") - .withTaskPriority("0").withTaskComplete(TaskStatus.INCOMPLETE).build(); + .withTaskPriority("0").withRecurringType(RecurringType.NO_RECURRING).withTaskComplete(TaskStatus.INCOMPLETE).build(); inspectWarehouse = new TaskBuilder().withDescription("Inspect warehouse").withTaskType(Task.EVENT_TASK) .withStartDate("11-1-2100").withEndDate("1-12-2100").withStartTime("12:30AM").withEndTime("12:45AM") - .withTaskPriority("0").withTaskComplete(TaskStatus.INCOMPLETE).build(); + .withTaskPriority("0").withRecurringType(RecurringType.NO_RECURRING).withTaskComplete(TaskStatus.INCOMPLETE).build(); floatingTask_Valid = new TaskBuilder().withDescription("floating task").withTaskType(Task.FLOATING_TASK) .withStartDate(TaskDate.DEFAULT_DATE).withEndDate(TaskDate.DEFAULT_DATE) .withStartTime(TaskTime.DEFAULT_START_TIME).withEndTime(TaskTime.DEFAULT_END_TIME) - .withTaskPriority(TaskPriority.DEFAULT_PRIORITY).withTaskComplete(TaskStatus.INCOMPLETE).build(); + .withTaskPriority(TaskPriority.DEFAULT_PRIORITY).withRecurringType(RecurringType.NO_RECURRING).withTaskComplete(TaskStatus.INCOMPLETE).build(); floatingTask_NonIntuitiveDescription = new TaskBuilder().withDescription("76@#$5632 on by at on") .withTaskType(Task.FLOATING_TASK).withStartDate(TaskDate.DEFAULT_DATE) .withEndDate(TaskDate.DEFAULT_DATE).withStartTime(TaskTime.DEFAULT_START_TIME) .withEndTime(TaskTime.DEFAULT_END_TIME).withTaskPriority(TaskPriority.DEFAULT_PRIORITY) - .withTaskComplete(TaskStatus.INCOMPLETE).build(); + .withRecurringType(RecurringType.NO_RECURRING).withTaskComplete(TaskStatus.INCOMPLETE).build(); } catch (IllegalValueException e) { e.printStackTrace(); diff --git a/collated/test/A0139257Xreused.md b/collated/test/A0139257Xreused.md index f1f8df64ce13..c51a52cb8586 100644 --- a/collated/test/A0139257Xreused.md +++ b/collated/test/A0139257Xreused.md @@ -79,7 +79,7 @@ public class AddCommandTest extends TaskManagerGuiTest { assertCommandBehavior( "add Valid Description with startDate after endDate from 1-jan-2200 to 1-jan-2100", EventTask.MESSAGE_EVENT_CONSTRAINTS); assertCommandBehavior( - "add Valid Description with startTime before Today's current time at 2am", EventTask.MESSAGE_EVENT_CONSTRAINTS); + "add Valid Description with startTime before Today's current time at 12am", EventTask.MESSAGE_EVENT_CONSTRAINTS); assertCommandBehavior( "add Valid Description p/invalidPriority ", TaskPriority.MESSAGE_TASK_PRIORITY_CONSTRAINTS); assertCommandBehavior( diff --git a/collated/test/A0142073R.md b/collated/test/A0142073R.md index 8436c8b58cee..15880d8dd6a6 100644 --- a/collated/test/A0142073R.md +++ b/collated/test/A0142073R.md @@ -1,306 +1,386 @@ # A0142073R -###### \java\guitests\EditDescriptionCommandTest.java +###### \java\guitests\EditCommandTest.java ``` java package guitests; import org.junit.Test; +import seedu.taskell.commons.core.Messages; import seedu.taskell.commons.exceptions.IllegalValueException; +import seedu.taskell.model.task.Description; +import seedu.taskell.model.task.TaskDate; +import seedu.taskell.model.task.TaskPriority; +import seedu.taskell.model.task.TaskTime; import seedu.taskell.testutil.TestTask; import seedu.taskell.testutil.TestUtil; import static org.junit.Assert.assertTrue; -import static seedu.taskell.logic.commands.edit.EditDescriptionCommand.MESSAGE_EDIT_TASK_SUCCESS; +import static seedu.taskell.logic.commands.EditCommand.MESSAGE_EDIT_TASK_SUCCESS; +import static seedu.taskell.logic.commands.EditCommand.MESSAGE_USAGE; +import static seedu.taskell.logic.commands.EditCommand.COMMAND_WORD; -public class EditDescriptionCommandTest extends TaskManagerGuiTest { +public class EditCommandTest extends TaskManagerGuiTest { - @Test - public void edit() throws IllegalValueException { + public static final String INVALID_PRIORITY = "4"; + public static final String INVALID_END_TIME = "12am"; + public static final String INVALID_START_TIME = "1159pm"; + public static final String INVALID_TIME = "1400"; + public static final String VALID_DATE = "30-10-2100"; + public static final String VALID_START_DATE = "1-12-2100"; + public static final String VALID_END_DATE = "10-12-2100"; + public static final String INVALID_DATE = "30Nov"; - // edit the first in the list + @Test + public void edit_desc_exceptionThrown() throws IllegalValueException { TestTask[] currentList = td.getTypicalTasks(); int targetIndex = 1; - String newDescription = "make tea"; - asserteditSuccess(targetIndex, currentList, newDescription); - // edit the last in the list + // edit the description of first task in the list + TestTask oldTask = currentList[targetIndex - 1]; + TestTask newTask = new TestTask(new Description("make tea"), oldTask.getTaskType(), oldTask.getTaskPriority(), + oldTask.getStartTime(), oldTask.getEndTime(), oldTask.getStartDate(), oldTask.getEndDate(), + oldTask.getRecurringType(), oldTask.getTaskStatus(), oldTask.getTags()); + + commandBox.runCommand("edit " + targetIndex + " desc: make tea"); + currentList[0] = newTask; + assertEditSuccess(targetIndex, currentList, oldTask, newTask); + + // edit the description of last task in the list targetIndex = currentList.length; - newDescription = "get ready for software demo"; - asserteditSuccess(targetIndex, currentList, newDescription); + oldTask = currentList[targetIndex - 1]; + newTask = new TestTask(new Description("finish software demo"), oldTask.getTaskType(), + oldTask.getTaskPriority(), oldTask.getStartTime(), oldTask.getEndTime(), oldTask.getStartDate(), + oldTask.getEndDate(), oldTask.getRecurringType(), oldTask.getTaskStatus(), oldTask.getTags()); + + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " desc: finish software demo"); + assertEditSuccess(targetIndex, currentList, oldTask, newTask); // invalid index - commandBox.runCommand("edit-name " + currentList.length + 1 + " go shopping"); - assertResultMessage("The task index provided is invalid"); + commandBox.runCommand(COMMAND_WORD + " " + currentList.length + 1 + " desc: go shopping"); + assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); // invalid command - commandBox.runCommand("edit-desc "); - assertResultMessage("Invalid command format! \n" + "edit-desc" - + "/"+ "edit-name" - + ": Edits the description task identified by the index number used in the last task listing.\n" - + "Parameters: INDEX (must be a positive integer) NEW_DESCRIPTION\n" - + "Example: " + "edit-desc" + " 1 buy cake\n" - + "Example: " + "edit-name" + " 2 do 2103t\n"); + commandBox.runCommand(COMMAND_WORD); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); - } + commandBox.runCommand(COMMAND_WORD + " " + COMMAND_WORD); + assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); - /** - * Runs the edit command to edit the description of a task at specified - * index and confirms the result is correct. - * - * @param targetIndexOneIndexed - * e.g. to edit the description of first task in the list, 1 - * should be given as the target index. - * @param currentList - * A copy of the current list of tasks (before deletion). - * @throws IllegalValueException - */ - private void asserteditSuccess(int targetIndexOneIndexed, final TestTask[] currentList, String newDescription) - throws IllegalValueException { - TestTask taskToedit = currentList[targetIndexOneIndexed - 1]; // -1 - // because - // array - // uses - // zero - // indexing - TestTask newTask = TestUtil.editTaskDescription(taskToedit, newDescription); - - commandBox.runCommand("edit-desc " + targetIndexOneIndexed + " " + newDescription); - TestTask[] current = TestUtil.replaceTaskFromList(currentList, newTask, targetIndexOneIndexed - 1); - // confirm the list now contains all previous tasks except the edited - // task - assertTrue(taskListPanel.isListMatching(current)); + commandBox.runCommand( + COMMAND_WORD + " " + targetIndex + " desc: finish homework " + " st: 8am " + " desc: submit homework"); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); - // confirm the result message is correct - assertResultMessage(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToedit, newTask)); } -} -``` -###### \java\guitests\EditEndTimeCommandTest.java -``` java -package guitests; - -import org.junit.Test; - -import seedu.taskell.commons.exceptions.IllegalValueException; -import seedu.taskell.testutil.TestTask; -import seedu.taskell.testutil.TestUtil; - -import static org.junit.Assert.assertTrue; -import static seedu.taskell.logic.commands.edit.EditEndTimeCommand.MESSAGE_EDIT_TASK_SUCCESS; - -public class EditEndTimeCommandTest extends TaskManagerGuiTest { - @Test - public void edit() throws IllegalValueException { - - // edit the first in the list + public void edit_priority_exceptionThrown() throws IllegalValueException { TestTask[] currentList = td.getTypicalTasks(); int targetIndex = 1; - String newDate = "5pm"; - asserteditSuccess(targetIndex, currentList, newDate); - // edit the last in the list + // edit the priority of first task in the list + targetIndex = 1; + TestTask oldTask = currentList[targetIndex - 1]; + TestTask newTask = new TestTask(oldTask.getDescription(), oldTask.getTaskType(), + new TaskPriority(TaskPriority.DEFAULT_PRIORITY), oldTask.getStartTime(), oldTask.getEndTime(), + oldTask.getStartDate(), oldTask.getEndDate(), oldTask.getRecurringType(), oldTask.getTaskStatus(), + oldTask.getTags()); + + commandBox.runCommand("edit " + targetIndex + " p: " + TaskPriority.DEFAULT_PRIORITY); + currentList[0] = newTask; + assertEditSuccess(targetIndex, currentList, oldTask, newTask); + + // edit the priority of last task in the list targetIndex = currentList.length; - newDate = "12.35am"; - asserteditSuccess(targetIndex, currentList, newDate); + oldTask = currentList[targetIndex - 1]; + newTask = new TestTask(oldTask.getDescription(), oldTask.getTaskType(), + new TaskPriority(TaskPriority.HIGH_PRIORITY), oldTask.getStartTime(), oldTask.getEndTime(), + oldTask.getStartDate(), oldTask.getEndDate(), oldTask.getRecurringType(), oldTask.getTaskStatus(), + oldTask.getTags()); + + commandBox.runCommand("edit " + targetIndex + " p: " + TaskPriority.HIGH_PRIORITY); + assertEditSuccess(targetIndex, currentList, oldTask, newTask); // invalid index - commandBox.runCommand("edit-endTime " + currentList.length + 1 + " 10am"); - assertResultMessage("The task index provided is invalid"); + commandBox.runCommand(COMMAND_WORD + " " + currentList.length + 1 + " p: " + TaskPriority.DEFAULT_PRIORITY); + assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); - //invalid command format - commandBox.runCommand("edit-endTime 1 to 4pm "); - assertResultMessage("Invalid command format! \n" - + "edit-endTime" - + ": Edits the end time of a task identified by the index number used in the last task listing.\n" - + "Parameters: INDEX (must be a positive integer) NEW_END_TIME\n" - + "Example: " + "edit-endTime" + " 1 9pm "); + // invalid command + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " p:"); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); + + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " p: " + TaskPriority.DEFAULT_PRIORITY + " "+ TaskPriority.HIGH_PRIORITY); + + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); - } + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " p: " + INVALID_PRIORITY); + assertResultMessage("Invalid command format! \n" + TaskPriority.MESSAGE_TASK_PRIORITY_CONSTRAINTS); - /** - * Runs the edit command to edit the end time of a task at specified - * index and confirms the result is correct. - * - * @param targetIndexOneIndexed - * e.g. to edit the end time of first task in the list, 1 - * should be given as the target index. - * @param currentList - * A copy of the current list of tasks (before deletion). - * @throws IllegalValueException - */ - private void asserteditSuccess(int targetIndexOneIndexed, final TestTask[] currentList, String newDate) - throws IllegalValueException { - TestTask taskToedit = currentList[targetIndexOneIndexed - 1]; // -1 - // because - // array - // uses - // zero - // indexing - TestTask newTask = TestUtil.editTaskEndTime(taskToedit, newDate); - - commandBox.runCommand("edit-endTime " + targetIndexOneIndexed + " " + newDate); - TestTask[] current = TestUtil.replaceTaskFromList(currentList, newTask, targetIndexOneIndexed - 1); - // confirm the list now contains all previous tasks except the edited - // task - assertTrue(taskListPanel.isListMatching(current)); + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " p: " + TaskPriority.DEFAULT_PRIORITY + " st: 8am" + + " p: " + TaskPriority.HIGH_PRIORITY); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); - // confirm the result message is correct - assertResultMessage(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToedit, newTask)); } -} -``` -###### \java\guitests\EditPriorityCommandTest.java -``` java -package guitests; + @Test + public void edit_startTime_exceptionThrown() throws IllegalValueException { + TestTask[] currentList = td.getTypicalTasks(); + int targetIndex = 1; -import org.junit.Test; + // edit the start time of first task in the list + targetIndex = 1; + TestTask oldTask = currentList[targetIndex - 1]; + TestTask newTask = new TestTask(oldTask.getDescription(), oldTask.getTaskType(), oldTask.getTaskPriority(), + new TaskTime(TaskTime.MIDNIGHT), oldTask.getEndTime(), oldTask.getStartDate(), oldTask.getEndDate(), + oldTask.getRecurringType(), oldTask.getTaskStatus(), oldTask.getTags()); -import seedu.taskell.commons.exceptions.IllegalValueException; -import seedu.taskell.testutil.TestTask; -import seedu.taskell.testutil.TestUtil; + commandBox.runCommand("edit " + targetIndex + " st: " + TaskTime.MIDNIGHT); + currentList[0] = newTask; + assertEditSuccess(targetIndex, currentList, oldTask, newTask); -import static org.junit.Assert.assertTrue; -import static seedu.taskell.logic.commands.edit.EditPriorityCommand.MESSAGE_EDIT_TASK_SUCCESS; + // edit the start time of last task in the list + targetIndex = currentList.length; + oldTask = currentList[targetIndex - 1]; + newTask = new TestTask(oldTask.getDescription(), oldTask.getTaskType(), oldTask.getTaskPriority(), + new TaskTime(TaskTime.DEFAULT_START_TIME), oldTask.getEndTime(), oldTask.getStartDate(), + oldTask.getEndDate(), oldTask.getRecurringType(), oldTask.getTaskStatus(), oldTask.getTags()); -public class EditPriorityCommandTest extends TaskManagerGuiTest { + commandBox.runCommand("edit " + targetIndex + " st: " + TaskTime.DEFAULT_START_TIME); + assertEditSuccess(targetIndex, currentList, oldTask, newTask); - @Test - public void edit() throws IllegalValueException { + // invalid index + commandBox.runCommand(COMMAND_WORD + " " + currentList.length + 1 + " st: " + TaskTime.DEFAULT_START_TIME); + assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + + // invalid command + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " st:"); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); + + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " st: " + TaskTime.DEFAULT_START_TIME + " " + TaskTime.DEFAULT_END_TIME); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); + + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " st: " + INVALID_TIME); + assertResultMessage("Invalid command format! \n" + TaskTime.MESSAGE_TASK_TIME_CONSTRAINTS); - // edit the first in the list + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " st: " + TaskTime.DEFAULT_START_TIME + " p: " + + TaskPriority.DEFAULT_PRIORITY + " st: " + TaskTime.DEFAULT_START_TIME); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); + + } + + @Test + public void edit_endTime_exceptionThrown() throws IllegalValueException { TestTask[] currentList = td.getTypicalTasks(); int targetIndex = 1; - String newPriority = "3"; - asserteditSuccess(targetIndex, currentList, newPriority); - // edit the last in the list + // edit the end time of first task in the list + targetIndex = 1; + TestTask oldTask = currentList[targetIndex - 1]; + TestTask newTask = new TestTask(oldTask.getDescription(), oldTask.getTaskType(), oldTask.getTaskPriority(), + oldTask.getStartTime(), new TaskTime(TaskTime.DEFAULT_END_TIME), oldTask.getStartDate(), + oldTask.getEndDate(), oldTask.getRecurringType(), oldTask.getTaskStatus(), oldTask.getTags()); + + commandBox.runCommand("edit " + targetIndex + " et: " + TaskTime.DEFAULT_END_TIME); + currentList[0] = newTask; + assertEditSuccess(targetIndex, currentList, oldTask, newTask); + + // edit the end time of last task in the list targetIndex = currentList.length; - newPriority = "2"; - asserteditSuccess(targetIndex, currentList, newPriority); + oldTask = currentList[targetIndex - 1]; + newTask = new TestTask(oldTask.getDescription(), oldTask.getTaskType(), oldTask.getTaskPriority(), + oldTask.getStartTime(), new TaskTime(TaskTime.DEFAULT_END_TIME), oldTask.getStartDate(), + oldTask.getEndDate(), oldTask.getRecurringType(), oldTask.getTaskStatus(), oldTask.getTags()); + + commandBox.runCommand("edit " + targetIndex + " et: " + TaskTime.DEFAULT_END_TIME); + assertEditSuccess(targetIndex, currentList, oldTask, newTask); // invalid index - commandBox.runCommand("edit-priority " + currentList.length + 1 + " 2"); - assertResultMessage("The task index provided is invalid"); + commandBox.runCommand(COMMAND_WORD + " " + currentList.length + 1 + " et: 3pm"); + assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); // invalid command - commandBox.runCommand("edit-priority "); - assertResultMessage("Invalid command format! \n" + "edit-priority" - + ": Edits the priority of a task identified by the index number used in the last task listing.\n" - + "Parameters: INDEX (must be a positive integer) NEW_PRIORITY(must be between 0 to 3)\n" + "Example: " + "edit-priority" + " 1 3 "); + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " et:"); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); + + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " et: " + TaskTime.DEFAULT_END_TIME + " " + TaskTime.DEFAULT_START_TIME); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); - } + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " et: " + INVALID_TIME); + assertResultMessage("Invalid command format! \n" + TaskTime.MESSAGE_TASK_TIME_CONSTRAINTS); - /** - * Runs the edit command to edit the priority of a task at specified - * index and confirms the result is correct. - * - * @param targetIndexOneIndexed - * e.g. to edit the priority of first task in the list, 1 - * should be given as the target index. - * @param currentList - * A copy of the current list of tasks (before deletion). - * @throws IllegalValueException - */ - private void asserteditSuccess(int targetIndexOneIndexed, final TestTask[] currentList, String newPriority) - throws IllegalValueException { - TestTask taskToedit = currentList[targetIndexOneIndexed - 1]; // -1 - // because - // array - // uses - // zero - // indexing - TestTask newTask = TestUtil.editTaskPriority(taskToedit, newPriority); - - commandBox.runCommand("edit-priority " + targetIndexOneIndexed + " " + newPriority); - TestTask[] current = TestUtil.replaceTaskFromList(currentList, newTask, targetIndexOneIndexed - 1); - // confirm the list now contains all previous tasks except the edited - // task - assertTrue(taskListPanel.isListMatching(current)); + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " et: " + TaskTime.DEFAULT_START_TIME + " p: " + + TaskPriority.DEFAULT_PRIORITY + " et: " + TaskTime.DEFAULT_START_TIME); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); - // confirm the result message is correct - assertResultMessage(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToedit, newTask)); } -} -``` -###### \java\guitests\EditStartTimeCommandTest.java -``` java -package guitests; + @Test + public void edit_endDate_exceptionThrown() throws IllegalValueException { + TestTask[] currentList = td.getTypicalTasks(); + int targetIndex = 1; -import org.junit.Test; + // edit the end date of first task in the list + targetIndex = 1; + TestTask oldTask = currentList[targetIndex - 1]; + TestTask newTask = new TestTask(oldTask.getDescription(), oldTask.getTaskType(), oldTask.getTaskPriority(), + oldTask.getStartTime(), oldTask.getEndTime(), oldTask.getStartDate(), new TaskDate(VALID_END_DATE), + oldTask.getRecurringType(), oldTask.getTaskStatus(), oldTask.getTags()); -import seedu.taskell.commons.exceptions.IllegalValueException; -import seedu.taskell.testutil.TestTask; -import seedu.taskell.testutil.TestUtil; + commandBox.runCommand("edit " + targetIndex + " ed: " + VALID_END_DATE); + currentList[0] = newTask; + assertEditSuccess(targetIndex, currentList, oldTask, newTask); -import static org.junit.Assert.assertTrue; -import static seedu.taskell.logic.commands.edit.EditStartTimeCommand.MESSAGE_EDIT_TASK_SUCCESS; + // invalid index + commandBox.runCommand(COMMAND_WORD + " " + currentList.length + 1 + " ed: " + VALID_END_DATE); + assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); -public class EditStartTimeCommandTest extends TaskManagerGuiTest { + // invalid command + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " ed:"); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); + + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " ed: " + VALID_END_DATE + " " + VALID_END_DATE); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); - @Test - public void edit() throws IllegalValueException { + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " ed: " + INVALID_DATE); + assertResultMessage("Invalid command format! \n" + TaskDate.MESSAGE_TASK_DATE_CONSTRAINTS); - // edit the first in the list + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " ed: " + VALID_END_DATE + " st: " + + TaskTime.DEFAULT_START_TIME + " ed: " + VALID_END_DATE); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); + + } + + @Test + public void edit_startDate_exceptionThrown() throws IllegalValueException { TestTask[] currentList = td.getTypicalTasks(); int targetIndex = 1; - String newTime = "5am"; - asserteditSuccess(targetIndex, currentList, newTime); - // edit the last in the list + // edit the start date of first task in the list + targetIndex = 1; + TestTask oldTask = currentList[targetIndex - 1]; + TestTask newTask = new TestTask(oldTask.getDescription(), oldTask.getTaskType(), oldTask.getTaskPriority(), + oldTask.getStartTime(), oldTask.getEndTime(), new TaskDate(VALID_DATE), oldTask.getEndDate(), + oldTask.getRecurringType(), oldTask.getTaskStatus(), oldTask.getTags()); + + commandBox.runCommand("edit " + targetIndex + " sd: " + VALID_DATE); + currentList[0] = newTask; + assertEditSuccess(targetIndex, currentList, oldTask, newTask); + + // edit the start date of last task in the list targetIndex = currentList.length; - newTime = "12.35pm"; - asserteditSuccess(targetIndex, currentList, newTime); + oldTask = currentList[targetIndex - 1]; + newTask = new TestTask(oldTask.getDescription(), oldTask.getTaskType(), oldTask.getTaskPriority(), + oldTask.getStartTime(), oldTask.getEndTime(), new TaskDate(VALID_DATE), oldTask.getEndDate(), + oldTask.getRecurringType(), oldTask.getTaskStatus(), oldTask.getTags()); + + commandBox.runCommand("edit " + targetIndex + " sd: " + VALID_DATE); + assertEditSuccess(targetIndex, currentList, oldTask, newTask); // invalid index - commandBox.runCommand("edit-startTime " + currentList.length + 1 + " 1am"); - assertResultMessage("The task index provided is invalid"); + commandBox.runCommand(COMMAND_WORD + " " + currentList.length + 1 + " sd: " + VALID_DATE); + assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + + // invalid command + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " sd:"); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); + + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " sd: " + VALID_START_DATE + " " + VALID_END_DATE); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); + + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " sd: " + INVALID_DATE); + assertResultMessage("Invalid command format! \n" + TaskDate.MESSAGE_TASK_DATE_CONSTRAINTS); + + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " sd: " + VALID_DATE + " st: " + + TaskTime.DEFAULT_START_TIME + " sd: " + VALID_DATE); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); + + } + + @Test + public void edit_fewPart_exceptionThrown() throws IllegalValueException { + TestTask[] currentList = td.getTypicalTasks(); + int targetIndex = 1; - //invalid command format - commandBox.runCommand("edit-startTime 3 to 4pm "); - assertResultMessage("Invalid command format! \n" - + "edit-startTime" - + ": Edits the start time of a task identified by the index number used in the last task listing.\n" - + "Parameters: INDEX (must be a positive integer) NEW_START_TIME\n" - + "Example: edit-startTime 1 2pm "); + // edit the description, start time and priority of first task in the + // list + TestTask oldTask = currentList[targetIndex - 1]; + TestTask newTask = new TestTask(new Description("send emails"), oldTask.getTaskType(), + new TaskPriority(TaskPriority.DEFAULT_PRIORITY), new TaskTime("12am"), oldTask.getEndTime(), + oldTask.getStartDate(), oldTask.getEndDate(), oldTask.getRecurringType(), oldTask.getTaskStatus(), + oldTask.getTags()); + + commandBox.runCommand("edit " + targetIndex + " desc: send emails st: " + TaskTime.DEFAULT_START_TIME + " p: " + + TaskPriority.DEFAULT_PRIORITY); + currentList[0] = newTask; + assertEditSuccess(targetIndex, currentList, oldTask, newTask); + + // edit start time and end time of first task in the + // list + oldTask = currentList[targetIndex - 1]; + newTask = new TestTask(oldTask.getDescription(), oldTask.getTaskType(), oldTask.getTaskPriority(), + new TaskTime(TaskTime.DEFAULT_START_TIME), new TaskTime(TaskTime.DEFAULT_END_TIME), + oldTask.getStartDate(), oldTask.getEndDate(), oldTask.getRecurringType(), oldTask.getTaskStatus(), + oldTask.getTags()); + + commandBox.runCommand( + "edit " + targetIndex + " st: " + TaskTime.DEFAULT_START_TIME + " et: " + TaskTime.DEFAULT_END_TIME); + currentList[0] = newTask; + assertEditSuccess(targetIndex, currentList, oldTask, newTask); + + // edit start date and end date of first task in the + // list + oldTask = currentList[targetIndex - 1]; + newTask = new TestTask(oldTask.getDescription(), oldTask.getTaskType(), oldTask.getTaskPriority(), + oldTask.getStartTime(), oldTask.getEndTime(), new TaskDate(VALID_START_DATE), + new TaskDate(VALID_END_DATE), oldTask.getRecurringType(), oldTask.getTaskStatus(), oldTask.getTags()); + + commandBox.runCommand("edit " + targetIndex + " sd: " + VALID_START_DATE + " ed: " + VALID_END_DATE); + currentList[0] = newTask; + assertEditSuccess(targetIndex, currentList, oldTask, newTask); + // invalid command + commandBox.runCommand("edit " + targetIndex + " st: st: st: "); + currentList[0] = newTask; + assertResultMessage("Invalid command format! \n" + TaskTime.MESSAGE_TASK_TIME_CONSTRAINTS); + + commandBox.runCommand("edit " + targetIndex + " st: " + TaskTime.DEFAULT_START_TIME + " st: " + + TaskTime.DEFAULT_START_TIME + " st: " + TaskTime.DEFAULT_START_TIME); + currentList[0] = newTask; + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); + + commandBox.runCommand(COMMAND_WORD + " " + targetIndex + " sd: " + VALID_DATE + " st: " + + TaskTime.DEFAULT_START_TIME + " sd: " + VALID_DATE); + assertResultMessage("Invalid command format! \n" + MESSAGE_USAGE); } /** - * Runs the edit command to edit the start time of a task at specified + * Runs the edit command to edit the description of a task at specified * index and confirms the result is correct. * * @param targetIndexOneIndexed - * e.g. to edit the start time of first task in the list, 1 - * should be given as the target index. + * e.g. to edit the first task in the list, 1 should be given as + * the target index. * @param currentList * A copy of the current list of tasks (before deletion). + * @param oldTask + * A copy of the old task which is not updated + * @param newTask + * A copy of the updated task * @throws IllegalValueException */ - private void asserteditSuccess(int targetIndexOneIndexed, final TestTask[] currentList, String newTime) - throws IllegalValueException { - TestTask taskToedit = currentList[targetIndexOneIndexed - 1]; // -1 - // because - // array - // uses - // zero - // indexing - TestTask newTask = TestUtil.editTaskStartTime(taskToedit, newTime); - - commandBox.runCommand("edit-startTime " + targetIndexOneIndexed + " " + newTime); + private void assertEditSuccess(int targetIndexOneIndexed, final TestTask[] currentList, TestTask oldTask, + TestTask newTask) throws IllegalValueException { + TestTask[] current = TestUtil.replaceTaskFromList(currentList, newTask, targetIndexOneIndexed - 1); // confirm the list now contains all previous tasks except the edited // task assertTrue(taskListPanel.isListMatching(current)); // confirm the result message is correct - assertResultMessage(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToedit, newTask)); + assertResultMessage(String.format(MESSAGE_EDIT_TASK_SUCCESS, oldTask, newTask)); } } + ``` ###### \java\guitests\ListDateCommandTest.java ``` java @@ -308,29 +388,55 @@ package guitests; import org.junit.Test; +import static seedu.taskell.logic.commands.list.ListDateCommand.COMMAND_WORD; + import seedu.taskell.commons.exceptions.IllegalValueException; +import seedu.taskell.model.task.TaskDate; import seedu.taskell.testutil.TestTask; import static org.junit.Assert.assertTrue; public class ListDateCommandTest extends TaskManagerGuiTest { + private static final String INVALID_DATE = "123"; + @Test - public void listDate() throws IllegalValueException { + public void listDate_valid_thrownException() throws IllegalValueException { // list 2 tasks in the list TestTask[] currentList = td.getTypicalTasks(); String date = "1-1-2100"; - assertlistDateSuccess(currentList, date, td.archivePastEmails, td.borrowBooks, td.collectParcel, + assertListDateSuccess(currentList, date, td.archivePastEmails, td.borrowBooks, td.collectParcel, td.discardBooks, td.editPowerpoint, td.fixbugs, td.getNewUniform); // no tasks to list date = "1-1-2016"; - assertlistDateSuccess(currentList, date); + assertListDateSuccess(currentList, date); + + } + + @Test + public void listDate_invalid_thrownException() throws IllegalValueException { + + // list 2 tasks in the list + TestTask[] currentList = td.getTypicalTasks(); + String date = "1-1-2100"; + + // no tasks to list + date = "1-1-2016"; + assertListDateSuccess(currentList, date); // invalid command format - commandBox.runCommand("list-date"); - assertResultMessage("Invalid command format! \n" + "list-date" + ": Lists tasks on a specific date.\n" + commandBox.runCommand(COMMAND_WORD); + assertResultMessage("Invalid command format! \n" + COMMAND_WORD + ": Lists tasks on 1 specific date only.\n" + + "Parameters: DATE (must be a positive integer)\n" + "Example: " + "list-date" + " 8-8-2016 "); + + commandBox.runCommand(COMMAND_WORD + " " + INVALID_DATE); + assertResultMessage("Invalid command format! \n" + COMMAND_WORD + ": Lists tasks on 1 specific date only.\n" + + "Parameters: DATE (must be a positive integer)\n" + "Example: " + "list-date" + " 8-8-2016 "); + + commandBox.runCommand(COMMAND_WORD + " " + TaskDate.DEFAULT_DATE + " " + TaskDate.getTomorrowDate()); + assertResultMessage("Invalid command format! \n" + COMMAND_WORD + ": Lists tasks on 1 specific date only.\n" + "Parameters: DATE (must be a positive integer)\n" + "Example: " + "list-date" + " 8-8-2016 "); } @@ -347,10 +453,10 @@ public class ListDateCommandTest extends TaskManagerGuiTest { * @param * @throws IllegalValueException */ - private void assertlistDateSuccess(final TestTask[] currentList, String date, TestTask... values) + private void assertListDateSuccess(final TestTask[] currentList, String date, TestTask... values) throws IllegalValueException { - commandBox.runCommand("list-date " + date); + commandBox.runCommand(COMMAND_WORD + " " + date); assertListSize(values.length); // confirm the result message is correct @@ -368,16 +474,21 @@ package guitests; import org.junit.Test; +import static seedu.taskell.logic.commands.list.ListPriorityCommand.COMMAND_WORD; + import seedu.taskell.commons.exceptions.IllegalValueException; import seedu.taskell.model.task.TaskPriority; +import seedu.taskell.model.task.TaskTime; import seedu.taskell.testutil.TestTask; import static org.junit.Assert.assertTrue; public class ListPriorityCommandTest extends TaskManagerGuiTest { + + private static final String INVALID_PRIORITY = "777"; @Test - public void listPriority() throws IllegalValueException { + public void listPriority_valid_exceptionThrown() throws IllegalValueException { // list 2 tasks in the list TestTask[] currentList = td.getTypicalTasks(); @@ -387,13 +498,35 @@ public class ListPriorityCommandTest extends TaskManagerGuiTest { //no tasks to list priority = TaskPriority.NO_PRIORITY; assertlistPrioritySuccess(currentList, priority); + + priority = TaskPriority.HIGH_PRIORITY; + assertlistPrioritySuccess(currentList, priority); + + } + + @Test + public void listPriority_invalid_exceptionThrown() throws IllegalValueException { // invalid command format - commandBox.runCommand("list-priority"); - assertResultMessage("Invalid command format! \n" + "list-priority" + ": List the task with the specified priority. " + commandBox.runCommand(COMMAND_WORD); + assertResultMessage("Invalid command format! \n" + COMMAND_WORD + ": List the task with the specified priority. " + "Parameters: INDEX (must be between 0 and 3 inclusive).\n" + "Example: list-priority 1"); - + + commandBox.runCommand(COMMAND_WORD + " p:" + INVALID_PRIORITY); + assertResultMessage("Invalid command format! \n" + COMMAND_WORD + ": List the task with the specified priority. " + + "Parameters: INDEX (must be between 0 and 3 inclusive).\n" + + "Example: list-priority 1"); + + commandBox.runCommand(COMMAND_WORD + " " + TaskTime.DEFAULT_START_TIME); + assertResultMessage("Invalid command format! \n" + COMMAND_WORD + ": List the task with the specified priority. " + + "Parameters: INDEX (must be between 0 and 3 inclusive).\n" + + "Example: list-priority 1"); + + //invalid priority value + commandBox.runCommand(COMMAND_WORD + " " + INVALID_PRIORITY); + assertResultMessage(TaskPriority.MESSAGE_TASK_PRIORITY_CONSTRAINTS); + } /** @@ -402,16 +535,16 @@ public class ListPriorityCommandTest extends TaskManagerGuiTest { * * @param priority * e.g. to list tasks with priority 1, "1" - * should be given as the date. + * should be given as the priority. * @param currentList - * A copy of the current list of tasks (before prioritising). + * A copy of the current list of tasks (before prioritizing). * @param * @throws IllegalValueException */ private void assertlistPrioritySuccess(final TestTask[] currentList, String priority, TestTask... values) throws IllegalValueException { - commandBox.runCommand("list-priority " + priority); + commandBox.runCommand(COMMAND_WORD + " " + priority); assertListSize(values.length); // confirm the result message is correct @@ -419,39 +552,20 @@ public class ListPriorityCommandTest extends TaskManagerGuiTest { // confirm the list now contains all previous tasks except the edited // task assertTrue(taskListPanel.isListMatching(values)); + } } ``` ###### \java\seedu\taskell\testutil\TestUtil.java ``` java - - public static TestTask editTaskDescription(TestTask taskToEdit, String newDescription) + + public static TestTask editTask(TestTask taskToEdit, String newDescription) throws IllegalValueException { TestTask newTask = new TestTask(new Description(newDescription), taskToEdit.getTaskType(), taskToEdit.getTaskPriority(), taskToEdit.getStartTime(), taskToEdit.getEndTime(), - taskToEdit.getStartDate(), taskToEdit.getEndDate(), taskToEdit.getTaskStatus(), taskToEdit.getTags()); - return newTask; - } - - public static TestTask editTaskStartTime(TestTask taskToEdit, String newStartTime) throws IllegalValueException { - TestTask newTask = new TestTask(taskToEdit.getDescription(), taskToEdit.getTaskType(), - taskToEdit.getTaskPriority(), new TaskTime(newStartTime), taskToEdit.getEndTime(), - taskToEdit.getStartDate(), taskToEdit.getEndDate(), taskToEdit.getTaskStatus(), taskToEdit.getTags()); - return newTask; - } - - public static TestTask editTaskEndTime(TestTask taskToEdit, String newEndTime) throws IllegalValueException { - TestTask newTask = new TestTask(taskToEdit.getDescription(), taskToEdit.getTaskType(), - taskToEdit.getTaskPriority(), taskToEdit.getStartTime(), new TaskTime(newEndTime), - taskToEdit.getStartDate(), taskToEdit.getEndDate(), taskToEdit.getTaskStatus(), taskToEdit.getTags()); - return newTask; - } - - public static TestTask editTaskPriority(TestTask taskToEdit, String newPriority) throws IllegalValueException { - TestTask newTask = new TestTask(taskToEdit.getDescription(), taskToEdit.getTaskType(), - new TaskPriority(newPriority), taskToEdit.getStartTime(), taskToEdit.getEndTime(), - taskToEdit.getStartDate(), taskToEdit.getEndDate(), taskToEdit.getTaskStatus(), taskToEdit.getTags()); + taskToEdit.getStartDate(), taskToEdit.getEndDate(), taskToEdit.getRecurringType(), taskToEdit.getTaskStatus(), taskToEdit.getTags()); return newTask; } + ``` diff --git a/collated/test/A0142130A.md b/collated/test/A0142130A.md index f2f5abd8205a..1998ed24e63f 100644 --- a/collated/test/A0142130A.md +++ b/collated/test/A0142130A.md @@ -3,7 +3,7 @@ ``` java @Test - public void find_nonEmptyList_byTag() { + public void find_nonEmptyList_byTag_success() { assertFindResult("find chicken"); //no results assertFindResult("find friends", td.archivePastEmails, td.borrowBooks); //multiple results @@ -13,7 +13,7 @@ } @Test - public void find_byMoreThanOneTags() { + public void find_byMoreThanOneTags_success() { assertFindResult("find friends owesMoney", td.borrowBooks); } @@ -31,7 +31,7 @@ import seedu.taskell.testutil.TestTask; public class FindTagCommandTest extends TaskManagerGuiTest { @Test - public void findTag_nonEmptyList() { + public void findTag_nonEmptyList_success() { assertFindResult("find-tag chicken"); //no results assertFindResult("find-tag friends", td.archivePastEmails, td.borrowBooks); //multiple results @@ -41,12 +41,12 @@ public class FindTagCommandTest extends TaskManagerGuiTest { } @Test - public void findTag_MulitpleKeywords() { + public void findTag_multipleKeywords_success() { assertFindResult("find-tag friends owesMoney", td.archivePastEmails, td.borrowBooks, td.collectParcel); //multiple results } @Test - public void findTag_emptyList(){ + public void findTag_emptyList_noResults(){ commandBox.runCommand("clear"); assertFindResult("find-tag friends"); //no results } @@ -101,7 +101,7 @@ public class SaveStorageLocationCommandTest extends TaskManagerGuiTest { private static final String DEFAULT_SAVE_LOCATION = TestApp.SAVE_LOCATION_FOR_TESTING; @Test - public void saveToValidFilePath() throws DataConversionException, IOException, DuplicateTaskException { + public void saveToValidFilePath_success() throws DataConversionException, IOException, DuplicateTaskException { String testFilePath = "./src/test/data/SaveLocationCommandTest/newStorageLocation/"; commandBox.runCommand("save " + testFilePath); assertWriteToJsonSuccess(); @@ -153,14 +153,19 @@ import org.junit.Test; import guitests.guihandles.TaskCardHandle; import seedu.taskell.logic.commands.UndoCommand; +import seedu.taskell.model.History; +import seedu.taskell.model.HistoryManager; import seedu.taskell.testutil.TestTask; import seedu.taskell.testutil.TestUtil; public class UndoCommandTest extends TaskManagerGuiTest { + private static final String UNDO = "undo"; + private History history = HistoryManager.getInstance(); + @Test public void undoAdd() { - UndoCommand.clearCommandHistory(); + history.clear(); TestTask[] currentList = td.getTypicalTasks(); TestTask taskToAdd = td.holdMeeting; @@ -170,15 +175,15 @@ public class UndoCommandTest extends TaskManagerGuiTest { assertAddSuccess(taskToAdd, currentList); currentList = TestUtil.addTasksToList(currentList, taskToAdd); - commandBox.runCommand("undo 1"); + commandBox.runCommand(UNDO); assertDeleteSuccess(currentList.length, currentList); - UndoCommand.clearCommandHistory(); + history.clear(); } @Test public void undoDelete() { - UndoCommand.clearCommandHistory(); + history.clear(); TestTask[] currentList = td.getTypicalTasks(); TestTask taskToDelete = currentList[0]; @@ -189,15 +194,15 @@ public class UndoCommandTest extends TaskManagerGuiTest { assertDeleteSuccess(target, currentList); currentList = TestUtil.removeTaskFromList(currentList, 1); - commandBox.runCommand("undo 1"); + commandBox.runCommand(UNDO); assertAddSuccess(taskToDelete, currentList); - UndoCommand.clearCommandHistory(); + history.clear(); } @Test public void undoAndRedoAdd() { - UndoCommand.clearCommandHistory(); + history.clear(); TestTask[] currentList = td.getTypicalTasks(); TestTask taskToAdd = td.holdMeeting; @@ -207,19 +212,19 @@ public class UndoCommandTest extends TaskManagerGuiTest { assertAddSuccess(taskToAdd, currentList); currentList = TestUtil.addTasksToList(currentList, taskToAdd); - commandBox.runCommand("undo 1"); + commandBox.runCommand(UNDO); assertDeleteSuccess(currentList.length, currentList); currentList = TestUtil.removeTaskFromList(currentList, currentList.length); - commandBox.runCommand("undo 1"); + commandBox.runCommand(UNDO); assertAddSuccess(taskToAdd, currentList); - UndoCommand.clearCommandHistory(); + history.clear(); } @Test public void undoAndRedoDelete() { - UndoCommand.clearCommandHistory(); + history.clear(); TestTask[] currentList = td.getTypicalTasks(); TestTask taskToDelete = currentList[0]; @@ -230,15 +235,15 @@ public class UndoCommandTest extends TaskManagerGuiTest { assertDeleteSuccess(target, currentList); currentList = TestUtil.removeTaskFromList(currentList, 1); - commandBox.runCommand("undo 1"); + commandBox.runCommand(UNDO); assertAddSuccess(taskToDelete, currentList); currentList = TestUtil.addTasksToList(currentList, taskToDelete); target = currentList.length; - commandBox.runCommand("undo 1"); + commandBox.runCommand(UNDO); assertDeleteSuccess(target, currentList); - UndoCommand.clearCommandHistory(); + history.clear(); } private void assertAddSuccess(TestTask taskToAdd, TestTask... currentList) { @@ -271,11 +276,13 @@ package guitests; import org.junit.Test; +import seedu.taskell.logic.commands.ViewCalendarCommand; + public class ViewCalendarCommandTest extends TaskManagerGuiTest { @Test - public void viewCal() { - String expected = "Displayed calendar."; + public void viewCal_success() { + String expected = ViewCalendarCommand.MESSAGE_SUCCESS; commandBox.runCommand("calendar"); assertResultMessage(expected); @@ -285,3 +292,50 @@ public class ViewCalendarCommandTest extends TaskManagerGuiTest { } } ``` +###### \java\guitests\ViewHistoryCommandTest.java +``` java +package guitests; + +import java.util.ArrayList; + +import org.junit.Test; + +import seedu.taskell.logic.commands.ViewHistoryCommand; +import seedu.taskell.model.HistoryManager; +import seedu.taskell.ui.DisplayPanel; + +public class ViewHistoryCommandTest extends TaskManagerGuiTest { + + @Test + public void viewHistory_success() { + HistoryManager.getInstance().clear(); + + String expectedMessage = ViewHistoryCommand.MESSAGE_SUCCESS; + + commandBox.runCommand("add smth by tmr"); + commandBox.runCommand("history"); + assertResultMessage(expectedMessage); + String text = displayPanel.getText(); + assertListMatch(text, HistoryManager.getInstance().getListCommandText()); + +// commandBox.runCommand("edit 1 desc: find socks"); +// commandBox.runCommand("hist"); +// assertResultMessage(expectedMessage); +// text = displayPanel.getText(); +// assertListMatch(text, HistoryManager.getInstance().getListCommandText()); + + HistoryManager.getInstance().clear(); + } + + private void assertListMatch(String result, ArrayList list) { + String expected = DisplayPanel.MESSAGE_DISPLAY_HISTORY; + + for (int i=0; i