-
Notifications
You must be signed in to change notification settings - Fork 361
[Truong Minh Duong] iP #366
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
Open
Zhongli5712
wants to merge
42
commits into
nus-cs2103-AY2223S2:master
Choose a base branch
from
Zhongli5712:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
556af3f
Add Gradle support
98b0b8b
Level 1 complete
b286d41
Level 2 complete
29e0afb
Level 2 complete
1f85f96
Level 3 complete
0e983da
Level 4 complete
9039f8e
Level 5 complete
58c0f95
Level 5 complete
0c4a800
Level 6 complete
a3d3477
Complete Level 7
9b818a7
Complete Level 8
f6fda6f
Merge branch 'branch-level-7'
24786a7
Complete Level 8
4f67fd1
Resolve conflict between level 8 and master
cfb9c77
Complete A-MoreOOP
b678e36
Complete A-Packages
e7dbf2d
Merge branch 'add-gradle-support'
a5dd3ce
Complete A-Gradle
b16ac23
Complete A-JUnit
04c4fe7
Complete A-Jar
e18d496
Complete A-JavaDoc
217c71b
Complete A-CodingStandard
9846241
Complete Level-9
0f0592c
Complete level 10
7a5165e
Complete level 10
35f3de5
Complete A-Varargs
a3698bd
Add images
94aa96a
Complete A-Assertions
6fdfd7e
Complete A-CodeQuality
b0a88ed
Merge pull request #2 from Zhongli5712/branch-A-Assertions
Zhongli5712 10e8b1e
Merge branch 'master' into branch-A-CodeQuality
9ec8791
Merge pull request #3 from Zhongli5712/branch-A-CodeQuality
Zhongli5712 a352bac
Complete BCD-Exetension
c5c2081
Merge pull request #4 from Zhongli5712/branch-BCD-Extension
Zhongli5712 4ba6b4d
Fix some error
7db313a
Complete A-UserGuide
2e7d8bc
Trigger rebuild
68dc253
Fix Readme
f4f17f8
Make Duke compatible with Linux
4a64ff0
Update Readme.md
1a8a463
Update README.md
Zhongli5712 4692bc5
Update README.md
Zhongli5712 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package duke; | ||
|
|
||
| import duke.command.Command; | ||
|
|
||
| public class Duke { | ||
| private Ui ui; | ||
|
|
||
| public Duke() { | ||
| this.ui = new Ui(); | ||
| } | ||
|
|
||
| private void run() { | ||
| ui.begin(); | ||
|
|
||
| Storage storage = new Storage(); | ||
| TodoList todoList = storage.load(); | ||
|
|
||
| Parser bot = new Parser(todoList); | ||
|
|
||
| String input = ui.readCommand(); | ||
|
|
||
| while (!input.equals("bye")) { | ||
| try { | ||
| Command command = bot.parse(input); | ||
| command.execute(); | ||
| } catch (DukeExceptions error) { | ||
| System.out.println(error.getErrorMessage()); | ||
| } | ||
| ui.showLine(); | ||
| input = ui.readCommand();; //ready for next input | ||
| } | ||
| storage.save(todoList); | ||
| ui.bye(); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| new Duke().run(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package duke; | ||
|
|
||
| public class DukeExceptions extends Exception{ | ||
| private String error; | ||
| public DukeExceptions(String error) { | ||
| this.error = error; | ||
| } | ||
|
|
||
| public String getErrorMessage() { | ||
| return this.error; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package duke; | ||
|
|
||
| import duke.command.*; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.time.format.DateTimeParseException; | ||
|
|
||
| /** | ||
| * Parse the command | ||
| * | ||
| */ | ||
| public class Parser { | ||
| private TodoList todoList; | ||
|
|
||
| private enum Instructions {todo, deadline, event, mark, unmark, delete} | ||
|
|
||
| public Parser(TodoList todoList) { | ||
| this.todoList = todoList; | ||
| } | ||
|
|
||
| public Command parse(String command) throws DukeExceptions { | ||
| String[] split_command = command.split(" ", 2); | ||
| String instruction = split_command[0]; | ||
|
|
||
| if (instruction.equals("list")) { | ||
| if (split_command.length == 1) { | ||
| return new ListCommand(todoList); | ||
| } else { | ||
| throw new DukeExceptions("OOPS!!! The description of a list cannot have other parameters"); | ||
| } | ||
| } | ||
|
|
||
| //check for valid instructions | ||
| for (Instructions validInstruction : Instructions.values()) { | ||
| if (validInstruction.name().equals(instruction)) { | ||
| if (split_command.length == 1) { | ||
| throw new DukeExceptions(String.format("OOPS!!! The description of a %s cannot be empty.", instruction)); | ||
| } else if (instruction.equals("mark")) { | ||
| int digit = Integer.parseInt(split_command[1]); | ||
| return new MarkCommand(todoList, digit); | ||
| } else if (instruction.equals("unmark")) { | ||
| int digit = Integer.parseInt(split_command[1]); | ||
| return new UnmarkCommand(todoList, digit); | ||
| } else if (instruction.equals("delete")) { | ||
| int digit = Integer.parseInt(split_command[1]); | ||
| return new DeleteCommand(todoList, digit); | ||
| } else { | ||
| return new AddTaskCommand(todoList, instruction, split_command[1]); | ||
| } | ||
| } | ||
| } | ||
| throw new DukeExceptions("OOPS!!! I'm sorry, but I don't know what that means."); | ||
| } | ||
|
|
||
| public static LocalDate parseDate(String[] possibleDateTime) throws DateTimeParseException { | ||
| try { | ||
| //parse date | ||
| LocalDate possibleDeadlineDate = LocalDate.parse(possibleDateTime[0]); | ||
| return possibleDeadlineDate; | ||
| } catch (DateTimeParseException ex) { | ||
| //can not parse date | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| public static String parseStringDate(LocalDate possibleDeadlineDate) { | ||
| return possibleDeadlineDate.format(DateTimeFormatter.ofPattern("MMM d yyyy")); | ||
| } | ||
|
|
||
| public static LocalTime parseTime(String[] possibleDateTime) throws DateTimeParseException { | ||
| try { | ||
| //parse date | ||
| LocalTime possibleDeadlineTime = (possibleDateTime.length == 1) | ||
| ? LocalTime.parse(possibleDateTime[0]) | ||
| : LocalTime.parse(possibleDateTime[1]); | ||
| return possibleDeadlineTime; | ||
| } catch (DateTimeParseException ex) { | ||
| //can not parse date | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| public static String parseStringTime(LocalTime possibleDeadlineTime) { | ||
| return possibleDeadlineTime.format(DateTimeFormatter.ofPattern("hh:mm a")); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package duke; | ||
|
|
||
| import java.io.*; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
|
|
||
| /** | ||
| * Represents a storage that load previous to do list and save current to do list. | ||
| */ | ||
|
|
||
| public class Storage { | ||
| private Path path; | ||
| private boolean doesDirectoryExist; | ||
|
|
||
| public Storage() { | ||
| this.path = Paths.get(".", "src", "main", "ToDoListCS2103.txt"); | ||
| this.doesDirectoryExist = java.nio.file.Files.exists(path); | ||
| } | ||
|
|
||
| public TodoList load() { | ||
| try { | ||
| File previousToDoList = new File(path.toString()); | ||
| if (doesDirectoryExist) { | ||
| FileInputStream fis = new FileInputStream(previousToDoList); | ||
| ObjectInputStream ois = new ObjectInputStream(fis); | ||
| TodoList savedTodoList = (TodoList) ois.readObject(); | ||
| ois.close(); | ||
| fis.close(); | ||
| return savedTodoList; | ||
| } else { | ||
| previousToDoList.createNewFile(); | ||
| return new TodoList(); | ||
| } | ||
| } catch (Exception ex) { | ||
| ex.printStackTrace(); | ||
| } | ||
| return new TodoList(); | ||
| } | ||
|
|
||
| public void save(TodoList todoList) { | ||
| try{ | ||
| FileOutputStream fos = new FileOutputStream(path.toFile()); | ||
| ObjectOutputStream oos = new ObjectOutputStream(fos); | ||
| oos.writeObject(todoList); | ||
| oos.flush(); | ||
| oos.close(); | ||
| fos.close(); | ||
| } catch (Exception ex) { | ||
| ex.printStackTrace(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
While the class name is valid according to coding standards, perhaps it would be more intuitive if it was named
DukeExceptioninstead since it only represents an instance of 1 Exception