Skip to content

Commit

Permalink
Merge branch 'branch-Level-9'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrystalquek committed Aug 27, 2020
2 parents b253f1c + ae60e04 commit 2738b79
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
10 changes: 4 additions & 6 deletions src/main/java/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
public class ListCommand extends Command {

private final Date on;
private final String keyWord;

public ListCommand() {
this.on = null;
}

public ListCommand(Date on) {
public ListCommand(Date on, String keyWord) {
this.on = on;
this.keyWord = keyWord;
}

/**
Expand All @@ -25,6 +23,6 @@ public ListCommand(Date on) {
*/
@Override
public void execute(TaskList tasks, Ui ui, Storage storage) {
ui.showTaskList(tasks, on);
ui.showTaskList(tasks, on, keyWord);
}
}
10 changes: 8 additions & 2 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static Date parseDate(String str) {
*/
public static Command parse(String display) throws DukeException, TaskException {
if (display.equals("list")) {
return new ListCommand();
return new ListCommand(null, null);
} else if (display.length() >= 4 && display.startsWith("done")) {
try {
int idx = Integer.parseInt(String.valueOf(display.charAt(5))) - 1;
Expand All @@ -55,7 +55,13 @@ public static Command parse(String display) throws DukeException, TaskException
if (parseDate(display.substring(13)) == null) {
throw new DukeException("time is of the wrong format");
} else {
return new ListCommand(parseDate(display.substring(13)));
return new ListCommand(parseDate(display.substring(13)), null);
}
} else if (display.startsWith("find")) {
if (display.substring(4).isBlank()) {
throw new DukeException("keyword is absent");
} else {
return new ListCommand(null, display.substring(5));
}
} else if (display.equals("bye")) {
return new ExitCommand();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public boolean isOccuringOn(Date date) {
return false;
}

public boolean fulfilCriteria(Date date, String keyWord) {
return (date == null || isOccuringOn(date)) && (keyWord == null || description.toLowerCase().contains(keyWord.toLowerCase()));
}

@Override
public String toString() {
return "[" + taskType.getSymbol() + "]" + getStatusIcon() + " " + description;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public int getCount() {
return tasks.size();
}

public ArrayList<String> toString(Date date) {
public ArrayList<String> toString(Date date, String keyWord) {
ArrayList<String> lst = new ArrayList<>();
int i = 1;
for (Task task: tasks) {
if (date == null || task.isOccuringOn(date)) {
if (task.fulfilCriteria(date, keyWord)) {
lst.add((i++) + ". " + task.toString());
}
}
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,11 @@ public String showListCount(TaskList tasks) {
* @param tasks Tasks to display.
* @param date Date to filter tasks by.
*/
public void showTaskList(TaskList tasks, Date date) {
ArrayList<String> lst = tasks.toString(date);
if (date == null) {
lst.add(0, "Here are the tasks in your list:");
} else {
lst.add(0,
"Here are the tasks in your list that occur on " + formatDate(date) + ":");
}
public void showTaskList(TaskList tasks, Date date, String keyWord) {
ArrayList<String> lst = tasks.toString(date, keyWord);
lst.add(0, "Here are the " + ((keyWord == null) ? "" : "matching ") + "tasks in your list" + ((date == null) ?
"" :
" that occur on " + formatDate(date)) + ":");
showResponse(lst);
}

Expand Down

0 comments on commit 2738b79

Please sign in to comment.