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 pull request #3 from marcus2k/branch-C-Tagging
Add tagging support
- Loading branch information
Showing
9 changed files
with
191 additions
and
16 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,17 @@ | ||
package duke; | ||
|
||
public class FindTagCommand extends Command { | ||
private final String tag; | ||
|
||
public FindTagCommand(String tag) { | ||
this.tag = tag; | ||
} | ||
|
||
public String execute(TaskList list, Ui ui, Storage storage) throws DukeException { | ||
TaskList taskList = list.findTag(this.tag); | ||
String textOutput = "Here are your tasks tagged with #" + this.tag + ":\n"; | ||
textOutput += taskList; | ||
storage.updateTextFile(list); | ||
return ui.getLine(textOutput); | ||
} | ||
} |
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,19 @@ | ||
package duke; | ||
|
||
public class TagCommand extends Command { | ||
private final int index; | ||
private final String tag; | ||
|
||
public TagCommand(int index, String tag) { | ||
this.index = index; | ||
this.tag = tag; | ||
} | ||
|
||
public String execute(TaskList list, Ui ui, Storage storage) throws DukeException { | ||
Task task = list.tagTask(this.index, this.tag); | ||
String textOutput = "Nice! I've tagged this task with #" + this.tag + ":\n"; | ||
textOutput += task; | ||
storage.updateTextFile(list); | ||
return ui.getLine(textOutput); | ||
} | ||
} |
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,31 @@ | ||
package duke; | ||
|
||
public class UntagCommand extends Command { | ||
private static final int ALL = -1; | ||
private final int index; | ||
private final String tag; | ||
|
||
public UntagCommand(int index, String tag) { | ||
this.index = index; | ||
this.tag = tag; | ||
} | ||
|
||
public UntagCommand(String tag) { | ||
this(ALL, tag); | ||
} | ||
|
||
public String execute(TaskList list, Ui ui, Storage storage) throws DukeException { | ||
String textOutput = "Nice! I've removed the tag #" + this.tag; | ||
if (this.index != ALL) { | ||
Task task = list.untagTask(this.index, this.tag); | ||
textOutput += " from this task:\n"; | ||
textOutput += task; | ||
} else { | ||
TaskList taskList = list.untagAllTasks(this.tag); | ||
textOutput += " from these tasks:\n"; | ||
textOutput += taskList; | ||
} | ||
storage.updateTextFile(list); | ||
return ui.getLine(textOutput); | ||
} | ||
} |