-
Notifications
You must be signed in to change notification settings - Fork 0
Description
@RingoftheKing 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
Example from src/main/java/BadApple/task/Messenger.java lines 6-6:
public static boolean suppressMessages = false;Suggestion: Follow the given naming convention for boolean variables/methods (e.g., use a boolean-sounding prefix).You may ignore the above if you think the name already follows the convention (the script can report false positives in some cases)
Aspect: Brace Style
No easy-to-detect issues 👍
Aspect: Package Name Style
Example from src/main/java/BadApple/main/BadAppleException.java lines 1-1:
package BadApple.main;Example from src/main/java/BadApple/main/BadPingGuo.java lines 1-1:
package BadApple.main;Example from src/main/java/BadApple/main/Launcher.java lines 1-1:
package BadApple.main;Suggestion: Follow the package naming convention specified by the coding standard.
Aspect: Class Name Style
No easy-to-detect issues 👍
Aspect: Dead Code
Example from src/main/java/BadApple/main/BadPingGuo.java lines 37-37:
// public static void main(String[] args) {Example from src/main/java/BadApple/main/BadPingGuo.java lines 38-38:
// Ui.showWelcome();Example from src/main/java/BadApple/main/BadPingGuo.java lines 39-39:
// Scanner sc = new Scanner(System.in);Suggestion: Remove dead code from the codebase.
Aspect: Method Length
Example from src/main/java/BadApple/main/BadPingGuo.java lines 96-179:
public void start(Stage stage) {
//Step 1. Setting up required components
scrollPane = new ScrollPane();
dialogContainer = new VBox();
dialogContainer.setSpacing(25);
scrollPane.setContent(dialogContainer);
userInput = new TextField();
sendButton = new Button("Send");
AnchorPane mainLayout = new AnchorPane();
mainLayout.getChildren().addAll(scrollPane, userInput, sendButton);
scene = new Scene(mainLayout);
stage.setScene(scene);
stage.show();
//Step 2. Formatting the window to look as expected
stage.setTitle("Duke");
stage.setResizable(false);
stage.setMinHeight(800.0);
stage.setMinWidth(600.0);
mainLayout.setPrefSize(600.0, 8000.0);
scrollPane.setPrefSize(590, 740);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
scrollPane.setVvalue(1.0);
scrollPane.setFitToWidth(true);
//You will need to import `javafx.scene.layout.Region` for this.
dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE);
userInput.setPrefWidth(455.0);
userInput.setPrefHeight(30.0);
sendButton.setPrefWidth(100.0);
sendButton.setPrefHeight(30);
AnchorPane.setTopAnchor(scrollPane, 1.0);
AnchorPane.setBottomAnchor(sendButton, 1.0);
AnchorPane.setRightAnchor(sendButton, 1.0);
AnchorPane.setLeftAnchor(userInput , 1.0);
AnchorPane.setBottomAnchor(userInput, 1.0);
// initialisation step 1: welcome
dialogContainer.getChildren().add(getDialogLabel(Ui.showWelcome()));
// initialisation step 2: load save
try {
Storage.loadSave(new File(FILENAME));
dialogContainer.getChildren().add(DialogBox.getDukeDialog(
(TaskList.listTasks(new BufferedReader(new FileReader(FILENAME)))),
(duke)));
} catch (IOException e) {
dialogContainer.getChildren().add(getDialogLabel("FAILED"));
}
sendButton.setOnMouseClicked((event) -> {
dialogContainer.getChildren().add(getDialogLabel(userInput.getText()));
userInput.clear();
});
userInput.setOnAction((event) -> {
dialogContainer.getChildren().add(getDialogLabel(userInput.getText()));
userInput.clear();
});
//Scroll down to the end every time dialogContainer's height changes.
dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0));
sendButton.setOnMouseClicked((event) -> {
handleUserInput();
});
userInput.setOnAction((event) -> {
handleUserInput();
});
}Example from src/main/java/BadApple/task/Parser.java lines 22-117:
public static String ProcessQuery(String s) throws IOException {
String[] tokens = s.split(" ");
ArrayList<String> args = new ArrayList<String>(Arrays.asList(tokens));
String reply = "DEFAULT";
switch (args.get(0).toLowerCase()) {
case "list":
return TaskList.listTasks(new BufferedReader(new FileReader(BadPingGuo.FILENAME)));
case "mark":
try {
int taskIndex = parseInt(tokens[1]) - 1;
Task t = TaskList.tasks.get(taskIndex);
reply = t.mark(true, taskIndex);
} catch (NumberFormatException e) {
reply = "Usage: mark <taskNumber>";
System.out.println(reply);
} catch (IndexOutOfBoundsException e) {
reply = "Hey you don't have that task!";
System.out.println(reply);
}
break;
case "unmark":
try {
int taskIndex = parseInt(tokens[1]) - 1;
Task t = TaskList.tasks.get(taskIndex);
reply = t.mark(false, taskIndex);
} catch (NumberFormatException e) {
reply = "Usage: mark <taskNumber>";
System.out.println(reply);
} catch (IndexOutOfBoundsException e) {
reply = "Calm down! You don't have THAT many tasks!";
System.out.println(reply);
}
break;
case "todo":
// it is possible to relegate exception handling to addTask
// you must use fp and implement lazy evaluation
try {
reply = Storage.addTask(Todo.extractDetails(s));
} catch (BadAppleException be) {
System.out.println(be);
reply = be.toString();
}
break;
case "deadline":
try {
reply = Storage.addTask(Deadline.extractDetails(args));
} catch (BadAppleException be) {
System.out.println(be);
reply = be.toString();
} catch (DateTimeParseException dateError) {
reply = "Help me by phrasing the deadline in YYYY-MM-DD format";
System.out.println(reply);
}
break;
case "event":
try {
reply = Storage.addTask(Event.extractDetails(args));
} catch (BadAppleException be) {
System.out.println(be);
reply = be.toString();
}
break;
case "delete":
if (tokens.length <= 1) {
reply = "Kel nuked, but he missed what task you wanted to remove!";
System.out.println(reply);
break;
}
int taskIndex;
try {
taskIndex = parseInt(tokens[1]) - 1;
} catch (NumberFormatException e) {
reply = "Usage: delete <taskNumber>";
break;
}
if (taskIndex >= 0 && taskIndex < TaskList.tasks.size()) {
reply = Storage.removeTask(taskIndex);
} else {
reply = "welcome to BLACK SPACE, you keyed in a non-existent task!";
}
break;
case "find":
if (tokens.length <= 1) {
System.out.println("There is nothing here... to find");
break;
}
reply = TaskList.filterTasks(s.substring(5).trim());
break;
default:
reply = "Whatcha sayin? scream 'help!' for list of my services";
}
Storage.updateTasks(new File(BadPingGuo.FILENAME));
return reply;
}Example from src/main/java/BadApple/task/Storage.java lines 55-147:
public static void loadSave(File file) throws IOException, BadAppleException {
// check the file to see what tasks are already available.
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
StringBuilder stringBuilder = new StringBuilder();
int taskIndex = 1;
while (bufferedReader.ready()) {
String line = bufferedReader.readLine();
// deconstruct the line:
ArrayList<String> args = new ArrayList<>(Arrays.asList(line.split(" ")));
String command = "";
String query = "";
StringBuilder taskName;
boolean status = args.get(2).equals("[X]");
if (!(args.size() < 2)) {
command = args.get(1);
} else {
return;
}
switch (command.toLowerCase()) {
case "todo":
// the fourth token should be the task name for this command.
if (args.size() < 4) {
throw new BadAppleException("Todo Task in wrong format, " +
"should be <number> todo <status> <taskName>");
}
taskName = new StringBuilder();
for (int i = 3; i < args.size(); i++) {
taskName.append(args.get(i));
}
query = "todo " + taskName;
break;
case "deadline":
if (args.size() < 6 || !args.contains("(by:")) {
throw new BadAppleException("Deadline in wrong format" +
"should be <number> 'deadline' <status> <description> '(by: ' <ByValue>");
}
taskName = new StringBuilder();
StringBuilder by = new StringBuilder();
int separator = args.indexOf("(by:");
for (int i = 3; i < separator; i++) {
taskName.append(args.get(i)).append(" ");
}
for (int i = separator + 1; i < args.size() - 1; i++) {
by.append(args.get(i)).append(" ");
}
by.deleteCharAt(by.length() - 1);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMM uuuu");
LocalDate byValue = LocalDate.parse(by, formatter);
query = "deadline " + taskName + "/by " + byValue;
break;
case "event":
if (args.size() < 8 || !(args.contains("(from:") && args.contains("to:"))) {
throw new BadAppleException("Event in wrong format" +
"should be <no.> 'event' <status> <description> " +
"'(from: ' <fromValue> 'to: ' <toValue>");
}
taskName = new StringBuilder();
StringBuilder from = new StringBuilder();
StringBuilder to = new StringBuilder();
int fromSeparator = args.indexOf("(from:");
for (int i = 3; i < fromSeparator; i++) {
taskName.append(args.get(i)).append(" ");
}
int toSeparator = args.indexOf("to:");
for (int i = fromSeparator + 1; i < toSeparator; i++) {
from.append(args.get(i)).append(" ");
}
for (int i = toSeparator + 1; i < args.size() - 1; i++) {
to.append(args.get(i)).append(" ");
}
query = "event " + taskName + "/from " + from + "/to " + to;
break;
default:
System.out.println("unrecognizable command detected");
throw new BadAppleException("The sun shined brighter when your files weren't corrupted");
}
// upon reconstructing the command, execute it.
Parser.ProcessQuery(query);
if (status) {
// if this task is already complete, mark it.
Parser.ProcessQuery("mark " + taskIndex);
}
taskIndex++;
}
}Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods e.g., extract some code blocks into separate 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/BadApple/main/BadPingGuo.java lines 188-192:
/**
* Iteration 2:
* Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to
* the dialog container. Clears the user input after processing.
*/Example from src/main/java/BadApple/main/BadPingGuo.java lines 208-211:
/**
* You should have your own function to generate a response to user input.
* Replace this stub with your completed method.
*/Example from src/main/java/BadApple/task/Storage.java lines 12-17:
/**
* After each request by the user, erases previous contents of the file
* and rebuilds the file based on task list
* @param file the file to write tasks to
* @throws IOException if file writing fails for any reason
*/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
possible problems in commit 3617dba:
Follow SE-Edu coding standard.
Coding standards are good practices
Following them provides readability.
- Subject line should not end with a period
Suggestion: Follow the given conventions for Git commit messages for future commits (do not modify past commit messages as doing so will change the commit timestamp that we used to detect your commit timings).
Aspect: Binary files in repo
No easy-to-detect issues 👍
ℹ️ The bot account used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact cs2103@comp.nus.edu.sg if you want to follow up on this post.