Skip to content

Commit

Permalink
Enhance package structure
Browse files Browse the repository at this point in the history
  • Loading branch information
simonteozw committed Sep 4, 2020
1 parent 4e3158d commit 1a9bdc1
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 85 deletions.
19 changes: 12 additions & 7 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@

import java.io.IOException;

import duke.exception.InvalidDataException;
import duke.exception.InvalidTypeException;
import duke.misc.Parser;
import duke.misc.TaskList;

public class Duke {

private TaskList taskList;
private Parser parser;

/**
* Constructor for Duke class
*/
public Duke() {
taskList = new TaskList();
}

/**
* Function to get Duke's response to user inputs.
*
Expand All @@ -27,11 +39,4 @@ public String getResponse(String input) {
}
return parser.allocate(input, taskList);
}

/**
* Constructor for Duke class
*/
public Duke() {
taskList = new TaskList();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.exception;

/**
* Exception class unique to Duke.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.exception;

/**
* Invalid Data Exception that extends Duke Exception class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.exception;

/**
* Invalid Description Exception that extends Duke Exception class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.exception;

/**
* Invalid Index Exception that extends Duke Exception class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.exception;

/**
* Invalid Type Exception that extends Duke Exception class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package duke;
package duke.misc;

import java.io.IOException;

import duke.exception.InvalidDescriptionException;
import duke.exception.InvalidIndexException;
import duke.exception.InvalidTypeException;
import duke.task.Deadline;
import duke.task.Event;
import duke.task.Task;
import duke.task.Todo;

/**
* Parser class to handle user inputs.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.misc;

import java.io.BufferedReader;
import java.io.FileReader;
Expand All @@ -10,6 +10,13 @@
import java.nio.file.Paths;
import java.util.ArrayList;

import duke.exception.InvalidDataException;
import duke.exception.InvalidTypeException;
import duke.task.Deadline;
import duke.task.Event;
import duke.task.Task;
import duke.task.Todo;

/**
* Storage class that interacts with the .txt file to store and retrieve data.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package duke;
package duke.misc;

import java.io.IOException;
import java.util.ArrayList;

import duke.exception.InvalidDataException;
import duke.exception.InvalidDescriptionException;
import duke.exception.InvalidIndexException;
import duke.exception.InvalidTypeException;
import duke.task.Task;

/**
* TaskList class to store all the tasks in Duke.
*/
Expand All @@ -18,15 +24,21 @@ public TaskList() {
this.items = new ArrayList<>();
}

/**
* Function to read in data from .txt file.
* @throws IOException In case data has errors
* @throws InvalidTypeException In cases data has an invalid type.
* @throws InvalidDataException In case data is invalid.
*/
public void initialise() throws IOException, InvalidTypeException, InvalidDataException {
try {
this.items = this.storage.readData();
} catch (IOException e) {
throw e;
} catch (InvalidTypeException e) {
throw e;
} catch (InvalidDataException e) {
throw e;
} catch (IOException e) {
throw e;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package duke;
package duke.misc;

/**
* UI class to handle aesthetics of Duke.
*/
public class Ui {
private static final String OPENING = " ____ _ \n"
static final String OPENING = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";

static final String WELCOME = OPENING + "\nHello I am Duke!\nWhat can I help you with?";
static final String GOODBYE = "Goodbye. See you soon!";
static final String WELCOME = OPENING + "\nHello I am Duke!\nWhat can I help you with?";
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.task;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
Expand All @@ -22,8 +22,6 @@ public class DateTime {
public DateTime(String date) {
if (isValidFormat(date)) {
this.date = LocalDate.parse(date);
} else {
System.out.println(INVALID_DATE_MESSAGE);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package duke;
package duke.task;

/**
* Deadline class for tasks that have a set deadline.
*/
public class Deadline extends Task {
static final String symbol = "D";
static final String SYMBOL = "D";
private DateTime deadline;

/**
Expand Down Expand Up @@ -38,7 +38,7 @@ public Deadline(String title, boolean isComplete, String deadline) {
@Override
public String saveString() {
int completeSymbol = this.complete ? 1 : 0;
return String.format("%s|%d|%s|%s", symbol, completeSymbol, this.title, this.deadline.saveString());
return String.format("%s|%d|%s|%s", SYMBOL, completeSymbol, this.title, this.deadline.saveString());
}

/**
Expand All @@ -49,6 +49,6 @@ public String saveString() {
@Override
public String toString() {
String completeSymbol = this.complete ? "[/]" : "[X]";
return String.format("[%s]%s %s (by: %s)", symbol, completeSymbol, this.title, this.deadline);
return String.format("[%s]%s %s (by: %s)", SYMBOL, completeSymbol, this.title, this.deadline);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package duke;
package duke.task;

/**
* Event class for tasks that have a set timing.
*/
public class Event extends Task {
static final String symbol = "E";
static final String SYMBOL = "E";
private DateTime time;

/**
Expand Down Expand Up @@ -38,7 +38,7 @@ public Event(String title, boolean isComplete, String time) {
@Override
public String saveString() {
int completeSymbol = this.complete ? 1 : 0;
return String.format("%s|%d|%s|%s", symbol, completeSymbol, this.title, this.time.saveString());
return String.format("%s|%d|%s|%s", SYMBOL, completeSymbol, this.title, this.time.saveString());
}

/**
Expand All @@ -49,6 +49,6 @@ public String saveString() {
@Override
public String toString() {
String completeSymbol = this.complete ? "[/]" : "[X]";
return String.format("[%s]%s %s (at: %s)", symbol, completeSymbol, this.title, this.time);
return String.format("[%s]%s %s (at: %s)", SYMBOL, completeSymbol, this.title, this.time);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package duke;
package duke.task;

/**
* Task class to represent a task to be manipulated by Duke.
*/
public class Task {
static final String symbol = "T";
static final String SYMBOL = "T";
protected String title;
protected boolean complete;

Expand Down Expand Up @@ -43,7 +43,7 @@ public void complete() {
*/
public String saveString() {
int completeSymbol = this.complete ? 1 : 0;
return String.format("%s|%d|%s", symbol, completeSymbol, this.title);
return String.format("%s|%d|%s", SYMBOL, completeSymbol, this.title);
}

/**
Expand All @@ -54,6 +54,6 @@ public String saveString() {
@Override
public String toString() {
String completeSymbol = this.complete ? "[/]" : "[X]";
return String.format("[%s]%s %s", symbol, completeSymbol, this.title);
return String.format("[%s]%s %s", SYMBOL, completeSymbol, this.title);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.task;

/**
* Todo class for Tasks that need to be completed.
Expand Down
48 changes: 0 additions & 48 deletions src/test/java/duke/DukeTest.java

This file was deleted.

23 changes: 23 additions & 0 deletions src/test/java/duke/misc/ParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package duke.misc;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

import duke.exception.InvalidDescriptionException;
import duke.exception.InvalidTypeException;

public class ParserTest {
@Test
public void invalidCommandTest() {
try {
Parser.handleInput("example hello");
} catch (InvalidTypeException e) {
assertEquals("OOPS!!! I'm sorry, but I don't know what that means :-(",
e.getMessage());
} catch (InvalidDescriptionException e) {
assertEquals("OOPS!!! The description of a task cannot be empty",
e.getMessage());
}
}
}
25 changes: 25 additions & 0 deletions src/test/java/duke/misc/StorageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package duke.misc;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

import duke.exception.InvalidDataException;
import duke.exception.InvalidTypeException;

public class StorageTest {
private Storage s = new Storage();

@Test
public void invalidDataTest() {
try {
s.stringToTask("example hello");
} catch (InvalidTypeException e) {
assertEquals("OOPS!!! I'm sorry, but I don't know what that means :-(",
e.getMessage());
} catch (InvalidDataException e) {
assertEquals("OOPS!!! The data here is invalid!",
e.getMessage());
}
}
}
21 changes: 21 additions & 0 deletions src/test/java/duke/misc/TaskListTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package duke.misc;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

import duke.exception.InvalidIndexException;

public class TaskListTest {
private TaskList t = new TaskList();

@Test
public void invalidIndexTest() {
try {
t.completeTask(-1);
} catch (InvalidIndexException e) {
assertEquals("OOPS!!! The index you have chosen is out of bounds",
e.getMessage());
}
}
}

0 comments on commit 1a9bdc1

Please sign in to comment.