Skip to content

Commit ef24350

Browse files
committed
Refactor code to be more inline with code quality standards
1 parent 46c7cb6 commit ef24350

16 files changed

+95
-96
lines changed

config/checkstyle/suppressions.xml

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
<suppressions>
88
<suppress checks="JavadocType" files=".*Test\.java"/>
99
<suppress checks="MissingJavadocMethodCheck" files=".*Test\.java"/>
10+
<suppress checks="AbbreviationAsWordInName"/>
1011
</suppressions>

src/main/java/duke/Duke.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
*/
1010
public class Duke {
1111

12-
private final Storage storage;
12+
private final Storage STORAGE;
1313
private TaskList tasks;
14-
private final Ui ui;
14+
private final Ui UI;
1515

1616
/**
1717
* Constructor of Duke.
1818
*
1919
* @param filePath file path of to retrieve save file
2020
*/
2121
public Duke(String filePath) {
22-
ui = new Ui();
23-
storage = new Storage(filePath);
22+
UI = new Ui();
23+
STORAGE = new Storage(filePath);
2424
}
2525

2626
/**
@@ -30,11 +30,11 @@ public Duke(String filePath) {
3030
*/
3131
public String initialize() {
3232
try {
33-
tasks = new TaskList(storage.load(), storage);
34-
return ui.greet();
33+
tasks = new TaskList(STORAGE.load(), STORAGE);
34+
return UI.greet();
3535
} catch (DukeException e) {
36-
tasks = new TaskList(storage);
37-
return ui.showLoadingError() + ui.greet();
36+
tasks = new TaskList(STORAGE);
37+
return UI.showLoadingError() + UI.greet();
3838
}
3939
}
4040

@@ -43,9 +43,9 @@ public String getResponse(String input) {
4343
try {
4444
Command c = Parser.parse(input);
4545
isExit = c.isExit();
46-
return c.execute(tasks, ui, storage);
46+
return c.execute(tasks, UI, STORAGE);
4747
} catch (DukeException e) {
48-
return ui.printError(e.getMessage());
48+
return UI.printError(e.getMessage());
4949
}
5050
}
5151
}

