-
Notifications
You must be signed in to change notification settings - Fork 590
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
[chashaobao] iP #640
base: master
Are you sure you want to change the base?
[chashaobao] iP #640
Changes from 12 commits
68c58c1
03523ec
81a9c53
60e495d
fddb9e9
48f9b91
064c6c3
97639d6
4f01857
1df1350
55989ae
957bf55
dfae243
0dea61f
cd8b26e
421974d
08746c5
ba6a7ef
91afd9e
3da8d0b
fb664fa
991b22f
6df0184
c7862f4
1ee7602
5f50efb
e73a476
b01a403
5656a9d
620f3de
20e7261
e543672
668af35
c088340
78d3987
1c02284
ac340f4
55d7ca0
cd35b95
b6f266c
a0b1e69
6bf7a93
6f02cc0
e4dc31b
dabdb0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"CurrentProjectSetting": null | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"ExpandedNodes": [ | ||
"" | ||
], | ||
"PreviewInSolutionExplorer": false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"Version": 1, | ||
"WorkspaceRootPath": "C:\\Users\\65814\\OneDrive\\NUSY2S1\\CS2103T\\IP\\ip\\", | ||
"Documents": [], | ||
"DocumentGroupContainers": [ | ||
{ | ||
"Orientation": 0, | ||
"VerticalTabListWidth": 256, | ||
"DocumentGroups": [] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"CurrentProjectSetting": null | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"ExpandedNodes": [ | ||
"" | ||
], | ||
"PreviewInSolutionExplorer": false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"Version": 1, | ||
"WorkspaceRootPath": "C:\\Users\\65814\\OneDrive\\NUSY2S1\\CS2103T\\IP\\ip\\src\\main\\java\\", | ||
"Documents": [], | ||
"DocumentGroupContainers": [ | ||
{ | ||
"Orientation": 0, | ||
"VerticalTabListWidth": 256, | ||
"DocumentGroups": [] | ||
} | ||
] | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main.LittleMissHelpful.Command; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeParseException; | ||
|
||
import main.LittleMissHelpful.Exception.InvalidCommandException; | ||
import main.LittleMissHelpful.Task.Deadline; | ||
import main.LittleMissHelpful.TaskList; | ||
import main.LittleMissHelpful.Ui; | ||
import main.LittleMissHelpful.Storage; | ||
|
||
public class AddDeadlineCommand extends Command { | ||
private String description; | ||
private String byString; | ||
|
||
public AddDeadlineCommand(String description, String byString) { | ||
this.description = description; | ||
this.byString = byString; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { | ||
LocalDateTime by; | ||
try { | ||
if (byString.equalsIgnoreCase("today")) { | ||
// Use current date and set time to 23:59 | ||
by = LocalDateTime.now().withHour(23).withMinute(59); | ||
} else { | ||
// Try parsing by LocalDateTime | ||
by = LocalDateTime.parse(byString); | ||
} | ||
} catch (DateTimeParseException e) { | ||
// If parsing fails, try parsing as LocalDate and set time to 23:59 | ||
try { | ||
LocalDate deadlineDate = LocalDate.parse(byString); | ||
by = deadlineDate.atTime(23, 59); | ||
} catch (DateTimeParseException ex) { | ||
throw new InvalidCommandException("Invalid date format for deadline. Please use 'yyyy-MM-ddTHH:mm' or 'yyyy-MM-dd'."); | ||
} | ||
} | ||
|
||
Deadline deadline = new Deadline(this.description, by); | ||
tasks.add(deadline); | ||
ui.showAddedNewTask(deadline, tasks); | ||
storage.save(tasks.getTasks()); | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The header comment for the class and the public methods is also missed out here, would be nice to add in! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main.LittleMissHelpful.Command; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeParseException; | ||
|
||
import main.LittleMissHelpful.Exception.InvalidCommandException; | ||
import main.LittleMissHelpful.Task.Event; | ||
import main.LittleMissHelpful.TaskList; | ||
import main.LittleMissHelpful.Ui; | ||
import main.LittleMissHelpful.Storage; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The commands naming is named well! Easy to understand what the class is handling! |
||
public class AddEventCommand extends Command { | ||
private final String description; | ||
private final String fromString; | ||
private final String toString; | ||
|
||
public AddEventCommand(String description, String fromString, String toString) { | ||
this.description = description; | ||
this.fromString = fromString; | ||
this.toString = toString; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { | ||
LocalDateTime from; | ||
LocalDateTime to; | ||
|
||
try { | ||
from = parseDateTime(fromString); | ||
to = parseDateTime(toString); | ||
|
||
Event event = new Event(description, from, to); | ||
tasks.add(event); | ||
ui.showAddedNewTask(event, tasks); | ||
storage.save(tasks.getTasks()); | ||
|
||
} catch (DateTimeParseException e) { | ||
throw new InvalidCommandException("Invalid date format. Please use 'yyyy-MM-ddTHH:mm' or 'yyyy-MM-dd'."); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return false; | ||
} | ||
|
||
private LocalDateTime parseDateTime(String dateTimeString) throws DateTimeParseException { | ||
/** | ||
* Parses string into LocalDateTime | ||
*/ | ||
|
||
if (dateTimeString.equalsIgnoreCase("today")) { | ||
// Use current date and set time to 00:00 (start of the day) | ||
return LocalDateTime.now().withHour(00).withMinute(00); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line breaks could be added here to seperate the section and make the code more readabel : ) |
||
try { | ||
// Try parsing as LocalDateTime | ||
return LocalDateTime.parse(dateTimeString); | ||
} catch (DateTimeParseException e) { | ||
try { | ||
// If LocalDateTime parsing fails, try parsing as LocalDate | ||
LocalDate date = LocalDate.parse(dateTimeString); | ||
return date.atTime(00, 00); | ||
} catch (DateTimeParseException ex) { | ||
throw ex; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main.LittleMissHelpful.Command; | ||
|
||
import main.LittleMissHelpful.Exception.InvalidCommandException; | ||
import main.LittleMissHelpful.Task.Todo; | ||
import main.LittleMissHelpful.TaskList; | ||
import main.LittleMissHelpful.Ui; | ||
import main.LittleMissHelpful.Storage; | ||
|
||
public class AddTodoCommand extends Command { | ||
private String description; | ||
|
||
public AddTodoCommand(String description) { | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { | ||
Todo todo = new Todo(description); | ||
tasks.add(todo); | ||
ui.showAddedNewTask(todo, tasks); | ||
storage.save(tasks.getTasks()); | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing header comment for the class too |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main.LittleMissHelpful.Command; | ||
|
||
import main.LittleMissHelpful.Exception.InvalidCommandException; | ||
import main.LittleMissHelpful.TaskList; | ||
import main.LittleMissHelpful.Ui; | ||
import main.LittleMissHelpful.Storage; | ||
|
||
public abstract class Command { | ||
public abstract void execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException; | ||
public abstract boolean isExit(); | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main.LittleMissHelpful.Command; | ||
|
||
import main.LittleMissHelpful.Exception.InvalidCommandException; | ||
import main.LittleMissHelpful.Exception.InvalidTaskFormatException; | ||
import main.LittleMissHelpful.Task.Task; | ||
import main.LittleMissHelpful.TaskList; | ||
import main.LittleMissHelpful.Ui; | ||
import main.LittleMissHelpful.Storage; | ||
|
||
public class DeleteTaskCommand extends Command { | ||
private final int taskIndex; | ||
|
||
public DeleteTaskCommand(int taskIndex) { | ||
this.taskIndex = taskIndex; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { | ||
try { | ||
Task task = tasks.get(taskIndex); | ||
tasks.delete(taskIndex); | ||
ui.showDeletedTask(task, tasks); | ||
storage.save(tasks.getTasks()); | ||
|
||
} catch (InvalidTaskFormatException e) { | ||
throw new InvalidCommandException("Task number out of range. Please provide a valid task number."); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main.LittleMissHelpful.Command; | ||
|
||
import main.LittleMissHelpful.Exception.InvalidCommandException; | ||
import main.LittleMissHelpful.TaskList; | ||
import main.LittleMissHelpful.Ui; | ||
import main.LittleMissHelpful.Storage; | ||
|
||
public class ExitCommand extends Command { | ||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { | ||
ui.showExit(); | ||
storage.save(tasks.getTasks()); | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main.LittleMissHelpful.Command; | ||
|
||
import main.LittleMissHelpful.Exception.InvalidCommandException; | ||
import main.LittleMissHelpful.TaskList; | ||
import main.LittleMissHelpful.Ui; | ||
import main.LittleMissHelpful.Storage; | ||
|
||
public class ListCommand extends Command { | ||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { | ||
if (tasks.size() == 0) { | ||
ui.showNoTasks(); | ||
} else { | ||
ui.showAllTasks(tasks.getTasks()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main.LittleMissHelpful.Command; | ||
|
||
import main.LittleMissHelpful.Exception.InvalidCommandException; | ||
import main.LittleMissHelpful.Exception.InvalidTaskFormatException; | ||
import main.LittleMissHelpful.Task.Task; | ||
import main.LittleMissHelpful.TaskList; | ||
import main.LittleMissHelpful.Ui; | ||
import main.LittleMissHelpful.Storage; | ||
|
||
public class MarkTaskCommand extends Command { | ||
private final int taskIndex; | ||
|
||
public MarkTaskCommand(int i) { | ||
this.taskIndex = i - 1; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { | ||
try { | ||
Task task = tasks.get(this.taskIndex); | ||
tasks.markTask(this.taskIndex); | ||
ui.showMarkedTask(task); | ||
storage.save(tasks.getTasks()); | ||
} catch (InvalidTaskFormatException e) { | ||
throw new InvalidCommandException("Task number out of range. Please provide a valid task number."); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main.LittleMissHelpful.Command; | ||
|
||
import main.LittleMissHelpful.Exception.InvalidCommandException; | ||
import main.LittleMissHelpful.Exception.InvalidTaskFormatException; | ||
import main.LittleMissHelpful.Task.Task; | ||
import main.LittleMissHelpful.TaskList; | ||
import main.LittleMissHelpful.Ui; | ||
import main.LittleMissHelpful.Storage; | ||
|
||
public class UnmarkTaskCommand extends Command { | ||
private final int taskIndex; | ||
|
||
public UnmarkTaskCommand(int i) { | ||
this.taskIndex = i - 1; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) throws InvalidCommandException { | ||
try { | ||
Task task = tasks.get(this.taskIndex); | ||
tasks.unmarkTask(this.taskIndex); | ||
ui.showUnmarkedTask(task); | ||
storage.save(tasks.getTasks()); | ||
} catch (InvalidTaskFormatException e) { | ||
throw new InvalidCommandException("Task number out of range. Please provide a valid task number."); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The exceptions class name is named well to let developer understand what exception it is handling too! Well done! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main.LittleMissHelpful.Exception; | ||
public class InvalidCommandException extends Exception { | ||
public InvalidCommandException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main.LittleMissHelpful.Exception; | ||
public class InvalidTaskFormatException extends Exception { | ||
public InvalidTaskFormatException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main.LittleMissHelpful.Exception; | ||
public class TaskNotFoundException extends Exception { | ||
public TaskNotFoundException(String message) { | ||
super(message); | ||
} | ||
} |
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.
The header comment for the class might be missed out, will be good if it could be added in