forked from nus-cs2103-AY2223S2/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
171 additions
and
153 deletions.
There are no files selected for viewing
This file contains 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
2 changes: 2 additions & 0 deletions
2
src/main/java/CmdType.java → src/main/java/wessy/CmdType.java
This file contains 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package wessy; | ||
|
||
import java.util.Map; | ||
import java.util.HashMap; | ||
import java.util.Set; | ||
|
This file contains 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
11 changes: 7 additions & 4 deletions
11
src/main/java/Storage.java → src/main/java/wessy/Storage.java
This file contains 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
15 changes: 9 additions & 6 deletions
15
src/main/java/TaskList.java → src/main/java/wessy/TaskList.java
This file contains 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
This file contains 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
15 changes: 9 additions & 6 deletions
15
src/main/java/UserInputChecker.java → src/main/java/wessy/UserInputChecker.java
This file contains 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
229 changes: 116 additions & 113 deletions
229
src/main/java/Wessy.java → src/main/java/wessy/Wessy.java
This file contains 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 |
---|---|---|
@@ -1,113 +1,116 @@ | ||
import exceptions.WessyException; | ||
import exceptions.CommandNotFoundException; | ||
import exceptions.int_exceptions.NotAnIntegerException; | ||
import exceptions.num_of_input_exceptions.MissingInputException; | ||
import exceptions.num_of_input_exceptions.TooManyInputException; | ||
import task.Task; | ||
|
||
import java.io.IOException; | ||
import java.time.format.DateTimeParseException; | ||
|
||
public class Wessy { | ||
private final Storage storage; | ||
private TaskList tasks; | ||
private final Ui ui; | ||
|
||
public Wessy(String filePath) { | ||
ui = new Ui(); | ||
storage = new Storage(filePath); | ||
try { | ||
tasks = new TaskList(storage.load()); | ||
} catch (IOException | SecurityException ex) { | ||
System.err.println(ex.getMessage()); | ||
ex.printStackTrace(); | ||
tasks = new TaskList(); | ||
} | ||
} | ||
|
||
public void run() { | ||
startsUp(); | ||
while (ui.hasNextLine()) { | ||
try { | ||
String userInput = ui.readNextLine(); | ||
CmdType cmd = Parser.getCmd(userInput); | ||
if (cmd == null) { | ||
throw new CommandNotFoundException(); | ||
} | ||
UserInputChecker.checkSpacingAftCmd(userInput, cmd); | ||
switch (cmd) { | ||
case BYE: | ||
ui.printBye(); | ||
return; | ||
case LIST: | ||
ui.printListMessage(tasks.getSize(), tasks.printAsStr()); | ||
break; | ||
case TODO: | ||
case DEADLINE: | ||
case EVENT: | ||
UserInputChecker.checkForMissingInput(userInput, cmd); | ||
UserInputChecker.checkMissingKeyword(userInput, cmd); | ||
if (cmd == CmdType.DEADLINE) { | ||
UserInputChecker.checkForDeadlineMissingInput(userInput, cmd); | ||
} else if (cmd == CmdType.EVENT) { | ||
UserInputChecker.checkForEventMissingInput(userInput, cmd); | ||
} | ||
String[] taskComponents = Parser.getTaskComponents(userInput, cmd); | ||
Task newTask = tasks.add(taskComponents); | ||
save2Storage(); | ||
ui.printAdded(newTask, tasks.getSize()); | ||
break; | ||
case MARK: | ||
case UNMARK: | ||
checkB4Parse(userInput, cmd); | ||
boolean isMark = cmd == CmdType.MARK; | ||
Task updatedTask = tasks.markOrUnmark(Parser.parseInt(userInput, cmd), isMark); | ||
save2Storage(); | ||
ui.printMarkUnmark(updatedTask, isMark); | ||
break; | ||
case DELETE: | ||
checkB4Parse(userInput, cmd); | ||
Task deletedTask = tasks.delete(Parser.parseInt(userInput, cmd)); | ||
save2Storage(); | ||
ui.printDelete(deletedTask, tasks.getSize()); | ||
break; | ||
case CLEAR: | ||
tasks.clear(); | ||
save2Storage(); | ||
ui.printClear(); | ||
} | ||
} catch (DateTimeParseException dtpe) { | ||
ui.handleException("Please enter the date (and time, if any) in the correct format."); | ||
} catch (SecurityException se) { | ||
ui.handleException("You do not have the permission to access the file."); | ||
se.printStackTrace(); | ||
} catch (IOException ioe) { | ||
ui.handleException("There is some issue in the input-output operation."); | ||
ioe.printStackTrace(); | ||
} catch (WessyException we) { | ||
ui.handleException(we.toString()); | ||
} catch (Exception ex) { | ||
ui.handleException(ex.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
new Wessy("data/savedTasks.txt").run(); | ||
} | ||
|
||
// HELPER FUNCTIONS | ||
private void startsUp() { | ||
ui.showWelcome(tasks.printAsStr(), tasks.getSize()); | ||
} | ||
|
||
void save2Storage() throws IOException { | ||
storage.save(tasks.saveAsStr()); | ||
} | ||
|
||
void checkB4Parse(String userInput, CmdType cmd) throws MissingInputException, NotAnIntegerException, TooManyInputException { | ||
UserInputChecker.checkForMissingInput(userInput, cmd); | ||
UserInputChecker.checkNotNumerical(userInput, cmd); | ||
UserInputChecker.checkTooManyInputs(userInput, cmd); | ||
} | ||
} | ||
package wessy; | ||
|
||
import wessy.Parser; | ||
import wessy.exceptions.WessyException; | ||
import wessy.exceptions.CommandNotFoundException; | ||
import wessy.exceptions.int_exceptions.NotAnIntegerException; | ||
import wessy.exceptions.num_of_input_exceptions.MissingInputException; | ||
import wessy.exceptions.num_of_input_exceptions.TooManyInputException; | ||
import wessy.task.Task; | ||
|
||
import java.io.IOException; | ||
import java.time.format.DateTimeParseException; | ||
|
||
public class Wessy { | ||
private final Storage storage; | ||
private TaskList tasks; | ||
private final Ui ui; | ||
|
||
public Wessy(String filePath) { | ||
ui = new Ui(); | ||
storage = new Storage(filePath); | ||
try { | ||
tasks = new TaskList(storage.load()); | ||
} catch (IOException | SecurityException ex) { | ||
System.err.println(ex.getMessage()); | ||
ex.printStackTrace(); | ||
tasks = new TaskList(); | ||
} | ||
} | ||
|
||
public void run() { | ||
startsUp(); | ||
while (ui.hasNextLine()) { | ||
try { | ||
String userInput = ui.readNextLine(); | ||
CmdType cmd = Parser.getCmd(userInput); | ||
if (cmd == null) { | ||
throw new CommandNotFoundException(); | ||
} | ||
UserInputChecker.checkSpacingAftCmd(userInput, cmd); | ||
switch (cmd) { | ||
case BYE: | ||
ui.printBye(); | ||
return; | ||
case LIST: | ||
ui.printListMessage(tasks.getSize(), tasks.printAsStr()); | ||
break; | ||
case TODO: | ||
case DEADLINE: | ||
case EVENT: | ||
UserInputChecker.checkForMissingInput(userInput, cmd); | ||
UserInputChecker.checkMissingKeyword(userInput, cmd); | ||
if (cmd == CmdType.DEADLINE) { | ||
UserInputChecker.checkForDeadlineMissingInput(userInput, cmd); | ||
} else if (cmd == CmdType.EVENT) { | ||
UserInputChecker.checkForEventMissingInput(userInput, cmd); | ||
} | ||
String[] taskComponents = Parser.getTaskComponents(userInput, cmd); | ||
Task newTask = tasks.add(taskComponents); | ||
save2Storage(); | ||
ui.printAdded(newTask, tasks.getSize()); | ||
break; | ||
case MARK: | ||
case UNMARK: | ||
checkB4Parse(userInput, cmd); | ||
boolean isMark = cmd == CmdType.MARK; | ||
Task updatedTask = tasks.markOrUnmark(Parser.parseInt(userInput, cmd), isMark); | ||
save2Storage(); | ||
ui.printMarkUnmark(updatedTask, isMark); | ||
break; | ||
case DELETE: | ||
checkB4Parse(userInput, cmd); | ||
Task deletedTask = tasks.delete(Parser.parseInt(userInput, cmd)); | ||
save2Storage(); | ||
ui.printDelete(deletedTask, tasks.getSize()); | ||
break; | ||
case CLEAR: | ||
tasks.clear(); | ||
save2Storage(); | ||
ui.printClear(); | ||
} | ||
} catch (DateTimeParseException dtpe) { | ||
ui.handleException("Please enter the date (and time, if any) in the correct format."); | ||
} catch (SecurityException se) { | ||
ui.handleException("You do not have the permission to access the file."); | ||
se.printStackTrace(); | ||
} catch (IOException ioe) { | ||
ui.handleException("There is some issue in the input-output operation."); | ||
ioe.printStackTrace(); | ||
} catch (WessyException we) { | ||
ui.handleException(we.toString()); | ||
} catch (Exception ex) { | ||
ui.handleException(ex.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
new Wessy("data/savedTasks.txt").run(); | ||
} | ||
|
||
// HELPER FUNCTIONS | ||
private void startsUp() { | ||
ui.showWelcome(tasks.printAsStr(), tasks.getSize()); | ||
} | ||
|
||
void save2Storage() throws IOException { | ||
storage.save(tasks.saveAsStr()); | ||
} | ||
|
||
void checkB4Parse(String userInput, CmdType cmd) throws MissingInputException, NotAnIntegerException, TooManyInputException { | ||
UserInputChecker.checkForMissingInput(userInput, cmd); | ||
UserInputChecker.checkNotNumerical(userInput, cmd); | ||
UserInputChecker.checkTooManyInputs(userInput, cmd); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../exceptions/CommandNotFoundException.java → .../exceptions/CommandNotFoundException.java
This file contains 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
2 changes: 1 addition & 1 deletion
2
...a/exceptions/MissingSpacingException.java → ...y/exceptions/MissingSpacingException.java
This file contains 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
2 changes: 1 addition & 1 deletion
2
...va/exceptions/TimeSpecifierException.java → ...sy/exceptions/TimeSpecifierException.java
This file contains 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
2 changes: 1 addition & 1 deletion
2
.../exceptions/UnspecifiedTimeException.java → .../exceptions/UnspecifiedTimeException.java
This file contains 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
2 changes: 1 addition & 1 deletion
2
src/main/java/exceptions/WessyException.java → ...java/wessy/exceptions/WessyException.java
This file contains 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
4 changes: 2 additions & 2 deletions
4
...ns/int_exceptions/EmptyListException.java → ...ns/int_exceptions/EmptyListException.java
This file contains 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
4 changes: 2 additions & 2 deletions
4
...t_exceptions/InvalidIntegerException.java → ...t_exceptions/InvalidIntegerException.java
This file contains 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
4 changes: 2 additions & 2 deletions
4
...int_exceptions/NotAnIntegerException.java → ...int_exceptions/NotAnIntegerException.java
This file contains 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
4 changes: 2 additions & 2 deletions
4
...ceptions/NotPositiveIntegerException.java → ...ceptions/NotPositiveIntegerException.java
This file contains 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
4 changes: 2 additions & 2 deletions
4
...put_exceptions/MissingInputException.java → ...put_exceptions/MissingInputException.java
This file contains 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
4 changes: 2 additions & 2 deletions
4
...put_exceptions/TooManyInputException.java → ...put_exceptions/TooManyInputException.java
This file contains 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
Oops, something went wrong.