Skip to content

Commit

Permalink
Fix bug with code due to checkstyle changes
Browse files Browse the repository at this point in the history
Changing code from a previous commit to comply with checkstyle
guidelines is causing commands to result in NullPointerExceptions
because the commands are not registered in the Parser object.

Let's,
 * Edit TaskList to make use of name variable from Parser.
  • Loading branch information
macareonie committed Feb 13, 2024
1 parent f9062b8 commit cb25e8b
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/main/java/tsundere/task/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
public class TaskList {
protected static ArrayList<Task> taskList = new ArrayList<>();
protected static String name = Parser.getName();

private static final String INVALID_TASK_NUMBER_INPUTTED_MSG = "Im pretty sure that's the wrong task number! "
+ "Check again!";

Expand All @@ -30,7 +28,7 @@ public static String unmarkTask() throws GeneralException {
throw new GeneralException("What you tryna unmark huh?");
}
try {
Task t = TaskList.taskList.get(Integer.parseInt(TaskList.name.substring(7, 8)) - 1);
Task t = TaskList.taskList.get(Integer.parseInt(Parser.getName().substring(7, 8)) - 1);
if (t.getStatusIcon().equals(" ")) {
return "You haven't even started this task dummy!";
} else {
Expand Down Expand Up @@ -58,7 +56,7 @@ public static String markTask() throws GeneralException {
throw new GeneralException("What you tryna mark huh?");
}
try {
Task t = TaskList.taskList.get(Integer.parseInt(TaskList.name.substring(5, 6)) - 1);
Task t = TaskList.taskList.get(Integer.parseInt(Parser.getName().substring(5, 6)) - 1);
if (t.isDone) {
return "You already finished this!";
} else {
Expand Down Expand Up @@ -87,7 +85,7 @@ public static String deleteTask() throws GeneralException {
}

try {
int idx = Integer.parseInt(TaskList.name.substring(7, 8)) - 1;
int idx = Integer.parseInt(Parser.getName().substring(7, 8)) - 1;
Task t = TaskList.taskList.get(idx);
TaskList.taskList.remove(idx);
return getListSize("deleted", t);
Expand Down Expand Up @@ -129,7 +127,7 @@ public static String listTasks() throws GeneralException {
public static String addToDoTask() throws GeneralException {

try {
String todo = TaskList.name.split(" ", 2)[1];
String todo = Parser.getName().split(" ", 2)[1];

Task t = new ToDo(todo);
TaskList.taskList.add(t);
Expand All @@ -150,7 +148,7 @@ public static String addToDoTask() throws GeneralException {
public static String addEventTask() throws GeneralException {

try {
String event = TaskList.name.split(" ", 2)[1];
String event = Parser.getName().split(" ", 2)[1];
String[] x = event.split(",");

Task t = new Event(x[0], x[1].trim().split(" ", 2)[1], x[2].trim().split(" ", 2)[1]);
Expand All @@ -172,7 +170,7 @@ public static String addEventTask() throws GeneralException {
public static String addDeadlineTask() throws GeneralException {

try {
String deadline = TaskList.name.split(" ", 2)[1];
String deadline = Parser.getName().split(" ", 2)[1];
String[] x = deadline.split(",");
LocalDate d1 = LocalDate.parse(x[1].trim().split(" ", 2)[1]);
String date = d1.format(DateTimeFormatter.ofPattern("MMM d yyyy"));
Expand Down Expand Up @@ -203,7 +201,7 @@ public static String findTasks() throws GeneralException {
StringBuilder response = new StringBuilder();
try {
int count = 0;
String keyword = TaskList.name.split(" ", 2)[1];
String keyword = Parser.getName().split(" ", 2)[1];
for (int i = 0; i < size; i++) {
Task t = TaskList.taskList.get(i);
if (t.description.contains(keyword)) {
Expand Down Expand Up @@ -233,7 +231,7 @@ public static String tagTask() throws GeneralException {
throw new GeneralException("Theres's nothing to find here!");
}
try {
String[] x = TaskList.name.split(" ");
String[] x = Parser.getName().split(" ");
int idx = Integer.parseInt(x[1]) - 1;
String tag = x[2];
Task t = TaskList.taskList.get(idx);
Expand All @@ -258,7 +256,7 @@ public static String untagTask() throws GeneralException {
throw new GeneralException("Theres's nothing to find here!");
}
try {
String[] x = TaskList.name.split(" ");
String[] x = Parser.getName().split(" ");
int idx = Integer.parseInt(x[1]) - 1;
String tag = x[2];
Task t = TaskList.taskList.get(idx);
Expand Down

0 comments on commit cb25e8b

Please sign in to comment.