@RyanCheungJF We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, to help you improve the iP code further.
IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.
Aspect: Tab Usage
No easy-to-detect issues ๐
Aspect: Naming boolean variables/methods
No easy-to-detect issues ๐
Aspect: Brace Style
No easy-to-detect issues ๐
Aspect: Package Name Style
No easy-to-detect issues ๐
Aspect: Class Name Style
No easy-to-detect issues ๐
Aspect: Dead Code
No easy-to-detect issues ๐
Aspect: Method Length
Example from src/main/java/duke/exception/DukeException.java
lines 31-78
:
public static String[] isTaskValid(int index, String input, String taskType, Tasklist list) throws DukeException {
if (taskType.equals("event")) {
if (index == -1) {
throw new DukeException("Please specify a date using '/at'.\n");
}
if (index - 1 < 6 || input.substring(6, index - 1).strip().equals("")) {
throw new DukeException("Please key in a valid task name.\n");
}
DukeException.isDuplicatedTask(input.substring(6, index - 1).strip(), list);
} else if (taskType.equals("deadline")) {
if (index == -1) {
throw new DukeException("Please specify a date using '/by'.\n");
}
if (index - 1 < 9 || input.substring(9, index - 1).strip().equals("")) {
throw new DukeException("Please key in a valid task name.\n");
}
DukeException.isDuplicatedTask(input.substring(9, index - 1).strip(), list);
} else {
throw new DukeException("Please use 'todo, deadline, event' to start adding tasks.\n");
}
if (index + 4 > input.length() || input.substring(index + 4).strip().equals("")) {
throw new DukeException("Please key in a valid time.\n");
}
if (input.contains("|")) {
throw new DukeException("Sorry, avoid using '|' as it is a special character.\n");
}
String timeString = input.substring(index + 4);
String[] timeArray = timeString.split(" ");
if (timeArray.length == 0 || timeArray.length > 2) {
throw new DukeException("Please provide time in the format 'DD/MM/YYYY <time>'.\n");
}
String[] dateArray = timeArray[0].split("/");
if (dateArray.length != 3) {
throw new DukeException("Please provide time in the format 'DD/MM/YYYY <time>'.\n");
}
String regex = "[0-9]+";
Pattern p = Pattern.compile(regex);
for (int i = 0; i < 3; i++) {
if (!p.matcher(dateArray[i]).matches()) {
throw new DukeException("Please provide time in the format 'DD/MM/YYYY <time>'.\n");
}
}
if (timeArray.length == 1) {
return dateArray;
} else {
return new String[]{dateArray[0], dateArray[1], dateArray[2], timeArray[1]};
}
}
Example from src/main/java/duke/handler/FileHandler.java
lines 39-81
:
public static void readFromFile(Tasklist list) {
FileHandler.pathAssertionCheck();
if (!java.nio.file.Files.exists(FileHandler.PATH)) {
FileHandler.createFolder();
}
try {
String input = Files.readString(FileHandler.PATH);
String[] tasks = input.split("\\r?\\n");
for (int i = 0; i < tasks.length; i++) {
String[] taskInfo = tasks[i].split("\\|");
boolean completed = taskInfo[1].equals(COMPLETED);
switch (taskInfo[0]) {
case "T":
list.addTask(new Todo(completed, taskInfo[2]));
break;
case "D":
if (taskInfo.length == 4) {
list.addTask(new Deadline(completed, taskInfo[2],
Time.convertToDate(taskInfo[3]), ""));
} else {
list.addTask(new Deadline(completed, taskInfo[2],
Time.convertToDate(taskInfo[3]), taskInfo[4]));
}
break;
case "E":
if (taskInfo.length == 4) {
list.addTask(new Event(completed, taskInfo[2],
Time.convertToDate(taskInfo[3]), ""));
} else {
list.addTask(new Event(completed, taskInfo[2],
Time.convertToDate(taskInfo[3]), taskInfo[4]));
}
break;
default:
throw new ArrayIndexOutOfBoundsException();
}
}
} catch (IOException err) {
System.out.println("Path specified incorrectly.");
} catch (ArrayIndexOutOfBoundsException err) {
FileHandler.createFolder();
}
}
Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods. You may ignore this suggestion if you think a longer method is justified in a particular case.
Aspect: Class size
No easy-to-detect issues ๐
Aspect: Header Comments
Example from src/main/java/duke/Launcher.java
lines 10-14
:
/**
* Entry point of the application
*
* @param args Arguments to be passed into the program, if any.
*/
Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement
Aspect: Recent Git Commit Message (Subject Only)
No easy-to-detect issues ๐
โน๏ธ The bot account @nus-se-bot used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact [email protected]
if you want to follow up on this post.