leeyi45 / ip Goto Github PK
View Code? Open in Web Editor NEWThis project forked from nus-cs2103-ay2223s2/ip
This project forked from nus-cs2103-ay2223s2/ip
@leeyi45 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 ๐
Example from src/test/java/duke/commands/taskCommand/TaskCommandTest.java
lines 1-1
:
package duke.commands.taskCommand;
Suggestion: Follow the package naming convention specified by the coding standard.
No easy-to-detect issues ๐
Example from src/main/java/duke/Utils.java
lines 48-48
:
// System.out.format("Couldn't match %s with %s\n", str, pattern);
Suggestion: Remove dead code from the codebase.
Example from src/main/java/duke/App.java
lines 33-77
:
public void start(Stage primaryStage) throws IOException {
List<Task> tasks;
while (true) {
try {
tasks = Storage.loadFromDisk("data.dat");
break;
} catch (Exception e) {
ButtonType res = UI.showRetryDialog(AlertType.ERROR, "Failed to load your saved tasks! Try again?");
if (res == ButtonType.NO) {
tasks = new ArrayList<>();
break;
}
}
}
Duke instance = new Duke(tasks);
MainWindow controller = new MainWindow();
VBox box = Utils.loadFxmlFile(getClass().getResource("/view/MainWindow.fxml"), controller);
controller.setDuke(instance);
Scene scene = new Scene(box);
primaryStage.setScene(scene);
primaryStage.show();
this.primaryStage = primaryStage;
scene.getWindow()
.addEventFilter(WindowEvent.WINDOW_CLOSE_REQUEST, e -> {
while (true) {
try {
Storage.saveToDisk("data.dat", instance.getTaskList());
return;
} catch (IOException ex) {
ButtonType res = UI.showRetryDialog(
AlertType.ERROR,
String.format("Failed to save your tasks: %s Try again?", ex.getMessage()
));
if (res == ButtonType.NO) {
break;
}
}
}
});
singleton = this;
}
Example from src/main/java/duke/Utils.java
lines 64-113
:
public final static LocalDateTime parseDateTime(String str0, String str1) {
List<String> dateFormats = List.of(
"dd/MM"
);
List<String> timeFormats = List.of(
"hh:mma",
"kk:mm",
"kkmm"
);
Function<String, Optional<MonthDay>> dateParser = createParser(dateFormats, MonthDay::parse);
Function<String, Optional<LocalTime>> timeParser = createParser(timeFormats, LocalTime::parse);
if (str0 == null && str1 == null) {
throw new IllegalArgumentException("Both str0 and str1 cannot be null!", null);
} else if (str0 == null && str1 != null) {
return parseDateTime(str1, null);
}
LocalDateTime currentTime = LocalDateTime.now();
if (str0 != null && str1 == null) {
Optional<MonthDay> dateValue = dateParser.apply(str0);
if (dateValue.isEmpty()) {
Optional<LocalTime> timeValue = timeParser.apply(str0.toUpperCase());
if (timeValue.isEmpty()) {
throw new DateTimeParseException("Invalid date/time string!", str0, 0);
}
return LocalDateTime.of(currentTime.toLocalDate(), timeValue.get());
}
return LocalDateTime.of(dateValue.get().atYear(currentTime.getYear()), currentTime.toLocalTime());
} else {
Optional<MonthDay> date = dateParser.apply(str0);
Optional<LocalTime> time = timeParser.apply(str1.toUpperCase());
if (date.isEmpty() || time.isEmpty()) {
date = dateParser.apply(str1);
time = timeParser.apply(str0.toUpperCase());
}
if (date.isEmpty() || time.isEmpty()) {
throw new DateTimeParseException("Invalid date/time string!", str1, 0);
}
LocalDate dateValue = date.get().atYear(currentTime.getYear());
return LocalDateTime.of(dateValue, time.get());
}
}
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.
No easy-to-detect issues ๐
Example from src/main/java/duke/Duke.java
lines 64-68
:
/**
* Try to execute the command as specified by the input string
* @param input Raw string as entered by the user
* @param instance Instance of Duke to run the command with
*/
Example from src/main/java/duke/Utils.java
lines 23-30
:
/**
* Recombine an array of strings into a singular string, starting from the provided
* start index to the end index exclusive.
* @param args Array containing strings to join
* @param from From index, inclusive
* @param to To index, exclusive
* @return Recombined string
*/
Example from src/main/java/duke/Utils.java
lines 55-63
:
/**
* Parse the strings for date and time information. Passing null for one of the arguments indicates
* that only either date or time information was available. Passing both will create a LocalDateTime
* with both time and date information. If there is a missing component, it will be filled with LocalDateTime.now().
* @param str0 Null or string to parse for either date or time
* @param str1 Null or string to parse for either date or time
* @return LocalDateTime containing either the parsed date and time or the parsed arguments
* combined with the current time.
*/
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.
@leeyi45 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/Task.java
lines 19-19
:
private 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/duke/commands/indexedCommand/DeleteCommand.java
lines 1-1
:
package duke.commands.indexedCommand;
Example from src/main/java/duke/commands/indexedCommand/IndexedCommand.java
lines 1-1
:
package duke.commands.indexedCommand;
Example from src/main/java/duke/commands/indexedCommand/MarkCommand.java
lines 1-1
:
package duke.commands.indexedCommand;
Suggestion: Follow the package naming convention specified by the coding standard.
No easy-to-detect issues ๐
Example from src/main/java/duke/Utils.java
lines 48-48
:
// System.out.format("Couldn't match %s with %s\n", str, pattern);
Suggestion: Remove dead code from the codebase.
Example from src/main/java/duke/Utils.java
lines 64-113
:
public final static LocalDateTime parseDateTime(String str0, String str1) {
List<String> dateFormats = List.of(
"dd/MM"
);
List<String> timeFormats = List.of(
"hh:mma",
"kk:mm",
"kkmm"
);
Function<String, Optional<MonthDay>> dateParser = createParser(dateFormats, MonthDay::parse);
Function<String, Optional<LocalTime>> timeParser = createParser(timeFormats, LocalTime::parse);
if (str0 == null && str1 == null) {
throw new IllegalArgumentException("Both str0 and str1 cannot be null!", null);
} else if (str0 == null && str1 != null) {
return parseDateTime(str1, null);
}
LocalDateTime currentTime = LocalDateTime.now();
if (str0 != null && str1 == null) {
Optional<MonthDay> dateValue = dateParser.apply(str0);
if (dateValue.isEmpty()) {
Optional<LocalTime> timeValue = timeParser.apply(str0.toUpperCase());
if (timeValue.isEmpty()) {
throw new DateTimeParseException("Invalid date/time string!", str0, 0);
}
return LocalDateTime.of(currentTime.toLocalDate(), timeValue.get());
}
return LocalDateTime.of(dateValue.get().atYear(currentTime.getYear()), currentTime.toLocalTime());
} else {
Optional<MonthDay> date = dateParser.apply(str0);
Optional<LocalTime> time = timeParser.apply(str1.toUpperCase());
if (date.isEmpty() || time.isEmpty()) {
date = dateParser.apply(str1);
time = timeParser.apply(str0.toUpperCase());
}
if (date.isEmpty() || time.isEmpty()) {
throw new DateTimeParseException("Invalid date/time string!", str1, 0);
}
LocalDate dateValue = date.get().atYear(currentTime.getYear());
return LocalDateTime.of(dateValue, time.get());
}
}
Example from src/main/java/duke/commands/taskCommand/EventCommand.java
lines 16-62
:
protected Event getTask(String[] args, Duke instance) throws ValidationException {
int fromIndex = -1, toIndex = -1;
for (int i = 1; i < args.length; i++) {
if (args[i].equalsIgnoreCase("/from")) {
fromIndex = i;
} else if (args[i].equalsIgnoreCase("/to")) {
toIndex = i;
}
if (fromIndex != -1 && toIndex != -1) {
break;
}
}
validate(fromIndex != -1, "Expected a /from directive!");
validate(toIndex != -1, "Expected a /to directive!");
int fromLength, toLength;
if (fromIndex > toIndex) {
fromLength = args.length - fromIndex - 1;
toLength = fromIndex - toIndex - 1;
} else {
toLength = args.length - toIndex - 1;
fromLength = toIndex - fromIndex - 1;
}
validate(Math.min(fromIndex, toIndex) > 1, "Expected a task!");
validate(toLength > 0, "Expected a time after /to!");
validate(fromLength > 0, "Expected a time after /from!");
try {
LocalDateTime fromTime = Utils.parseDateTime(
args[fromIndex + 1],
fromLength < 2 ? null : args[fromIndex + 2]
);
LocalDateTime toTime = Utils.parseDateTime(
args[toIndex + 1],
toLength < 2 ? null : args[toIndex + 2]
);
validate(fromTime.isBefore(toTime), " I can't create an event that ends before it starts!");
String taskStr = Utils.stringJoiner(args, 1, Math.min(fromIndex, toIndex));
return new Event(taskStr, fromTime, toTime);
} catch (DateTimeParseException e) {
throw new ValidationException("Failed to parse the date you've given: %s\n", e.getParsedString());
}
}
Example from src/main/java/duke/ui/AddTaskWindow.java
lines 40-90
:
public static Dialog<Optional<Task>> getAddTaskDialog() throws IOException {
AddTaskWindow controller = new AddTaskWindow();
DialogPane pane = Utils.loadFxmlFile(AddTaskWindow.class.getResource("/view/AddTaskWindow.fxml"), controller);
Dialog<Optional<Task>> diag = new Dialog<>();
diag.setDialogPane(pane);
diag.setResultConverter((buttonType) -> {
if (buttonType == ButtonType.OK) {
Task newTask = controller.createTask();
return Optional.of(newTask);
} else {
return Optional.empty();
}
});
pane.getButtonTypes().addAll(
ButtonType.OK,
ButtonType.CANCEL
);
pane.lookupButton(ButtonType.OK).addEventFilter(ActionEvent.ACTION, event -> {
String error = null;
String typeToAdd = controller.taskTypeComboBox.getValue();
if (typeToAdd == null || typeToAdd.isBlank()) {
error = "Select a type for the task!";
}
String taskDesc = controller.taskDescField.getText();
if (taskDesc == null || taskDesc.isBlank()) {
error = "A valid description for the task must be provided!";
}
if (typeToAdd.equals("Deadline")) {
if (controller.endDatePicker.getValue() == null) {
error = "Need a deadline!";
}
} else if (typeToAdd.equals("Event")) {
if (controller.startDatePicker.getValue() == null) {
error = "Need a start time for event!";
} else if (controller.endDatePicker.getValue() == null) {
error = "Need an end time for event!";
}
}
if (error != null) {
Alert alert = new Alert(AlertType.ERROR, error, new ButtonType[] { ButtonType.OK });
alert.show();
event.consume();
}
});
return diag;
}
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.
No easy-to-detect issues ๐
Example from src/main/java/duke/Utils.java
lines 23-30
:
/**
* Recombine an array of strings into a singular string, starting from the provided
* start index to the end index exclusive.
* @param args Array containing strings to join
* @param from From index, inclusive
* @param to To index, exclusive
* @return Recombined string
*/
Example from src/main/java/duke/Utils.java
lines 55-63
:
/**
* Parse the strings for date and time information. Passing null for one of the arguments indicates
* that only either date or time information was available. Passing both will create a LocalDateTime
* with both time and date information. If there is a missing component, it will be filled with LocalDateTime.now().
* @param str0 Null or string to parse for either date or time
* @param str1 Null or string to parse for either date or time
* @return LocalDateTime containing either the parsed date and time or the parsed arguments
* combined with the current time.
*/
Example from src/main/java/duke/commands/Command.java
lines 28-33
:
/**
* Throw {@link #ValidationException ValidationException} if the provided condition is false.
* @param condition Condition to check
* @param errMsg Error message to return to the user
* @throws ValidationException
*/
Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement.
possible problems in commit 2a00f01
:
Added a UI to Duke
Suggestion: Follow the given conventions for Git commit messages for future commits (no need to modify past commit messages).
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 [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.