-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Long Zeling] iP #235
base: master
Are you sure you want to change the base?
[Long Zeling] iP #235
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I think your code is very clean and well-structured aside from some minor fixable places here and there. Also, I really like your logo :)
src/main/java/seedu/duke/Parser.java
Outdated
* @return Command. | ||
* @throws DukeException If the input is incomplete. | ||
*/ | ||
public static Command parse(String str) throws DukeException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps consider a clearer name for the method's parameter such as "command" or "input"?
src/main/java/seedu/duke/Parser.java
Outdated
import java.time.format.DateTimeFormatter; | ||
import java.util.regex.Pattern; | ||
|
||
import main.java.seedu.duke.commands.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this import statement list all sub-packages explicitly?
src/main/java/seedu/duke/Parser.java
Outdated
* @throws DukeException If the input is incomplete. | ||
*/ | ||
public static Command parse(String str) throws DukeException { | ||
String[] split1 = str.split(" ", 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps consider changing "split1" into another name like "tokens" or "words"?
src/main/java/seedu/duke/Parser.java
Outdated
*/ | ||
public static Task parseTaskFromStorage(String taskStr) { | ||
Task savedTask; | ||
String[] split = taskStr.split(Pattern.quote(" | ")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this variable name "split" here and some other places below might could be changed into a more meaningful name, too.
System.out.println(" " + " " + | ||
"[" + taskToBeDeleted.getStatusIcon() + "] " + | ||
taskToBeDeleted.getDescription()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work for remembering to break lines before they get too long! But shouldn't the line be broken before the operators? I think you could move the trailing plus signs to the beginning of the next line.
<<<<<<< HEAD | ||
tasks.doneTasks(taskNo); | ||
======= | ||
tasks.doneTask(taskNo); | ||
// ui.showDoneMessage(); | ||
>>>>>>> branch-A-CodingStandard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the merge conflict be resolved before being pushed into the remote repo?
* Represents an event happening at a particular time. | ||
*/ | ||
public class Event extends Task { | ||
protected LocalDate at; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the variable name be changed into a more meaningful one like "time" or "date"?
data/duke.txt
Outdated
T | 0 | borrow book | ||
E | 0 | project meeting | Oct 15 2020 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the data file be ignored?
src/main/java/seedu/duke/Parser.java
Outdated
if (commandWord.equals("list")) { | ||
return new ListCommand(); | ||
} else if (commandWord.equals("bye")) { | ||
return new ExitCommand(); | ||
} else if (commandWord.equals("done")) { | ||
throw new DukeException("Please tell me the task number that you have completed."); | ||
} else if (commandWord.equals("date")) { | ||
throw new DukeException("Please provide a date."); | ||
} else if (commandWord.equals("delete")) { | ||
throw new DukeException("Please tell me the task number that you want to delete."); | ||
} else if (commandWord.equals("todo")) { | ||
throw new DukeException("OOPS!!! The description of a todo cannot be empty."); | ||
} else if (commandWord.equals("deadline")) { | ||
throw new DukeException("OOPS!!! The description of a deadline cannot be empty."); | ||
} else if (commandWord.equals("event")) { | ||
throw new DukeException("OOPS!!! The description of a event cannot be empty."); | ||
} else { | ||
throw new DukeException("OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this part should use switch case? And also for the todo/deadline/event, I think you can use String format to reduce the number of duplicate code
src/main/java/seedu/duke/Parser.java
Outdated
* @return Task. | ||
*/ | ||
public static Task parseTask(String taskStr) { | ||
String[] splits = taskStr.split(" ",2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change the name here from splits to tokens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi I have finished reviewing your PR! Nice job!
public void readFile() { | ||
// load the file first | ||
File directory = new File(DIRECTORY_PATH); | ||
if (!directory.exists()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the method name should be a verb, so maybe change exists() to checkExist instead?
} catch (IOException e) { | ||
System.out.println(e.getMessage()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is an exception here, should the program be ended?
} else { | ||
writeToFile(FILE_PATH, taskList.tasks.get(0).getData()); | ||
for (int i = 1; i < taskList.tasks.size(); i++) { | ||
String taskData = taskList.tasks.get(i).getData(); | ||
appendToFile(FILE_PATH, taskData); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe if you write return above then no need this else? To keep the "HAPPY" path straight?
public void appendToFile(String filePath, String textToAdd) { | ||
try { | ||
FileWriter fw = new FileWriter(filePath, true); | ||
fw.write(textToAdd + System.lineSeparator()); | ||
fw.close(); | ||
} catch (IOException e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Write text to local file at filePath. This overwrites the whole file. | ||
* @param filePath The relative path of the file. | ||
* @param textToAdd The text to be added. | ||
*/ | ||
public void writeToFile(String filePath, String textToAdd) { | ||
try { | ||
FileWriter fw = new FileWriter(filePath); | ||
fw.write(textToAdd + System.lineSeparator()); | ||
fw.close(); | ||
} catch (IOException e) { | ||
System.out.println(e.getMessage()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the two function should be merged into one to reduce duplicate codes?
if (tasks.size() <= 0) { | ||
throw new DukeException("You don't have any tasks."); | ||
} | ||
ArrayList<Task> taskList = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the name of the taskList should be changed since it can be mistaken with tasks!
if (taskDate != null) { | ||
if (taskDate.isEqual(date)) { | ||
taskList.add(task); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the 2 if should be merged together!
* Marks the task as done. | ||
* @param taskNo The task number in the list. | ||
*/ | ||
public void doneTask(int taskNo) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think function names should be in verb-form
} | ||
|
||
public void searchKeyword(String keyword) throws DukeException { | ||
if (tasks.size() <= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A very small thing but I think you may find useful that the size of the array cannot be negative, so I think just check if it's equal to 0 or not is enough! A better way is to check task.isEmpty()==true
src/main/java/seedu/duke/Ui.java
Outdated
public String getHorizontalLine() { | ||
String line = ""; | ||
for (int i = 0; i < lengthOfLine; i++) { | ||
line = line + "-"; | ||
} | ||
return line; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the horizontal line should be a static variable and should only be created once
src/main/java/seedu/duke/Ui.java
Outdated
*/ | ||
public class Ui { | ||
private int lengthOfLine = 55; | ||
private String line; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the name line can be more descriptive!
added assertions
make changes in accordance to coding quality
No description provided.