aryagiat / ip Goto Github PK
View Code? Open in Web Editor NEWThis project forked from nus-cs2103-ay2122s1/ip
This project forked from nus-cs2103-ay2122s1/ip
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 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 ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
Example from src/main/java/duke/Duke.java
lines 83-178
:
public String getResponse(String input) {
assert input != null : "[duke.Duke.getResponse]: input parameter is null";
String output = "";
try {
// Parses user input.
HashMap<String, String> inputs = parser.parseInput(input);
Constant.Command command = Constant.Command.valueOf(inputs.get("command"));
String task;
// Process user input.
switch (command) {
case HELP:
// Gets user manual.
output = ui.getHelpMenu();
break;
case BYE:
// Quits program.
isRunning = false;
break;
case LIST:
// Gets the string represented tasks in the task list.
output = taskList.getAllTask();
break;
case DONE:
// Marks a task as being completed.
int index = parser.convertToInt(inputs.get("index"));
output = taskList.markDone(index);
// Edits the file content.
task = storage.getFileLine(index - 1);
task = task.substring(0, 4) + "1" + task.substring(5);
storage.updateLineFile(index - 1, task);
break;
case TODO:
// Adds a todo-typed task to the task list.
Todo todo = new Todo(inputs.get("description"));
output = taskList.addItem(todo);
// Add to file content.
task = todo.savedToString();
storage.addToFile(task);
break;
case DEADLINE:
// Adds a deadline-typed task in the task list.
Deadline deadline = new Deadline(inputs.get("description"), inputs.get("date"));
output = taskList.addItem(deadline);
// Add to file content.
task = deadline.savedToString();
storage.addToFile(task);
break;
case EVENT:
// Adds an event-typed task in the task list.
Event event = new Event(inputs.get("description"), inputs.get("date"));
output = taskList.addItem(event);
// Add to file content.
task = event.savedToString();
storage.addToFile(task);
break;
case DELETE:
// Deletes a task from the task list.
int id = parser.convertToInt(inputs.get("index"));
output = taskList.removeItem(id);
// Remove from file content.
storage.removeFromFile(id - 1);
break;
case DATES:
// Gets the accepted date types.
output = ui.getAllAcceptedDates();
break;
case FIND:
// Gets the task matching the queried keyword.
output = taskList.find(inputs.get("keyword"));
break;
default:
output = "Invalid Message";
}
// Return the output message.
return output;
} catch (Exception e) {
return e.getMessage();
}
}
Example from src/main/java/duke/Parser.java
lines 23-169
:
public HashMap<String, String> parseInput(String rawInput) throws DukeException {
assert rawInput != null : "[duke.Parser.parseInput]: rawInput is null";
String[] inputs = rawInput.split("\\s+");
if (inputs.length < 1) {
throw new DukeException(DukeException.Errors.INVALID_COMMAND.toString());
}
Constant.Command command;
String commandStr = inputs[0].toUpperCase();
try {
command = Constant.Command.valueOf(commandStr);
} catch (Exception e) {
throw new DukeException(DukeException.Errors.INVALID_COMMAND.toString());
}
HashMap<String, String> parsedInput = new HashMap<>();
switch (command) {
case LIST:
if (inputs.length != 1) {
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString()
+ " `list` command has no arguments");
}
parsedInput.put("command", commandStr);
break;
case DONE:
if (inputs.length != 2) {
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString()
+ " (example: 'done 5')");
}
try {
// Checks if the argument is a number.
Integer.parseInt(inputs[1]);
} catch (Exception e) {
throw new DukeException(DukeException.Errors.WRONG_ARGUMENT_TYPE.toString()
+ " (example: 'done 5')");
}
parsedInput.put("command", commandStr);
parsedInput.put("index", inputs[1]);
break;
case TODO:
if (inputs.length < 2) {
throw new DukeException(DukeException.Errors.MISSING_DESCRIPTION.toString()
+ " (example: 'todo watch Borat')");
}
String description = combineStringArray(inputs, 1, inputs.length);
parsedInput.put("command", commandStr);
parsedInput.put("description", description);
break;
case DEADLINE:
if (inputs.length < 2) {
throw new DukeException(DukeException.Errors.MISSING_DESCRIPTION.toString()
+ " (example: 'deadline watch Borat /by 2021-08-21 18:00')");
}
String argument = combineStringArray(inputs, 1, inputs.length);
String[] arguments = argument.split(" /by ");
if (arguments.length < 2) {
throw new DukeException(DukeException.Errors.MISSING_DATE.toString()
+ " (example: 'deadline watch Borat /by 2021-08-21 18:00')");
} else if (arguments.length > 2) {
throw new DukeException(DukeException.Errors.INVALID_DATE.toString()
+ " (example: 'deadline watch Borat /by 2021-08-21 18:00')");
}
String date = parseDateTime(arguments[1]);
parsedInput.put("command", commandStr);
parsedInput.put("description", arguments[0]);
parsedInput.put("date", date);
break;
case EVENT:
if (inputs.length < 2) {
throw new DukeException(DukeException.Errors.MISSING_DESCRIPTION.toString()
+ " (example: 'event Borat concert /at 2021-08-21 18:00')");
}
String arg = combineStringArray(inputs, 1, inputs.length);
String[] args = arg.split(" /at ");
if (args.length < 2) {
throw new DukeException(DukeException.Errors.MISSING_DATE.toString()
+ " (example: 'event watch Borat /at 2021-08-21 18:00')");
} else if (args.length > 2) {
throw new DukeException(DukeException.Errors.INVALID_DATE.toString()
+ " (example: 'event watch Borat /at 2021-08-21 18:00')");
}
String dateTest = parseDateTime(args[1]);
parsedInput.put("command", commandStr);
parsedInput.put("description", args[0]);
parsedInput.put("date", dateTest);
break;
case BYE:
if (inputs.length != 1) {
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString()
+ " `bye` command has no arguments");
}
parsedInput.put("command", commandStr);
break;
case DELETE:
if (inputs.length != 2) {
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString()
+ " (example: 'delete 5')");
}
try {
// Check if the argument is a number
Integer.parseInt(inputs[1]);
} catch (Exception e) {
throw new DukeException(DukeException.Errors.WRONG_ARGUMENT_TYPE.toString()
+ " (example: 'delete 5')");
}
parsedInput.put("command", commandStr);
parsedInput.put("index", inputs[1]);
break;
case HELP:
if (inputs.length != 1) {
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString()
+ " `help` command has no arguments");
};
parsedInput.put("command", commandStr);
break;
case DATES:
if (inputs.length != 1) {
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString()
+ " `dates` command has no arguments");
}
parsedInput.put("command", commandStr);
break;
case FIND:
if (inputs.length < 2) {
throw new DukeException(DukeException.Errors.MISSING_DESCRIPTION.toString()
+ " (example: 'find book')");
}
String keyword = combineStringArray(inputs, 1, inputs.length);
parsedInput.put("command", commandStr);
parsedInput.put("keyword", keyword);
break;
default:
// Invalid command
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString());
}
return parsedInput;
}
Example from src/main/java/duke/Parser.java
lines 213-284
:
private String parseDate(String[] dateTime) throws DukeException {
String date = dateTime[0].toUpperCase();
String formatPattern = "yyyy-MM-dd";
String result = "";
LocalDate todayDate = LocalDate.now();
try {
switch (date) {
case "TODAY":
result += todayDate.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "TOMORROW":
LocalDate tomorrowDate = todayDate.plusDays(1);
result += tomorrowDate.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "MON":
case "MONDAY":
LocalDate nextMonday = todayDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
result += nextMonday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "TUE":
case "TUESDAY":
LocalDate nextTuesday = todayDate.with(TemporalAdjusters.next(DayOfWeek.TUESDAY));
result += nextTuesday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "WED":
case "WEDNESDAY":
LocalDate nextWednesday = todayDate.with(TemporalAdjusters.next(DayOfWeek.WEDNESDAY));
result += nextWednesday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "THU":
case "THURSDAY":
LocalDate nextThursday = todayDate.with(TemporalAdjusters.next(DayOfWeek.THURSDAY));
result += nextThursday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "FRI":
case "FRIDAY":
LocalDate nextFriday = todayDate.with(TemporalAdjusters.next(DayOfWeek.FRIDAY));
result += nextFriday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "SAT":
case "SATURDAY":
LocalDate nextSaturday = todayDate.with(TemporalAdjusters.next(DayOfWeek.SATURDAY));
result += nextSaturday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "SUN":
case "SUNDAY":
LocalDate nextSunday = todayDate.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));
result += nextSunday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
default:
String[] date1 = date.split("-");
String[] date2 = date.split("/");
if (date1.length == 3 || date2.length == 3) {
result = date1.length == 3 ? stringToDate(date1) : stringToDate(date2);
} else {
throw new DukeException(DukeException.Errors.INVALID_DATE.toString());
}
}
} catch (Exception e) {
throw new DukeException(DukeException.Errors.INVALID_DATE.toString());
}
return result;
}
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.
Example from src/main/java/duke/Duke.java
lines 48-51
:
/**
* Entry point of the Duke program.
* @param args Command line arguments.
*/
Example from src/main/java/duke/Storage.java
lines 145-148
:
/**
* Saving the file content to the hard drive.
* @throws DukeException when saving the file fails.
*/
Example from src/main/java/duke/Ui.java
lines 50-53
:
/**
* Get the user input
* @return The string representation of the user input
*/
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 @cs2103-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.
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 ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
Example from src/main/java/duke/Parser.java
lines 45-183
:
public Command parseInput(String rawInput) throws DukeException {
assert rawInput != null : "[duke.Parser.parseInput]: rawInput is null";
// Splitting of raw input by white space.
String[] inputs = rawInput.split("\\s+");
if (inputs.length < 1) {
throw new DukeException(DukeException.Errors.INVALID_COMMAND.toString());
}
// Check if the command is valid.
Constant.Command command;
String commandStr = inputs[0].toUpperCase();
try {
command = Constant.Command.valueOf(commandStr);
} catch (Exception e) {
throw new DukeException(DukeException.Errors.INVALID_COMMAND.toString());
}
// Process the command and the raw input.
switch (command) {
case LIST:
if (inputs.length != 1) {
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString()
+ " `list` command has no arguments");
}
return new ListCommand(taskList);
case DONE:
if (inputs.length != 2) {
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString()
+ " (example: 'done 5')");
}
try {
// The index in the backend is 0-based (that's why the input is subtracted by 1).
int index = convertToInt(inputs[1]) - 1;
return new DoneCommand(index, taskList);
} catch (Exception e) {
throw new DukeException(DukeException.Errors.WRONG_ARGUMENT_TYPE.toString()
+ " (example: 'done 5')");
}
case TODO:
if (inputs.length < 2) {
throw new DukeException(DukeException.Errors.MISSING_DESCRIPTION.toString()
+ " (example: 'todo watch Borat')");
}
String description = combineStringArray(inputs, 1, inputs.length);
return new TodoCommand(description, taskList);
case DEADLINE:
if (inputs.length < 2) {
throw new DukeException(DukeException.Errors.MISSING_DESCRIPTION.toString()
+ " (example: 'deadline watch Borat /by 2021-08-21 18:00')");
}
// Split the deadline description and date.
String argument = combineStringArray(inputs, 1, inputs.length);
String[] arguments = argument.split(" /by ");
if (arguments.length < 2) {
throw new DukeException(DukeException.Errors.MISSING_DATE.toString()
+ " (example: 'deadline watch Borat /by 2021-08-21 18:00')");
} else if (arguments.length > 2) {
throw new DukeException(DukeException.Errors.INVALID_DATE.toString()
+ " (example: 'deadline watch Borat /by 2021-08-21 18:00')");
}
// Get the deadline date.
String date = parseDateTime(arguments[1]);
return new DeadlineCommand(arguments[0], date, taskList);
case EVENT:
if (inputs.length < 2) {
throw new DukeException(DukeException.Errors.MISSING_DESCRIPTION.toString()
+ " (example: 'event Borat concert /at 2021-08-21 18:00')");
}
// Split the event description and date.
String arg = combineStringArray(inputs, 1, inputs.length);
String[] args = arg.split(" /at ");
if (args.length < 2) {
throw new DukeException(DukeException.Errors.MISSING_DATE.toString()
+ " (example: 'event watch Borat /at 2021-08-21 18:00')");
} else if (args.length > 2) {
throw new DukeException(DukeException.Errors.INVALID_DATE.toString()
+ " (example: 'event watch Borat /at 2021-08-21 18:00')");
}
// Get the event date.
String eventDate = parseDateTime(args[1]);
return new EventCommand(args[0], eventDate, taskList);
case BYE:
if (inputs.length != 1) {
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString()
+ " `bye` command has no arguments");
}
return new ByeCommand();
case DELETE:
if (inputs.length != 2) {
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString()
+ " (example: 'delete 5')");
}
try {
// The index in the backend is 0-based (that's why the input is subtracted by 1).
int index = convertToInt(inputs[1]) - 1;
return new DeleteCommand(index, taskList);
} catch (Exception e) {
throw new DukeException(DukeException.Errors.WRONG_ARGUMENT_TYPE.toString()
+ " (example: 'delete 5')");
}
case HELP:
if (inputs.length != 1) {
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString()
+ " `help` command has no arguments");
}
return new HelpCommand();
case DATES:
if (inputs.length != 1) {
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString()
+ " `dates` command has no arguments");
}
return new DatesCommand();
case FIND:
if (inputs.length < 2) {
throw new DukeException(DukeException.Errors.MISSING_DESCRIPTION.toString()
+ " (example: 'find book')");
}
String keyword = combineStringArray(inputs, 1, inputs.length);
return new FindCommand(keyword, taskList);
default:
// Invalid command
throw new DukeException(DukeException.Errors.INVALID_ARGUMENT.toString());
}
}
Example from src/main/java/duke/Parser.java
lines 269-340
:
private String parseDate(String[] dateTime) throws DukeException {
String date = dateTime[0].toUpperCase();
String formatPattern = "yyyy-MM-dd";
String result = "";
LocalDate todayDate = LocalDate.now();
try {
switch (date) {
case "TODAY":
result += todayDate.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "TOMORROW":
LocalDate tomorrowDate = todayDate.plusDays(1);
result += tomorrowDate.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "MON":
case "MONDAY":
LocalDate nextMonday = todayDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
result += nextMonday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "TUE":
case "TUESDAY":
LocalDate nextTuesday = todayDate.with(TemporalAdjusters.next(DayOfWeek.TUESDAY));
result += nextTuesday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "WED":
case "WEDNESDAY":
LocalDate nextWednesday = todayDate.with(TemporalAdjusters.next(DayOfWeek.WEDNESDAY));
result += nextWednesday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "THU":
case "THURSDAY":
LocalDate nextThursday = todayDate.with(TemporalAdjusters.next(DayOfWeek.THURSDAY));
result += nextThursday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "FRI":
case "FRIDAY":
LocalDate nextFriday = todayDate.with(TemporalAdjusters.next(DayOfWeek.FRIDAY));
result += nextFriday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "SAT":
case "SATURDAY":
LocalDate nextSaturday = todayDate.with(TemporalAdjusters.next(DayOfWeek.SATURDAY));
result += nextSaturday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
case "SUN":
case "SUNDAY":
LocalDate nextSunday = todayDate.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));
result += nextSunday.format(DateTimeFormatter.ofPattern(formatPattern));
break;
default:
String[] date1 = date.split("-");
String[] date2 = date.split("/");
if (date1.length == 3 || date2.length == 3) {
result = date1.length == 3 ? stringToDate(date1) : stringToDate(date2);
} else {
throw new DukeException(DukeException.Errors.INVALID_DATE.toString());
}
}
} catch (Exception e) {
throw new DukeException(DukeException.Errors.INVALID_DATE.toString());
}
return result;
}
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/Duke.java
lines 44-47
:
/**
* Entry point of the Duke program.
* @param args Command line arguments.
*/
Example from src/main/java/duke/Storage.java
lines 130-133
:
/**
* Saving the file content to the hard drive.
* @throws DukeException when saving the file fails.
*/
Example from src/main/java/duke/Ui.java
lines 60-63
:
/**
* Get the user input
* @return The string representation of the user input
*/
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 ๐
โ 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 @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.