Skip to content

Commit

Permalink
Includes history log V1.0 (nusCS2113-AY1920S1#69)
Browse files Browse the repository at this point in the history
* Remove instanceof from ReminderCommand

* Updates to ReminderCommand V1.0

* Sorts reminders in ascending order

* Includes Event as part of reminder display

* Merges with upstream

* Changes to Indent Case

* Changes to switch case alignment

* Includes history log V1.0

* Includes history log V1.1
  • Loading branch information
muserr authored Oct 4, 2019
1 parent 2a69c16 commit a48c1fc
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ bin/

# Data files
data.json
/data.json
text_file

4 changes: 3 additions & 1 deletion data.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
["duchess.model.task.TaskList",{"tasks":["java.util.ArrayList",[]]}]
[ "duchess.storage.Store", {
"taskList" : [ "java.util.ArrayList", [ [ "duchess.model.task.Todo", {
"description" : "work"
6 changes: 5 additions & 1 deletion src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import duchess.logic.commands.Command;
import duchess.logic.parser.Parser;
import duchess.model.task.DuchessLog;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.TaskList;

public class Duke {

private Storage storage;
private Store store;
private Ui ui;
private DuchessLog duchessLog;

/**
* Creates an instant of Duke to be executed.
Expand All @@ -34,10 +35,13 @@ private Duke(String filePath) {
*/
private void run() {
ui.showWelcome();
duchessLog = new DuchessLog();

boolean isExit = false;
while (!isExit) {
try {
String fullCommand = ui.readCommand();
duchessLog.add(fullCommand);
ui.beginBlock();
Command c = Parser.parse(fullCommand);
c.execute(store, ui, storage);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.model.task.TaskList;
import duchess.model.task.Task;
import duchess.model.task.Deadline;
import duchess.logic.commands.exceptions.DukeException;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/duchess/logic/commands/AddEventCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import duchess.storage.Storage;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.Event;
import duchess.model.task.TaskList;
import duchess.storage.Store;
import duchess.ui.Ui;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/duchess/logic/commands/AddTodoCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.model.task.TaskList;
import duchess.model.task.Todo;
import duchess.model.task.Task;
import duchess.logic.commands.exceptions.DukeException;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/duchess/logic/commands/ByeCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.model.task.TaskList;
import duchess.logic.commands.exceptions.DukeException;
import duchess.storage.Store;
import duchess.ui.Ui;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duchess/logic/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public boolean isExit() {
}

public abstract void execute(Store store, Ui ui, Storage storage) throws DukeException;
}
}
1 change: 0 additions & 1 deletion src/main/java/duchess/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.model.task.TaskList;
import duchess.model.task.Task;
import duchess.logic.commands.exceptions.DukeException;
import duchess.storage.Store;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/duchess/logic/commands/DoneCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package duchess.logic.commands;

import duchess.storage.Storage;
import duchess.model.task.TaskList;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.Task;
import duchess.storage.Store;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/duchess/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import duchess.storage.Storage;
import duchess.model.task.Task;
import duchess.model.task.TaskList;
import duchess.logic.commands.exceptions.DukeException;
import duchess.storage.Store;
import duchess.ui.Ui;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/duchess/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import duchess.storage.Storage;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.TaskList;
import duchess.storage.Store;
import duchess.ui.Ui;

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/duchess/logic/commands/LogCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package duchess.logic.commands;

import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.DuchessLog;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;

/**
* Command to display input history.
*/
public class LogCommand extends Command {

@Override
public void execute(Store store, Ui ui, Storage storage) throws DukeException {
ui.showUserHistory(DuchessLog.getLog());
}
}
1 change: 0 additions & 1 deletion src/main/java/duchess/logic/commands/SnoozeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import duchess.storage.Storage;
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.task.Task;
import duchess.model.task.TaskList;
import duchess.storage.Store;
import duchess.ui.Ui;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import duchess.logic.commands.exceptions.DukeException;
import duchess.model.TimeFrame;
import duchess.model.task.Task;
import duchess.model.task.TaskList;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/duchess/logic/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import duchess.logic.commands.DoneCommand;
import duchess.logic.commands.FindCommand;
import duchess.logic.commands.ListCommand;
import duchess.logic.commands.LogCommand;
import duchess.logic.commands.ReminderCommand;
import duchess.logic.commands.SnoozeCommand;
import duchess.logic.commands.ViewScheduleCommand;
Expand Down Expand Up @@ -53,6 +54,8 @@ public static Command parse(String input) throws DukeException {
return new ViewScheduleCommand(arguments);
case "bye":
return new ByeCommand();
case "log":
return new LogCommand();
default:
throw new DukeException("Please enter a valid command.");
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/duchess/model/task/DuchessLog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package duchess.model.task;

import java.util.ArrayList;
import java.util.List;

public class DuchessLog {
private static List<String> duchessLog;

public DuchessLog() {
duchessLog = new ArrayList<>();
}

public void add(String input) {
duchessLog.add(input);
}

public static List<String> getLog() {
return duchessLog;
}
}
14 changes: 14 additions & 0 deletions src/main/java/duchess/ui/Ui.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

package duchess.ui;

import duchess.logic.commands.Command;
import duchess.model.task.Task;

import java.util.List;
Expand Down Expand Up @@ -197,6 +198,19 @@ public void showDeadlines(List<Task> tasks) {
showTasks(tasks);
}

/**
* Displays user history.
*
* @param log list of user log
*/
public void showUserHistory(List<String> log) {
printIndented("These are the commands you entered:");
int counter = 1;
for (String userInput : log) {
printIndented(counter++ + ". " + userInput);
}
}

/**
* Prints a straight line.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/ReminderCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import duchess.logic.commands.AddDeadlineCommand;
import duchess.logic.commands.ReminderCommand;
import duchess.logic.parser.Parser;
import duchess.model.task.DuchessLog;
import duchess.storage.Storage;
import duchess.storage.Store;
import duchess.ui.Ui;
Expand Down Expand Up @@ -38,6 +39,7 @@ public void testExecuteWithDeadlines() throws DukeException {
Ui ui = new Ui();
Storage storage = new Storage(filename);
Parser parser = new Parser();
DuchessLog duchessLog = new DuchessLog();

// Adding the firstDeadline
List<String> firstWords = Arrays.asList(firstDeadline.split(" "));
Expand All @@ -53,4 +55,4 @@ public void testExecuteWithDeadlines() throws DukeException {
assertTrue(store.getTaskList().size() == 2);
ReminderCommand reminderCommand = new ReminderCommand();
}
}
}

0 comments on commit a48c1fc

Please sign in to comment.