diff --git a/docs/AboutUs.md b/docs/AboutUs.md
index 0d69bafa1c04..be1c83e9519e 100644
--- a/docs/AboutUs.md
+++ b/docs/AboutUs.md
@@ -10,9 +10,9 @@ We are a team of students studying CS2103 based in the [School of Computing, Nat
* Features implemented:
* [Support for non floating task and integration of Date Time Model](https://github.com/CS2103AUG2016-T14-C4/main/pull/45)
* [Ability to Change Storage](https://github.com/CS2103AUG2016-T14-C4/main/pull/64)
- * [More natural commands]()
- * [Google Calendar Integration(IP)]()
-* Code written: [[functional code]()][[test code]()][[docs]()]
+ * [More natural commands](https://github.com/CS2103AUG2016-T14-C4/main/pull/69)
+ * [Alias Commands](https://github.com/CS2103AUG2016-T14-C4/main/pull/82)
+* Code written: [[functional code](https://github.com/CS2103AUG2016-T14-C4/main/blob/master/collated/main/A0144939R.md)][[test code](https://github.com/CS2103AUG2016-T14-C4/main/blob/master/collated/test/A0144939R.md)][[docs](https://github.com/CS2103AUG2016-T14-C4/main/blob/master/collated/docs/A0144939R.md)]
* Other major contributions:
* Did the initial refactoring from AddressBook to ToDoList [[#39](https://github.com/CS2103AUG2016-T14-C4/main/pull/39) ]
* Set up Codacy
diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md
index bb1c8e3709a1..2a569816aaba 100644
--- a/docs/DeveloperGuide.md
+++ b/docs/DeveloperGuide.md
@@ -252,6 +252,7 @@ Priority | As a ... | I want to ... | So that I can...
`* * *` | user | add a task without start time and deadline| keep track of general, non-time based tasks
`* * *` | user | add an event with start time and close time|
`* * *` | user | add an event/task with tag|
+`* * *` | user | add recurring tasks
`* * *` | user | delete a task| remove tasks that I do not have to take any further action on
`* * *` |user | undo my previous action | recover from commands entered by mistake
`* * *` | user | find a task from to-do list| find details of tasks without having to go through the entire list
@@ -259,8 +260,9 @@ Priority | As a ... | I want to ... | So that I can...
`* * *` | user | see the entire to-do list | know the number of task/ event that I have
`* * *` | user | specify the file location of the task list | store the list in a more convenient location (such as Dropbox)
`* *` | user | mark a task as completed | distinguish between completed and pending tasks
-`* *` | user | sync events and tasks with due dates with Google Calendar| collate my tasks
`* *` |user | be able to mark certain tasks as important | easily distinguish tasks that require attention/action to be taken
+`* *` | user | alias commands to symbols
+`* *` | user | do a live search for commands
## Appendix B : Use Cases
@@ -283,7 +285,30 @@ Use case ends.
1b. The task name already exists on the list.
> MESS shows a message to inform user that task already exists
Use case ends.
+
+
+#### Use case: Alias command
+
+**MSS**
+1. User requests to alias a command
+2. MESS aliases the command to the given symbol
+Use case ends.
+
+**Extensions**
+
+1a. The symbol is already aliased to another command
+> MESS changes the mapping to the new command.
+Use case ends.
+
+1b. The symbol is a standard command name(Eg: add, edit)
+> MESS shows an error message.
+Use case ends.
+
+1c. The command already has an alias
+> MESS maps the given symbol to the command, as a command can have multiple aliases
+Use case ends.
+
#### Use case: Delete task by task name
diff --git a/docs/UserGuide.md b/docs/UserGuide.md
index af848069a2f6..afdbb8f7fda4 100644
--- a/docs/UserGuide.md
+++ b/docs/UserGuide.md
@@ -20,15 +20,16 @@
e.g. typing **`help`** and pressing Enter will open the help window.
5. Some example commands you can try:
* **`list`** : lists all tasks
- * **`add`**`meeting`: adds a task named CS2103 Tutorial
- * **`find`**`meeting `: searches the task named tutorial
+ * **`add`**`CS2103 Tutorial`: adds a task named CS2103 Tutorial
+ * **`alias`**`add a`: aliases the add command to the 'a' key
+ * **`find`**`tutorial `: searches the task named tutorial
* **`delete`**`1`: delete the first task in the list
* **`complete`** `1`: mark the first task as completed
* **`uncomplete`** `1`: mark the completed first task on the list as not completed
- * **`update`**`1 presentation c/10/10/2016:1200` : updates first task on the list to presentation having a deadline on 10/10/2016 on 12:00 while the number '1' is the index of task on the list
+ * **`update`**`1 name presentation ends tomorrow` : updates first task on the list to presentation having a deadline tomorrow while the number '1' is the index of task on the list
* **`undo`** : undo previous one action
* **`pin`**`1` : pin the first task in the list
- * **'change-to'**`1`: change the storage location
+ * **'change-to'**`data/taskmanager.xml`: change the storage location
* **`unpin`**`1` : unpin the pinned first task in the list
* **`exit`** :exit the program
6. Refer to the [Features](#features) section below for details of each command.
@@ -41,32 +42,45 @@
* The order of parameters is fixed.
* Words in `UPPER_CASE` are the parameters.
* Words in `SQUARE_BRACKET` are optional.
+
#### Adding a task or event: `add`
Adds a task to the to-do list
-Format: `add TASK_NAME [s/START_DATE:START_TIME c/CLOSE_DATE:CLOSE_TIME t/TAG r/NUMBER_OF_WEEKLY_RECURRING_TASK]`
+Format: `add TASK_NAME [starts START_DATETIME ends CLOSE_DATETIME tag TAG recurs NUMBER_OF_WEEKLY_RECURRING_TASK]`
> Date format of START_DATE and CLOSE_DATE includes words like today, tomorrow, 3 days from now, day after tomorrow, noon, 12pm, 6am
* `TASK_NAME` need not be unique.
* If there is no argument, the task will become floating.
* `START_DATE` refer to the starting date and time of an event. For a task, the timestamp will be automatically saved as start date and time when the task is created. User can input start date and time for events.
-* `TAG` is for users to write tags for different tasks. Mulitple tags are available by typing `t/TAG t/TAG`.
+* `TAG` is for users to write tags for different tasks. Mulitple tags are available by typing `tag TAG tag TAG`.
* `NUMBER_OF_RECURRING TASK` is for users to create weekly recurring task. For example, when NUMBER_OF_WEEKLY_RECURRING_TASK is 1 which means one more tasks will be created with the openTime and endTime one weekly later.
-
Examples:
-* `add proposal c/10-10-2016:2100`
Adds a proposal task with a deadline on 10-10-2016 at 21:00
-* `add meeting s/01-10-2016:1300 c/01-10-2016:2200`
Adds a meeting event which start on 1-10-2016 at 1 p.m. and ends at 10 p.m.
+* `add proposal ends tomorrow`
Adds a proposal task with a deadline 24 hours from now
+* `add meeting starts tomorrow 1pm ends tomorrow 3pm`
Adds a meeting event which start tomorrow at 1pm and ends tomorrow at 3pm
* `add shopping`
Adds a floating task named revision test which has not specify the start and end date
-* `add tutorial t/cs2103`
Adds a flaoting task named tutorial with a tag CS2013
-* `add quiz t/cs2102 t/easy`
Adds a flaoting task named tutorial with a tag CS2012 and easy
-* `add test s/today r/1`
Adds a task start today and recur for one more week.
+* `add tutorial tag cs2103`
Adds a floating task named tutorial with a tag CS2013
+* `add quiz tag cs2102 tag easy`
Adds a floating task named tutorial with a tag CS2012 and easy
+* `add test starts today recurs 1`
Adds a task start today and recur for one more week.
-Examples on date time flexibility:
-* `add project c/3 days from now`
Adds a project task three days later from the time you input this command
-
+#### Aliasing a command: `alias`
+Aliases a command to a symbol
+Format: `alias COMMAND_NAME SYMBOL`
+
+> Once aliased, the original command will still continue to work. Hence, symbols cannot be command names.
+> One symbol can map to at most one command
+
+* `COMMAND_NAME` Must be a valid command
+* `SYMBOL` refers to the symbol you wish to alias to. SYMBOL cannot be a command name.
+
+Examples:
+* `alias add +`
Aliases the add command to the symbol +
+* `alias alias q`
Aliases the alias command to the symbol q
+
+
+
#### Deleting a task : `delete`
Deletes a specific task by task name or index from the to-do list.
Format: `delete TASK_NAME` or `delete INDEX`
@@ -78,7 +92,7 @@ Examples:
Deletes `meeting` task.
* `delete 1`
Deletes the first task in the to-do list.
-
+
#### Marking a task as completed: `complete`
Marks a specific task by index from the to-do list.
FormatL `complete INDEX`
@@ -118,7 +132,7 @@ Format: `unpin INDEX`
Example:
* `unpin 1`
unpin the pinned and first task on the list.
-
+
#### Listing all persons : `list`
Shows a list of tasks and events in the todo list.
Format: `list`
@@ -136,7 +150,7 @@ Format: `find KEYWORD` or `find t/TAG`
Examples:
* `find meeting`
Returns tasks having name `meeting`
-* `find t/cs2103`
+* `find tag cs2103`
Returns tasks having tag `cs2103`
@@ -149,27 +163,34 @@ Format: `searchbox`
+
+
+
+
#### Update entries : `update`
Update a specific task.
-Format: `update INDEX [TASKNAME s/START_DATE:START_TIME c/CLOSE_DATE:CLOSE_TIME t/TAG rt/TO_REMOVE_TAG]`
+Format: `update INDEX [name TASKNAME starts STARTDATETIME ends ENDDATETIME tag TAG remove-tag TO_REMOVE_TAG]`
> * INDEX refers to the number appears on the list in front the task name.
-> * The TAG here will be added to the referred task and the orginial tag remains. If you want to delete a tag, use `rt/TO_REMOVE_TAG` to delete tag by name.
+> * THE task name is optional, but needs to be preceeded by name
+> * The TAG here will be added to the referred task and the orginial tag remains. If you want to delete a tag, use `remove-tag TO_REMOVE_TAG` to delete tag by name.
> * TO_REMOVE_TAG refers to the tag (or tags) that you want to be removed by typing the tags' name that you want to delete.
> * You can choose what to update. It depends on you whether you want to update only one information or update multiple information.
Examples:
-* `update 2 shopping c/03/10/2016:2100`
- update the taks name of the second task on the list to shopping and the start time to 3/10/2016 9 p.m.
+* `update 2 name shopping ends 9pm`
+ update the task name of the second task on the list to shopping and the start time to 3/10/2016 9 p.m.
-* `update 1 t/cs2103`
+* `update 1 tag cs2103`
add the tag of the first task on to-do list to cs2103
-* `update 3 c/three hours later`
- update the taks name of the third task on the list to a deadline three hours after you type this command
+* `update 3 ends three hours later`
+ update the task name of the third task on the list to a deadline three hours after you type this command
-* `update 2 t/family rt/friends`
+* `update 2 tag family remove-tag friends`
add a tag family to the second task and remove the tag named friends
+
+
#### Undo action : `undo`
@@ -177,7 +198,7 @@ Undo the previous action.
Format: `undo`
> * Will only undo `add`, `delete` and `update` actions.
-
+
#### Viewing help : `help`
Show the help menu. Format: `help`
> Help is also shown if you enter an incorrect command e.g. `123abc`
@@ -202,7 +223,7 @@ Example: 'change-to data/taskmanager.xml'
## FAQ
**Q**: Can I add event which have a start date and time to my to-do list ?
-**A**: Yes, you can create an event by typing command with a start and end date. For example, you have a trip from 10/10/2016 8:00 to 13/10/2016 21:00. You can type command like this: `add trip s/8am 10th October c/9pm 13th October`.
+**A**: Yes, you can create an event by typing command with a start and end date. For example, you have a trip from 10/10/2016 8:00 to 13/10/2016 21:00. You can type command like this: `add trip starts 8am 10th October ends 9pm 13th October`.
**Q**: If I don't know the deadline of my task yet, can I still add my task?
@@ -215,16 +236,18 @@ In this example, you can see shopping is a floating task without a start time an
Command | Format
-------- | :--------
-Add | `add TASK_NAME [s/START_DATE:START_TIME c/CLOSE_DATE:CLOSE_TIME t/TAG]`
+Add | `add TASK_NAME [starts START_DATE_TIME ends CLOSE_DATE_TIME tag TAG]`
+Alias | `alias add a`
Delete | `delete TASK_NAME` or `delete INDEX`
Complete | `complete INDEX`
Uncomplete | `uncomplete INDEX`
List | `list`
Find | `find KEYWORD` or `find t/TAG`
-Update | `update INDEX [TASKNAME s/START_DATE:START_TIME c/CLOSE_DATE:CLOSE_TIME t/TAG rt/TO_REMOVE_TAG]`
+Update | `update INDEX [name NAME starts START_DATE_TIME ends CLOSE_DATE_TIME tag TAG remove-tag TAG]`
Undo | `undo`
Pin | `pin`
Unpin | `unpin`
Live Search | `searchbox`
+Change Storage | `change-to`
Help | `help`
Exit | `exit`
diff --git a/src/main/java/seedu/task/commons/logic/CommandKeys.java b/src/main/java/seedu/task/commons/logic/CommandKeys.java
new file mode 100644
index 000000000000..b23ba1e97e44
--- /dev/null
+++ b/src/main/java/seedu/task/commons/logic/CommandKeys.java
@@ -0,0 +1,44 @@
+//@@author A0144939R
+package seedu.task.commons.logic;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.stream.Collectors;
+
+/**
+ * Represents all commands in the TaskManager
+ * @author advaypal
+ *
+ */
+public class CommandKeys {
+
+ public enum Commands {
+ ADD("add"),
+ ALIAS("alias"),
+ CLEAR("clear"),
+ COMPLETE("complete"),
+ CHANGE_TO("change-to"),
+ DELETE("delete"),
+ EXIT("exit"),
+ FIND("find"),
+ HELP("help"),
+ LIST("list"),
+ PIN("pin"),
+ SEARCH_BOX("searchbox"),
+ SELECT("select"),
+ UNDO("undo"),
+ UPDATE("update"),
+ UNCOMPLETE("uncomplete"),
+ UNPIN("unpin");
+
+ private String value;
+
+ Commands(String command) {
+ this.value = command;
+ }
+
+ }
+ //create hashmap from command names to ENUM values
+ public static final HashMap commandKeyMap = (HashMap) Arrays.stream(Commands.values()).collect(Collectors.toMap(command -> command.value, command -> command));
+
+}
diff --git a/src/main/java/seedu/task/logic/LogicManager.java b/src/main/java/seedu/task/logic/LogicManager.java
index 8c6e4f3a81b1..cc9d4a572b15 100644
--- a/src/main/java/seedu/task/logic/LogicManager.java
+++ b/src/main/java/seedu/task/logic/LogicManager.java
@@ -1,6 +1,7 @@
package seedu.task.logic;
import javafx.collections.ObservableList;
+
import seedu.task.commons.core.ComponentManager;
import seedu.task.commons.core.LogsCenter;
import seedu.task.logic.commands.Command;
@@ -27,7 +28,7 @@ public class LogicManager extends ComponentManager implements Logic {
public LogicManager(Model model, Storage storage) {
this.model = model;
- this.parser = new ParseSwitcher();
+ this.parser = new ParseSwitcher(model.getAliasMap());
this.previousCommand = null;
}
diff --git a/src/main/java/seedu/task/logic/commands/AddCommand.java b/src/main/java/seedu/task/logic/commands/AddCommand.java
index 02634a759a36..f37f8cb03b05 100644
--- a/src/main/java/seedu/task/logic/commands/AddCommand.java
+++ b/src/main/java/seedu/task/logic/commands/AddCommand.java
@@ -1,6 +1,7 @@
//@@author A0144939R
package seedu.task.logic.commands;
+import java.time.temporal.ChronoUnit;
import java.util.HashSet;
import java.util.Set;
@@ -22,15 +23,17 @@ public class AddCommand extends UndoableCommand {
public static final String COMMAND_WORD = "add";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a task to the task list. "
- + "Parameters: NAME s/start-datetime c/closedatetime [t/TAG r/NUMBER_TO_RECUR]...\n"
+ + "Parameters: NAME starts DATETIME ends DATETIME tag TAG1 tag TAG2 recurs NUMBER_TO_RECUR\n"
+ "Example: " + COMMAND_WORD
- + " Finish CS2103";
+ + " Finish CS2103 ends tomorrow starts today tag important tag urgent";
public static final String MESSAGE_SUCCESS = "New task added: %1$s";
public static final String MESSAGE_ROLLBACK_SUCCESS = "Added task removed: %1$s";
public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task list";
public static final String MESSAGE_WRONG_NUMBER_OF_RECURRENCE = "Maximum number of recurrence is 20!";
public static final String MESSAGE_NEGATIVE_NUMBER_OF_RECURRENCE = "The number recurrence should be positive!";
+
private final Task toAdd;
+ private final int amountRecurring;
/**
@@ -45,67 +48,62 @@ public AddCommand(String name, String openTime, String closeTime, Set ta
tagSet.add(new Tag(tagName));
}
+ this.amountRecurring = recurrence;
+
this.toAdd = new Task(
new Name(name),
- new DateTime(openTime),
- new DateTime(closeTime),
+ DateTime.fromUserInput(openTime),
+ DateTime.fromUserInput(closeTime),
false,
false,
- new UniqueTagList(tagSet),
- recurrence
- );
+ new UniqueTagList(tagSet)
+ );
}
- //@@author A0153467Y
+ //@@author A0153467Y
@Override
public CommandResult execute() {
assert model != null;
+
+ if (this.amountRecurring > MAX_NUMBER_OF_RECURRENCE_WEEK) {
+ return new CommandResult(false, MESSAGE_WRONG_NUMBER_OF_RECURRENCE);
+ } else if (this.amountRecurring < 0) {
+ return new CommandResult(false, MESSAGE_NEGATIVE_NUMBER_OF_RECURRENCE);
+ }
+
try {
-
- if (toAdd.getRecurrentWeek() > MAX_NUMBER_OF_RECURRENCE_WEEK) {
- return new CommandResult(false, MESSAGE_WRONG_NUMBER_OF_RECURRENCE);
- }
-
- if(toAdd.getRecurrentWeek() < 0) {
- return new CommandResult(false, MESSAGE_NEGATIVE_NUMBER_OF_RECURRENCE);
- }
-
- if (toAdd.getRecurrentWeek() == 0) {
- model.addTask(toAdd);
- return new CommandResult(true, String.format(MESSAGE_SUCCESS, toAdd));
- } else {
- model.addTask(toAdd);
- createRecurringTask(toAdd.getRecurrentWeek());
- }
+ createRecurringTask(this.amountRecurring + 1);
} catch (UniqueTaskList.DuplicateTaskException e) {
return new CommandResult(false, MESSAGE_DUPLICATE_TASK);
+ } catch (IllegalValueException e) {
+ assert false : "Not possible!";
}
return new CommandResult(true, String.format(MESSAGE_SUCCESS, toAdd));
}
- //@@author A0153467Y
- private void createRecurringTask(int recurringTime) {
- try{
- for(int i=1;i<=recurringTime;i++) {
- Task recurrTask=new Task(
- toAdd.getName(),
- new DateTime(toAdd.getOpenTime().getDateTimeValue().get().plusSeconds(604800*i).toString()),
- new DateTime(toAdd.getCloseTime().getDateTimeValue().get().plusSeconds(604800*i).toString()),
- false,
- false,
- toAdd.getTags(),
- 0
- );
- model.addTask(recurrTask);
- }
- } catch (IllegalValueException e) {
- assert false : "Impossible";
+ //@@author A0141052Y
+ /**
+ * Creates a set number of Tasks, with distance between two adjacent tasks being 1 week, and adds it to the
+ * TaskList.
+ * @param timesToRecur number of weeks to recur the Task for
+ * @throws IllegalValueException if there's a duplicate task or if
+ */
+ private void createRecurringTask(int timesToRecur) throws IllegalValueException {
+ for (int i = 0; i < timesToRecur; i++) {
+ DateTime newOpenTime = DateTime.fromDateTimeOffset(toAdd.getOpenTime(), i * 7, ChronoUnit.DAYS);
+ DateTime newCloseTime = DateTime.fromDateTimeOffset(toAdd.getCloseTime(), i * 7, ChronoUnit.DAYS);
+ Task newTask = new Task(
+ toAdd.getName(),
+ newOpenTime,
+ newCloseTime,
+ false,
+ false,
+ toAdd.getTags());
+ model.addTask(newTask);
}
}
-
-
-
-//@author
+ //@@author
+
@Override
public CommandResult rollback() {
assert model != null;
diff --git a/src/main/java/seedu/task/logic/commands/AliasCommand.java b/src/main/java/seedu/task/logic/commands/AliasCommand.java
new file mode 100644
index 000000000000..e0924bd81d3d
--- /dev/null
+++ b/src/main/java/seedu/task/logic/commands/AliasCommand.java
@@ -0,0 +1,60 @@
+//@@author A0144939R
+package seedu.task.logic.commands;
+
+import seedu.task.commons.logic.CommandKeys;
+import seedu.task.commons.logic.CommandKeys.Commands;
+
+/**
+ * Alias command
+ */
+public class AliasCommand extends Command {
+
+ public static final String COMMAND_WORD = "alias";
+
+ public static final String MESSAGE_USAGE = COMMAND_WORD + ": Aliases a command to a given string "
+ + "Parameters: ALIASED VALUE"
+ + "Example: " + COMMAND_WORD
+ + "add a";
+
+ public static final String MESSAGE_SUCCESS = "Command successfully aliased";
+ public static final String MESSAGE_FAILURE = "Error, cannot alias command";
+
+ private String commandString;
+ private String alias;
+
+
+ public AliasCommand(String command, String alias) {
+ this.commandString = command.trim();
+ this.alias = alias.trim();
+ }
+
+
+ @Override
+ public CommandResult execute() {
+ if(isValidAliasCommandPair(alias, commandString)) {
+ Commands command = CommandKeys.commandKeyMap.get(commandString);
+ model.setMapping(command, alias);
+ return new CommandResult(true, MESSAGE_SUCCESS);
+ } else {
+ return new CommandResult(false, MESSAGE_FAILURE);
+ }
+ }
+ /**
+ * Checks if a given alias can be mapped to given command
+ * Note: one command can have multiple aliases
+ * @param alias Alias specified by user
+ * @param command Command the alias aliases to
+ * @return
+ */
+ public boolean isValidAliasCommandPair(String alias, String command) {
+ //check that alias is not null and that alias is not a command
+ //checks that command is valid command
+ if (alias != null && command != null) {
+ return CommandKeys.commandKeyMap.containsKey(commandString) && CommandKeys.commandKeyMap.get(commandString) != null;
+ } else {
+ return false;
+ }
+ }
+
+}
+
diff --git a/src/main/java/seedu/task/logic/commands/UpdateCommand.java b/src/main/java/seedu/task/logic/commands/UpdateCommand.java
index 43bae3151011..b6d12047c278 100644
--- a/src/main/java/seedu/task/logic/commands/UpdateCommand.java
+++ b/src/main/java/seedu/task/logic/commands/UpdateCommand.java
@@ -20,9 +20,9 @@ public class UpdateCommand extends UndoableCommand {
public static final String COMMAND_WORD = "update";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Update a task in the task list.\n "
- + "Parameters: INDEX (must be a positive integer) [NAME t/TAGADD rt/TAGREMOVE]...\n"
+ + "Parameters: INDEX (must be a positive integer) [NAME tag TAGADD remove-tag TAGREMOVE]...\n"
+ "Example: " + COMMAND_WORD
- + " 1 cs2103 t/quiz";
+ + " 1 cs2103 tag quiz ends tomorrow";
public static final String MESSAGE_UPDATE_TASK_SUCCESS = "Updated Task: %1$s";
public static final String MESSAGE_ROLLBACK_SUCCESS = "Rollback changes to updated task!";
@@ -38,14 +38,14 @@ public class UpdateCommand extends UndoableCommand {
public UpdateCommand(int targetIndex, String name, String openTime, String closeTime, Set tagsToAdd, Set tagsToRemove) throws IllegalValueException {
this.targetIndex = targetIndex;
- this.newTaskName = (name.isEmpty()) ? null : new Name(name);
+ this.newTaskName = (name == null || name.isEmpty()) ? null : new Name(name);
final Set tagSet = new HashSet<>();
for (String tagName : tagsToAdd) {
tagSet.add(new Tag(tagName));
}
- this.newOpenTime = new DateTime(openTime);
- this.newCloseTime = new DateTime(closeTime);
+ this.newOpenTime = DateTime.fromUserInput(openTime);
+ this.newCloseTime = DateTime.fromUserInput(closeTime);
this.newTaskTags = new UniqueTagList(tagSet);
this.removedTags = tagsToRemove;
@@ -90,8 +90,7 @@ public CommandResult execute() {
updatedCloseTime,
taskToUpdate.getImportance(),
taskToUpdate.getComplete(),
- newTaskTags,
- taskToUpdate.getRecurrentWeek()
+ newTaskTags
);
} catch (IllegalValueException e1) {
return new CommandResult(false, e1.getMessage());
diff --git a/src/main/java/seedu/task/logic/parser/AddParser.java b/src/main/java/seedu/task/logic/parser/AddParser.java
index cc3bc39adb0e..dd920ae52902 100644
--- a/src/main/java/seedu/task/logic/parser/AddParser.java
+++ b/src/main/java/seedu/task/logic/parser/AddParser.java
@@ -5,6 +5,8 @@
import java.util.HashSet;
import java.util.Set;
+import java.util.StringJoiner;
+
import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.logic.commands.AddCommand;
@@ -13,19 +15,19 @@
public class AddParser extends BaseParser {
- private final String FLAG_NAME = "";
- private final String FLAG_START_TIME = "s";
- private final String FLAG_CLOSE_TIME = "c";
- private final String FLAG_TAGS = "t";
- private final String FLAG_RECURRING = "r";
+ private final static String FLAG_NAME = "name";
+ private final static String FLAG_START_TIME = "starts";
+ private final static String FLAG_CLOSE_TIME = "ends";
+ private final static String FLAG_TAGS = "tag";
+ private final static String FLAG_RECURRING = "recurs";
- private final String[] KEYWORD_ARGS_REQUIRED = new String[]{FLAG_NAME};
- private final String[] KEYWORD_ARGS_OPTIONAL = new String[]{FLAG_START_TIME,
+ private final static String[] KEYWORD_ARGS_REQUIRED = new String[]{FLAG_NAME};
+ private final static String[] KEYWORD_ARGS_OPTIONAL = new String[]{FLAG_START_TIME,
FLAG_CLOSE_TIME,
FLAG_TAGS,
FLAG_RECURRING
};
-
+
@Override
public Command parse(String command, String arguments) {
this.extractArguments(arguments);
@@ -61,4 +63,42 @@ private Set getTags() {
return new HashSet<>();
}
}
-}
\ No newline at end of file
+
+ //@@author A0144939R
+ /**
+ * Extracts the arguments and puts them in a HashMap
+ * This method has been overriden to support the different nature of the add command's arguments
+ */
+ @Override
+ protected void extractArguments(String args) {
+ argumentsTable.clear();
+ String[] segments = args.trim().split(" ");
+ String currentKey = "name";
+ StringJoiner joiner = new StringJoiner(" ");
+ for (String segment : segments) {
+ if (isDelimiter(segment)) {
+ addToArgumentsTable(currentKey, joiner.toString().trim());
+ currentKey = segment;
+ joiner = new StringJoiner(" ");
+ } else {
+ joiner.add(segment);
+ }
+ }
+ addToArgumentsTable(currentKey, joiner.toString());
+ }
+
+ /**
+ * Checks if a string is a valid delimiter for the add command
+ * @param argument a string from the user input
+ * @return true if the String is a valid delimiter, and false otherwise
+ */
+ private boolean isDelimiter(String argument) {
+ for(int i = 0; i < KEYWORD_ARGS_OPTIONAL.length; i++) {
+ if(argument.equals(KEYWORD_ARGS_OPTIONAL[i])) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/src/main/java/seedu/task/logic/parser/AliasParser.java b/src/main/java/seedu/task/logic/parser/AliasParser.java
new file mode 100644
index 000000000000..4fa73c81fa6f
--- /dev/null
+++ b/src/main/java/seedu/task/logic/parser/AliasParser.java
@@ -0,0 +1,40 @@
+//@@author A0144939R
+package seedu.task.logic.parser;
+
+import static seedu.task.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
+
+import seedu.task.logic.commands.AliasCommand;
+import seedu.task.logic.commands.Command;
+import seedu.task.logic.commands.IncorrectCommand;
+
+public class AliasParser extends BaseParser {
+
+ private final String FLAG_ALIAS_COMMAND = "aliasCommand";
+ private final String FLAG_ALIAS_VALUE ="aliasValue";
+ private final int FLAG_ALIAS_COMMAND_LENGTH = 2;
+
+ @Override
+ public Command parse(String command, String arguments) {
+ this.extractArguments(arguments);
+ String aliasCommand = getSingleKeywordArgValue(FLAG_ALIAS_COMMAND);
+ String aliasValue = getSingleKeywordArgValue(FLAG_ALIAS_VALUE);
+ if( aliasCommand != null && aliasValue != null) {
+ return new AliasCommand(aliasCommand, aliasValue);
+ } else {
+ return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AliasCommand.MESSAGE_USAGE));
+ }
+
+ }
+
+ @Override
+ protected void extractArguments(String args) {
+ argumentsTable.clear();
+ String[] segments = args.trim().split(" ");
+ if(segments.length == FLAG_ALIAS_COMMAND_LENGTH) {
+ addToArgumentsTable(FLAG_ALIAS_COMMAND, segments[0]);
+ addToArgumentsTable(FLAG_ALIAS_VALUE, segments[1]);
+ }
+ //do nothing if false. The parse method will detect if there's an error.
+ }
+
+}
diff --git a/src/main/java/seedu/task/logic/parser/BaseParser.java b/src/main/java/seedu/task/logic/parser/BaseParser.java
index 1a090996e44a..a2fc78584c7a 100644
--- a/src/main/java/seedu/task/logic/parser/BaseParser.java
+++ b/src/main/java/seedu/task/logic/parser/BaseParser.java
@@ -26,23 +26,8 @@ protected void extractArguments(String args) {
StringJoiner joiner = new StringJoiner(" ");
for (String segment : segments) {
- if (segment.contains("/")) {
- addToArgumentsTable(currentKey, joiner.toString().trim());
-
- String[] kwargComponent = segment.split("/", 2);
-
- // set to next keyword
- currentKey = kwargComponent[0];
-
- joiner = new StringJoiner(" ");
- if (kwargComponent.length > 1) {
- joiner.add(kwargComponent[1]);
- }
-
- continue;
- } else {
- joiner.add(segment);
- }
+ joiner.add(segment);
+
}
addToArgumentsTable(currentKey, joiner.toString());
diff --git a/src/main/java/seedu/task/logic/parser/ParseSwitcher.java b/src/main/java/seedu/task/logic/parser/ParseSwitcher.java
index f0074f891578..976bdb956a2a 100644
--- a/src/main/java/seedu/task/logic/parser/ParseSwitcher.java
+++ b/src/main/java/seedu/task/logic/parser/ParseSwitcher.java
@@ -4,8 +4,10 @@
import static seedu.task.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;
import static seedu.task.commons.core.Messages.MESSAGE_INTERNAL_ERROR;
+import java.util.HashMap;
import java.util.Optional;
+import seedu.task.commons.logic.CommandKeys.Commands;
import seedu.task.logic.commands.Command;
import seedu.task.logic.commands.IncorrectCommand;
@@ -17,10 +19,14 @@
*
*/
public class ParseSwitcher {
-
- private final ParserMapping parserMappings = new ParserMapping();
-
- public ParseSwitcher() { }
+ private final ParserMapping parserMappings;
+ private final HashMap aliasMappings;
+
+ public ParseSwitcher(HashMap aliasMappings) {
+ parserMappings = new ParserMapping(aliasMappings);
+ this.aliasMappings = aliasMappings;
+
+ }
/**
* Parses the user's input and determines the appropriate command
@@ -42,7 +48,6 @@ public Command parseCommand(String userInput) {
parser = selectedParser.get().newInstance();
return parser.parse(commandWord, commandArgs);
} catch (InstantiationException | IllegalAccessException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
return new IncorrectCommand(MESSAGE_INTERNAL_ERROR);
}
diff --git a/src/main/java/seedu/task/logic/parser/ParserMapping.java b/src/main/java/seedu/task/logic/parser/ParserMapping.java
index e94466985d2b..12a965dd0208 100644
--- a/src/main/java/seedu/task/logic/parser/ParserMapping.java
+++ b/src/main/java/seedu/task/logic/parser/ParserMapping.java
@@ -4,9 +4,9 @@
import java.util.HashMap;
import java.util.Optional;
import java.util.logging.Logger;
-
import seedu.task.commons.core.LogsCenter;
-import seedu.task.logic.LogicManager;
+import seedu.task.commons.logic.CommandKeys;
+import seedu.task.commons.logic.CommandKeys.Commands;
/**
* Provides command word and alias mappings
@@ -14,33 +14,36 @@
*
*/
public class ParserMapping {
- HashMap> mappingTable = new HashMap<>();
+ HashMap> mappingTable = new HashMap<>();
private final Logger logger = LogsCenter.getLogger(ParserMapping.class);
+ private final HashMap aliasMappings;
- public ParserMapping() {
+ public ParserMapping(HashMap aliasMappings) {
populateMappings();
+ this.aliasMappings = aliasMappings;
}
-
+
/**
* Populates the command word to command parsers mapping table
*/
private void populateMappings() {
- mappingTable.put("add", AddParser.class);
- mappingTable.put("clear", ClearParser.class);
- mappingTable.put("complete", CompleteParser.class);
- mappingTable.put("change-to", ChangePathParser.class);
- mappingTable.put("delete", DeleteParser.class);
- mappingTable.put("exit", ExitParser.class);
- mappingTable.put("find", FindParser.class);
- mappingTable.put("help", HelpParser.class);
- mappingTable.put("list", ListParser.class);
- mappingTable.put("pin", PinParser.class);
- mappingTable.put("searchbox", SearchParser.class);
- mappingTable.put("select", SelectParser.class);
- mappingTable.put("undo", UndoParser.class);
- mappingTable.put("update", UpdateParser.class);
- mappingTable.put("uncomplete", UncompleteParser.class);
- mappingTable.put("unpin", UnpinParser.class);
+ mappingTable.put(Commands.ADD, AddParser.class);
+ mappingTable.put(Commands.ALIAS, AliasParser.class);
+ mappingTable.put(Commands.CLEAR, ClearParser.class);
+ mappingTable.put(Commands.COMPLETE, CompleteParser.class);
+ mappingTable.put(Commands.CHANGE_TO, ChangePathParser.class);
+ mappingTable.put(Commands.DELETE, DeleteParser.class);
+ mappingTable.put(Commands.EXIT, ExitParser.class);
+ mappingTable.put(Commands.FIND, FindParser.class);
+ mappingTable.put(Commands.HELP, HelpParser.class);
+ mappingTable.put(Commands.LIST, ListParser.class);
+ mappingTable.put(Commands.PIN, PinParser.class);
+ mappingTable.put(Commands.SEARCH_BOX, SearchParser.class);
+ mappingTable.put(Commands.SELECT, SelectParser.class);
+ mappingTable.put(Commands.UNDO, UndoParser.class);
+ mappingTable.put(Commands.UPDATE, UpdateParser.class);
+ mappingTable.put(Commands.UNCOMPLETE, UncompleteParser.class);
+ mappingTable.put(Commands.UNPIN, UnpinParser.class);
}
/**
@@ -48,9 +51,17 @@ private void populateMappings() {
* @param commandWord
* @return
*/
- public Optional> getParserForCommand(String commandWord) {
- if (mappingTable.containsKey(commandWord) && mappingTable.get(commandWord) != null) {
- return Optional.of(mappingTable.get(commandWord));
+ public Optional> getParserForCommand(String commandWord) {
+
+ //check if it's an alias
+ if(aliasMappings.containsKey(commandWord) && aliasMappings.get(commandWord) != null) {
+ Commands command = aliasMappings.get(commandWord);
+ return Optional.of(mappingTable.get(command));
+ }
+
+ if (CommandKeys.commandKeyMap.containsKey(commandWord) && CommandKeys.commandKeyMap.get(commandWord) != null) {
+ Commands command = CommandKeys.commandKeyMap.get(commandWord);
+ return Optional.of(mappingTable.get(command));
} else {
logger.info("[USER COMMAND][" + commandWord + "] not found!");
return Optional.empty();
diff --git a/src/main/java/seedu/task/logic/parser/UpdateParser.java b/src/main/java/seedu/task/logic/parser/UpdateParser.java
index 8d8dca6d81b9..8eb4d85240b1 100644
--- a/src/main/java/seedu/task/logic/parser/UpdateParser.java
+++ b/src/main/java/seedu/task/logic/parser/UpdateParser.java
@@ -6,6 +6,7 @@
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
+import java.util.StringJoiner;
import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.logic.commands.Command;
@@ -13,26 +14,25 @@
import seedu.task.logic.commands.UpdateCommand;
public class UpdateParser extends BaseParser {
- private final String FLAG_NAME = "";
- private final String FLAG_START_TIME = "s";
- private final String FLAG_CLOSE_TIME = "c";
- private final String FLAG_TAGS = "t";
- private final String FLAG_REMOVE_TAGS = "rt";
-
+ private final static String FLAG_NAME = "name";
+ private final static String FLAG_START_TIME = "starts";
+ private final static String FLAG_CLOSE_TIME = "ends";
+ private final static String FLAG_TAGS = "tag";
+ private final static String FLAG_REMOVE_TAGS = "remove-tag";
+ private final static String[] KEYWORD_ARGS_OPTIONAL = new String[]{
+ FLAG_NAME,
+ FLAG_START_TIME,
+ FLAG_CLOSE_TIME,
+ FLAG_TAGS,
+ FLAG_REMOVE_TAGS
+ };
+ //@@author A0144939R
@Override
public Command parse(String command, String arguments) {
this.extractArguments(arguments);
- String[] nameIdPair = extractNameAndId(getSingleKeywordArgValue(FLAG_NAME));
- String name = "";
-
- if (nameIdPair.length < 1) {
- return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, UpdateCommand.MESSAGE_USAGE));
- } else if (nameIdPair.length > 1) {
- name = nameIdPair[1];
- }
-
- Optional possibleIndex = parseIndex(nameIdPair[0]);
+ String index = getSingleKeywordArgValue("index");
+ Optional possibleIndex = parseIndex(index);
if (!possibleIndex.isPresent()) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, UpdateCommand.MESSAGE_USAGE));
@@ -41,7 +41,7 @@ public Command parse(String command, String arguments) {
try {
return new UpdateCommand(
possibleIndex.get(),
- name,
+ getSingleKeywordArgValue(FLAG_NAME),
getSingleKeywordArgValue(FLAG_START_TIME),
getSingleKeywordArgValue(FLAG_CLOSE_TIME),
getTags(FLAG_TAGS),
@@ -59,8 +59,40 @@ private Set getTags(String keyword) {
return new HashSet<>();
}
}
+
+ /**
+ * Extracts the arguments and puts them in a HashMap
+ * This method has been overriden to support the different nature of the update command's arguments
+ */
+ @Override
+ protected void extractArguments(String args) {
+ argumentsTable.clear();
+ String[] segments = args.trim().split(" ");
+ String currentKey = "index";
+ StringJoiner joiner = new StringJoiner(" ");
+ for (String segment : segments) {
+ if (isDelimiter(segment)) {
+ addToArgumentsTable(currentKey, joiner.toString().trim());
+ currentKey = segment;
+ joiner = new StringJoiner(" ");
+ } else {
+ joiner.add(segment);
+ }
+ }
+ addToArgumentsTable(currentKey, joiner.toString());
+ }
- private String[] extractNameAndId(String combinedArgument) {
- return combinedArgument.split("\\s", 2);
+ /**
+ * Checks if a string is a valid delimiter for the add command
+ * @param argument a string from the user input
+ * @return true if the String is a valid delimiter, and false otherwise
+ */
+ private boolean isDelimiter(String argument) {
+ for(int i = 0; i < KEYWORD_ARGS_OPTIONAL.length; i++) {
+ if(argument.equals(KEYWORD_ARGS_OPTIONAL[i])) {
+ return true;
+ }
+ }
+ return false;
}
}
diff --git a/src/main/java/seedu/task/model/Model.java b/src/main/java/seedu/task/model/Model.java
index ba9c794a1fb0..8bbc79aaa5ad 100644
--- a/src/main/java/seedu/task/model/Model.java
+++ b/src/main/java/seedu/task/model/Model.java
@@ -1,8 +1,10 @@
package seedu.task.model;
+import java.util.HashMap;
import java.util.Set;
import seedu.task.commons.core.UnmodifiableObservableList;
+import seedu.task.commons.logic.CommandKeys.Commands;
import seedu.task.model.task.ReadOnlyTask;
import seedu.task.model.task.Task;
import seedu.task.model.task.UniqueTaskList;
@@ -58,5 +60,18 @@ public interface Model {
* keywords
*/
void updateFilteredTaskList(Set keywords);
-
+
+ //@@author A0144939R
+ /**
+ * Gets the alias map
+ * @return The command represented by the alias, or null if no mapping exists
+ */
+ public HashMap getAliasMap();
+
+ /**
+ * Sets mapping for given alias
+ * @param command
+ * @param alias
+ */
+ public void setMapping(Commands command, String alias);
}
diff --git a/src/main/java/seedu/task/model/ModelManager.java b/src/main/java/seedu/task/model/ModelManager.java
index 49125ed0f36c..418b0d8cba97 100644
--- a/src/main/java/seedu/task/model/ModelManager.java
+++ b/src/main/java/seedu/task/model/ModelManager.java
@@ -5,11 +5,13 @@
import seedu.task.commons.core.LogsCenter;
import seedu.task.commons.core.UnmodifiableObservableList;
import seedu.task.commons.events.model.TaskManagerChangedEvent;
+import seedu.task.commons.logic.CommandKeys.Commands;
import seedu.task.commons.util.StringUtil;
import seedu.task.model.task.ReadOnlyTask;
import seedu.task.model.task.Task;
import seedu.task.model.task.UniqueTaskList;
+import java.util.HashMap;
import java.util.Set;
import java.util.logging.Logger;
@@ -22,6 +24,7 @@ public class ModelManager extends ComponentManager implements Model {
private final TaskManager taskManager;
private final FilteredList filteredTasks;
+ private final UserPrefs userPrefs;
/**
* Initializes a ModelManager with the given TaskManager
@@ -36,6 +39,7 @@ public ModelManager(TaskManager src, UserPrefs userPrefs) {
taskManager = new TaskManager(src);
filteredTasks = new FilteredList<>(taskManager.getTasks());
+ this.userPrefs = userPrefs;
}
public ModelManager() {
@@ -45,6 +49,7 @@ public ModelManager() {
public ModelManager(ReadOnlyTaskManager initialData, UserPrefs userPrefs) {
taskManager = new TaskManager(initialData);
filteredTasks = new FilteredList<>(taskManager.getTasks());
+ this.userPrefs = userPrefs;
}
@Override
@@ -190,6 +195,17 @@ public boolean run(ReadOnlyTask task) {
public String toString() {
return "name=" + String.join(", ", nameKeyWords);
}
+
}
+
+ //@@author A0144939R
+ public HashMap getAliasMap() {
+ return userPrefs.getAliasMap();
+ }
+
+ public void setMapping(Commands command, String alias) {
+ userPrefs.setMapping(command, alias);
+ }
+
}
diff --git a/src/main/java/seedu/task/model/UserPrefs.java b/src/main/java/seedu/task/model/UserPrefs.java
index 96786c8cb449..f645d197a570 100644
--- a/src/main/java/seedu/task/model/UserPrefs.java
+++ b/src/main/java/seedu/task/model/UserPrefs.java
@@ -2,13 +2,17 @@
import java.util.Objects;
+import java.util.HashMap;
import seedu.task.commons.core.GuiSettings;
+import seedu.task.commons.logic.CommandKeys.Commands;
/**
* Represents User's preferences.
*/
public class UserPrefs {
-
+ //@@author A0144939R
+ private HashMap aliases = new HashMap();
+ //@@author
public GuiSettings guiSettings;
public GuiSettings getGuiSettings() {
@@ -50,5 +54,23 @@ public int hashCode() {
public String toString(){
return guiSettings.toString();
}
-
+
+ //@@author A0144939R
+ /**
+ * Gets mapping for a given alias.
+ * @param alias: a user defined string
+ * @return The command represented by the alias, or null if no mapping exists
+ */
+ public HashMap getAliasMap() {
+ return aliases;
+ }
+
+ /**
+ * Sets mapping for given alias
+ * @param command
+ * @param alias
+ */
+ public void setMapping(Commands command, String alias) {
+ aliases.put(alias, command);
+ }
}
diff --git a/src/main/java/seedu/task/model/task/DateTime.java b/src/main/java/seedu/task/model/task/DateTime.java
index 09ee5c05b56d..61632bd18724 100644
--- a/src/main/java/seedu/task/model/task/DateTime.java
+++ b/src/main/java/seedu/task/model/task/DateTime.java
@@ -6,6 +6,7 @@
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalUnit;
import java.util.Date;
import java.util.List;
import java.util.Locale;
@@ -26,33 +27,70 @@ public class DateTime {
public final Optional value;
private static PrettyTime p = new PrettyTime();
+
+ //@@author A0141052Y
+ /**
+ * Constructs a DateTime from an Instant
+ * @param dateTime the Instant of the time and date to be represented
+ */
+ public DateTime(Instant dateTime) {
+ if (dateTime == null) {
+ this.value = Optional.empty();
+ return;
+ }
+
+ this.value = Optional.of(dateTime.truncatedTo(ChronoUnit.MINUTES));
+ }
/**
* Validates given Date and Time entered by the user.
- *
+ * @param dateTime the String representation of the input from the user
* @throws IllegalValueException if given date/time string is invalid.
*/
- public DateTime(String dateTime) throws IllegalValueException {
+ public static DateTime fromUserInput(String dateTime) throws IllegalValueException {
if (dateTime == null || dateTime.equals("")) {
- this.value = Optional.empty();
- return;
+ return new DateTime(null);
}
+
if (!isValidDateTime(dateTime)) {
throw new IllegalValueException(MESSAGE_DATETIME_CONSTRAINTS);
}
+
List possibleDates = new PrettyTimeParser().parse(dateTime);
- this.value = Optional.of(possibleDates.get(0).toInstant().truncatedTo(ChronoUnit.MINUTES));
+ return new DateTime(possibleDates.get(0).toInstant());
}
- public DateTime(Long epochMilli, boolean isEpoch) {
- if (epochMilli == null || !isEpoch) {
- this.value = Optional.empty();
- return;
+ /**
+ * Create a new DateTime object using the number of milliseconds from 01-01-1970
+ * @param epochMilli the number of milliseconds elapsed from the epoch
+ * @return a new DateTime object for the specified epoch offset
+ */
+ public static DateTime fromEpoch(Long epochMilli) {
+ if (epochMilli == null) {
+ return new DateTime(null);
}
- this.value = Optional.of(Instant.ofEpochMilli(epochMilli).truncatedTo(ChronoUnit.MINUTES));
+ return new DateTime(Instant.ofEpochMilli(epochMilli));
+ }
+
+ /**
+ * Creates a new DateTime based off an offset from another DateTime
+ * @param offsetFrom the DateTime to offset from
+ * @param amountToAdd the amount of the specified unit to add to the DateTime
+ * @param unit the time unit of the amount
+ * @return a new DateTime object with a value that is offset from another DateTime
+ */
+ public static DateTime fromDateTimeOffset(DateTime offsetFrom, long amountToAdd, TemporalUnit unit) {
+ if (offsetFrom == null || offsetFrom.isEmpty()) {
+ return new DateTime(null);
+ }
+
+ Instant offsetInstant = offsetFrom.value.get();
+ return new DateTime(offsetInstant.plus(amountToAdd, unit));
}
+ //@@author A0144939R
+
/**
* Returns true if a given string is a valid date/time that can be parsed
*
diff --git a/src/main/java/seedu/task/model/task/ReadOnlyTask.java b/src/main/java/seedu/task/model/task/ReadOnlyTask.java
index ff67cb85dd3c..70fb760550ae 100644
--- a/src/main/java/seedu/task/model/task/ReadOnlyTask.java
+++ b/src/main/java/seedu/task/model/task/ReadOnlyTask.java
@@ -14,7 +14,6 @@ public interface ReadOnlyTask {
DateTime getCloseTime();
boolean getImportance();
boolean getComplete();
- int getRecurrentWeek();
/**
* The returned TagList is a deep copy of the internal TagList,
@@ -28,7 +27,9 @@ public interface ReadOnlyTask {
default boolean isSameVisualStateAs(ReadOnlyTask other) {
return other == this // short circuit if same object
|| (other != null // this is first to avoid NPE below
- && other.getName().equals(this.getName()) // state checks here onwards
+
+ // state checks here onwards
+ && other.getName().equals(this.getName())
&& other.getOpenTime().toPrettyString().equals(this.getOpenTime().toPrettyString())
&& other.getCloseTime().toPrettyString().equals(this.getCloseTime().toPrettyString())
&& other.getImportance() == this.getImportance());
@@ -40,7 +41,9 @@ default boolean isSameVisualStateAs(ReadOnlyTask other) {
default boolean isSameStateAs(ReadOnlyTask other) {
return other == this // short circuit if same object
|| (other != null // this is first to avoid NPE below
- && other.getName().equals(this.getName()) // state checks here onwards
+
+ // state checks here onwards
+ && other.getName().equals(this.getName())
&& other.getOpenTime().equals(this.getOpenTime())
&& other.getCloseTime().equals(this.getCloseTime())
&& other.getImportance() == this.getImportance());
@@ -52,14 +55,6 @@ default boolean isSameStateAs(ReadOnlyTask other) {
default String getAsText() {
final StringBuilder builder = new StringBuilder();
builder.append(getName())
- /**
- .append(" Open Time: ")
- .append(getOpenTime())
- .append(" Close Time: ")
- .append(getCloseTime())
- .append("Important: ")
- .append(getImportance())
- **/
.append(" Tags: ");
getTags().forEach(builder::append);
return builder.toString();
diff --git a/src/main/java/seedu/task/model/task/Task.java b/src/main/java/seedu/task/model/task/Task.java
index acbead044471..845a8676dac3 100644
--- a/src/main/java/seedu/task/model/task/Task.java
+++ b/src/main/java/seedu/task/model/task/Task.java
@@ -19,7 +19,6 @@ public class Task implements ReadOnlyTask {
private DateTime closeTime;
private boolean isCompleted;
private boolean isImportant;
- private int recurrentWeek;
private UniqueTagList tags;
public static final String MESSAGE_DATETIME_CONSTRAINTS = "Please ensure that your start and end time combination is valid.";
@@ -27,7 +26,7 @@ public class Task implements ReadOnlyTask {
* Assigns instance variables
* @throws IllegalValueException if DateTime pair is invalid
*/
- public Task(Name name, DateTime openTime, DateTime closeTime, boolean isImportant, boolean isCompleted, UniqueTagList tags, int recurrentWeek) throws IllegalValueException {
+ public Task(Name name, DateTime openTime, DateTime closeTime, boolean isImportant, boolean isCompleted, UniqueTagList tags) throws IllegalValueException {
assert !CollectionUtil.isAnyNull(name, tags);
this.name = name;
this.openTime = openTime;
@@ -35,7 +34,6 @@ public Task(Name name, DateTime openTime, DateTime closeTime, boolean isImportan
this.tags = new UniqueTagList(tags); // protect internal tags from changes in the arg list
this.isCompleted = isCompleted;
this.isImportant = isImportant;
- this.recurrentWeek=recurrentWeek;
if (!isValidDateTimePair()) {
throw new IllegalValueException(MESSAGE_DATETIME_CONSTRAINTS);
}
@@ -59,7 +57,7 @@ private boolean isValidDateTimePair() {
* @throws IllegalValueException
*/
public Task(ReadOnlyTask source) throws IllegalValueException {
- this(source.getName(), source.getOpenTime(), source.getCloseTime(), source.getImportance(), source.getComplete(), source.getTags(), source.getRecurrentWeek());
+ this(source.getName(), source.getOpenTime(), source.getCloseTime(), source.getImportance(), source.getComplete(), source.getTags());
}
@Override
public Name getName() {
@@ -87,11 +85,6 @@ public boolean getComplete() {
return isCompleted;
}
//@@author
-
- @Override
- public int getRecurrentWeek() {
- return recurrentWeek;
- }
@Override
public UniqueTagList getTags() {
@@ -104,7 +97,9 @@ public UniqueTagList getTags() {
public void setTags(UniqueTagList replacement) {
tags.setTags(replacement);
}
- //@@author A0153467Y
+
+ //@@author A0141052Y
+
/**
* Retrieves an immutable version of the task. Will not mutate if task is changed afterwards.
*/
@@ -117,6 +112,8 @@ public ReadOnlyTask getImmutable() {
}
}
+ //@@author A0153467Y
+
/**
* Sets the task's importance flag
* @param isImportant is a variable to show whether the task is important or not
diff --git a/src/main/java/seedu/task/storage/XmlAdaptedTask.java b/src/main/java/seedu/task/storage/XmlAdaptedTask.java
index 836c9079d759..29b20a4d4c0c 100644
--- a/src/main/java/seedu/task/storage/XmlAdaptedTask.java
+++ b/src/main/java/seedu/task/storage/XmlAdaptedTask.java
@@ -31,9 +31,6 @@ public class XmlAdaptedTask {
@XmlElement(required = false)
private boolean isImportant;
-
- @XmlElement(required = false)
- private int recurrenceWeek;
@XmlElement
private List tagged = new ArrayList<>();
@@ -73,13 +70,12 @@ public Task toModelType() throws IllegalValueException {
taskTags.add(tag.toModelType());
}
final Name name = new Name(this.name);
- final DateTime openTime = new DateTime(this.openTime, true);
- final DateTime closeTime = new DateTime(this.closeTime, true);
+ final DateTime openTime = DateTime.fromEpoch(this.openTime);
+ final DateTime closeTime = DateTime.fromEpoch(this.closeTime);
final UniqueTagList tags = new UniqueTagList(taskTags);
final boolean isImportant = this.isImportant;
final boolean isComplete = this.isComplete;
- final int recurrenceWeek= this.recurrenceWeek;
- return new Task(name, openTime, closeTime, isImportant, isComplete, tags, recurrenceWeek);
+ return new Task(name, openTime, closeTime, isImportant, isComplete, tags);
}
}
//@@author
\ No newline at end of file
diff --git a/src/test/java/guitests/AddCommandTest.java b/src/test/java/guitests/AddCommandTest.java
index 013ac63a9588..fe71feb449f0 100644
--- a/src/test/java/guitests/AddCommandTest.java
+++ b/src/test/java/guitests/AddCommandTest.java
@@ -4,15 +4,17 @@
import static seedu.task.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.task.model.task.Task.MESSAGE_DATETIME_CONSTRAINTS;
+import java.time.temporal.ChronoUnit;
+
import org.junit.Test;
import guitests.guihandles.TaskCardHandle;
import seedu.task.commons.core.Messages;
import seedu.task.logic.commands.AddCommand;
+import seedu.task.model.task.DateTime;
import seedu.task.testutil.TestTask;
import seedu.task.testutil.TestUtil;
-//@@author A0153467Y
public class AddCommandTest extends TaskManagerGuiTest {
@Test
public void add() {
@@ -34,7 +36,7 @@ public void add() {
assertAddSuccess(td.cs2103);
//add a task which has endTime < openTime
- commandBox.runCommand("add testEvent s/tomorrow c/today");
+ commandBox.runCommand("add testEvent starts tomorrow ends today");
assertResultMessage(MESSAGE_DATETIME_CONSTRAINTS);
//add test with only name
@@ -68,28 +70,38 @@ public void invalid_add() {
assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}
+ //@@author A0153467Y
@Test
public void add_recurring_task() {
+ TestTask[] currentList = td.getTypicalTasks();
+
+ //recur a task zero times (i.e. no recurrence at all)
TestTask taskToAdd = td.recur;
- commandBox.runCommand(taskToAdd.getAddCommand());
+ currentList = assertAddRecurringSuccess(0, taskToAdd, currentList);
+ assertResultMessage(String.format(AddCommand.MESSAGE_SUCCESS, taskToAdd));
+
+ //recur a task twenty times (maximum amount)
+ taskToAdd = td.recur2;
+ currentList = assertAddRecurringSuccess(20, taskToAdd, currentList);
assertResultMessage(String.format(AddCommand.MESSAGE_SUCCESS, taskToAdd));
//recurring task number exceeds the maximum
- commandBox.runCommand("add testRecurring r/21");
+ commandBox.runCommand("add testRecurring recurs 21");
assertResultMessage(AddCommand.MESSAGE_WRONG_NUMBER_OF_RECURRENCE);
// recurring number of task is negative
- commandBox.runCommand("add testRecurring r/-1");
+ commandBox.runCommand("add testRecurring recurs -1");
assertResultMessage(AddCommand.MESSAGE_NEGATIVE_NUMBER_OF_RECURRENCE);
//invalid recurring argument with alphanumeric is not allowed
- commandBox.runCommand("add testRecurring r/abc");
+ commandBox.runCommand("add testRecurring recurs abc");
assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
//missing recurring argument
- commandBox.runCommand("add testRecurring r/");
+ commandBox.runCommand("add testRecurring recurs ");
assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}
+ //@@author
private void assertAddSuccess(TestTask taskToAdd, TestTask... currentList) {
commandBox.runCommand(taskToAdd.getAddCommand());
@@ -102,5 +114,33 @@ private void assertAddSuccess(TestTask taskToAdd, TestTask... currentList) {
TestTask[] expectedList = TestUtil.addTasksToList(currentList, taskToAdd);
assertTrue(taskListPanel.isListMatching(expectedList));
}
+
+ //@@author A0141052Y
+ private TestTask[] assertAddRecurringSuccess(int numTimes, TestTask taskToAdd, TestTask... currentList) {
+ commandBox.runCommand(taskToAdd.getAddCommand() + " recurs " + numTimes);
+
+ TestTask[] expectedList = currentList.clone();
+
+ //confirm that instances have same distance and the other properties are same
+ for (int i = 0; i <= numTimes; i++) {
+ TestTask recurringTask = new TestTask(taskToAdd); // insulate the passed TestTask from changes
+
+ DateTime newOpenTime = DateTime.fromDateTimeOffset(taskToAdd.getOpenTime(), i * 7, ChronoUnit.DAYS);
+ DateTime newCloseTime = DateTime.fromDateTimeOffset(taskToAdd.getCloseTime(), i * 7, ChronoUnit.DAYS);
+
+ recurringTask.setOpenTime(newOpenTime);
+ recurringTask.setCloseTime(newCloseTime);
+
+ TaskCardHandle addedCard = taskListPanel.navigateToTask(recurringTask);
+ assertMatching(recurringTask, addedCard);
+
+ expectedList = TestUtil.addTasksToList(expectedList, recurringTask);
+ }
+
+ //assert that the listing is correct after checking individually
+ assertTrue(taskListPanel.isListMatching(expectedList));
+
+ return expectedList;
+ }
}
diff --git a/src/test/java/guitests/ChangePathCommandTest.java b/src/test/java/guitests/ChangePathCommandTest.java
index f1f1a54adc95..5834e19278e5 100644
--- a/src/test/java/guitests/ChangePathCommandTest.java
+++ b/src/test/java/guitests/ChangePathCommandTest.java
@@ -9,17 +9,7 @@
public class ChangePathCommandTest extends TaskManagerGuiTest {
@Test
- public void changePath() throws InterruptedException {
-
-
- //Add successfully
- String validPath = TestUtil.getFilePathInSandboxFolder("yxz.xml");
- File writeableFolder = new File(validPath).getParentFile();
- writeableFolder.setWritable(true);
- Thread.sleep(300);
- commandBox.runCommand("change-to "+validPath);
- assertResultMessage(String.format(ChangePathCommand.MESSAGE_PATH_CHANGE_SUCCESS, validPath));
-
+ public void changePath() throws InterruptedException {
//Try with non xml file
String nonXmlFilePath = TestUtil.getFilePathInSandboxFolder("taskmanager.txt");
diff --git a/src/test/java/guitests/UpdateCommandTest.java b/src/test/java/guitests/UpdateCommandTest.java
index 7407ba21847c..85da74450210 100644
--- a/src/test/java/guitests/UpdateCommandTest.java
+++ b/src/test/java/guitests/UpdateCommandTest.java
@@ -34,27 +34,27 @@ public void update() throws IllegalValueException {
// add new tags
Tag tagToAdd = new Tag("urgent");
- commandBox.runCommand("update " + targetIndex + " t/urgent");
+ commandBox.runCommand("update " + targetIndex + " tag urgent");
ReadOnlyTask newTask = taskListPanel.getTask(targetIndex - 1);
assertTrue(newTask.getTags().contains(tagToAdd));
// remove existing tags
- commandBox.runCommand("update " + targetIndex + " rt/urgent");
+ commandBox.runCommand("update " + targetIndex + " remove-tag urgent");
newTask = taskListPanel.getTask(targetIndex - 1);
assertTrue(!newTask.getTags().contains(tagToAdd));
// modify open time
- commandBox.runCommand("update " + targetIndex + " s/2 hour later");
+ commandBox.runCommand("update " + targetIndex + " starts 2 hour later");
TaskCardHandle updatedCard = taskListPanel.navigateToTask(targetIndex-1);
TestTask expectedTask = currentList[targetIndex - 1];
- expectedTask.setOpenTime(new DateTime("2 hour later"));
+ expectedTask.setOpenTime(DateTime.fromUserInput("2 hour later"));
assertMatching(expectedTask, updatedCard);
// modify close time
- commandBox.runCommand("update " + targetIndex + " c/the day after tomorrow");
+ commandBox.runCommand("update " + targetIndex + " ends the day after tomorrow");
updatedCard = taskListPanel.navigateToTask(targetIndex-1);
expectedTask = currentList[targetIndex - 1];
- expectedTask.setCloseTime(new DateTime("the day after tomorrow"));
+ expectedTask.setCloseTime(DateTime.fromUserInput("the day after tomorrow"));
assertMatching(expectedTask, updatedCard);
// update with no changes
@@ -65,11 +65,11 @@ public void update() throws IllegalValueException {
// update own task without changing name
targetIndex = 3;
- commandBox.runCommand("update " + targetIndex + td.carl.getArgs());
+ commandBox.runCommand("update " + targetIndex + " name"+ td.carl.getArgs());
assertTrue(taskListPanel.isListMatching(currentList));
// invalid index
- commandBox.runCommand("update " + (currentList.length+1) + td.ida.getArgs());
+ commandBox.runCommand("update " + (currentList.length+1) + " name"+ td.ida.getArgs());
assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
assertTrue(taskListPanel.isListMatching(currentList));
@@ -84,7 +84,7 @@ public void update() throws IllegalValueException {
}
private void assertUpdateSuccess(int targetIndex, TestTask taskToUpdate, TestTask... currentList) {
- commandBox.runCommand("update " + targetIndex + taskToUpdate.getArgs() );
+ commandBox.runCommand("update " + targetIndex + " name"+ taskToUpdate.getArgs() );
//confirm the new card contains the right data
TaskCardHandle updatedCard = taskListPanel.navigateToTask(targetIndex-1);
diff --git a/src/test/java/seedu/task/logic/LogicManagerTest.java b/src/test/java/seedu/task/logic/LogicManagerTest.java
index 53cfaa68fb93..b722c95ab897 100644
--- a/src/test/java/seedu/task/logic/LogicManagerTest.java
+++ b/src/test/java/seedu/task/logic/LogicManagerTest.java
@@ -25,12 +25,12 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static seedu.task.commons.core.Messages.*;
@@ -154,13 +154,16 @@ public void execute_clear() throws Exception {
}
//@@author A0144939R
+
+ /**
+ * Tests for add command
+ * @throws Exception
+ */
@Test
public void execute_add_invalidArgsFormat() throws Exception {
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE);
assertCommandBehavior(
- "add s/today c/tomorrow", expectedMessage);
- assertCommandBehavior(
- "add Valid Name a/sadsadsad", expectedMessage);
+ "add starts today ends tomorrow", expectedMessage);
}
@Test
@@ -168,12 +171,12 @@ public void execute_add_invalidTaskData() throws Exception {
assertCommandBehavior(
"add []\\[;]", Name.MESSAGE_NAME_CONSTRAINTS);
assertCommandBehavior(
- "add Do CS2103 t/invalid_-[.tag", Tag.MESSAGE_TAG_CONSTRAINTS);
- assertCommandBehavior("add Do CS2103 s/hello", DateTime.MESSAGE_DATETIME_CONSTRAINTS);
- assertCommandBehavior("add Do CS2103 s/hello c/bbye", DateTime.MESSAGE_DATETIME_CONSTRAINTS);
- assertCommandBehavior("add Do CS2103 c/bbye", DateTime.MESSAGE_DATETIME_CONSTRAINTS);
- assertCommandBehavior("add Do CS2103 s/tomorrow c/today", Task.MESSAGE_DATETIME_CONSTRAINTS);
- assertCommandBehavior("add Do CS2103 s/6 hours from now c/3 hours from now", Task.MESSAGE_DATETIME_CONSTRAINTS);
+ "add Do CS2103 tag invalid_-[.tag", Tag.MESSAGE_TAG_CONSTRAINTS);
+ assertCommandBehavior("add Do CS2103 starts hello", DateTime.MESSAGE_DATETIME_CONSTRAINTS);
+ assertCommandBehavior("add Do CS2103 starts hello ends bbye", DateTime.MESSAGE_DATETIME_CONSTRAINTS);
+ assertCommandBehavior("add Do CS2103 ends bbye", DateTime.MESSAGE_DATETIME_CONSTRAINTS);
+ assertCommandBehavior("add Do CS2103 starts tomorrow ends today", Task.MESSAGE_DATETIME_CONSTRAINTS);
+ assertCommandBehavior("add Do CS2103 starts 6 hours from now ends 3 hours from now", Task.MESSAGE_DATETIME_CONSTRAINTS);
}
@@ -186,13 +189,12 @@ public void execute_add_successful() throws Exception {
expectedAB.addTask(toBeAdded);
// execute command and verify result
- assertCommandBehavior(helper.generateAddCommand(toBeAdded),
+ assertCommandBehavior(helper.generateAddCommand("add", toBeAdded),
String.format(AddCommand.MESSAGE_SUCCESS, toBeAdded),
expectedAB,
expectedAB.getTaskList());
}
- //@@author
@Test
public void execute_addDuplicate_notAllowed() throws Exception {
// setup expectations
@@ -206,7 +208,7 @@ public void execute_addDuplicate_notAllowed() throws Exception {
// execute command and verify result
assertCommandBehavior(
- helper.generateAddCommand(toBeAdded),
+ helper.generateAddCommand("add", toBeAdded),
AddCommand.MESSAGE_DUPLICATE_TASK,
expectedAB,
expectedAB.getTaskList());
@@ -228,7 +230,57 @@ public void execute_list_showsAllTasks() throws Exception {
expectedAB,
expectedList);
}
+
+ /**
+ * Tests for alias command
+ * @throws Exception
+ */
+ @Test
+ public void execute_alias_invalidFormat() throws Exception {
+ assertCommandBehavior("alias", String.format(MESSAGE_INVALID_COMMAND_FORMAT, AliasCommand.MESSAGE_USAGE));
+ assertCommandBehavior("alias add", String.format(MESSAGE_INVALID_COMMAND_FORMAT, AliasCommand.MESSAGE_USAGE));
+ assertCommandBehavior("alias add + -", String.format(MESSAGE_INVALID_COMMAND_FORMAT, AliasCommand.MESSAGE_USAGE));
+ }
+
+ @Test
+ public void execute_noCommand() throws Exception {
+ assertCommandBehavior("alias - +", AliasCommand.MESSAGE_FAILURE);
+ }
+
+ @Test
+ public void execute_alias_alreadyTaken() throws Exception {
+ assertCommandBehavior("alias add +", String.format(AliasCommand.MESSAGE_SUCCESS));
+ assertCommandBehavior("alias edit +", String.format(AliasCommand.MESSAGE_FAILURE));
+ assertCommandBehavior("alias add -", String.format(AliasCommand.MESSAGE_SUCCESS));
+ }
+
+ @Test
+ public void execute_alias_successful() throws Exception {
+ assertCommandBehavior("alias add +", String.format(AliasCommand.MESSAGE_SUCCESS));
+
+ TestDataHelper helper = new TestDataHelper();
+ Task toBeAdded = helper.adam();
+ TaskManager expectedTM = new TaskManager();
+ expectedTM.addTask(toBeAdded);
+ // execute command and verify result
+ assertCommandBehavior(helper.generateAddCommand("+", toBeAdded),
+ String.format(AddCommand.MESSAGE_SUCCESS, toBeAdded),
+ expectedTM,
+ expectedTM.getTaskList());
+
+ assertCommandBehavior("alias delete -",
+ String.format(AliasCommand.MESSAGE_SUCCESS),
+ expectedTM,
+ expectedTM.getTaskList());
+ expectedTM.removeTask(toBeAdded);
+
+ assertCommandBehavior("- 1",
+ String.format(DeleteCommand.MESSAGE_DELETE_TASK_SUCCESS, toBeAdded),
+ expectedTM,
+ expectedTM.getTaskList());
+ }
+ //@@author
/**
* Confirms the 'invalid argument index number behaviour' for the given command
@@ -401,8 +453,7 @@ Task adam() throws Exception {
boolean isImportant = false;
boolean isComplete = false;
- int recurrenceWeek=0;
- return new Task(name, new DateTime(null), new DateTime(null), isImportant, isComplete, tags, recurrenceWeek);
+ return new Task(name, new DateTime(null), new DateTime(null), isImportant, isComplete, tags);
}
/**
@@ -415,31 +466,31 @@ Task adam() throws Exception {
Task generateTask(int seed) throws Exception {
return new Task(
new Name("Task " + seed),
- new DateTime("" + Math.abs(seed)+" days from now"),
- new DateTime(""),
+ DateTime.fromUserInput("" + Math.abs(seed)+" days from now"),
+ DateTime.fromUserInput(""),
false,
false,
- new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1))),
- 0
+ new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1)))
);
}
-
+ //@@author A0144939R
/** Generates the correct add command based on the Task given */
- String generateAddCommand(Task p) {
+ public String generateAddCommand(String alias, Task p) {
StringBuffer cmd = new StringBuffer();
- cmd.append("add ");
+ cmd.append(alias+" ");
cmd.append(p.getName().toString());
UniqueTagList tags = p.getTags();
for(Tag t: tags){
- cmd.append(" t/").append(t.tagName);
+ cmd.append(" tag ").append(t.tagName);
}
return cmd.toString();
}
+ //@@author
/**
* Generates an TaskManager with auto-generated Tasks.
@@ -514,12 +565,11 @@ List generateTaskList(Task... Tasks) {
Task generateTaskWithName(String name) throws Exception {
return new Task(
new Name(name),
- new DateTime("tomorrow"),
- new DateTime("day after tomorrow"),
+ DateTime.fromUserInput("tomorrow"),
+ DateTime.fromUserInput("day after tomorrow"),
false,
false,
- new UniqueTagList(new Tag("tag")),
- 0
+ new UniqueTagList(new Tag("tag"))
);
}
}
diff --git a/src/test/java/seedu/task/testutil/TaskBuilder.java b/src/test/java/seedu/task/testutil/TaskBuilder.java
index c37a5c6ccc0a..3ba81ed43a85 100644
--- a/src/test/java/seedu/task/testutil/TaskBuilder.java
+++ b/src/test/java/seedu/task/testutil/TaskBuilder.java
@@ -33,17 +33,12 @@ public TaskBuilder withImportance(boolean isImportant) throws IllegalValueExcept
}
//@@author A0144939R
public TaskBuilder withOpenTime(String openTime) throws IllegalValueException {
- this.task.setOpenTime(new DateTime(openTime));
+ this.task.setOpenTime(DateTime.fromUserInput(openTime));
return this;
}
public TaskBuilder withCloseTime(String closeTime) throws IllegalValueException {
- this.task.setCloseTime(new DateTime(closeTime));
- return this;
- }
-
- public TaskBuilder withRecurrentWeek(int recurrentWeek){
- this.task.setRecurrentWeek(recurrentWeek);
+ this.task.setCloseTime(DateTime.fromUserInput(closeTime));
return this;
}
diff --git a/src/test/java/seedu/task/testutil/TestTask.java b/src/test/java/seedu/task/testutil/TestTask.java
index 77c275e9b1ee..d8eeaedcb42b 100644
--- a/src/test/java/seedu/task/testutil/TestTask.java
+++ b/src/test/java/seedu/task/testutil/TestTask.java
@@ -15,12 +15,26 @@ public class TestTask implements ReadOnlyTask {
private UniqueTagList tags;
private boolean isImportant;
private boolean isCompleted;
- private int recurrentWeek;
public TestTask() {
tags = new UniqueTagList();
}
+ //@@author A0141052Y
+ /**
+ * Creates a duplicate (copy) of an existing TestTask
+ * @param task the TestTask to copy from
+ */
+ public TestTask(TestTask task) {
+ this.name = task.getName();
+ this.openTime = task.getOpenTime();
+ this.closeTime = task.getCloseTime();
+ this.isCompleted = task.getComplete();
+ this.isImportant = task.getImportance();
+ this.tags = new UniqueTagList(task.getTags());
+ }
+ //@@author
+
public void setName(Name name) {
this.name = name;
}
@@ -40,10 +54,6 @@ public void setCloseTime(DateTime closeTime) {
public void setIsCompleted(boolean isCompleted){
this.isCompleted = isCompleted;
}
-
- public void setRecurrentWeek(int recurrentWeek){
- this.recurrentWeek=recurrentWeek;
- }
@Override
public Name getName() {
@@ -69,11 +79,6 @@ public DateTime getCloseTime() {
public UniqueTagList getTags() {
return tags;
}
-
- @Override
- public int getRecurrentWeek() {
- return recurrentWeek;
- }
@Override
public boolean getImportance() {
@@ -87,19 +92,19 @@ public String toString() {
public String getAddCommand() {
StringBuilder sb = new StringBuilder();
sb.append("add " + this.getName().taskName + " ");
- sb.append("s/" + this.getOpenTime().toPrettyString() + " ");
- sb.append("c/" + this.getCloseTime().toPrettyString() + " ");
- this.getTags().getInternalList().stream().forEach(s -> sb.append("t/" + s.tagName + " "));
- sb.append("r/" + this.getRecurrentWeek()+ " ");
+ sb.append("starts " + this.getOpenTime().toPrettyString() + " ");
+ sb.append("ends " + this.getCloseTime().toPrettyString() + " ");
+ this.getTags().getInternalList().stream().forEach(s -> sb.append("tag " + s.tagName + " "));
+ System.out.println("COMMAND" +sb.toString());
return sb.toString();
}
public String getArgs() {
StringBuilder sb = new StringBuilder();
sb.append(" "+this.getName().taskName + " ");
- sb.append("s/" + this.getOpenTime().toPrettyString() + " ");
- sb.append("c/" + this.getCloseTime().toPrettyString() + " ");
- this.getTags().getInternalList().stream().forEach(s -> sb.append("t/" + s.tagName + " "));
+ sb.append("starts " + this.getOpenTime().toPrettyString() + " ");
+ sb.append("ends " + this.getCloseTime().toPrettyString() + " ");
+ this.getTags().getInternalList().stream().forEach(s -> sb.append("tag " + s.tagName + " "));
return sb.toString();
}
}
diff --git a/src/test/java/seedu/task/testutil/TestUtil.java b/src/test/java/seedu/task/testutil/TestUtil.java
index 1fde6b953812..9878ad06a0b9 100644
--- a/src/test/java/seedu/task/testutil/TestUtil.java
+++ b/src/test/java/seedu/task/testutil/TestUtil.java
@@ -66,15 +66,15 @@ public static void assertThrows(Class extends Throwable> expected, Runnable ex
private static Task[] getSampleTaskData() {
try {
return new Task[]{
- new Task(new Name("Ali Muster"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList(), 0 ),
- new Task(new Name("Boris Mueller"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList(),0),
- new Task(new Name("Carl Kurz"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList(), 0),
- new Task(new Name("Daniel Meier"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList(), 0),
- new Task(new Name("Elle Meyer"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList(), 0),
- new Task(new Name("Fiona Kunz"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList(), 0),
- new Task(new Name("George Best"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList(), 0),
- new Task(new Name("Hoon Meier"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList(), 0),
- new Task(new Name("Ida Mueller"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList(), 0),
+ new Task(new Name("Ali Muster"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()),
+ new Task(new Name("Boris Mueller"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()),
+ new Task(new Name("Carl Kurz"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()),
+ new Task(new Name("Daniel Meier"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()),
+ new Task(new Name("Elle Meyer"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()),
+ new Task(new Name("Fiona Kunz"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()),
+ new Task(new Name("George Best"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()),
+ new Task(new Name("Hoon Meier"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()),
+ new Task(new Name("Ida Mueller"), new DateTime(null), new DateTime(null), false, false, new UniqueTagList()),
};
} catch (IllegalValueException e) {
assert false;
diff --git a/src/test/java/seedu/task/testutil/TypicalTestTasks.java b/src/test/java/seedu/task/testutil/TypicalTestTasks.java
index bb72749884d6..7c73a48ed952 100644
--- a/src/test/java/seedu/task/testutil/TypicalTestTasks.java
+++ b/src/test/java/seedu/task/testutil/TypicalTestTasks.java
@@ -10,7 +10,7 @@
*/
public class TypicalTestTasks {
- public static TestTask cs2103, laundry, carl, daniel, elle, fiona, george, hoon, ida, same, recur, name;
+ public static TestTask cs2103, laundry, carl, daniel, elle, fiona, george, hoon, ida, same, recur, recur2, name;
public TypicalTestTasks() {
try {
@@ -37,8 +37,10 @@ public TypicalTestTasks() {
same =new TaskBuilder().withName("Ida Mueller").withOpenTime("one week from now")
.withCloseTime("two weeks from now").build();
recur = new TaskBuilder().withName("Ida").withOpenTime("one week from now")
- .withCloseTime("two weeks from now").withRecurrentWeek(2).build();
- name = new TaskBuilder().withName("task name").withRecurrentWeek(2).build();
+ .withCloseTime("two weeks from now").build();
+ recur2 = new TaskBuilder().withName("Do Homework").withOpenTime("two days from now")
+ .withCloseTime("five days from now").build();
+ name = new TaskBuilder().withName("task name").build();
} catch (IllegalValueException e) {
e.printStackTrace();