Skip to content

Commit

Permalink
A-Packages
Browse files Browse the repository at this point in the history
  • Loading branch information
DerenC committed Feb 9, 2023
1 parent 4a61459 commit 0a0f3f6
Show file tree
Hide file tree
Showing 23 changed files with 171 additions and 153 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ text-ui-test/data/

data/savedTasks.txt
Event flow.txt
src/main/java/exceptions/All wrong cmds.txt
src/main/java/wessy.exceptions/All wrong cmds.txt
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import exceptions.int_exceptions.NotPositiveIntegerException;
package wessy;

import wessy.exceptions.int_exceptions.NotPositiveIntegerException;
import java.time.LocalDateTime;
import java.time.format.DateTimeParseException;

Expand Down
11 changes: 7 additions & 4 deletions src/main/java/Storage.java → src/main/java/wessy/Storage.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import task.Deadline;
import task.Event;
import task.ToDo;
import task.Task;
package wessy;

import wessy.Parser;
import wessy.task.Deadline;
import wessy.task.Event;
import wessy.task.ToDo;
import wessy.task.Task;
import java.util.List;
import java.util.ArrayList;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import exceptions.int_exceptions.EmptyListException;
import exceptions.int_exceptions.InvalidIntegerException;
import task.Deadline;
import task.Event;
import task.Task;
import task.ToDo;
package wessy;

import wessy.Parser;
import wessy.exceptions.int_exceptions.EmptyListException;
import wessy.exceptions.int_exceptions.InvalidIntegerException;
import wessy.task.Deadline;
import wessy.task.Event;
import wessy.task.Task;
import wessy.task.ToDo;

import java.time.format.DateTimeParseException;
import java.util.ArrayList;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/Ui.java → src/main/java/wessy/Ui.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package wessy;

import java.util.Scanner;
import task.Task;
import wessy.task.Task;

public class Ui {
private final Scanner sc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import exceptions.MissingSpacingException;
import exceptions.TimeSpecifierException;
import exceptions.UnspecifiedTimeException;
import exceptions.int_exceptions.NotAnIntegerException;
import exceptions.num_of_input_exceptions.MissingInputException;
import exceptions.num_of_input_exceptions.TooManyInputException;
package wessy;

import wessy.Parser;
import wessy.exceptions.MissingSpacingException;
import wessy.exceptions.TimeSpecifierException;
import wessy.exceptions.UnspecifiedTimeException;
import wessy.exceptions.int_exceptions.NotAnIntegerException;
import wessy.exceptions.num_of_input_exceptions.MissingInputException;
import wessy.exceptions.num_of_input_exceptions.TooManyInputException;

public class UserInputChecker {
// Check for "Missing space after command"
Expand Down
229 changes: 116 additions & 113 deletions src/main/java/Wessy.java → src/main/java/wessy/Wessy.java
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exceptions;
package wessy.exceptions;

public class CommandNotFoundException extends WessyException {
public CommandNotFoundException() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exceptions;
package wessy.exceptions;

public class MissingSpacingException extends WessyException {
public MissingSpacingException(String cmd) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exceptions;
package wessy.exceptions;

public class TimeSpecifierException extends WessyException {
public TimeSpecifierException(String specifier) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exceptions;
package wessy.exceptions;

public class UnspecifiedTimeException extends WessyException {
public UnspecifiedTimeException(String keyword, boolean isBefore) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exceptions;
package wessy.exceptions;

public class WessyException extends Exception {
private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package exceptions.int_exceptions;
package wessy.exceptions.int_exceptions;

import exceptions.WessyException;
import wessy.exceptions.WessyException;

public class EmptyListException extends WessyException {
public EmptyListException(String cmd) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package exceptions.int_exceptions;
package wessy.exceptions.int_exceptions;

import exceptions.WessyException;
import wessy.exceptions.WessyException;

public class InvalidIntegerException extends WessyException {
public InvalidIntegerException(String cmd, int taskNum, int total) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package exceptions.int_exceptions;
package wessy.exceptions.int_exceptions;

import exceptions.WessyException;
import wessy.exceptions.WessyException;

public class NotAnIntegerException extends WessyException {
public NotAnIntegerException() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package exceptions.int_exceptions;
package wessy.exceptions.int_exceptions;

import exceptions.WessyException;
import wessy.exceptions.WessyException;

public class NotPositiveIntegerException extends WessyException {
public NotPositiveIntegerException() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package exceptions.num_of_input_exceptions;
package wessy.exceptions.num_of_input_exceptions;

import exceptions.WessyException;
import wessy.exceptions.WessyException;

public class MissingInputException extends WessyException {
static String ENDING = " is missing.";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package exceptions.num_of_input_exceptions;
package wessy.exceptions.num_of_input_exceptions;

import exceptions.WessyException;
import wessy.exceptions.WessyException;

public class TooManyInputException extends WessyException {
public TooManyInputException(String cmd) {
Expand Down

0 comments on commit 0a0f3f6

Please sign in to comment.