zixin448 / ip Goto Github PK
View Code? Open in Web Editor NEWThis project forked from nus-cs2103-ay2122s2/ip
This project forked from nus-cs2103-ay2122s2/ip
@zixin448 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.
No easy-to-detect issues ๐
Example from src/main/java/duke/Task.java
lines 4-4
:
boolean done;
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)
No easy-to-detect issues ๐
Example from src/main/java/Control/DialogBox.java
lines 1-1
:
package Control;
Example from src/main/java/Control/MainWindow.java
lines 1-1
:
package Control;
Suggestion: Follow the package naming convention specified by the coding standard.
No easy-to-detect issues ๐
Example from src/main/java/duke/Storage.java
lines 29-29
:
// String directory_path = "src/main/data";
Example from src/main/java/duke/Storage.java
lines 30-30
:
// String directory_path = "./";
Example from src/main/java/duke/Storage.java
lines 31-31
:
// File directory = new File(directory_path);
Suggestion: Remove dead code from the codebase.
Example from src/main/java/duke/FindCommand.java
lines 32-95
:
public void execute(TaskList tasklist, Ui ui, Storage storage) throws DukeException {
ArrayList<Task> all = tasklist.getAllTasks();
ArrayList<Task> filtered = new ArrayList<Task>();
for (Task t : all) {
if (t instanceof Deadline) {
Deadline deadline = (Deadline) t;
if (deadline.getDate().equals(keyword)) {
filtered.add(t);
} else {
String deadlineName = deadline.getName();
String[] splitName = deadlineName.split(" ");
for (String s : splitName) {
if (s.equals(keyword)) {
filtered.add(t);
}
}
}
} else if (t instanceof ToDo) {
ToDo todo = (ToDo) t;
String todoName = todo.getName();
String[] splitName = todoName.split(" ");
for (String s : splitName) {
if (s.equals(keyword)) {
filtered.add(t);
}
}
} else if (t instanceof Event) {
Event event = (Event) t;
String venue = event.getVenue();
String name = event.getName();
String[] splitVenue = venue.split(" ");
String[] splitName = name.split(" ");
int length = splitName.length + splitVenue.length;
String[] merged = new String[length];
int pointer = 0;
for (String s : splitVenue) {
merged[pointer] = s;
pointer++;
}
for (String s : splitName) {
merged[pointer] = s;
pointer++;
}
for (String s : merged) {
if (s.equals(keyword)) {
filtered.add(t);
}
}
} else {
throw new DukeException("I'm not sure what happened! Please try again later or call 999...");
}
}
if (filtered.size() == 0) {
ui.printFilteredDeadline(0);
} else {
TaskList filteredTasklist = new TaskList(filtered);
// do nothing to storage
ui.printFilteredDeadline(filteredTasklist);
}
}
Example from src/main/java/duke/Parser.java
lines 24-139
:
public static Command parse(String input) throws IOException, DukeException, DukeDeadlineException, DukeEventException {
String[] words = input.split(" ", 2);
if (words[0].equals("bye")) {
return new ByeCommand(); //ending sentence
} else if (words[0].equals("list")) {
return new ListCommand();
} else if (words[0].equals("mark")) {
if (words.length != 2) {
throw new DukeEventException(
"OOPS!!! Please enter in format: mark <task_number>\n " +
"e.g. mark 1");
} else {
try {
int ranking = Integer.parseInt(words[1]);
return new MarkCommand(ranking);
} catch (Exception e) {
throw new DukeException("Ranking should be a number! Call 'list' to see what tasks you have.");
}
}
} else if (words[0].equals("unmark")) {
if (words.length != 2) {
throw new DukeEventException(
"OOPS!!! Please enter in format: unmark <task_number>\n " +
"e.g. unmark 1");
} else {
try {
int ranking = Integer.parseInt(words[1]);
return new UnmarkCommand(ranking);
} catch (Exception e) {
throw new DukeException("Ranking should be a number! Call 'list' to see what tasks you have.");
}
}
} else if (words[0].equals("delete")) {
if (words.length != 2) {
throw new DukeEventException(
"OOPS!!! Please enter in format: delete <task_number>\n " +
"e.g. delete 1");
} else {
try {
int ranking = Integer.parseInt(words[1]);
return new DeleteCommand(ranking);
} catch (Exception e) {
throw new DukeException("Ranking should be a number! Call 'list' to see what tasks you have.");
}
}
} else if (words[0].equals("todo")) {
if (words.length != 2) {
throw new DukeEventException(
"OOPS!!! Please enter in format: todo <task>\n " +
"e.g. todo sing a song");
} else {
Task task = new ToDo(words[1]);
if (task == null) {
throw new DukeDeadlineException("Todo not added...");
} else {
return new AddCommand(task);
}
}
} else if (words[0].equals("event")) {
if (words.length != 2) {
throw new DukeEventException(
"OOPS!!! Please enter in format: event <event> /at <event venue> \n " +
"e.g. event Lesson /at Com1");
} else {
try {
Task task = Event.setEvent(words[1]);
if (task == null) {
throw new DukeDeadlineException("Event not added...");
} else {
return new AddCommand(task);
}
} catch (Exception e) {
throw e;
}
}
} else if (words[0].equals("deadline")) {
if (words.length != 2) {
throw new DukeDeadlineException("OOPS!!! Please enter in format: deadline <task> /by <yyyy-mm-dd> \n " +
"e.g. deadline complete project /by 2022-12-24");
} else {
try {
Task task = Deadline.setDeadline(words[1]);
if (task == null) {
throw new DukeDeadlineException("Deadline not added...");
} else {
return new AddCommand(task);
}
} catch (Exception e) {
throw e;
}
}
} else if (words[0].equals("delete")) {
int ranking = Integer.parseInt(words[1]);
return new DeleteCommand(ranking);
} else if (words[0].equals("find")) {
try {
return new FindCommand(words[1]);
} catch (Exception e) {
throw new DukeException("I'm not sure what's happening. Please try again later!");
}
} else {
throw new DukeException("Invalid Command!! Try something else hehe:)");
}
}
Example from src/main/java/duke/Storage.java
lines 55-123
:
public ArrayList<Task> getAllTasks() throws IOException, DukeDeadlineException, DukeException, DukeEventException {
ArrayList<Task> all = new ArrayList<Task>();
Scanner s = new Scanner(file);
String str;
while (s.hasNextLine()) {
str = s.nextLine();
// str is in format [_type_][_completion_] rest_of_the_task
// str.split("]", 3) returns [ "[_type_", "[_completion_", " rest_of_the_task" ]
String[] str_split = str.split("\\]", 3);
String[] type = str_split[0].split("\\[");
String[] completion = str_split[1].split("\\[");
String[] content = str_split[2].split(" ", 2);
if (type[1].equals("T")) {
Task todo = new ToDo(content[1]);
if (completion[1].equals("X")) {
todo.markDone();
}
all.add(todo);
} else if (type[1].equals("E")) {
// format of Event is [E][ ] event_name (at: event_venue)
// str_split[] = { "[E", "[ ", " event_name (at: event_venue)" }
// content = { " ", "event_name (at: event_venue)" }
String separator = " \\(at:";
String[] getEventName = content[1].split(separator, 2);
String eventName = getEventName[0];
String eventVenue = getEventName[1].split("\\)")[0];
Task event = Event.setEvent(eventName + " /at " + eventVenue);
if (completion[1].equals("X")) {
event.markDone();
}
all.add(event);
} else if (type[1].equals("D")) {
// format of Deadline is [D][] task_name (by: deadline_in_yyyy-mm-dd)
// str_split[] = { "[D", "[ ", " task_name (by: deadline_in_yyyy-mm-dd)" }
// content = { " ", "task_name (by: deadline_in_yyyy-mm-dd)" }
String separator = " \\(by:";
String[] getTaskName = content[1].split(separator, 2);
String taskName = getTaskName[0];
String taskBy = getTaskName[1].split("\\)")[0];
// formatting to input
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd yyyy");
String taskByDate = LocalDate.parse(taskBy, formatter).toString();
Task deadline = Deadline.setDeadline(taskName + " /by " + taskByDate);
if (completion[1].equals("X")) {
deadline.markDone();
}
all.add(deadline);
} else {
throw new DukeException("Error when reading storage file");
}
}
return all;
}
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.
No easy-to-detect issues ๐
Example from src/main/java/duke/ByeCommand.java
lines 8-15
:
/**
* Call ui method to print bye statement
* Set isExit to true and exit program
* @param tasklist TaskList has all current tasks
* @param ui Ui handles printing to output
* @param storage Storage saves tasklist
* @return void
*/
Example from src/main/java/duke/Command.java
lines 27-29
:
/**
* Set isExit to true
*/
Example from src/main/java/duke/Deadline.java
lines 28-33
:
/**
* Static method to return a Deadline object
* @param input String to be parsed
* @return Deadline Task object
* @throws DukeDeadlineException
*/
Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement.
No easy-to-detect issues ๐
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 [email protected]
if you want to follow up on this post.
@zixin448 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.
No easy-to-detect issues ๐
Example from src/main/java/duke/Task.java
lines 4-4
:
boolean done;
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)
No easy-to-detect issues ๐
Example from src/main/java/Control/DialogBox.java
lines 1-1
:
package Control;
Example from src/main/java/Control/MainWindow.java
lines 1-1
:
package Control;
Suggestion: Follow the package naming convention specified by the coding standard.
No easy-to-detect issues ๐
Example from src/main/java/duke/Storage.java
lines 29-29
:
// String directory_path = "src/main/data";
Example from src/main/java/duke/Storage.java
lines 30-30
:
// String directory_path = "./";
Example from src/main/java/duke/Storage.java
lines 31-31
:
// File directory = new File(directory_path);
Suggestion: Remove dead code from the codebase.
Example from src/main/java/duke/FindCommand.java
lines 32-95
:
public void execute(TaskList tasklist, Ui ui, Storage storage) throws DukeException {
ArrayList<Task> all = tasklist.getAllTasks();
ArrayList<Task> filtered = new ArrayList<Task>();
for (Task t : all) {
if (t instanceof Deadline) {
Deadline deadline = (Deadline) t;
if (deadline.getDate().equals(keyword)) {
filtered.add(t);
} else {
String deadlineName = deadline.getName();
String[] splitName = deadlineName.split(" ");
for (String s : splitName) {
if (s.equals(keyword)) {
filtered.add(t);
}
}
}
} else if (t instanceof ToDo) {
ToDo todo = (ToDo) t;
String todoName = todo.getName();
String[] splitName = todoName.split(" ");
for (String s : splitName) {
if (s.equals(keyword)) {
filtered.add(t);
}
}
} else if (t instanceof Event) {
Event event = (Event) t;
String venue = event.getVenue();
String name = event.getName();
String[] splitVenue = venue.split(" ");
String[] splitName = name.split(" ");
int length = splitName.length + splitVenue.length;
String[] merged = new String[length];
int pointer = 0;
for (String s : splitVenue) {
merged[pointer] = s;
pointer++;
}
for (String s : splitName) {
merged[pointer] = s;
pointer++;
}
for (String s : merged) {
if (s.equals(keyword)) {
filtered.add(t);
}
}
} else {
throw new DukeException("I'm not sure what happened! Please try again later or call 999...");
}
}
if (filtered.size() == 0) {
ui.printFilteredDeadline(0);
} else {
TaskList filteredTasklist = new TaskList(filtered);
// do nothing to storage
ui.printFilteredDeadline(filteredTasklist);
}
}
Example from src/main/java/duke/Parser.java
lines 24-139
:
public static Command parse(String input) throws IOException, DukeException, DukeDeadlineException, DukeEventException {
String[] words = input.split(" ", 2);
if (words[0].equals("bye")) {
return new ByeCommand(); //ending sentence
} else if (words[0].equals("list")) {
return new ListCommand();
} else if (words[0].equals("mark")) {
if (words.length != 2) {
throw new DukeEventException(
"OOPS!!! Please enter in format: mark <task_number>\n " +
"e.g. mark 1");
} else {
try {
int ranking = Integer.parseInt(words[1]);
return new MarkCommand(ranking);
} catch (Exception e) {
throw new DukeException("Ranking should be a number! Call 'list' to see what tasks you have.");
}
}
} else if (words[0].equals("unmark")) {
if (words.length != 2) {
throw new DukeEventException(
"OOPS!!! Please enter in format: unmark <task_number>\n " +
"e.g. unmark 1");
} else {
try {
int ranking = Integer.parseInt(words[1]);
return new UnmarkCommand(ranking);
} catch (Exception e) {
throw new DukeException("Ranking should be a number! Call 'list' to see what tasks you have.");
}
}
} else if (words[0].equals("delete")) {
if (words.length != 2) {
throw new DukeEventException(
"OOPS!!! Please enter in format: delete <task_number>\n " +
"e.g. delete 1");
} else {
try {
int ranking = Integer.parseInt(words[1]);
return new DeleteCommand(ranking);
} catch (Exception e) {
throw new DukeException("Ranking should be a number! Call 'list' to see what tasks you have.");
}
}
} else if (words[0].equals("todo")) {
if (words.length != 2) {
throw new DukeEventException(
"OOPS!!! Please enter in format: todo <task>\n " +
"e.g. todo sing a song");
} else {
Task task = new ToDo(words[1]);
if (task == null) {
throw new DukeDeadlineException("Todo not added...");
} else {
return new AddCommand(task);
}
}
} else if (words[0].equals("event")) {
if (words.length != 2) {
throw new DukeEventException(
"OOPS!!! Please enter in format: event <event> /at <event venue> \n " +
"e.g. event Lesson /at Com1");
} else {
try {
Task task = Event.setEvent(words[1]);
if (task == null) {
throw new DukeDeadlineException("Event not added...");
} else {
return new AddCommand(task);
}
} catch (Exception e) {
throw e;
}
}
} else if (words[0].equals("deadline")) {
if (words.length != 2) {
throw new DukeDeadlineException("OOPS!!! Please enter in format: deadline <task> /by <yyyy-mm-dd> \n " +
"e.g. deadline complete project /by 2022-12-24");
} else {
try {
Task task = Deadline.setDeadline(words[1]);
if (task == null) {
throw new DukeDeadlineException("Deadline not added...");
} else {
return new AddCommand(task);
}
} catch (Exception e) {
throw e;
}
}
} else if (words[0].equals("delete")) {
int ranking = Integer.parseInt(words[1]);
return new DeleteCommand(ranking);
} else if (words[0].equals("find")) {
try {
return new FindCommand(words[1]);
} catch (Exception e) {
throw new DukeException("I'm not sure what's happening. Please try again later!");
}
} else {
throw new DukeException("Invalid Command!! Try something else hehe:)");
}
}
Example from src/main/java/duke/Storage.java
lines 55-123
:
public ArrayList<Task> getAllTasks() throws IOException, DukeDeadlineException, DukeException, DukeEventException {
ArrayList<Task> all = new ArrayList<Task>();
Scanner s = new Scanner(file);
String str;
while (s.hasNextLine()) {
str = s.nextLine();
// str is in format [_type_][_completion_] rest_of_the_task
// str.split("]", 3) returns [ "[_type_", "[_completion_", " rest_of_the_task" ]
String[] str_split = str.split("\\]", 3);
String[] type = str_split[0].split("\\[");
String[] completion = str_split[1].split("\\[");
String[] content = str_split[2].split(" ", 2);
if (type[1].equals("T")) {
Task todo = new ToDo(content[1]);
if (completion[1].equals("X")) {
todo.markDone();
}
all.add(todo);
} else if (type[1].equals("E")) {
// format of Event is [E][ ] event_name (at: event_venue)
// str_split[] = { "[E", "[ ", " event_name (at: event_venue)" }
// content = { " ", "event_name (at: event_venue)" }
String separator = " \\(at:";
String[] getEventName = content[1].split(separator, 2);
String eventName = getEventName[0];
String eventVenue = getEventName[1].split("\\)")[0];
Task event = Event.setEvent(eventName + " /at " + eventVenue);
if (completion[1].equals("X")) {
event.markDone();
}
all.add(event);
} else if (type[1].equals("D")) {
// format of Deadline is [D][] task_name (by: deadline_in_yyyy-mm-dd)
// str_split[] = { "[D", "[ ", " task_name (by: deadline_in_yyyy-mm-dd)" }
// content = { " ", "task_name (by: deadline_in_yyyy-mm-dd)" }
String separator = " \\(by:";
String[] getTaskName = content[1].split(separator, 2);
String taskName = getTaskName[0];
String taskBy = getTaskName[1].split("\\)")[0];
// formatting to input
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd yyyy");
String taskByDate = LocalDate.parse(taskBy, formatter).toString();
Task deadline = Deadline.setDeadline(taskName + " /by " + taskByDate);
if (completion[1].equals("X")) {
deadline.markDone();
}
all.add(deadline);
} else {
throw new DukeException("Error when reading storage file");
}
}
return all;
}
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.
No easy-to-detect issues ๐
Example from src/main/java/duke/ByeCommand.java
lines 8-15
:
/**
* Call ui method to print bye statement
* Set isExit to true and exit program
* @param tasklist TaskList has all current tasks
* @param ui Ui handles printing to output
* @param storage Storage saves tasklist
* @return void
*/
Example from src/main/java/duke/Command.java
lines 27-29
:
/**
* Set isExit to true
*/
Example from src/main/java/duke/Deadline.java
lines 28-33
:
/**
* Static method to return a Deadline object
* @param input String to be parsed
* @return Deadline Task object
* @throws DukeDeadlineException
*/
Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.