This repository has been archived by the owner on Nov 13, 2020. It is now read-only.
forked from nus-cs2103-AY2021S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'branch-Level-9' into master
- Loading branch information
Showing
4 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package duke.command; | ||
|
||
import duke.DukeException; | ||
import duke.Storage; | ||
import duke.TaskList; | ||
import duke.Ui; | ||
import duke.task.Task; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
import java.util.List; | ||
|
||
public class FindCommand extends Command { | ||
private final String keyword; | ||
|
||
public FindCommand(String keyword) { | ||
this.keyword = keyword; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException { | ||
List<Task> foundTasks = tasks.findTasks(keyword); | ||
|
||
if (foundTasks.size() == 0) { | ||
throw new DukeException("There are no tasks in your list with the keyword \"" | ||
+ keyword + "\"."); | ||
} | ||
|
||
StringBuilder output = new StringBuilder("Here are the matching tasks in your list:\n"); | ||
|
||
for (Task task : foundTasks) { | ||
output.append(tasks.getTasks().indexOf(task) + 1).append(".").append(task).append('\n'); | ||
} | ||
|
||
ui.showPrompt(output.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters