Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lee Bing Heng] iP #565

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
28ad2b8
Add Gradle support
May 24, 2020
ed6d4d2
Bump gradle and lib version
Eclipse-Dominator Aug 5, 2023
b25d3fc
Level-0
starrylight99 Aug 30, 2023
ab429f2
Level-1
starrylight99 Aug 30, 2023
5d0b01b
Level-1
starrylight99 Aug 30, 2023
5cff248
Level-2
starrylight99 Aug 31, 2023
4bcfb6d
Level-3
starrylight99 Aug 31, 2023
5b04fb0
save
starrylight99 Aug 31, 2023
846244f
Level-5
starrylight99 Sep 5, 2023
4d6ba07
Level-6
starrylight99 Sep 5, 2023
148378c
Level-7
starrylight99 Sep 6, 2023
6bd8f78
Added .gitkeep /data
starrylight99 Sep 7, 2023
4928ea2
Level-8
starrylight99 Sep 7, 2023
75cadb5
Merge branch 'add-gradle-support'
starrylight99 Sep 7, 2023
b3d5ded
A-Gradle
starrylight99 Sep 7, 2023
374f03c
A-JUnit
starrylight99 Sep 7, 2023
e54726b
A-Jar
starrylight99 Sep 7, 2023
d3b2b46
A-JavaDoc
starrylight99 Sep 7, 2023
191dc4e
A-CodingStandard
starrylight99 Sep 7, 2023
912cb5f
Level-9
starrylight99 Sep 7, 2023
e11d0a1
A-CheckStyle
starrylight99 Sep 10, 2023
feb6a69
Level-10
starrylight99 Sep 10, 2023
11c0197
Level-10
starrylight99 Sep 22, 2023
70a37ae
A-Assertions
starrylight99 Sep 22, 2023
191b988
Merge pull request #2 from starrylight99/branch-A-Assertions
starrylight99 Sep 22, 2023
5635950
save
starrylight99 Sep 22, 2023
d5d469d
A-CodeQuality
starrylight99 Sep 22, 2023
be0054b
A-CodeQuality
starrylight99 Sep 22, 2023
6d33c7c
Merge pull request #3 from starrylight99/branch-A-CodeQuality
starrylight99 Sep 22, 2023
3cb34ca
Refactored Session.java: Segmented initializeUI
starrylight99 Sep 22, 2023
598ab02
Merge pull request #4 from starrylight99/A-FullCommitMessage
starrylight99 Sep 22, 2023
999e1fb
BCD-Extension
starrylight99 Sep 22, 2023
724ec38
BCD-Extension
starrylight99 Sep 22, 2023
f00ce7a
Merge branch 'master' into branch-BCD-Extension
starrylight99 Sep 22, 2023
6d7c0e0
Merge pull request #5 from starrylight99/branch-BCD-Extension
starrylight99 Sep 22, 2023
f635ed8
A-Release
starrylight99 Sep 22, 2023
93693a1
Merge pull request #6 from starrylight99/branch-A-Release
starrylight99 Sep 22, 2023
e3abefc
A-UserGuide
starrylight99 Oct 4, 2023
31d7187
A-UserGuide
starrylight99 Oct 4, 2023
fafd23e
Ui.png
starrylight99 Oct 4, 2023
72a70f3
Fixed Ui.png name
starrylight99 Oct 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/duke/Utils/OutOfRangeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package duke.Utils;

/**
* The OutOfRangeException class represents an exception that is thrown when
* a user provides an input number that is out of range of the current tasks.
*/
public class OutOfRangeException extends DukeException {
/**
* Constructs a new OutOfRangeException with a default error message.
*/
protected OutOfRangeException() {
super("I'm sorry, but your input number is out of range of the current tasks");
}
}
25 changes: 22 additions & 3 deletions src/main/java/duke/Utils/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum Type {
DEADLINE("deadline"),
EVENT("event"),
DELETE("delete"),
FIND("find"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great that you have implemented enums to keep track of the long list of keywords!

NOTFOUND("");

private final String name;
Expand Down Expand Up @@ -102,6 +103,8 @@ protected Response execute(String input, String command) throws DukeException {
return this.delete(Command.assertInteger(input, command));
case LIST:
return this.list();
case FIND:
return this.find(Command.assertString(input, command));
default:
throw new CommandNotFoundException();
}
Expand Down Expand Up @@ -151,7 +154,7 @@ private boolean inRange(int idx) {
protected Response mark(int idx) throws DukeException {
ArrayList<String> output = new ArrayList<>();
if (!this.inRange(idx)) {
throw new TaskNotFoundException();
throw new OutOfRangeException();
}
Task task = this.tasks.get(--idx);
task.mark();
Expand All @@ -171,7 +174,7 @@ protected Response mark(int idx) throws DukeException {
protected Response unmark(int idx) throws DukeException {
ArrayList<String> output = new ArrayList<>();
if (!this.inRange(idx)) {
throw new TaskNotFoundException();
throw new OutOfRangeException();
}
Task task = this.tasks.get(--idx);
task.unmark();
Expand All @@ -191,7 +194,7 @@ protected Response unmark(int idx) throws DukeException {
protected Response delete(int idx) throws DukeException {
ArrayList<String> output = new ArrayList<>();
if (!this.inRange(idx)) {
throw new TaskNotFoundException();
throw new OutOfRangeException();
}
Task task = this.tasks.get(--idx);
output.add("Noted. I've removed this task:");
Expand All @@ -201,4 +204,20 @@ protected Response delete(int idx) throws DukeException {

return Response.generate(output);
}

protected Response find(String keyword) throws DukeException {
ArrayList<String> output = new ArrayList<>();
output.add("Here are the matching tasks in your list:");

int count = 0;
for (Task task : this.tasks) {
if (task.name().contains(keyword)) {
output.add(String.format("%d.%s", ++count, task.toString()));
}
}
if (count == 0) {
throw new TaskNotFoundException();
}
return Response.generate(output);
}
Comment on lines +219 to +233

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very short and clear code!

}
4 changes: 2 additions & 2 deletions src/main/java/duke/Utils/TaskNotFoundException.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

/**
* The TaskNotFoundException class represents an exception that is thrown when
* a user provides an input number that is out of range of the current tasks.
* a user provides a search keyword that does not match any of the current tasks.
*/
public class TaskNotFoundException extends DukeException {
/**
* Constructs a new TaskNotFoundException with a default error message.
*/
protected TaskNotFoundException() {
super("I'm sorry, but your input number is out of range of the current tasks");
super("I'm sorry, but none of the task matches your search keyword");
}
}