diff --git a/.gitignore b/.gitignore index 2873e189e..84acdadd4 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ bin/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT +*.txt diff --git a/src/main/java/duke/MissingParamsException.java b/src/main/java/duke/MissingParamsException.java index db1372ae5..703851e47 100644 --- a/src/main/java/duke/MissingParamsException.java +++ b/src/main/java/duke/MissingParamsException.java @@ -27,6 +27,9 @@ public String toString() { case END: errorMessage.append("to "); break; + case TARGET: + errorMessage.append("target "); + break; } } diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 0fe08fe74..70d7e41c5 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -5,7 +5,7 @@ public class Parser { public static final String[] validCommands = - {"list", "mark", "unmark", "todo", "deadline", "event", "bye", "delete"}; + {"list", "mark", "unmark", "todo", "deadline", "event", "bye", "delete", "find"}; protected TaskList taskList; public Parser(TaskList taskList) { @@ -30,7 +30,8 @@ public void executeCommand(String command, String argument) switch (command) { case "list": - taskList.printList(); + String message = ""; + taskList.printList(message); break; case "mark": taskList.markTask(argument, true); @@ -50,6 +51,9 @@ public void executeCommand(String command, String argument) case "delete": taskList.deleteTask(argument); break; + case "find": + taskList.findTask(argument); + break; } } } diff --git a/src/main/java/duke/TaskList.java b/src/main/java/duke/TaskList.java index 79c642e00..17e0da3cb 100644 --- a/src/main/java/duke/TaskList.java +++ b/src/main/java/duke/TaskList.java @@ -1,5 +1,6 @@ package duke; +import java.util.ArrayList; import java.util.List; import static duke.print.*; @@ -17,9 +18,17 @@ public List getTaskList() { /** * Prints list of tasks. + * If message is not empty, prints message in front of list. + * + * @param message Message to be printed before list. */ - public void printList(){ + public void printList(String message){ printLine(); + + if (!message.isEmpty()) { + System.out.println(message); + } + for(int i = 0; i < taskList.size(); i++){ Task task = taskList.get(i); System.out.println((i + 1) + "." + task); @@ -166,4 +175,34 @@ public void deleteTask(String instruction) throw new DukeException.IntegerOutOfBoundsException(); } } + + /** + * Finds tasks which descriptions match the target, + * before printing out list of matches. + * + * @param target Target phrase to search for. + */ + public void findTask(String target) throws MissingParamsException { + if (target.isEmpty()) { + List missingParams = new ArrayList<>(); + missingParams.add(TaskParams.TARGET); + + throw new MissingParamsException(missingParams); + } + + List matches = new ArrayList<>(); + + for (Task task : taskList){ + if(task.getDescription().contains(target)){ + matches.add(task); + } + } + + if (matches.isEmpty()){ + printMessage("No matches!!"); + } else { + new TaskList(matches).printList( + "Here are the matching tasks in your list-gari:"); + } + } } diff --git a/src/main/java/duke/TaskParams.java b/src/main/java/duke/TaskParams.java index 4bb0751ce..488e439f1 100644 --- a/src/main/java/duke/TaskParams.java +++ b/src/main/java/duke/TaskParams.java @@ -1,5 +1,5 @@ package duke; public enum TaskParams { - DESCRIPTION, BY, START, END + DESCRIPTION, BY, START, END, TARGET } diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 91d2dd532..e034cba65 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -21,6 +21,11 @@ Got it. I've added this task: Now you have 2 tasks in the list. ______________________________ ______________________________ +Got it. I've added this task: + [T][ ] Watch CEG Video +Now you have 3 tasks in the list. +______________________________ +______________________________ The following parameters are missing: description YOU GOTTA SAVE ME AND MY HEART!! @@ -28,16 +33,17 @@ ______________________________ ______________________________ 1.[T][ ] Eat Breakfast 2.[T][ ] Eat Lunch +3.[T][ ] Watch CEG Video ______________________________ ______________________________ Got it. I've added this task: [E][ ] Tutorial (from: 1pm to: 3pm) -Now you have 3 tasks in the list. +Now you have 4 tasks in the list. ______________________________ ______________________________ Got it. I've added this task: - [E][ ] Lecture (from: 3pm to: 5pm) -Now you have 4 tasks in the list. + [E][ ] CEG 1 Lecture (from: 3pm to: 5pm) +Now you have 5 tasks in the list. ______________________________ ______________________________ The following parameters are missing: @@ -67,24 +73,25 @@ ______________________________ ______________________________ Got it. I've added this task: [E][ ] Seminar (from: 5pm to: 7pm) -Now you have 5 tasks in the list. +Now you have 6 tasks in the list. ______________________________ ______________________________ 1.[T][ ] Eat Breakfast 2.[T][ ] Eat Lunch -3.[E][ ] Tutorial (from: 1pm to: 3pm) -4.[E][ ] Lecture (from: 3pm to: 5pm) -5.[E][ ] Seminar (from: 5pm to: 7pm) +3.[T][ ] Watch CEG Video +4.[E][ ] Tutorial (from: 1pm to: 3pm) +5.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm) +6.[E][ ] Seminar (from: 5pm to: 7pm) ______________________________ ______________________________ Got it. I've added this task: [D][ ] RealizeIt (by: Thursday) -Now you have 6 tasks in the list. +Now you have 7 tasks in the list. ______________________________ ______________________________ Got it. I've added this task: - [D][ ] Coursemology (by: Friday) -Now you have 7 tasks in the list. + [D][ ] CEG 1 Coursemology (by: Friday) +Now you have 8 tasks in the list. ______________________________ ______________________________ The following parameters are missing: @@ -104,17 +111,18 @@ ______________________________ ______________________________ Got it. I've added this task: [D][ ] Teammates (by: Saturday) -Now you have 8 tasks in the list. +Now you have 9 tasks in the list. ______________________________ ______________________________ 1.[T][ ] Eat Breakfast 2.[T][ ] Eat Lunch -3.[E][ ] Tutorial (from: 1pm to: 3pm) -4.[E][ ] Lecture (from: 3pm to: 5pm) -5.[E][ ] Seminar (from: 5pm to: 7pm) -6.[D][ ] RealizeIt (by: Thursday) -7.[D][ ] Coursemology (by: Friday) -8.[D][ ] Teammates (by: Saturday) +3.[T][ ] Watch CEG Video +4.[E][ ] Tutorial (from: 1pm to: 3pm) +5.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm) +6.[E][ ] Seminar (from: 5pm to: 7pm) +7.[D][ ] RealizeIt (by: Thursday) +8.[D][ ] CEG 1 Coursemology (by: Friday) +9.[D][ ] Teammates (by: Saturday) ______________________________ ______________________________ Nice! I've marked this task as done @@ -122,51 +130,53 @@ Nice! I've marked this task as done ______________________________ ______________________________ Nice! I've marked this task as done - [E][X] Tutorial (from: 1pm to: 3pm) + [T][X] Watch CEG Video ______________________________ ______________________________ Nice! I've marked this task as done - [E][X] Seminar (from: 5pm to: 7pm) + [E][X] CEG 1 Lecture (from: 3pm to: 5pm) ______________________________ ______________________________ Nice! I've marked this task as done - [D][X] Coursemology (by: Friday) + [D][X] RealizeIt (by: Thursday) ______________________________ ______________________________ 1.[T][X] Eat Breakfast 2.[T][ ] Eat Lunch -3.[E][X] Tutorial (from: 1pm to: 3pm) -4.[E][ ] Lecture (from: 3pm to: 5pm) -5.[E][X] Seminar (from: 5pm to: 7pm) -6.[D][ ] RealizeIt (by: Thursday) -7.[D][X] Coursemology (by: Friday) -8.[D][ ] Teammates (by: Saturday) +3.[T][X] Watch CEG Video +4.[E][ ] Tutorial (from: 1pm to: 3pm) +5.[E][X] CEG 1 Lecture (from: 3pm to: 5pm) +6.[E][ ] Seminar (from: 5pm to: 7pm) +7.[D][X] RealizeIt (by: Thursday) +8.[D][ ] CEG 1 Coursemology (by: Friday) +9.[D][ ] Teammates (by: Saturday) ______________________________ ______________________________ Nice! I've marked this task as undone - [E][ ] Tutorial (from: 1pm to: 3pm) + [T][ ] Watch CEG Video ______________________________ ______________________________ Nice! I've marked this task as undone - [E][ ] Lecture (from: 3pm to: 5pm) + [E][ ] Tutorial (from: 1pm to: 3pm) ______________________________ ______________________________ Nice! I've marked this task as undone - [E][ ] Seminar (from: 5pm to: 7pm) + [E][ ] CEG 1 Lecture (from: 3pm to: 5pm) ______________________________ ______________________________ Nice! I've marked this task as undone - [D][ ] RealizeIt (by: Thursday) + [E][ ] Seminar (from: 5pm to: 7pm) ______________________________ ______________________________ 1.[T][X] Eat Breakfast 2.[T][ ] Eat Lunch -3.[E][ ] Tutorial (from: 1pm to: 3pm) -4.[E][ ] Lecture (from: 3pm to: 5pm) -5.[E][ ] Seminar (from: 5pm to: 7pm) -6.[D][ ] RealizeIt (by: Thursday) -7.[D][X] Coursemology (by: Friday) -8.[D][ ] Teammates (by: Saturday) +3.[T][ ] Watch CEG Video +4.[E][ ] Tutorial (from: 1pm to: 3pm) +5.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm) +6.[E][ ] Seminar (from: 5pm to: 7pm) +7.[D][X] RealizeIt (by: Thursday) +8.[D][ ] CEG 1 Coursemology (by: Friday) +9.[D][ ] Teammates (by: Saturday) ______________________________ ______________________________ Please input an integer!! @@ -185,14 +195,38 @@ Task does not exist!! Invalid instruction ZENBU FAKE!! ______________________________ ______________________________ +The following parameters are missing: +target +YOU GOTTA SAVE ME AND MY HEART!! +______________________________ +______________________________ +No matches!! +______________________________ +______________________________ +Here are the matching tasks in your list-gari: +1.[T][ ] Watch CEG Video +2.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm) +3.[D][ ] CEG 1 Coursemology (by: Friday) +______________________________ +______________________________ +Here are the matching tasks in your list-gari: +1.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm) +2.[D][ ] CEG 1 Coursemology (by: Friday) +______________________________ +______________________________ +Here are the matching tasks in your list-gari: +1.[T][ ] Watch CEG Video +______________________________ +______________________________ 1.[T][X] Eat Breakfast 2.[T][ ] Eat Lunch -3.[E][ ] Tutorial (from: 1pm to: 3pm) -4.[E][ ] Lecture (from: 3pm to: 5pm) -5.[E][ ] Seminar (from: 5pm to: 7pm) -6.[D][ ] RealizeIt (by: Thursday) -7.[D][X] Coursemology (by: Friday) -8.[D][ ] Teammates (by: Saturday) +3.[T][ ] Watch CEG Video +4.[E][ ] Tutorial (from: 1pm to: 3pm) +5.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm) +6.[E][ ] Seminar (from: 5pm to: 7pm) +7.[D][X] RealizeIt (by: Thursday) +8.[D][ ] CEG 1 Coursemology (by: Friday) +9.[D][ ] Teammates (by: Saturday) ______________________________ ______________________________ Noted. I've removed this task: @@ -200,11 +234,11 @@ ______________________________ ______________________________ ______________________________ Noted. I've removed this task: - [E][ ] Tutorial (from: 1pm to: 3pm) + [T][ ] Watch CEG Video ______________________________ ______________________________ Noted. I've removed this task: - [D][ ] RealizeIt (by: Thursday) + [E][ ] Seminar (from: 5pm to: 7pm) ______________________________ ______________________________ Task does not exist!! @@ -220,10 +254,11 @@ Invalid instruction ZENBU FAKE!! ______________________________ ______________________________ 1.[T][ ] Eat Lunch -2.[E][ ] Lecture (from: 3pm to: 5pm) -3.[E][ ] Seminar (from: 5pm to: 7pm) -4.[D][X] Coursemology (by: Friday) -5.[D][ ] Teammates (by: Saturday) +2.[E][ ] Tutorial (from: 1pm to: 3pm) +3.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm) +4.[D][X] RealizeIt (by: Thursday) +5.[D][ ] CEG 1 Coursemology (by: Friday) +6.[D][ ] Teammates (by: Saturday) ______________________________ ______________________________ Bye! Hope to see you again soon! MEGANE!! diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 3af8c0107..ca778ffa3 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,10 +1,11 @@ -todo Eat Breakfast +todo Eat Breakfast todo Eat Lunch +todo Watch CEG Video todo list event Tutorial /from 1pm /to 3pm -event Lecture /from 3pm /to 5pm -event Seminar +event CEG 1 Lecture /from 3pm /to 5pm +event Seminar event Seminar /from /to event Seminar /from 5pm event Seminar /to 7pm @@ -12,7 +13,7 @@ event /from 5pm /to 7pm event Seminar /from 5pm /to 7pm list deadline RealizeIt /by Thursday -deadline Coursemology /by Friday +deadline CEG 1 Coursemology /by Friday deadline deadline Teammates /by deadline /by Saturday @@ -32,6 +33,11 @@ mark string mark 1000 unmark string unmark 2000 +find +find target that does not exist +find CEG +find CEG 1 +find Watch CEG Video list delete 1 delete 2