@ddx-510 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/helptool/Parser.java
lines 129-224
:
public static Command parse(String input) throws DukeException {
if (input.equals("bye")) {
// detect bye
return new ExitCommand();
} else if (input.equals("list")) {
// detect list
return new ListCommand();
} else if (input.startsWith("find")) {
String findDetail = input.substring(4);
if (isEmpty(findDetail)) {
throw new DukeException("โน OOPS!!! The description of a find cannot be empty.");
}
return new FindCommand(findDetail);
} else {
if (input.startsWith("mark") || input.startsWith("unmark") || input.startsWith("delete")) {
boolean isDigit = !Character.isDigit(input.charAt(input.length() - 1));
int markDigit = Character.getNumericValue(input.charAt(input.length() - 1));
if (input.startsWith("mark")) {
// detect digit
if (isDigit) {
throw new DukeException("โน OOPS!!! The mark cannot be done.");
}
return new MarkCommand(markDigit);
}
if (input.startsWith("unmark")) {
// detect unmark
if (isDigit) {
throw new DukeException("โน OOPS!!! The unmark cannot be done.");
}
return new UnmarkCommand(markDigit);
}
if (input.startsWith("delete")) {
// detect delete
if (isDigit) {
throw new DukeException("โน OOPS!!! The delete cannot be done.");
}
return new DeleteCommand(markDigit);
}
} else if (input.startsWith("todo")) {
// generate
String description = getDescription(input, "T");
if (isEmpty(description)) {
throw new DukeException("โน OOPS!!! The description of a todo cannot be empty.");
}
Tag newTag = addTag(input);
return new AddCommand(description, "T", newTag);
} else if (input.startsWith("deadline")) {
if (isEmpty(input.substring(8))) {
throw new DukeException("โน OOPS!!! The description of a deadline cannot be empty.");
}
if (!input.contains("/by")) {
throw new DukeException("โน OOPS!!! The date of a deadline cannot be empty.");
}
int byPos = input.indexOf("/by");
String description = getDescription(input, "D");
String byDateTime;
if (!input.contains("#")) {
byDateTime = input.substring(byPos + 4);
} else {
byDateTime = input.substring(byPos + 4, getTagPos(input) - 1);
}
if (isValidDate(byDateTime)) {
LocalDateTime dateTime = LocalDateTime.parse(byDateTime, dateFormat);
Tag newTag = addTag(input);
return new AddCommand(description, "D", dateTime, newTag);
} else {
throw new DukeException("โน OOPS!!! The date time is not of correct format dd/MM/yyyy HHmm.");
}
} else if (input.startsWith("event")) {
if (isEmpty(input.substring(5))) {
throw new DukeException("โน OOPS!!! The description of a event cannot be empty.");
}
if (!input.contains("/at")) {
throw new DukeException("โน OOPS!!! The date of a event cannot be empty.");
}
int atPos = input.indexOf("/at");
String description = getDescription(input, "E");
String atDateTime;
if (!input.contains("#")) {
atDateTime = input.substring(atPos + 4);
} else {
atDateTime = input.substring(atPos + 4, getTagPos(input) - 1);
}
if (isValidDate(atDateTime)) {
Tag newTag = addTag(input);
LocalDateTime dateTime = LocalDateTime.parse(atDateTime, dateFormat);
return new AddCommand(description, "E", dateTime, newTag);
} else {
throw new DukeException("โน OOPS!!! The date time is not of correct format dd/MM/yyyy HHmm.");
}
} else {
throw new DukeException("โน OOPS!!! I'm sorry, but I don't know what that means :-(");
}
}
return null;
}
Example from src/main/java/duke/helptool/Storage.java
lines 87-137
:
public ArrayList<Task> load() throws DukeException {
try {
File myObj = new File(this.filePath);
Scanner myReader = new Scanner(myObj);
ArrayList<Task> tempTaskList = new ArrayList<>();
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
String tempType = data.substring(1, 2);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mm a");
switch (tempType) {
case "T":
Tag tag = getTag(data);
Task tempTask = new ToDo(data.substring(7), tag);
if (data.charAt(4) == 'X') {
tempTask.markAsDone();
}
tempTaskList.add(tempTask);
break;
case "D":
int byPos = data.indexOf("(by:");
String by = data.substring(byPos + 5, data.length() - 1);
String description = data.substring(7, byPos - 1);
tag = getTag(data);
tempTask = new Deadline(description, LocalDateTime.parse(by, formatter), tag);
if (data.charAt(4) == 'X') {
tempTask.markAsDone();
}
tempTaskList.add(tempTask);
break;
case "E":
int atPos = data.indexOf("(at:");
String at = data.substring(atPos + 5, data.length() - 1);
description = data.substring(7, atPos - 1);
tag = getTag(data);
tempTask = new Event(description, LocalDateTime.parse(at, formatter), tag);
if (data.charAt(4) == 'X') {
tempTask.markAsDone();
}
tempTaskList.add(tempTask);
break;
default:
break;
}
}
myReader.close();
return tempTaskList;
} catch (FileNotFoundException e) {
this.create();
return null;
}
}
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/Duke.java
lines 21-25
:
/**
* Create a chatterbot with record file located at filePath
*
* @param filePath The file's storage path
*/
Example from src/main/java/duke/Duke.java
lines 37-42
:
/**
* Generate response text based on user input
*
* @param input the input
* @return the response
*/
Example from src/main/java/duke/gui/Launcher.java
lines 9-13
:
/**
* The entry point of application.
*
* @param args the input arguments
*/
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.