diff --git a/src/application/Main.java b/src/application/Main.java deleted file mode 100644 index c0cfc7d..0000000 --- a/src/application/Main.java +++ /dev/null @@ -1,26 +0,0 @@ -package application; - -import javafx.application.Application; -import javafx.stage.Stage; -import javafx.scene.Scene; -import javafx.scene.layout.BorderPane; - - -public class Main extends Application { - @Override - public void start(Stage primaryStage) { - try { - BorderPane root = new BorderPane(); - Scene scene = new Scene(root,400,400); - scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); - primaryStage.setScene(scene); - primaryStage.show(); - } catch(Exception e) { - e.printStackTrace(); - } - } - - public static void main(String[] args) { - launch(args); - } -} diff --git a/src/application/application.css b/src/application/application.css deleted file mode 100644 index 83d6f33..0000000 --- a/src/application/application.css +++ /dev/null @@ -1 +0,0 @@ -/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ \ No newline at end of file diff --git a/src/todolist/MainApp.java b/src/todolist/MainApp.java index f6f8244..d5f55e5 100644 --- a/src/todolist/MainApp.java +++ b/src/todolist/MainApp.java @@ -13,6 +13,7 @@ import todolist.ui.controllers.SideBarController; import todolist.ui.controllers.TodayController; import todolist.ui.controllers.WeekController; + import javafx.animation.PauseTransition; import javafx.application.Application; import javafx.collections.ObservableList; @@ -22,7 +23,6 @@ import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.TextField; -import javafx.scene.control.TitledPane; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; @@ -52,7 +52,7 @@ public class MainApp extends Application { private static final String MESSAGE_ERROR_LOAD_MAIN = "Error loading main view. Exiting now ..."; private static final String MESSAGE_ERROR_LOAD_TITLEBAR = "Error loading title bar view. Exiting now ..."; private static final String MESSAGE_ERROR_LOAD_SIDEBAR = "Error loading side bar view. Exiting now ..."; - private static final String MESSAGE_ERROR_LOAD_EMPTY = "Error loading empty view. Exiting now ..."; +// private static final String MESSAGE_ERROR_LOAD_EMPTY = "Error loading empty view. Exiting now ..."; // Notification messages and delay private static final String NOTIFICATION_WELCOME = "Welcome to ToDoList! Let's get started..."; @@ -65,7 +65,7 @@ public class MainApp extends Application { public static final String DIRECTORY_TASKITEM = "ui/views/TaskNode.fxml"; private static final String STYLE_CLASS_ROOT = "root-layout"; - private static final String STYLE_CLASS_MAIN = "main-view"; +// private static final String STYLE_CLASS_MAIN = "main-view"; private static final String STYLE_CLASS_TITLEBAR = "title-bar"; private static final String STYLE_CLASS_SIDEBAR = "side-bar"; @@ -76,19 +76,18 @@ public class MainApp extends Application { private static final String DIRECTORY_ARCHIVE = "ui/views/ArchiveView.fxml"; private static final String DIRECTORY_SETTINGS = "ui/views/SettingsView.fxml"; private static final String DIRECTORY_HELP = "ui/views/HelpView.fxml"; - private static final String DIRECTORY_EMPTY = "ui/views/EmptyView.fxml"; +// private static final String DIRECTORY_EMPTY = "ui/views/EmptyView.fxml"; private static final String DIRECTORY_NOTIFICATION_SOUND = "ui/views/assets/notification-sound-flyff.wav"; private static final String DIRECTORY_WELCOME_SOUND = "ui/views/assets/notification-sound-twitch.mp3"; - // Views: Display and UI components private BorderPane rootView; private BorderPane mainView; private TextField commandField; private HBox titleBarView; private VBox sideBarView; - private BorderPane emptyView; +// private BorderPane emptyView; private BorderPane overdueView; private BorderPane todayView; private BorderPane weekView; diff --git a/src/todolist/common/stubs/CommandHandlerStub.java b/src/todolist/common/stubs/CommandHandlerStub.java new file mode 100644 index 0000000..97b3827 --- /dev/null +++ b/src/todolist/common/stubs/CommandHandlerStub.java @@ -0,0 +1,64 @@ +package todolist.common.stubs; + +//import java.util.ArrayList; +// +//import todolist.MainApp; +//import todolist.model.Category; +//import todolist.model.Reminder; +//import todolist.ui.TaskWrapper; + +public class CommandHandlerStub { + +// private static String status = "200: Okay"; +// private static ArrayList categoriesToDisplay = new ArrayList(); +// private static Category currentCategory = new Category("SAMPLE CATEGORY"); +// private static ArrayList tasksToDisplay = new ArrayList(); +// private static ArrayList remindersToTrack = new ArrayList(); +// private static String currentSearch = ""; + // private static Page page = Page.Home; + +// private MainApp main = null; + +// public CommandHandlerStub(MainApp main) { +// this.main = main; +// } + + // public void execute(Command command) { + + // Feedback feedback= new Feedback(status, page, + // categoriesToDisplay, currentCategory, + // tasksToDisplay, + // remindersToTrack, currentSearch); + + // ... Do something + + // ArrayList tasksToDisplay = new ArrayList(); + + // tasksToDisplay.add(new TaskWrapper("Do UI Handler (CHANGED)", + // LocalDateTime.now(), LocalDateTime.now().plusHours(3), + // new Category("CS2103T Project (CHANGED)"), new + // Reminder(LocalDateTime.now().plusHours(3)))); + // tasksToDisplay.add(new TaskWrapper("Setup Trello (THIS ALSO CHANGED)", + // LocalDateTime.now(), LocalDateTime.now().plusHours(3), + // new Category("CS2103T Project (CHANGED)"), new + // Reminder(LocalDateTime.now().plusHours(3)))); + // tasksToDisplay.add(new TaskWrapper("Prepare CV (CHANGED)", + // LocalDateTime.now(), LocalDateTime.now().plusHours(3), + // new Category("Personal (CHANGED)"), new Priority(1), new + // Reminder(LocalDateTime.now().plusHours(3)))); + // tasksToDisplay.add(new TaskWrapper("Buy leather shoes (CHANGED)", + // LocalDateTime.now(), LocalDateTime.now().plusHours(3), + // new Category("Personal (CHANGED)"), new Priority(1), new + // Reminder(LocalDateTime.now().plusHours(3)))); + // tasksToDisplay.add(new TaskWrapper("Send emails (CHANGED)", + // LocalDateTime.now(), LocalDateTime.now().plusHours(3), + // new Category("18th MC (CHANGED)"), new Priority(1), new + // Reminder(LocalDateTime.now().plusHours(3)))); + + // Call my functions ... + + // main.setDisplayTasks(tasksToDisplay); + + // return feedback; + // } +} diff --git a/src/todolist/storage/DataBaseTest.java b/src/todolist/common/tests/DataBaseTest.java similarity index 98% rename from src/todolist/storage/DataBaseTest.java rename to src/todolist/common/tests/DataBaseTest.java index 7856462..f999b2f 100644 --- a/src/todolist/storage/DataBaseTest.java +++ b/src/todolist/common/tests/DataBaseTest.java @@ -1,4 +1,4 @@ -package todolist.storage; +package todolist.common.tests; import static org.junit.Assert.*; @@ -13,6 +13,7 @@ import todolist.model.Name; import todolist.model.SearchCommand; import todolist.model.Task; +import todolist.storage.DataBase; public class DataBaseTest { diff --git a/src/todolist/common/tests/LogicTest.java b/src/todolist/common/tests/LogicTest.java new file mode 100644 index 0000000..2cc423b --- /dev/null +++ b/src/todolist/common/tests/LogicTest.java @@ -0,0 +1,166 @@ +package todolist.common.tests; + +import static org.junit.Assert.*; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; + +import org.junit.Test; + +import todolist.MainApp; +import todolist.logic.Logic; +import todolist.logic.MainAppStub; +import todolist.model.Name; +import todolist.model.Task; + +public class LogicTest { + + private MainApp mainAppStub = new MainAppStub(); + + private Logic logic = new Logic(mainAppStub); + + public void testProcess() { + boolean expected = true; + + Name name = new Name("title"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + LocalDateTime start = LocalDateTime.parse("2017-01-01" + " " + "14:00", formatter); + LocalDateTime end = start.plus(Long.parseLong("1"), ChronoUnit.DAYS); + Task newEvent = new Task(name, start, end, null, null, false, false, null); + + logic.process("add event title 2017-01-01 14:00 1 day"); + + Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName()); + + assertEquals(isEqual, expected); + } + + @Test + public void testStepForward() { + int original = logic.checkStep(); + logic.stepForward(1); + assertEquals(logic.checkStep(), original + 1); + } + + public void testAddRecurringEvent() { + fail("Not yet implemented"); + } + + public void testAddRecurringDeadline() { + fail("Not yet implemented"); + } + + @Test + public void testAddEvent() { + Name name = new Name("title"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + LocalDateTime start = LocalDateTime.parse("1970-01-01" + " " + "12:00", formatter); + LocalDateTime end = start.plus(Long.parseLong("1"), ChronoUnit.DAYS); + Task newEvent = new Task(name, start, end, null, null, false, false, null); + + logic.addEvent("title", "1970-01-01", "12:00", "1", "day"); + Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName()); + assert(isEqual); + } + + @Test + public void testAddDeadline() { + Name name = new Name("title"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + LocalDateTime end = LocalDateTime.parse("1970-01-01" + " " + "12:00", formatter); + Task newEvent = new Task(name, null, end, null, null, false, false, null); + + logic.addDeadline("title", "1970-01-01", "12:00"); + Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName()); + assert(isEqual); + } + + @Test + public void testAddTask() { + Name name = new Name("title"); + Task newEvent = new Task(name, null, null, null, null, false, false, null); + logic.addTask("title"); + Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName()); + assert(isEqual); + } + + @Test + public void testDone() { + logic.addTask("title"); + logic.done("title"); + Name name = new Name("title"); + Task newEvent = new Task(name, null, null, null, null, true, false, null); + Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName()); + assert(isEqual); + } + + @Test + public void testUndone() { + logic.addTask("title"); + logic.done("title"); + logic.undone("title"); + Name name = new Name("title"); + Task newEvent = new Task(name, null, null, null, null, false, false, null); + logic.addTask("title"); + Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName()); + assert(isEqual); + } + + public void testEdit() { + fail("Not yet implemented"); + } + + public void testDelete() { + fail("Not yet implemented"); + } + + public void testSearch() { + fail("Not yet implemented"); + } + + public void testLabel() { + fail("Not yet implemented"); + } + + public void testSetRecurring() { + fail("Not yet implemented"); + } + + public void testPostpone() { + fail("Not yet implemented"); + } + + public void testForward() { + fail("Not yet implemented"); + } + + public void testAddRemind() { + fail("Not yet implemented"); + } + + public void testAddRemindBef() { + fail("Not yet implemented"); + } + + public void testRemindBef() { + fail("Not yet implemented"); + } + + public void testRemind() { + fail("Not yet implemented"); + } + + public void testExit() { + fail("Not yet implemented"); + } + + public void testUndo() { + fail("Not yet implemented"); + } + + public void testRedo() { + fail("Not yet implemented"); + } + +} diff --git a/src/todolist/common/tests/MainParserTest.java b/src/todolist/common/tests/MainParserTest.java new file mode 100644 index 0000000..d204392 --- /dev/null +++ b/src/todolist/common/tests/MainParserTest.java @@ -0,0 +1,5 @@ +package todolist.common.tests; + +public class MainParserTest { + +} diff --git a/src/todolist/common/tests/NormalCommandParserTest.java b/src/todolist/common/tests/NormalCommandParserTest.java new file mode 100644 index 0000000..3e08ea2 --- /dev/null +++ b/src/todolist/common/tests/NormalCommandParserTest.java @@ -0,0 +1,45 @@ +package todolist.common.tests; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +import todolist.model.TokenizedCommand; +import todolist.parser.NormalCommandParser; + +public class NormalCommandParserTest { + NormalCommandParser normalCommandParser = null; + + @Before + public void initNormalCommandParser() { + normalCommandParser = new NormalCommandParser(); + } + + @Test + public void testParse() { + + final String testCase = " add event CS2103T-Tutorial 2016-03-23 13:00 1 hour"; + final String expectedAction = "add"; + final int expectedArgsSize = 7; + String[] expectedArgs = new String[expectedArgsSize]; + expectedArgs[0] = "add"; + expectedArgs[1] = "event"; + expectedArgs[2] = "CS2103T-Tutorial"; + expectedArgs[3] = "2016-03-23"; + expectedArgs[4] = "13:00"; + expectedArgs[5] = "1"; + expectedArgs[6] = "hour"; + + TokenizedCommand output = normalCommandParser.parse(testCase); + +// assertEquals(expectedAction, output.getAction()); + assertEquals(expectedArgsSize, output.getArgs().length); + + for (int i = 0; i < output.getArgs().length; ++i) { + String arg = output.getArgs()[i]; + assertEquals(expectedArgs[i], arg); + } + + } +} diff --git a/src/todolist/common/tests/UIHandlerTest.java b/src/todolist/common/tests/UIHandlerTest.java new file mode 100644 index 0000000..3f9ec14 --- /dev/null +++ b/src/todolist/common/tests/UIHandlerTest.java @@ -0,0 +1,5 @@ +package todolist.common.tests; + +public class UIHandlerTest { + +} diff --git a/src/todolist/logic/Logic.java b/src/todolist/logic/Logic.java index 4f33f4b..a9cbbab 100644 --- a/src/todolist/logic/Logic.java +++ b/src/todolist/logic/Logic.java @@ -1,6 +1,5 @@ package todolist.logic; -import java.io.IOException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; @@ -39,7 +38,7 @@ public class Logic { private static String LOGGING_TIME_ERROR = "This time was in the past"; public Logic(MainApp mainApp) { - this.mainApp = mainApp; + this.setMainApp(mainApp); this.dataBase = new DataBase(); this.mainParser = new MainParser(); this.uiHandler = new UIHandler(dataBase, mainApp, this); @@ -758,4 +757,12 @@ private Boolean noRepeat(String title) { return true; } } + + public MainApp getMainApp() { + return mainApp; + } + + public void setMainApp(MainApp mainApp) { + this.mainApp = mainApp; + } } \ No newline at end of file diff --git a/src/todolist/logic/LogicTest.java b/src/todolist/logic/LogicTest.java deleted file mode 100644 index 4c09303..0000000 --- a/src/todolist/logic/LogicTest.java +++ /dev/null @@ -1,181 +0,0 @@ -package todolist.logic; - -import static org.junit.Assert.*; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.time.temporal.ChronoUnit; - -import org.junit.Test; - -import todolist.MainApp; -import todolist.model.Name; -import todolist.model.Task; - -public class LogicTest { - -// private MainApp mainAppStub = new MainAppStub(); - -// private Logic logic = new Logic(mainAppStub); - -// @Test -// public void testProcess() { -// boolean expected = true; -// -// Name name = new Name("title"); -// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); -// LocalDateTime start = LocalDateTime.parse("2017-01-01" + " " + "14:00", formatter); -// LocalDateTime end = start.plus(Long.parseLong("1"), ChronoUnit.DAYS); -// Task newEvent = new Task(name, start, end, null, null, false, false, null); -// -// logic.process("add event title 2017-01-01 14:00 1 day"); -// -// Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName()); -// -// assertEquals(isEqual, expected); -// } -// -// @Test -// public void testStepForward() { -// int original = logic.checkStep(); -// logic.stepForward(1); -// assertEquals(logic.checkStep(), original + 1); -// } -// -// @Test -// public void testAddRecurringEvent() { -// fail("Not yet implemented"); -// } -// -// @Test -// public void testAddRecurringDeadline() { -// fail("Not yet implemented"); -// } -// -// @Test -// public void testAddEvent() { -// Name name = new Name("title"); -// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); -// LocalDateTime start = LocalDateTime.parse("1970-01-01" + " " + "12:00", formatter); -// LocalDateTime end = start.plus(Long.parseLong("1"), ChronoUnit.DAYS); -// Task newEvent = new Task(name, start, end, null, null, false, false, null); -// -// logic.addEvent("title", "1970-01-01", "12:00", "1", "day"); -// Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName()); -// assert(isEqual); -// } -// -// @Test -// public void testAddDeadline() { -// Name name = new Name("title"); -// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); -// LocalDateTime end = LocalDateTime.parse("1970-01-01" + " " + "12:00", formatter); -// Task newEvent = new Task(name, null, end, null, null, false, false, null); -// -// logic.addDeadline("title", "1970-01-01", "12:00"); -// Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName()); -// assert(isEqual); -// } -// -// @Test -// public void testAddTask() { -// Name name = new Name("title"); -// Task newEvent = new Task(name, null, null, null, null, false, false, null); -// logic.addTask("title"); -// Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName()); -// assert(isEqual); -// } -// -// @Test -// public void testDone() { -// logic.addTask("title"); -// logic.done("title"); -// Name name = new Name("title"); -// Task newEvent = new Task(name, null, null, null, null, true, false, null); -// Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName()); -// assert(isEqual); -// } -// -// @Test -// public void testUndone() { -// logic.addTask("title"); -// logic.done("title"); -// logic.undone("title"); -// Name name = new Name("title"); -// Task newEvent = new Task(name, null, null, null, null, false, false, null); -// logic.addTask("title"); -// Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName()); -// assert(isEqual); -// } - - @Test - public void testEdit() { - fail("Not yet implemented"); - } - - @Test - public void testDelete() { - fail("Not yet implemented"); - } - - @Test - public void testSearch() { - fail("Not yet implemented"); - } - - @Test - public void testLabel() { - fail("Not yet implemented"); - } - - @Test - public void testSetRecurring() { - fail("Not yet implemented"); - } - - @Test - public void testPostpone() { - fail("Not yet implemented"); - } - - @Test - public void testForward() { - fail("Not yet implemented"); - } - - @Test - public void testAddRemind() { - fail("Not yet implemented"); - } - - @Test - public void testAddRemindBef() { - fail("Not yet implemented"); - } - - @Test - public void testRemindBef() { - fail("Not yet implemented"); - } - - @Test - public void testRemind() { - fail("Not yet implemented"); - } - - @Test - public void testExit() { - fail("Not yet implemented"); - } - - @Test - public void testUndo() { - fail("Not yet implemented"); - } - - @Test - public void testRedo() { - fail("Not yet implemented"); - } - -} diff --git a/src/todolist/logic/UIHandler.java b/src/todolist/logic/UIHandler.java index f633a3b..37272d3 100644 --- a/src/todolist/logic/UIHandler.java +++ b/src/todolist/logic/UIHandler.java @@ -3,7 +3,6 @@ import java.util.ArrayList; import todolist.MainApp; -import todolist.model.SearchCommand; import todolist.model.Task; import todolist.storage.DataBase; @@ -18,9 +17,9 @@ public UIHandler(DataBase dataBase, MainApp mainApp, Logic logic) { this.mainApp = mainApp; this.logic = logic; } - + public void process(String input) { - logic.process(input); + logic.process(input); } public void refresh() { @@ -32,14 +31,14 @@ public void sendMessage(String message) { } public void highLight(Task task) { - mainApp.highLight(task); + mainApp.highLight(task); } - + public void display(ArrayList taskList) { - mainApp.setDisplayTasks(taskList); + mainApp.setDisplayTasks(taskList); } - + public void tab(int index) { - mainApp.loadPage(index); + mainApp.loadPage(index); } } \ No newline at end of file diff --git a/src/todolist/parser/FlexiCommandParser.java b/src/todolist/parser/FlexiCommandParser.java index 3f60255..1d08c6f 100755 --- a/src/todolist/parser/FlexiCommandParser.java +++ b/src/todolist/parser/FlexiCommandParser.java @@ -2,7 +2,7 @@ import java.util.Date; import java.util.List; -import java.util.Map; +//import java.util.Map; import java.util.TimeZone; import com.joestelmach.natty.DateGroup; @@ -22,13 +22,13 @@ public TokenizedCommand parse(String input) { List groups = parser.parse(input); for (DateGroup group : groups) { List dates = group.getDates(); - int line = group.getLine(); - int column = group.getPosition(); - String matchingValue = group.getText(); - String syntaxTree = group.getSyntaxTree().toStringTree(); - Map parseMap = group.getParseLocations(); - boolean isRecurreing = group.isRecurring(); - Date recursUntil = group.getRecursUntil(); +// int line = group.getLine(); +// int column = group.getPosition(); +// String matchingValue = group.getText(); +// String syntaxTree = group.getSyntaxTree().toStringTree(); +// Map parseMap = group.getParseLocations(); +// boolean isRecurreing = group.isRecurring(); +// Date recursUntil = group.getRecursUntil(); System.out.println(dates); } diff --git a/src/todolist/parser/MainParser.java b/src/todolist/parser/MainParser.java index ea983bb..4c50a01 100644 --- a/src/todolist/parser/MainParser.java +++ b/src/todolist/parser/MainParser.java @@ -3,63 +3,55 @@ import todolist.model.TokenizedCommand; public class MainParser { - - private FlexiCommandParser flexiCommandParser; + + private FlexiCommandParser flexiCommandParser; private NormalCommandParser normalCommandParser; - + public MainParser() { - this.flexiCommandParser = new FlexiCommandParser(); - this.normalCommandParser = new NormalCommandParser(); + this.setFlexiCommandParser(new FlexiCommandParser()); + this.normalCommandParser = new NormalCommandParser(); } - + /** - * This method takes in a string and parse it. - * - * - * @return TokenizedCommand - */ + * This method takes in a string and parse it. + * + * + * @return TokenizedCommand + */ public TokenizedCommand parse(String input) { - if(checkType(input)) { - return normalCommandParser.parse(input); - } else { + if (checkType(input)) { return normalCommandParser.parse(input); -// return flexiCommandParser.parse(input); - } + } else { + return normalCommandParser.parse(input); + // return flexiCommandParser.parse(input); + } } - + /** - * This method takes in a string and check whether it is a flexi command. - * - * - * @return Boolean - */ + * This method takes in a string and check whether it is a flexi command. + * + * + * @return Boolean + */ private Boolean checkType(String input) { - String temp[] = input.split(" "); - String head = temp[0]; - Boolean type = head.equals("add")|| - head.equals("edit")|| - head.equals("delete")|| - head.equals("search")|| - head.equals("filter")|| - head.equals("sort")|| - head.equals("insert")|| - head.equals("switchposition")|| - head.equals("label")|| - head.equals("postpone")|| - head.equals("forward")|| - head.equals("add-remind")|| - head.equals("remind")|| - head.equals("add-remind-bef")|| - head.equals("remind-bef")|| - head.equals("done")|| - head.equals("undone")|| - head.equals("exit")|| - head.equals("undo")|| - head.equals("redo")|| - head.equals("reset")|| - head.equals("tab")|| - head.equals("set-recurring")|| - head.equals("remove-recurring"); - return type; + String temp[] = input.split(" "); + String head = temp[0]; + Boolean type = head.equals("add") || head.equals("edit") || head.equals("delete") || head.equals("search") + || head.equals("filter") || head.equals("sort") || head.equals("insert") + || head.equals("switchposition") || head.equals("label") || head.equals("postpone") + || head.equals("forward") || head.equals("add-remind") || head.equals("remind") + || head.equals("add-remind-bef") || head.equals("remind-bef") || head.equals("done") + || head.equals("undone") || head.equals("exit") || head.equals("undo") || head.equals("redo") + || head.equals("reset") || head.equals("tab") || head.equals("set-recurring") + || head.equals("remove-recurring"); + return type; + } + + public FlexiCommandParser getFlexiCommandParser() { + return flexiCommandParser; + } + + public void setFlexiCommandParser(FlexiCommandParser flexiCommandParser) { + this.flexiCommandParser = flexiCommandParser; } } \ No newline at end of file diff --git a/src/todolist/storage/DataBase.java b/src/todolist/storage/DataBase.java index 330c0fa..b788dee 100755 --- a/src/todolist/storage/DataBase.java +++ b/src/todolist/storage/DataBase.java @@ -1,11 +1,7 @@ package todolist.storage; import java.io.IOException; -import java.time.LocalDateTime; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; import java.util.logging.Level; import java.util.logging.Logger; @@ -154,7 +150,7 @@ public String convert_TaskToString(Task currentTask) { return task_str; } - protected void loadFromFile() { + public void loadFromFile() { taskList = fh.read(); } diff --git a/src/todolist/storage/DatabaseModifier.java b/src/todolist/storage/DatabaseModifier.java index 2ad9a25..8fd81e9 100644 --- a/src/todolist/storage/DatabaseModifier.java +++ b/src/todolist/storage/DatabaseModifier.java @@ -2,68 +2,78 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.logging.Level; import todolist.model.Task; public class DatabaseModifier { - public static String EXCEPEPTION_REPEATED_TASK = "The task has already existed!"; - public static String EXCEPTION_TASKNOTEXIST = "The task to delete does not exist!"; - + public static String EXCEPEPTION_REPEATED_TASK = "The task has already existed!"; + public static String EXCEPTION_TASKNOTEXIST = "The task to delete does not exist!"; + private ArrayList taskList; - + public DatabaseModifier() { - taskList = new ArrayList(); + taskList = new ArrayList(); } - - + /** * add a task to the arraylist after checking whether it is already existing - * @param tasks list of tasks to which the task to add - * @param task the task to be added - * @return the resultant task list - * @throws IOException if the task is already existing + * + * @param tasks + * list of tasks to which the task to add + * @param task + * the task to be added + * @return the resultant task list + * @throws IOException + * if the task is already existing */ public ArrayList addTask(ArrayList tasks, Task task) throws IOException { - this.taskList = tasks; - if(isExistingTask(task)) { - //dataBase_Logger.log(Level.INFO, LOGGING_REPEATED_TASK + task.getName().getName()); - throw new IOException(EXCEPEPTION_REPEATED_TASK) ; + this.taskList = tasks; + if (isExistingTask(task)) { + // dataBase_Logger.log(Level.INFO, LOGGING_REPEATED_TASK + + // task.getName().getName()); + throw new IOException(EXCEPEPTION_REPEATED_TASK); } - - //dataBase_Logger.log(Level.INFO, LOGGING_ADDING_TASK + task.getName().getName()); - taskList.add(0, task); - return taskList; + + // dataBase_Logger.log(Level.INFO, LOGGING_ADDING_TASK + + // task.getName().getName()); + taskList.add(0, task); + return taskList; } - - //helper method for add function + + // helper method for add function private boolean isExistingTask(Task task) { - return taskList.contains(task); + return taskList.contains(task); } - + /** * delete the specific task from the list of tasks - * @param tasks list of tasks from where the task to be deleted - * @param taskToDelete the task to be deleted - * @return the list of - * @throws IOException when the task to delete not in the task list + * + * @param tasks + * list of tasks from where the task to be deleted + * @param taskToDelete + * the task to be deleted + * @return the list of + * @throws IOException + * when the task to delete not in the task list */ public ArrayList deleteTask(ArrayList tasks, Task taskToDelete) throws IOException { - taskList = tasks; - if (taskList.size() == 0) { - //dataBase_Logger.log(Level.INFO, LOGGING_TASK_NOTEXIST + taskToDelete.getName().getName()); + taskList = tasks; + if (taskList.size() == 0) { + // dataBase_Logger.log(Level.INFO, LOGGING_TASK_NOTEXIST + + // taskToDelete.getName().getName()); throw new IOException(EXCEPTION_TASKNOTEXIST); } Integer index = searchForIndexOfTask(taskToDelete); if (index == null) { - //dataBase_Logger.log(Level.INFO, LOGGING_TASK_NOTEXIST + taskToDelete.getName().getName()); + // dataBase_Logger.log(Level.INFO, LOGGING_TASK_NOTEXIST + + // taskToDelete.getName().getName()); System.out.println("why not throwing"); - throw new IOException(EXCEPTION_TASKNOTEXIST); + throw new IOException(EXCEPTION_TASKNOTEXIST); } taskList.remove(taskList.get(index)); - + return taskList; } diff --git a/src/todolist/storage/TaskRetriever.java b/src/todolist/storage/TaskRetriever.java index 94dae23..4923893 100644 --- a/src/todolist/storage/TaskRetriever.java +++ b/src/todolist/storage/TaskRetriever.java @@ -3,15 +3,12 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; -import java.util.logging.Level; import todolist.model.SearchCommand; import todolist.model.Task; - - public class TaskRetriever { - + private static enum FilterType { VIEW, CATEGORY, NAME, END_DATE, START_DATE; } @@ -19,175 +16,174 @@ private static enum FilterType { private static enum ViewType { ARCHIVE, OVERDUE, TODAY; } - - private ArrayList taskList; - - public TaskRetriever() { - taskList = new ArrayList(); - } - - public ArrayList retrieveHandler(ArrayList tasks, SearchCommand command) { -// System.out.println("is retrieving"); - assert(command instanceof SearchCommand); -// System.out.println("not even here"); - taskList = tasks; - - ArrayList resultList = new ArrayList(); - FilterType type = getFilterType(command); - //dataBase_Logger.log(Level.INFO, LOGGING_RETRIEVE_TASK + type); - switch (type) { - case CATEGORY: -// System.out.println("is retrieving 2222"); - resultList = retrieve_Category(command); - break; - case NAME: - System.out.println("name"); - resultList = retrieve_Name(command); - break; - case VIEW: - resultList = retrieve_View(command); - break; - default: -// System.out.println("is retrieving default"); - return resultList; - } - - //System.out.println(Arrays.toString(resultList.toArray())); - - return resultList; - } - - private FilterType getFilterType(SearchCommand command) { - String type = command.getType(); - if (isCategory(type)) { - return FilterType.CATEGORY; - } - if (isView(type)) { - return FilterType.VIEW; - } - if (isName(type)) { - return FilterType.NAME; - } - return null; - } - - private boolean isName(String type) { - return type.equalsIgnoreCase("name"); - } - - private boolean isView(String type) { - return type.equalsIgnoreCase("view"); - } - - private boolean isCategory(String type) { - return type.equalsIgnoreCase("category"); - } - - private ArrayList retrieve_View(SearchCommand command) { - ArrayList resultList = new ArrayList(); - ViewType viewToFilter = determineViewType(command.getContent()); - switch (viewToFilter) { - case OVERDUE: - resultList = retrieve_ViewOverDue(); - break; - case ARCHIVE: - resultList = retrieve_ViewArchive(); - break; - default: - return resultList; - } - return resultList; - } - - // helper method for retrieve_View - private ArrayList retrieve_ViewArchive() { - ArrayList resultList = new ArrayList(); - for (Task eachTask : taskList) { - if (eachTask.getDoneStatus()) { - resultList.add(eachTask); - } - } - return resultList; - } - - // helper method for retrieve_View - private ArrayList retrieve_ViewOverDue() { - ArrayList resultList = new ArrayList(); - for (Task eachTask : taskList) { - if (isTaskOverdue(eachTask.getEndTime())) { - resultList.add(eachTask); - } - } - return null; - } - - private boolean isTaskOverdue(LocalDateTime endTime) { - if (endTime == null) { - return false; - } - return endTime.isBefore(LocalDateTime.now()); - } - - private ViewType determineViewType(String content) { - if (isOverdue(content)) { - return ViewType.OVERDUE; - } - if (isArchive(content)) { - return ViewType.ARCHIVE; - } - return null; - } - - private boolean isArchive(String content) { - return content.equalsIgnoreCase("archive"); - } - - private boolean isOverdue(String content) { - return content.equalsIgnoreCase("overdue"); - } - - private ArrayList retrieve_Name(SearchCommand command) { - ArrayList resultList = new ArrayList(); - String requiredName = command.getContent(); - for (Task eachTask : taskList) { - if (isSubstring(eachTask.getName().getName(), requiredName)) { - resultList.add(eachTask); - } - } - System.out.println(Arrays.toString(resultList.toArray())); - return resultList; - } - - private boolean isSame(String str1, String str2) { - return str1.equalsIgnoreCase(str2); - } - - private boolean isSubstring(String str1, String str2) { - return str1.contains(str2); - } - - private ArrayList retrieve_Category(SearchCommand command) { - ArrayList resultList = new ArrayList(); - String requiredCategory = command.getContent(); - - System.out.println(requiredCategory); - - for (Task eachTask : taskList) { - if (eachTask.getCategory() != null && isSame(eachTask.getCategory().getCategory(), requiredCategory)) { - System.out.println(eachTask.getName().getName()); - resultList.add(eachTask); - } - } - return resultList; - } - - /** - * check whether the required task exist in the local storage file - * - */ - public boolean isTaskExisting(ArrayList taskList, Task taskToCheck) { - return taskList.contains(taskToCheck); + + private ArrayList taskList; + + public TaskRetriever() { + taskList = new ArrayList(); + } + + public ArrayList retrieveHandler(ArrayList tasks, SearchCommand command) { + // System.out.println("is retrieving"); + assert (command instanceof SearchCommand); + // System.out.println("not even here"); + taskList = tasks; + + ArrayList resultList = new ArrayList(); + FilterType type = getFilterType(command); + // dataBase_Logger.log(Level.INFO, LOGGING_RETRIEVE_TASK + type); + switch (type) { + case CATEGORY: + // System.out.println("is retrieving 2222"); + resultList = retrieve_Category(command); + break; + case NAME: + System.out.println("name"); + resultList = retrieve_Name(command); + break; + case VIEW: + resultList = retrieve_View(command); + break; + default: + // System.out.println("is retrieving default"); + return resultList; + } + + // System.out.println(Arrays.toString(resultList.toArray())); + + return resultList; + } + + private FilterType getFilterType(SearchCommand command) { + String type = command.getType(); + if (isCategory(type)) { + return FilterType.CATEGORY; + } + if (isView(type)) { + return FilterType.VIEW; + } + if (isName(type)) { + return FilterType.NAME; + } + return null; + } + + private boolean isName(String type) { + return type.equalsIgnoreCase("name"); + } + + private boolean isView(String type) { + return type.equalsIgnoreCase("view"); + } + + private boolean isCategory(String type) { + return type.equalsIgnoreCase("category"); + } + + private ArrayList retrieve_View(SearchCommand command) { + ArrayList resultList = new ArrayList(); + ViewType viewToFilter = determineViewType(command.getContent()); + switch (viewToFilter) { + case OVERDUE: + resultList = retrieve_ViewOverDue(); + break; + case ARCHIVE: + resultList = retrieve_ViewArchive(); + break; + default: + return resultList; } - + return resultList; + } + + // helper method for retrieve_View + private ArrayList retrieve_ViewArchive() { + ArrayList resultList = new ArrayList(); + for (Task eachTask : taskList) { + if (eachTask.getDoneStatus()) { + resultList.add(eachTask); + } + } + return resultList; + } + + // helper method for retrieve_View + private ArrayList retrieve_ViewOverDue() { + ArrayList resultList = new ArrayList(); + for (Task eachTask : taskList) { + if (isTaskOverdue(eachTask.getEndTime())) { + resultList.add(eachTask); + } + } + return null; + } + + private boolean isTaskOverdue(LocalDateTime endTime) { + if (endTime == null) { + return false; + } + return endTime.isBefore(LocalDateTime.now()); + } + + private ViewType determineViewType(String content) { + if (isOverdue(content)) { + return ViewType.OVERDUE; + } + if (isArchive(content)) { + return ViewType.ARCHIVE; + } + return null; + } + + private boolean isArchive(String content) { + return content.equalsIgnoreCase("archive"); + } + + private boolean isOverdue(String content) { + return content.equalsIgnoreCase("overdue"); + } + + private ArrayList retrieve_Name(SearchCommand command) { + ArrayList resultList = new ArrayList(); + String requiredName = command.getContent(); + for (Task eachTask : taskList) { + if (isSubstring(eachTask.getName().getName(), requiredName)) { + resultList.add(eachTask); + } + } + System.out.println(Arrays.toString(resultList.toArray())); + return resultList; + } + + private boolean isSame(String str1, String str2) { + return str1.equalsIgnoreCase(str2); + } + + private boolean isSubstring(String str1, String str2) { + return str1.contains(str2); + } + + private ArrayList retrieve_Category(SearchCommand command) { + ArrayList resultList = new ArrayList(); + String requiredCategory = command.getContent(); + + System.out.println(requiredCategory); + + for (Task eachTask : taskList) { + if (eachTask.getCategory() != null && isSame(eachTask.getCategory().getCategory(), requiredCategory)) { + System.out.println(eachTask.getName().getName()); + resultList.add(eachTask); + } + } + return resultList; + } + + /** + * check whether the required task exist in the local storage file + * + */ + public boolean isTaskExisting(ArrayList taskList, Task taskToCheck) { + return taskList.contains(taskToCheck); + } } diff --git a/src/todolist/ui/stubs/CommandHandlerStub.java b/src/todolist/ui/stubs/CommandHandlerStub.java deleted file mode 100644 index 99bd001..0000000 --- a/src/todolist/ui/stubs/CommandHandlerStub.java +++ /dev/null @@ -1,56 +0,0 @@ -package todolist.ui.stubs; - -import java.time.LocalDateTime; -import java.util.ArrayList; - -import todolist.MainApp; -//import todolist.model.Feedback.Page; -import todolist.model.Category; -import todolist.model.Reminder; -import todolist.ui.TaskWrapper; - -public class CommandHandlerStub { - - private static String status = "200: Okay"; - private static ArrayList categoriesToDisplay = new ArrayList(); - private static Category currentCategory = new Category("SAMPLE CATEGORY"); - private static ArrayList tasksToDisplay = new ArrayList(); - private static ArrayList remindersToTrack = new ArrayList(); - private static String currentSearch = ""; -// private static Page page = Page.Home; - - private MainApp main = null; - - public CommandHandlerStub(MainApp main) { - this.main = main; - } - - //public void execute(Command command) { - -// Feedback feedback= new Feedback(status, page, -// categoriesToDisplay, currentCategory, -// tasksToDisplay, -// remindersToTrack, currentSearch); - - // ... Do something - - //ArrayList tasksToDisplay = new ArrayList(); - -// tasksToDisplay.add(new TaskWrapper("Do UI Handler (CHANGED)", LocalDateTime.now(), LocalDateTime.now().plusHours(3), -// new Category("CS2103T Project (CHANGED)"), new Reminder(LocalDateTime.now().plusHours(3)))); -// tasksToDisplay.add(new TaskWrapper("Setup Trello (THIS ALSO CHANGED)", LocalDateTime.now(), LocalDateTime.now().plusHours(3), -// new Category("CS2103T Project (CHANGED)"), new Reminder(LocalDateTime.now().plusHours(3)))); -// tasksToDisplay.add(new TaskWrapper("Prepare CV (CHANGED)", LocalDateTime.now(), LocalDateTime.now().plusHours(3), -// new Category("Personal (CHANGED)"), new Priority(1), new Reminder(LocalDateTime.now().plusHours(3)))); -// tasksToDisplay.add(new TaskWrapper("Buy leather shoes (CHANGED)", LocalDateTime.now(), LocalDateTime.now().plusHours(3), -// new Category("Personal (CHANGED)"), new Priority(1), new Reminder(LocalDateTime.now().plusHours(3)))); -// tasksToDisplay.add(new TaskWrapper("Send emails (CHANGED)", LocalDateTime.now(), LocalDateTime.now().plusHours(3), -// new Category("18th MC (CHANGED)"), new Priority(1), new Reminder(LocalDateTime.now().plusHours(3)))); - - // Call my functions ... - -// main.setDisplayTasks(tasksToDisplay); - -// return feedback; - //} -}