Skip to content

Commit

Permalink
Merge pull request AY2324S1-CS2113T-W11-2#29 from woodenclock/master
Browse files Browse the repository at this point in the history
Update docs/team
  • Loading branch information
woodenclock authored Oct 15, 2023
2 parents bf15d75 + b0b42fe commit 6fb4e2f
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/wildwatch/command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Command class for listing all task in EntryList
*/
public class AddCommand extends Command {
public static void insertToDo(String inputBuffer, boolean isFromFile) {
public static void addEntry(String inputBuffer, boolean isFromFile) {
//Todo Split input into Date, Species, Remark
//Todo Insert into EntryList
}
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/seedu/wildwatch/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ public class DeleteCommand extends Command {
*
* @param numberInput
*/
public static void taskRemover(int numberInput) {
int taskToBeDeleted = numberInput - 1;
int arraySize = EntryList.getArraySize();
if (taskToBeDeleted >= arraySize || taskToBeDeleted < 0 || EntryList.isArrayEmpty()) {
Ui.noEntryfoundPrinter();
return;
}
public static void deleteEntry(int numberInput) {
Ui.entryRemovedMessagePrinter();
EntryList.entryRemover(numberInput);
Ui.entryCountPrinter();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package seedu.wildwatch.operation;
package seedu.wildwatch.command;

public class Helper {
public class HelpCommand {
/**
* Requires UPDATE
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/wildwatch/command/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ListCommand extends Command {
*
* @param isFromFile
*/
public static void listOut(boolean isFromFile) {
public static void listEntry(boolean isFromFile) {
if (!isFromFile) {
Ui.listMessagePrinter();
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/seedu/wildwatch/entry/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
public class Entry {
private LocalDate date;
private String species;
private String name;
private String remark;

public Entry(String date, String species, String remark) {
public Entry(String date, String species, String name, String remark) {
DateTimeFormatter inputFormat = DateTimeFormatter.ofPattern("dd-MM-yy");
this.date = LocalDate.parse(date, inputFormat);
this.species = species;
this.name = name;
this.remark = remark;
}

Expand All @@ -23,6 +25,10 @@ public String getSpecies() {
return species;
}

public String getName() {
return name;
}

public String getRemark() {
return remark;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/wildwatch/entry/EntryList.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public static void entryRemover(int numberInput){
entries.remove(numberInput);
}

public static void addEntry(String date, String species, String remark) {
entries.add(new Entry(date, species, remark));
public static void addEntry(String date, String species, String name, String remark) {
entries.add(new Entry(date, species, name, remark));
}

public static Entry getEntry(int nthTask) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package seedu.wildwatch.exception;

public class EntryNotFoundException extends Exception {
}
22 changes: 17 additions & 5 deletions src/main/java/seedu/wildwatch/operation/ErrorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
import java.time.format.DateTimeParseException;
import java.util.Scanner;

import seedu.wildwatch.command.HelpCommand;
import seedu.wildwatch.entry.EntryList;
import seedu.wildwatch.exception.EmptyAddException;
import seedu.wildwatch.exception.EmptyDeleteException;
import seedu.wildwatch.exception.EmptyListException;
import seedu.wildwatch.exception.EmptyInputException;
import seedu.wildwatch.exception.EntryNotFoundException;
import seedu.wildwatch.exception.UnknownInputException;
import seedu.wildwatch.exception.UnknownDateFormatException;

public class ErrorHandler {
private static final int DEFAULT_NUMBER_INPUT = -100;
public static void handleError(String inputBuffer) {
boolean validInput = false;
try {
checkError(inputBuffer);
Parser.taskManager(inputBuffer, false);
Parser.entryManager(inputBuffer, false);
validInput = true;
} catch (EmptyInputException exception) {
Ui.emptyDescriptionMessagePrinter(null);
Expand All @@ -27,35 +30,44 @@ public static void handleError(String inputBuffer) {
} catch (EmptyListException exception) {
Ui.emptyListMessagePrinter();
validInput = true;
} catch (EntryNotFoundException exception) {
Ui.entryNotFoundMessagePrinter();
validInput = true;
} catch (UnknownInputException exception) {
Ui.unknownInputMessagePrinter();
} catch (UnknownDateFormatException | DateTimeParseException exception) {
Ui.invalidDateTimeMessagePrinter();
Ui.invalidDateMessagePrinter();
} finally {
if (!validInput) {
Ui.printHorizontalLines();
Helper.printHelpMessage();
HelpCommand.printHelpMessage();
}
}
}

public static void checkError(String inputBuffer) throws EmptyInputException, EmptyAddException,
EmptyListException, EmptyDeleteException, UnknownDateFormatException {
EmptyListException, EmptyDeleteException, EntryNotFoundException, UnknownDateFormatException {

Scanner bufferScanner = new Scanner(inputBuffer); //Scanner for the buffer
String firstWord; //First word of input
int numberInput = DEFAULT_NUMBER_INPUT;
if (!bufferScanner.hasNext()) { //Checks for the case when there is no input
throw new EmptyInputException();
} else {
firstWord = bufferScanner.next();
}
if (bufferScanner.hasNextInt()) {
numberInput = bufferScanner.nextInt();
}

if (firstWord.equals("add") && !bufferScanner.hasNext()) {
throw new EmptyAddException();
} else if (firstWord.equals("add") && !(DateHandler.isDateValid(inputBuffer))) {
throw new UnknownDateFormatException();
} else if (firstWord.equals("delete") && !bufferScanner.hasNext()) {
} else if (firstWord.equals("delete") && numberInput == DEFAULT_NUMBER_INPUT) {
throw new EmptyDeleteException();
} else if (firstWord.equals("delete") && (numberInput < 1 || numberInput > EntryList.getArraySize())) {
throw new EntryNotFoundException();
} else if (firstWord.equals("list") && EntryList.isArrayEmpty()) {
throw new EmptyListException();
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/seedu/wildwatch/operation/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Scanner;

import seedu.wildwatch.command.HelpCommand;
import seedu.wildwatch.command.ListCommand;
import seedu.wildwatch.command.DeleteCommand;
import seedu.wildwatch.command.AddCommand;
Expand All @@ -19,7 +20,7 @@ public static void manualInputHandler() {
Ui.printHorizontalLines();
Ui.helpRequestMessagePrinter();
Ui.printHorizontalLines();
Helper.printHelpMessage();
HelpCommand.printHelpMessage();
} else {
Ui.printHorizontalLines();
ErrorHandler.handleError(inputBuffer);
Expand All @@ -29,7 +30,7 @@ public static void manualInputHandler() {
ShutDown.shutDown();
}

public static void taskManager(String inputBuffer, boolean isFromFile) throws UnknownInputException {
public static void entryManager(String inputBuffer, boolean isFromFile) throws UnknownInputException {
Scanner bufferScanner = new Scanner(inputBuffer); //Scanner for the buffer
String firstWord = bufferScanner.next(); //Stores first word in the input
boolean hasInteger = bufferScanner.hasNextInt(); //Indicates that some integer was input
Expand All @@ -40,11 +41,11 @@ public static void taskManager(String inputBuffer, boolean isFromFile) throws Un

//Functionalities
if (firstWord.equals("add")) {
AddCommand.insertToDo(inputBuffer, isFromFile);
AddCommand.addEntry(inputBuffer, isFromFile);
} else if (firstWord.equals("delete") && hasInteger && !bufferScanner.hasNext()) {
DeleteCommand.taskRemover(numberInput);
DeleteCommand.deleteEntry(numberInput);
} else if (inputBuffer.equals("list")) {
ListCommand.listOut(isFromFile);
ListCommand.listEntry(isFromFile);
}
throw new UnknownInputException();
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/wildwatch/operation/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ public static void unknownInputMessagePrinter() {
System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-(");
}

public static void invalidDateTimeMessagePrinter() {
public static void invalidDateMessagePrinter() {
System.out.println("OOPS!!! Invalid Date input :-(");
}

public static void emptyListMessagePrinter() {
System.out.println("OOPS!!! Nothing to list. :-(");
}

public static void noEntryfoundPrinter() {
System.out.println("OOPS!!! The entry number that u stated could not be found :-(");
public static void entryNotFoundMessagePrinter() {
System.out.println("OOPS!!! The entry number could not be found :-(");
}

public static void entryRemovedMessagePrinter() {
Expand Down

0 comments on commit 6fb4e2f

Please sign in to comment.