forked from nus-cs2103-AY2122S2/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClearAllCommand.java
48 lines (42 loc) · 1.25 KB
/
ClearAllCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package duke.command;
import java.util.Objects;
import duke.utils.CortanaException;
import duke.utils.Storage;
import duke.utils.TaskList;
import duke.utils.Ui;
/**
* The type Delete all command.
*/
public class ClearAllCommand extends Command {
/**
* Clear all tasks in the task list.
*
* @param taskList the task list to operate on
* @param ui the ui to operate on
* @param storage the storage to operate on
*/
public String execute(TaskList taskList, Ui ui, Storage storage) throws CortanaException {
try {
taskList.getTaskSet().clear();
taskList.getTaskList().clear();
assert taskList.getTaskSet().isEmpty() && taskList.getTaskList().isEmpty();
storage.writeFile(taskList);
assert storage.loadFile().isEmpty();
return ui.clearAll();
} catch (Exception e) {
throw new CortanaException("Something went wrong when attempting to clear all tasks.");
}
}
@Override
public boolean equals(Object obj) {
if (obj != null) {
return obj instanceof ClearAllCommand;
} else {
return false;
}
}
@Override
public int hashCode() {
return Objects.hash();
}
}