src/main/java/duke/Storage.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
*/
2020
public class Storage {
2121

22-
private final String filepath;
23-
private final ArrayList<Task> list = new ArrayList<>();
22+
private final String FILEPATH;
23+
private final ArrayList<Task> LIST = new ArrayList<>();
2424

2525

2626
/**
@@ -29,7 +29,7 @@ public class Storage {
2929
* @param filepath path for saving and loading
3030
*/
3131
public Storage(String filepath) {
32-
this.filepath = filepath;
32+
this.FILEPATH = filepath;
3333
}
3434

3535
/**
@@ -39,21 +39,21 @@ public Storage(String filepath) {
3939
* @throws DukeException Exceptions for file not found
4040
*/
4141
public ArrayList<Task> load() throws DukeException {
42-
File file = new File(filepath);
42+
File file = new File(FILEPATH);
4343
try {
4444
Scanner scanner = new Scanner(file);
4545
while (scanner.hasNextLine()) {
4646
String data = scanner.nextLine();
4747
Task t = processData(data);
4848
if (t != null) {
49-
list.add(t);
49+
LIST.add(t);
5050
}
5151
}
5252
scanner.close();
5353
} catch (FileNotFoundException e) {
5454
throw new DukeException("File is not found");
5555
}
56-
return list;
56+
return LIST;
5757
}
5858

5959
private Task processData(String str) throws DukeException {
@@ -76,10 +76,10 @@ private Task processData(String str) throws DukeException {
7676
}
7777
}
7878

79-
void saveFile(ArrayList<Task> list) throws DukeException {
79+
protected void saveFile(ArrayList<Task> list) throws DukeException {
8080
try {
8181

82-
File file = new File(filepath);
82+
File file = new File(FILEPATH);
8383
file.getParentFile().mkdir();
8484
file.createNewFile();
8585
FileWriter writer = new FileWriter(file);

src/main/java/duke/TaskList.java

+21-21
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
public class TaskList {
1717

18-
private final ArrayList<Task> list;
19-
private final Storage storage;
18+
private final ArrayList<Task> LIST;
19+
private final Storage STORAGE;
2020

2121
/**
2222
* Constructor for TaskList.
@@ -25,8 +25,8 @@ public class TaskList {
2525
* @param storage Storage object of Duke
2626
*/
2727
public TaskList(ArrayList<Task> list, Storage storage) {
28-
this.list = list;
29-
this.storage = storage;
28+
this.LIST = list;
29+
this.STORAGE = storage;
3030
}
3131

3232
/**
@@ -35,8 +35,8 @@ public TaskList(ArrayList<Task> list, Storage storage) {
3535
* @param storage Storage object of Duke
3636
*/
3737
public TaskList(Storage storage) {
38-
this.list = new ArrayList<>();
39-
this.storage = storage;
38+
this.LIST = new ArrayList<>();
39+
this.STORAGE = storage;
4040
}
4141

4242

@@ -50,11 +50,11 @@ public String deleteTask(String str) throws DukeException {
5050
try {
5151
int i = Integer.parseInt(str);
5252

53-
if (i > 0 && i <= list.size()) {
54-
Task t = list.remove(i - 1);
55-
storage.saveFile(list);
53+
if (i > 0 && i <= LIST.size()) {
54+
Task t = LIST.remove(i - 1);
55+
STORAGE.saveFile(LIST);
5656
return dukePrint("Got it. I've removed this task:\n" + t + "\n" + "Now you have "
57-
+ list.size() + " task" + (list.size() < 2 ? " " : "s ") + "in the list.");
57+
+ LIST.size() + " task" + (LIST.size() < 2 ? " " : "s ") + "in the list.");
5858
} else {
5959
throw new DukeException("No such task found in list.");
6060
}
@@ -73,10 +73,10 @@ public String markDone(String str) throws DukeException {
7373
try {
7474
int i = Integer.parseInt(str);
7575

76-
if (i > 0 && i <= list.size()) {
77-
Task t = list.get(i - 1);
76+
if (i > 0 && i <= LIST.size()) {
77+
Task t = LIST.get(i - 1);
7878
t.markDone();
79-
storage.saveFile(list);
79+
STORAGE.saveFile(LIST);
8080
return dukePrint("Nice! I've marked this task as done:\n" + t);
8181
} else {
8282
throw new DukeException("No such task found in list.");
@@ -130,21 +130,21 @@ public String addToDo(String str) throws DukeException {
130130
}
131131

132132
private String addTask(Task t) throws DukeException {
133-
list.add(t);
134-
storage.saveFile(list);
133+
LIST.add(t);
134+
STORAGE.saveFile(LIST);
135135
return dukePrint("Got it. I've added this task:\n" + t + "\n" + "Now you have "
136-
+ list.size() + " task" + (list.size() < 2 ? " " : "s ") + "in the list.");
136+
+ LIST.size() + " task" + (LIST.size() < 2 ? " " : "s ") + "in the list.");
137137
}
138138

139139
/**
140140
* Displays full list of task in TaskList.
141141
*/
142142
public String displayList() {
143-
if (list.size() == 0) {
143+
if (LIST.size() == 0) {
144144
return dukePrint("list empty");
145145
}
146146
return dukePrint("Here are the tasks in your list:\n"
147-
+ IntStream.range(0, list.size()).mapToObj((i) -> (i + 1) + ". " + list.get(i).toString())
147+
+ IntStream.range(0, LIST.size()).mapToObj((i) -> (i + 1) + ". " + LIST.get(i).toString())
148148
.reduce("", (str1, str2) -> str1 + str2 + "\n"));
149149
}
150150

@@ -156,10 +156,10 @@ public String displayList() {
156156
public String findTask(String desc) {
157157
StringBuilder builder = new StringBuilder("Here are the matching tasks in your list:\n");
158158
int count = 0;
159-
for (int i = 0; i < list.size(); i++) {
160-
if (list.get(i).toString().contains(desc)) {
159+
for (int i = 0; i < LIST.size(); i++) {
160+
if (LIST.get(i).toString().contains(desc)) {
161161
count++;
162-
builder.append(count + ". " + list.get(i).toString() + "\n");
162+
builder.append(count + ". " + LIST.get(i).toString() + "\n");
163163
}
164164
}
165165
if (count == 0) {

src/main/java/duke/Ui.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Ui helper for display functions.
77
*/
88
public class Ui {
9-
private static final String divider = "__________________________________________\n";
9+
private static final String DIVIDER = "__________________________________________\n";
1010

1111
/**
1212
* Prints greeting message for Duke.
@@ -24,12 +24,12 @@ public String greet() {
2424
public static String dukePrint(String str) {
2525
StringBuilder builder = new StringBuilder();
2626
Scanner scanner = new Scanner(str);
27-
builder.append(divider);
27+
builder.append(DIVIDER);
2828
while (scanner.hasNextLine()) {
2929
builder.append(scanner.nextLine());
3030
builder.append("\n");
3131
}
32-
builder.append(divider);
32+
builder.append(DIVIDER);
3333
return builder.toString();
3434
}
3535

src/main/java/duke/command/AddDeadlineCommand.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99
* Represents command to add Deadline.
1010
*/
1111
public class AddDeadlineCommand implements Command {
12-
private final String desc;
12+
private final String DESCRIPTION;
1313

1414
/**
1515
* Constructor for AddDeadlineCommand.
1616
*
1717
* @param desc Description for Command
1818
*/
1919
public AddDeadlineCommand(String desc) {
20-
this.desc = desc;
20+
this.DESCRIPTION = desc;
2121
}
2222

2323
@Override
2424
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
25-
return tasks.addDeadline(desc);
25+
return tasks.addDeadline(DESCRIPTION);
2626
}
2727

2828
@Override

src/main/java/duke/command/AddEventCommand.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99
* Represents command to add Event.
1010
*/
1111
public class AddEventCommand implements Command {
12-
private final String desc;
12+
private final String DESCRIPTION;
1313

1414
/**
1515
* Constructor for AddEventCommand.
1616
*
1717
* @param desc Description for Command
1818
*/
1919
public AddEventCommand(String desc) {
20-
this.desc = desc;
20+
this.DESCRIPTION = desc;
2121
}
2222

2323
@Override
2424
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
25-
return tasks.addEvent(desc);
25+
return tasks.addEvent(DESCRIPTION);
2626
}
2727

2828
@Override

src/main/java/duke/command/AddToDoCommand.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99
* Represents command to add ToDo.
1010
*/
1111
public class AddToDoCommand implements Command {
12-
private final String desc;
12+
private final String DESCRIPTION;
1313

1414
/**
1515
* Constructor for AddToDoCommand.
1616
*
1717
* @param desc Description for Command
1818
*/
1919
public AddToDoCommand(String desc) {
20-
this.desc = desc;
20+
this.DESCRIPTION = desc;
2121
}
2222

2323
@Override
2424
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
25-
return tasks.addToDo(desc);
25+
return tasks.addToDo(DESCRIPTION);
2626
}
2727

2828
@Override

src/main/java/duke/command/DeleteCommand.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99
* Represents command to delete Task.
1010
*/
1111
public class DeleteCommand implements Command {
12-
private final String desc;
12+
private final String DESCRIPTION;
1313

1414
/**
1515
* Constructor for DeleteCommand.
1616
*
1717
* @param desc Description for Command
1818
*/
1919
public DeleteCommand(String desc) {
20-
this.desc = desc;
20+
this.DESCRIPTION = desc;
2121
}
2222

2323
@Override
2424
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
25-
return tasks.deleteTask(desc);
25+
return tasks.deleteTask(DESCRIPTION);
2626
}
2727

2828
@Override

src/main/java/duke/command/DoneCommand.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99
* Represents command to mark task as done.
1010
*/
1111
public class DoneCommand implements Command {
12-
private final String desc;
12+
private final String DESCRIPTION;
1313

1414
/**
1515
* Constructor for DoneCommand.
1616
*
1717
* @param desc Description for Command
1818
*/
1919
public DoneCommand(String desc) {
20-
this.desc = desc;
20+
this.DESCRIPTION = desc;
2121
}
2222

2323
@Override
2424
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
25-
return tasks.markDone(desc);
25+
return tasks.markDone(DESCRIPTION);
2626
}
2727

2828
@Override

src/main/java/duke/command/FindCommand.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99
* Represents command to find task from list.
1010
*/
1111
public class FindCommand implements Command {
12-
private final String desc;
12+
private final String DESCRIPTION;
1313

1414
/**
1515
* Constructor for FindCommand.
1616
*
1717
* @param desc Description for Command
1818
*/
1919
public FindCommand(String desc) {
20-
this.desc = desc;
20+
this.DESCRIPTION = desc;
2121
}
2222

2323
@Override
2424
public String execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
25-
return tasks.findTask(desc);
25+
return tasks.findTask(DESCRIPTION);
2626
}
2727

2828
@Override

0 commit comments

Comments
 (0)