Skip to content
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

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open

Conversation

zeling595
Copy link

No description provided.

Copy link

@PhongTran98 PhongTran98 left a 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 :)

* @return Command.
* @throws DukeException If the input is incomplete.
*/
public static Command parse(String str) throws DukeException {

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"?

import java.time.format.DateTimeFormatter;
import java.util.regex.Pattern;

import main.java.seedu.duke.commands.*;

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?

* @throws DukeException If the input is incomplete.
*/
public static Command parse(String str) throws DukeException {
String[] split1 = str.split(" ", 2);

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"?

*/
public static Task parseTaskFromStorage(String taskStr) {
Task savedTask;
String[] split = taskStr.split(Pattern.quote(" | "));

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.

Comment on lines 101 to 103
System.out.println(" " + " " +
"[" + taskToBeDeleted.getStatusIcon() + "] " +
taskToBeDeleted.getDescription());

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.

Comment on lines 27 to 32
<<<<<<< HEAD
tasks.doneTasks(taskNo);
=======
tasks.doneTask(taskNo);
// ui.showDoneMessage();
>>>>>>> branch-A-CodingStandard

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;

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
Comment on lines 1 to 2
T | 0 | borrow book
E | 0 | project meeting | Oct 15 2020

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?

Comment on lines 30 to 48
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 :-(");
}

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

* @return Task.
*/
public static Task parseTask(String taskStr) {
String[] splits = taskStr.split(" ",2);

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?

Copy link

@UncleGrandpa925 UncleGrandpa925 left a 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()) {

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?

Comment on lines 50 to 52
} catch (IOException e) {
System.out.println(e.getMessage());
}

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?

Comment on lines 62 to 68
} 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);
}
}

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?

Comment on lines 76 to 98
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());
}

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<>();

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!

Comment on lines 44 to 47
if (taskDate != null) {
if (taskDate.isEqual(date)) {
taskList.add(task);
}

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) {

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) {

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

Comment on lines 22 to 28
public String getHorizontalLine() {
String line = "";
for (int i = 0; i < lengthOfLine; i++) {
line = line + "-";
}
return line;
}

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

*/
public class Ui {
private int lengthOfLine = 55;
private String line;

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants