Skip to content
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

Merge Main into branch-A-CodeQuality #3

Merged
merged 6 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/dude/commands/DeadlineCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ public class DeadlineCommand extends Command {
* Constructor for the DeadlineCommand class. Returns a command object to add a deadline task to
* the TaskList object upon execution.
*
*
* @param input The input string that resulted in the creation of this command.
* @param tasklist The TaskList object to which the deadline task is to be added.
*/
public DeadlineCommand(String input, TaskList tasklist) {
super(COMMAND_FORMAT, "deadline .* /by .*");

assert(input != null);
assert(tasklist != null);
assert(input.contains("deadline"));

this.input = input;
this.taskList = tasklist;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dude/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public class DeleteCommand extends Command {
*/
public DeleteCommand(String input, TaskList tasklist) {
super(COMMAND_FORMAT, "delete \\d+");

assert(input != null);
assert(tasklist != null);
assert(input.contains("delete"));

this.input = input.trim();
this.taskList = tasklist;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dude/commands/EventCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public class EventCommand extends Command {
*/
public EventCommand(String input, TaskList tasklist) {
super(COMMAND_FORMAT, "event .* /from .* /to .*");

assert(input != null);
assert(tasklist != null);
assert(input.contains("event"));


this.input = input;
this.taskList = tasklist;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dude/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public class FindCommand extends Command {
*/
public FindCommand(String input, TaskList taskList) {
super(COMMAND_FORMAT, "find .*");

assert(input != null);
assert(taskList != null);
assert(input.contains("find"));

this.input = input;
this.taskList = taskList;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/dude/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class HelpCommand extends Command {
*/
public HelpCommand(String input) {
super("help <?command>", "help");

assert(input != null);
assert(input.contains("help"));

this.input = input.trim();
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dude/commands/InvalidCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dude.commands;

/**
* The InvalidCommand class represents a command that is invalid.
* The InvalidCommand Class is used to wrap around any invalid commands that are input by the user.
*/
public class InvalidCommand extends Command {

Expand All @@ -15,7 +15,7 @@ public InvalidCommand() {
/**
* Does nothing
*
* @return The string message for an invalid command.
* @return The string message for trying to execute an invalid command.
*/
public String execute() {
return "Sorry I don't understand that command. Please try again.";
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/dude/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class ListCommand extends Command {
*/
public ListCommand(TaskList tasklist) {
super("list", "list");

assert(tasklist != null);

this.tasklist = tasklist;
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dude/commands/MarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public class MarkCommand extends Command {
*/
public MarkCommand(String input, TaskList tasklist) {
super(COMMAND_FORMAT, "mark \\d+");

assert(input != null);
assert(tasklist != null);
assert(input.contains("mark"));

this.input = input.trim();
this.taskList = tasklist;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/dude/commands/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class Parser {
* @return The parsed command from the user input.
*/
public static Command parse(String input, TaskList tasklist) {
assert(input != null);
assert(tasklist != null);

String[] command = input.split(" ", 2);
switch (command[0]) {
case "bye":
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dude/commands/TodoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public class TodoCommand extends Command {
*/
public TodoCommand(String input, TaskList tasklist) {
super(COMMAND_FORMAT, "todo .*");

assert(input != null);
assert(tasklist != null);
assert(input.contains("todo"));

this.input = input;
this.taskList = tasklist;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dude/commands/UnmarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public class UnmarkCommand extends Command {
*/
public UnmarkCommand(String input, TaskList tasklist) {
super(COMMAND_FORMAT, "unmark \\d+");

assert(input != null);
assert(tasklist != null);
assert(input.contains("unmark"));

this.input = input.trim();
this.taskList = tasklist;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dude/tasks/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public class Deadline extends Task {
*/
public Deadline(String description, LocalDateTime by) {
super(description);

assert (by != null);
assert (description != null);
assert (!description.isEmpty());

this.deadlineDate = by;
}

Expand All @@ -39,6 +44,7 @@ public Deadline(String description, LocalDateTime by) {
*/
public static Deadline from(String s) throws InvalidFormatException,
InvalidDescriptionException, InvalidArgumentException {
assert (s != null);
String rest = Utils.discardFirstWord(s.trim()).trim();
String[] arr = rest.split(" ");

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dude/tasks/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public class Event extends Task {
*/
public Event(String description, LocalDateTime fromTime, LocalDateTime toTime) {
super(description);

assert (fromTime != null);
assert (toTime != null);
assert (description != null);
assert (!description.isEmpty());

this.fromTime = fromTime;
this.toTime = toTime;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dude/tasks/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Task implements Serializable {
* @param description The description of the task.
*/
public Task(String description) {
assert (description != null);
this.description = description;
this.isDone = false;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dude/tasks/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public TaskList() {
* @return The TaskList object created from the ArrayList of Task objects.
*/
public static TaskList from(ArrayList<Task> tasks) {
assert (tasks != null);

TaskList taskList = new TaskList();
taskList.list.addAll(tasks);
return taskList;
Expand All @@ -39,6 +41,8 @@ public static TaskList from(ArrayList<Task> tasks) {
* @return The TaskList object created from the Task objects.
*/
public static TaskList from(Task... tasks) {
assert (tasks != null);

TaskList taskList = new TaskList();
for (Task task : tasks) {
taskList.list.add(task);
Expand All @@ -53,6 +57,7 @@ public static TaskList from(Task... tasks) {
* @throws TaskListFullException if the task list is full.
*/
public void add_task(Task task) throws TaskListFullException {
assert (task != null);
if (list.size() >= 100) {
throw new TaskListFullException("Sorry, the task list is full.");
}
Expand Down Expand Up @@ -105,6 +110,7 @@ public void mark_as_undone(int id) throws DudeException {
* @return An ArrayList of Task objects that contain the keyword.
*/
public ArrayList<Task> find(String keyword) {
assert (keyword != null);
ArrayList<Task> result = new ArrayList<>();
String taskString;
String keywordLowerCase = keyword.toLowerCase();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dude/tasks/Todo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Todo extends Task {
*/
public Todo(String description) {
super(description);
assert (description != null);
}


Expand Down
3 changes: 3 additions & 0 deletions src/main/java/dude/utils/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class Storage {
* @param fileLocation The file path to the storage file.
*/
public Storage(String fileLocation) {
assert (fileLocation != null);

this.filepath = extractFilePath(fileLocation);
this.filename = extractFileName(fileLocation);
}
Expand Down Expand Up @@ -76,6 +78,7 @@ public void deleteStorage() throws SecurityException {
* @throws SecurityException if a security manager exists and its checkWrite method denies write access to the file.
*/
public void saveTasks(TaskList taskList) throws IOException, SecurityException {
assert (taskList != null);
try {
FileOutputStream fos = new FileOutputStream(this.filepath + this.filename);
ObjectOutputStream oos = new ObjectOutputStream(fos);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dude/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Utils {
* @return The input string with the first word discarded.
*/
public static String discardFirstWord(String input) {
assert (input != null);
// Split the string by whitespace
String[] words = input.split(" ", 2);
// Check if there are at least two words
Expand Down Expand Up @@ -49,7 +50,8 @@ public static int countOccurrences(String[] array, String target) {
*
* @param array The array of strings.
* @param target The target string.
* @return The index of the first occurrence of the target string in the array.
* @return The index of the first occurrence of the target string in the array. If the target string is not found,
* -1 is returned.
*/
public static int findIndex(String[] array, String target) {
for (int i = 0; i < array.length; i++) {
Expand Down