-
Notifications
You must be signed in to change notification settings - Fork 0
Description
@Gu0Fengming We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, so that you can avoid similar problems in your tP code (which will be graded more strictly for code quality).
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
Example from src/test/java/Whiost/WhiostTest.java lines 1-1:
package Whiost;Example from src/test/java/Whiost/Ui/UiTest.java lines 1-1:
package Whiost.Ui;Example from src/test/java/Whiost/WhiostError/WhiostErrorTest.java lines 1-1:
package Whiost.WhiostError;Suggestion: Follow the package naming convention specified by the coding standard.
Aspect: Class Name Style
No easy-to-detect issues 👍
Aspect: Dead Code
No easy-to-detect issues 👍
Aspect: Method Length
Example from src/test/java/Whiost/InputCommand/InputCommandTest.java lines 17-110:
public InputCommandTest(String inp) {
this.response = new int[10];
for (int i = 0; i < 10; i++) {
this.response[i] = 0;
}
if (inp.length() >= 5 && inp.substring(0, 5).equals("todo ")) { //3
String check = "";
for (int i = 0; i < inp.length() - 5; i++) {
check += " ";
}
if (inp.equals("todo " + check)) {
this.response[0] = 1;
} else {
this.name = inp.substring(5);
this.response[3] = 1;
}
} else if (inp.equals("bye")) { //1
this.response[1] = 1;
} else if (inp.equals("list")) { //2
this.response[2] = 1;
} else if (inp.length() >= 9 && inp.substring(0, 9).equals("deadline ")) { //4
String check = "";
for (int i = 0; i < inp.length() - 9; i++) {
check += " ";
}
if (inp.equals("deadline " + check)) {
this.response[0] = 1;
} else {
this.target = inp.indexOf('/');
String sub = inp.substring(this.target + 1);
if (sub.length() > 10 && sub.charAt(7) == '-' && sub.charAt(10) == '-') {
this.timeChecker = 1;
this.month = sub.substring(8, 10);
this.date = sub.substring(11, 13);
this.year = sub.substring(3, 7);
} else {
this.time = inp.substring(this.target + 1);
this.timeChecker = 0;
}
this.name = inp.substring(9, this.target);
this.response[4] = 1;
}
} else if (inp.length() >= 6 && inp.substring(0, 6).equals("event ")) { //5
String check = "";
for (int i = 0; i < inp.length() - 6; i++) {
check += " ";
}
if (inp.equals("event " + check)) {
this.response[0] = 1;
} else {
this.target1 = inp.indexOf('/');
this.target2 = this.target1 + 1 + inp.substring(this.target1 + 1).indexOf('/');
this.name = inp.substring(6, this.target1);
this.startTime = inp.substring(this.target1 + 5, this.target2);
this.endTime = inp.substring(this.target2 + 4);
this.response[5] = 1;
}
} else if (inp.length() >= 5 && inp.substring(0, 5).equals("mark ")) { //6
String check = "";
for (int i = 0; i < inp.length() - 5; i++) {
check += " ";
}
if (inp.equals("mark " + check)) {
this.response[0] = 1;
} else {
this.target = Integer.parseInt(String.valueOf(inp.charAt(5))) - 1;
this.response[6] = 1;
}
} else if (inp.length() >= 7 && inp.substring(0, 7).equals("unmark ")) { //7
String check = "";
for (int i = 0; i < inp.length() - 7; i++) {
check += " ";
}
if (inp.equals("unmark " + check)) {
this.response[0] = 1;
} else {
this.target = Integer.parseInt(String.valueOf(inp.charAt(7))) - 1;
this.response[7] = 1;
}
} else if (inp.length() >= 7 && inp.substring(0, 7).equals("delete ")) { //8
String check = "";
for (int i = 0; i < inp.length() - 7; i++) {
check += " ";
}
if (inp.equals("delete " + check)) {
this.response[0] = 1;
} else {
this.target = Integer.parseInt(String.valueOf(inp.charAt(7))) - 1;
this.response[8] = 1;
}
} else { //9
this.response[9] = 1;
}
}Example from src/main/java/Whiost/Whiost.java lines 50-174:
public String run(String inputLine) {
int x = 0;
InputCommand inp = new InputCommand(inputLine);
int num = -1;
for (int i = 0; i < inp.response.length; i++) {
if (inp.response[i] == 1) {
num = i;
break;
}
}
if (num == 0) { // empty description
return this.error.showError(1);
} else if (num == 1){
x = 1;
assert x == 0;
return "0";
} else if (num == 2) { // list
if (this.task.lst.size() == 0) {
return this.error.showError(3);
}
StringBuilder fin = new StringBuilder();
for (int i = 0; i < this.task.lst.size(); i++) {
fin.append((i + 1)).append(".").append(this.task.typeLst.get(i)).append(this.task.markLst.get(i)).append(" ").append(this.task.lst.get(i)).append("\n");
}
return fin.toString();
} else if (num == 3) { // todo
StringBuilder fin = new StringBuilder();
fin.append(this.ui.addTask + "\n");
this.task.typeLst.add("[T]");
this.task.markLst.add("[ ]");
this.task.lst.add(inp.name);
fin.append(" " + "[T]" + "[ ]" + " " + inp.name + "\n");
fin.append(this.ui.reportTask1 + this.task.lst.size() + this.ui.reportTask2);
this.storage.save(this.task);
return fin.toString();
} else if (num == 4) { // deadline
StringBuilder fin = new StringBuilder();
fin.append(this.ui.addTask + "\n");
this.task.typeLst.add("[D]");
this.task.markLst.add("[ ]");
int pos = inp.target;
if (inp.timeChecker == 1) {
this.task.lst.add(inp.name + "(by " + this.ui.monthTrans[Integer.parseInt(inp.month) - 1] + " " + inp.date + ", " + inp.year + ")");
fin.append(" " + "[D]" + "[ ]" + " " + inp.name + "(by " + this.ui.monthTrans[Integer.parseInt(inp.month) - 1] + " " + inp.date + ", " + inp.year + ")" + "\n");
} else {
this.task.lst.add(inputLine.substring(9, pos) + "(" + inputLine.substring(pos + 1) + ")");
fin.append(" " + "[D]" + "[ ]" + " " + inp.name + "(" + inp.time + ")" + "\n");
}
fin.append(this.ui.reportTask1 + this.task.lst.size() + this.ui.reportTask2);
this.storage.save(this.task);
return fin.toString();
} else if (num == 5) { // event
StringBuilder fin = new StringBuilder();
fin.append(this.ui.addTask + "\n");
this.task.typeLst.add("[E]");
this.task.markLst.add("[ ]");
int pos1 = inp.target1;
int pos2 = inp.target2;
this.task.lst.add(inp.name + "(from:" + inp.startTime + " to:" + inp.endTime + ")");
fin.append(" " + "[E]" + "[ ]" + inp.name + "(from:" + inp.startTime + " to:" + inp.endTime + ")" + "\n");
fin.append(this.ui.reportTask1 + this.task.lst.size() + this.ui.reportTask2);
this.storage.save(this.task);
return fin.toString();
} else if (num == 6) { // mark
int pos = inp.target;
if (pos >= this.task.lst.size()) {
return this.error.showError(2);
}
StringBuilder fin = new StringBuilder();
fin.append(this.ui.marked + "\n");
this.task.markLst.set(pos, "[X]");
fin.append(" " + this.task.typeLst.get(pos) + this.task.markLst.get(pos) + " " + this.task.lst.get(pos));
this.storage.save(this.task);
return fin.toString();
} else if (num == 7) { // unmark
int pos = inp.target;
if (pos >= this.task.lst.size()) {
return this.error.showError(2);
}
StringBuilder fin = new StringBuilder();
fin.append(this.ui.unmarked + "\n");
this.task.markLst.set(pos, "[ ]");
fin.append(" " + this.task.typeLst.get(pos) + this.task.markLst.get(pos) + " " + this.task.lst.get(pos));
this.storage.save(this.task);
return fin.toString();
} else if (num == 8) { // delete
int pos = inp.target;
if (pos >= this.task.lst.size()) {
return this.error.showError(2);
}
StringBuilder fin = new StringBuilder();
fin.append(this.ui.deleted + "\n");
fin.append(" " + this.task.typeLst.get(pos) + this.task.markLst.get(pos) + this.task.lst.get(pos) + "\n");
this.task.lst.remove(pos);
this.task.markLst.remove(pos);
this.task.typeLst.remove(pos);
fin.append(this.ui.reportTask1 + this.task.lst.size() + this.ui.reportTask2);
this.storage.save(this.task);
return fin.toString();
} else if (num == 9) { //find
ArrayList<Integer> finded = new ArrayList<>();
for (int i = 0; i < this.task.lst.size(); i++) {
String cur = this.task.lst.get(i);
for (int j = 0; j < cur.length() - inp.name.length() + 1; j++){
if (Objects.equals(inp.name, cur.substring(j, j + inp.name.length()))){
finded.add(i);
break;
}
}
}
if (finded.size() == 0){
return this.error.showError(4);
} else {
StringBuilder fin = new StringBuilder();
fin.append(this.ui.finded + "\n");
for (int i = 0; i < finded.size(); i++) {
fin.append((i + 1) + "." + this.task.typeLst.get(finded.get(i)) + this.task.markLst.get(finded.get(i)) + " " + this.task.lst.get(finded.get(i)) + "\n");
}
return fin.toString();
}
} else {
return this.error.showError(0);
}
}Example from src/main/java/Whiost/InputCommand/InputCommand.java lines 25-127:
public InputCommand(String userInput) {
this.response = new int[11];
for (int i = 0; i < 11; i++) {
this.response[i] = 0;
}
if (userInput.length() >= 5 && userInput.substring(0, 5).equals("todo ")) { //3
String check = "";
for (int i = 0; i < userInput.length() - 5; i++) {
check += " ";
}
if (userInput.equals("todo " + check)) {
this.response[0] = 1;
} else {
this.name = userInput.substring(5);
this.response[3] = 1;
}
} else if (userInput.equals("list")) { //2
this.response[2] = 1;
} else if (userInput.length() >= 9 && userInput.substring(0, 9).equals("deadline ")) { //4
String check = "";
for (int i = 0; i < userInput.length() - 9; i++) {
check += " ";
}
if (userInput.equals("deadline " + check)) {
this.response[0] = 1;
} else {
this.target = userInput.indexOf('/');
String sub = userInput.substring(this.target + 1);
if (sub.length() > 10 && sub.charAt(7) == '-' && sub.charAt(10) == '-') {
this.timeChecker = 1;
this.month = sub.substring(8, 10);
this.date = sub.substring(11, 13);
this.year = sub.substring(3, 7);
} else {
this.time = userInput.substring(this.target + 1);
this.timeChecker = 0;
}
this.name = userInput.substring(9, this.target);
this.response[4] = 1;
}
} else if (userInput.length() >= 6 && userInput.substring(0, 6).equals("event ")) { //5
String check = "";
for (int i = 0; i < userInput.length() - 6; i++) {
check += " ";
}
if (userInput.equals("event " + check)) {
this.response[0] = 1;
} else {
this.target1 = userInput.indexOf('/');
this.target2 = this.target1 + 1 + userInput.substring(this.target1 + 1).indexOf('/');
this.name = userInput.substring(6, this.target1);
this.startTime = userInput.substring(this.target1 + 5, this.target2);
this.endTime = userInput.substring(this.target2 + 4);
this.response[5] = 1;
}
} else if (userInput.length() >= 5 && userInput.substring(0, 5).equals("mark ")) { //6
String check = "";
for (int i = 0; i < userInput.length() - 5; i++) {
check += " ";
}
if (userInput.equals("mark " + check)) {
this.response[0] = 1;
} else {
this.target = Integer.parseInt(String.valueOf(userInput.charAt(5))) - 1;
this.response[6] = 1;
}
} else if (userInput.length() >= 7 && userInput.substring(0, 7).equals("unmark ")) { //7
String check = "";
for (int i = 0; i < userInput.length() - 7; i++) {
check += " ";
}
if (userInput.equals("unmark " + check)) {
this.response[0] = 1;
} else {
this.target = Integer.parseInt(String.valueOf(userInput.charAt(7))) - 1;
this.response[7] = 1;
}
} else if (userInput.length() >= 7 && userInput.substring(0, 7).equals("delete ")) { //8
String check = "";
for (int i = 0; i < userInput.length() - 7; i++) {
check += " ";
}
if (userInput.equals("delete " + check)) {
this.response[0] = 1;
} else {
this.target = Integer.parseInt(String.valueOf(userInput.charAt(7))) - 1;
this.response[8] = 1;
}
} else if (userInput.length() >= 5 && userInput.substring(0, 5).equals("find ")){ //9
String check = "";
for (int i = 0; i < userInput.length() - 5; i++) {
check += " ";
}
if (userInput.equals("find " + check)) {
this.response[0] = 1;
} else {
this.name = userInput.substring(5);
this.response[9] = 1;
}
} else { //10
this.response[10] = 1;
}
}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/Whiost/Whiost.java lines 21-25:
/**
* Initialize chatbot Ui, Storage, Task and Errors
*
* @param filePath the filepath of a txt file where the tasks store at
*/Example from src/main/java/Whiost/Whiost.java lines 47-49:
/**
* Run the chatbot and Looping until exit
*/Example from src/main/java/Whiost/Ui/Ui.java lines 20-22:
/**
* Initializing all the words that could be said by chatbot
*/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 Messages
No easy-to-detect issues 👍
Aspect: Binary files in repo
No easy-to-detect issues 👍
❗ You are not required to (but you are welcome to) fix the above problems in your iP, unless you have been separately asked to resubmit the iP due to code quality 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.