From bb62ac21df93fc43de4798fa28ebcba0c83dd26f Mon Sep 17 00:00:00 2001 From: louietyj Date: Sun, 6 Nov 2016 05:52:14 +0800 Subject: [PATCH 1/2] Remove from TodoListDB --- .../java/seedu/todo/models/TodoListDB.java | 554 ------------------ 1 file changed, 554 deletions(-) diff --git a/src/main/java/seedu/todo/models/TodoListDB.java b/src/main/java/seedu/todo/models/TodoListDB.java index 8b277ea19e2c..777a0eb1d24a 100644 --- a/src/main/java/seedu/todo/models/TodoListDB.java +++ b/src/main/java/seedu/todo/models/TodoListDB.java @@ -190,37 +190,6 @@ public void destroyTasks(List clearTasks) { tasks.removeAll(clearTasks); } - /** - * Destroys all Task in the DB and persists the commit. - * - * @return true if the save was successful, false otherwise - * @@author Tiong YaoCong A0139922Y - */ - public void destroyAllTask() { - tasks = new LinkedHashSet(); - } - - /** - * Destroys all Task in the DB by date - * - * @return true if the save was successful, false otherwise - * @@author Tiong YaoCong A0139922Y - */ - public void destroyAllTaskByDate(LocalDateTime givenDate) { - List selectedTasks = getTaskByDate(givenDate); - tasks.removeAll(selectedTasks); - } - - /** - * Destroys all Task in the DB by a range of date - * - * @@author Tiong YaoCong A0139922Y - */ - public void destroyAllTaskByRange(LocalDateTime dateFrom, LocalDateTime dateTo) { - List selectedTasks = getTaskByRange(dateFrom, dateTo); - tasks.removeAll(selectedTasks); - } - /** * @@author A0093907W * @@ -256,37 +225,6 @@ public void destroyEvents(List clearEvents) { events.removeAll(clearEvents); } - /** - * Destroys all Event in the DB and persists the commit. - * - * @@author Tiong YaoCong A0139922Y - */ - public void destroyAllEvent() { - events = new LinkedHashSet(); - } - - /** - * Destroys all Event in the DB by date - * - * @@author Tiong YaoCong A0139922Y - */ - public void destroyAllEventByDate(LocalDateTime givenDate) { - List selectedEvents = getEventByDate(givenDate); - events.removeAll(selectedEvents); - } - - /** - * Destroys all Event in the DB by a range of date - * - * - * @return true if the save was successful, false otherwise - * @@author Tiong YaoCong A0139922Y - */ - public void destroyAllEventByRange(LocalDateTime dateFrom, LocalDateTime dateTo) { - List selectedEvents = getEventByRange(dateFrom, dateTo); - events.removeAll(selectedEvents); - } - /** * @@author A0093907W * @@ -408,497 +346,5 @@ public List getIncompleteTasksAndTaskFromTodayDate() { return incompleteTasks; } - /** - * Filter a list of tasks with a provided item name list - * - * @param tasks - * a list of tasks after searching condition - * @param itemNameList - * a list of keyword to search based on task name - * @return tasks - * @@author Tiong YaoCong A0139922Y - */ - public List getTaskByName(List tasks, HashSet itemNameList, HashSet tagNameList) { - ArrayList taskByName = new ArrayList(); - Iterator tagIterator = tasks.iterator(); - Iterator taskNameIterator = itemNameList.iterator(); - Iterator tagNameIterator = tagNameList.iterator(); - boolean isFound = false; - while (tagIterator.hasNext()) { - Task currTask = tagIterator.next(); - String currTaskName = currTask.getName().toLowerCase(); - ArrayList currTaskTagList = currTask.getTagList(); - String[] currTaskStartingNameBetweenSpace = currTaskName.split(" "); - while(taskNameIterator.hasNext() || tagNameIterator.hasNext()) { - String currentMatchingNameString = ""; - String currentMatchingTagNameString = ""; - - try { - currentMatchingNameString = taskNameIterator.next().toLowerCase(); - } catch (NoSuchElementException e) { - currentMatchingNameString = null; - } - - try { - currentMatchingTagNameString = tagNameIterator.next().toLowerCase(); - } catch (NoSuchElementException e) { - currentMatchingTagNameString = null; - } - - if (currentMatchingNameString != null && currentMatchingTagNameString != null) { - if (currTaskName.startsWith(currentMatchingNameString) || currTaskTagList.contains(currentMatchingTagNameString)){ - taskByName.add(currTask); - isFound = true; - } else { - for (int i = 0; i < currTaskStartingNameBetweenSpace.length; i ++) { - if(currTaskStartingNameBetweenSpace[i].startsWith(currentMatchingNameString)) { - taskByName.add(currTask); - isFound = true; - break; - } - } - } - } else if (currentMatchingNameString != null) { - if (currTaskName.startsWith(currentMatchingNameString)) { - taskByName.add(currTask); - } else { - for (int i = 0; i < currTaskStartingNameBetweenSpace.length; i ++) { - if(currTaskStartingNameBetweenSpace[i].startsWith(currentMatchingNameString)) { - taskByName.add(currTask); - isFound = true; - break; - } - } - } - } else { - if (currTaskTagList.contains(currentMatchingTagNameString)) { - taskByName.add(currTask); - } - } - if (isFound) { - isFound = false; - break; - } - } - tagNameIterator = tagNameList.iterator(); - taskNameIterator = itemNameList.iterator(); - } - return taskByName; - } - - /** - * Get a list of Task in the DB filtered by status , name and one date. - * - * @param givenDate - * LocalDateTime parsed by Natty - * @param isCompleted - * true if searching for completed task, else false for incomplete tasks - * @param listAllStatus - * true if searching for both completed and incomplete tasks, false if either one is been specify - * @param itemNameList - * list of String to be used to search against task name - * @return list of tasks - * @@author Tiong YaoCong A0139922Y - */ - public List getTaskByDateWithStatusAndName(LocalDateTime givenDate, boolean isCompleted, - boolean listAllStatus, HashSet itemNameList, HashSet tagNameList) { - ArrayList taskByDate = new ArrayList(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - Task currTask = iterator.next(); - LocalDateTime currTaskDueDate = DateUtil.floorDate(currTask.getDueDate()); - - if (currTaskDueDate == null) { - currTaskDueDate = LocalDateTime.MIN; - } - - if (listAllStatus) { - if (currTaskDueDate.equals(givenDate)) { - taskByDate.add(currTask); - } - } else { - if (currTaskDueDate.equals(givenDate) && currTask.isCompleted() == isCompleted) { - taskByDate.add(currTask); - } - } - } - - if (itemNameList.size() == 0) { - return taskByDate; - } else { - return getTaskByName(taskByDate, itemNameList, tagNameList); - } - } - - /** - * Get a list of Task in the DB filtered by a given date. - * - * @param givenDate - * LocalDateTime format parsed by Natty - * - * @return list of tasks - * @@author Tiong YaoCong A0139922Y - */ - public List getTaskByDate(LocalDateTime givenDate) { - ArrayList taskByDate = new ArrayList(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - Task currTask = iterator.next(); - LocalDateTime currTaskDueDate = DateUtil.floorDate(currTask.getDueDate()); - - if (currTaskDueDate == null) { - currTaskDueDate = LocalDateTime.MIN; - } - - if (currTaskDueDate.equals(givenDate)) { - taskByDate.add(currTask); - } - } - return taskByDate; - } - - /** - * Get a list of Task in the DB filtered by status and one date. - * - * @param givenDate - * LocalDateTime parsed by Natty - * @param isCompleted - * true if searching for completed task, else false for incomplete tasks - * @param listAllStatus - * true if searching for both completed and incomplete tasks, false if either one is been specify - * @return list of tasks - * @@author Tiong YaoCong A0139922Y - */ - public List getTaskByDateWithStatus(LocalDateTime givenDate, boolean isCompleted, boolean listAllStatus) { - ArrayList taskByDate = new ArrayList(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - Task currTask = iterator.next(); - LocalDateTime currTaskDueDate = DateUtil.floorDate(currTask.getDueDate()); - - if (currTaskDueDate == null) { - currTaskDueDate = LocalDateTime.MIN; - } - - if (listAllStatus) { - if (currTaskDueDate.equals(givenDate)) { - taskByDate.add(currTask); - } - } else { - if (currTaskDueDate.equals(givenDate) && currTask.isCompleted() == isCompleted) { - taskByDate.add(currTask); - } - } - } - return taskByDate; - } - - /** - * Get a list of Task in the DB filtered by status, name and range of date. - * - * @param fromDate - * LocalDateTime parsed by Natty to be used to search as Start Date - * @param toDate - * LocalDateTime parsed by Natty to be used to search as END Date - * @param isCompleted - * true if searching for completed task, else false for incomplete tasks - * @param listAllStatus - * true if searching for both completed and incomplete tasks, false if either one is been specify - * - * @return list of tasks - * @@author Tiong YaoCong A0139922Y - */ - public List getTaskByRangeWithName (LocalDateTime fromDate , LocalDateTime toDate, boolean isCompleted, - boolean listAllStatus, HashSet itemNameList, HashSet tagNameList) { - ArrayList taskByRange = new ArrayList(); - Iterator iterator = tasks.iterator(); - if (fromDate == null) { - fromDate = LocalDateTime.MIN; - } - - if (toDate == null) { - toDate = LocalDateTime.MAX; - } - while (iterator.hasNext()) { - Task currTask = iterator.next(); - LocalDateTime currTaskDueDate = DateUtil.floorDate(currTask.getDueDate()); - if (currTaskDueDate == null) { - currTaskDueDate = LocalDateTime.MIN; - } - - if (listAllStatus) { - if (currTaskDueDate.compareTo(fromDate) >= 0 && currTaskDueDate.compareTo(toDate) <= 0) { - taskByRange.add(currTask); - } - } else { - if (currTaskDueDate.compareTo(fromDate) >= 0 && currTaskDueDate.compareTo(toDate) <= 0 && - currTask.isCompleted() == isCompleted) { - taskByRange.add(currTask); - } - } - } - - if (itemNameList.size() == 0 && tagNameList.size() == 0) { - return taskByRange; - } else { - return getTaskByName(taskByRange, itemNameList, tagNameList); - } - } - - /** - * Get a list of Task in the DB filtered by range of date. - * - * @param fromDate - * LocalDateTime parsed by Natty to be used to search as Start Date - * @param toDate - * LocalDateTime parsed by Natty to be used to search as END Date - * @return list of tasks - * @@author Tiong YaoCong A0139922Y - */ - public List getTaskByRange (LocalDateTime fromDate , LocalDateTime toDate) { - ArrayList taskByRange = new ArrayList(); - Iterator iterator = tasks.iterator(); - if (fromDate == null) { - fromDate = LocalDateTime.MIN; - } - - if (toDate == null) { - toDate = LocalDateTime.MAX; - } - while (iterator.hasNext()) { - Task currTask = iterator.next(); - LocalDateTime currTaskDueDate = DateUtil.floorDate(currTask.getDueDate()); - if (currTaskDueDate == null) { - currTaskDueDate = LocalDateTime.MIN; - } - - if (currTaskDueDate.compareTo(fromDate) >= 0 && currTaskDueDate.compareTo(toDate) <= 0) { - taskByRange.add(currTask); - } - - } - return taskByRange; - } - - /** - * Get a list of Task in the DB filtered by status and range of date. - * - * @param fromDate - * LocalDateTime parsed by Natty to be used to search as Start Date - * @param toDate - * LocalDateTime parsed by Natty to be used to search as END Date - * @param isCompleted - * true if searching for completed task, else false for incomplete tasks - * @param listAllStatus - * true if status of task is not been specify else false if complete or incomplete is been specify - * - * @return list of tasks - * @@author Tiong YaoCong A0139922Y - */ - public List getTaskByRangeWithStatus (LocalDateTime fromDate , LocalDateTime toDate, - boolean isCompleted, boolean listAllStatus) { - ArrayList taskByRange = new ArrayList(); - Iterator iterator = tasks.iterator(); - if (fromDate == null) { - fromDate = LocalDateTime.MIN; - } - - if (toDate == null) { - toDate = LocalDateTime.MAX; - } - while (iterator.hasNext()) { - Task currTask = iterator.next(); - LocalDateTime currTaskDueDate = DateUtil.floorDate(currTask.getDueDate()); - if (currTaskDueDate == null) { - currTaskDueDate = LocalDateTime.MIN; - } - - if (listAllStatus) { - if (currTaskDueDate.compareTo(fromDate) >= 0 && currTaskDueDate.compareTo(toDate) <= 0) { - taskByRange.add(currTask); - } - } else { - if (currTaskDueDate.compareTo(fromDate) >= 0 && currTaskDueDate.compareTo(toDate) <= 0 && - currTask.isCompleted() == isCompleted) { - taskByRange.add(currTask); - } - } - } - - return taskByRange; - } - - /** - * Get a list of Event in the DB filtered by status, name and one date. - * - * @param givenDate - * LocalDateTime parsed by Natty to be used to search event that start from this date - * @return list of events - * @@author Tiong YaoCong A0139922Y - */ - public List getEventbyDateWithName(LocalDateTime givenDate, HashSet itemNameList, HashSet tagNameList) { - ArrayList eventByDate = new ArrayList(); - Iterator iterator = events.iterator(); - while (iterator.hasNext()) { - Event currEvent = iterator.next(); - if (DateUtil.floorDate(currEvent.getCalendarDateTime()).equals(givenDate)) { - eventByDate.add(currEvent); - } - } - - if (itemNameList.size() == 0) { - return eventByDate; - } else { - return getEventByName(eventByDate, itemNameList, tagNameList); - } - } - - /** - * Get a list of Event in the DB filtered by status and one date. - * - * @param givenDate - * LocalDateTime parsed by Natty to be used to search event that start from this date - * @param itemNameList - * list of name keyword entered by user , to be used for match event name - * @return list of events - * @@author Tiong YaoCong A0139922Y - */ - public List getEventByDate(LocalDateTime givenDate) { - ArrayList eventByDate = new ArrayList(); - Iterator iterator = events.iterator(); - while (iterator.hasNext()) { - Event currEvent = iterator.next(); - if (DateUtil.floorDate(currEvent.getCalendarDateTime()).equals(givenDate)) { - eventByDate.add(currEvent); - } - } - return eventByDate; - } - - /** - * Get a list of Event in the DB filtered by status, name and range of date. - * - * @param fromDate - * LocalDateTime parsed by Natty to be used to search as Start Date - * @param toDate - * LocalDateTime parsed by Natty to be used to search as END Date - * @param itemNameList - * list of name keyword entered by user , to be used for match event name - * @return list of events - * @@author Tiong YaoCong A0139922Y - */ - public List getEventByRangeWithName (LocalDateTime fromDate , LocalDateTime toDate, HashSet itemNameList, HashSet tagNameList) { - ArrayList eventByRange = new ArrayList(); - Iterator iterator = events.iterator(); - - //if either date are null, set it to min or max - if (fromDate == null) { - fromDate = LocalDateTime.MIN; - } - - if (toDate == null) { - toDate = LocalDateTime.MAX; - } - while (iterator.hasNext()) { - Event currEvent = iterator.next(); - if (DateUtil.floorDate(currEvent.getStartDate()).compareTo(fromDate) >= 0 && - DateUtil.floorDate(currEvent.getStartDate()).compareTo(toDate) <= 0) { - eventByRange.add(currEvent); - } - } - - if (itemNameList.size() == 0) { - return eventByRange; - } else { - return getEventByName(eventByRange, itemNameList, tagNameList); - } - } - /** - * Get a list of Event in the DB filtered by status and range of date. - * - * @param fromDate - * LocalDateTime parsed by Natty to be used to search as Start Date - * @param toDate - * LocalDateTime parsed by Natty to be used to search as END Date - * - * @return list of events - * @@author Tiong YaoCong A0139922Y - */ - public List getEventByRange (LocalDateTime fromDate , LocalDateTime toDate) { - ArrayList eventByRange = new ArrayList(); - Iterator iterator = events.iterator(); - - //if either date are null, set it to min or max - if (fromDate == null) { - fromDate = LocalDateTime.MIN; - } - - if (toDate == null) { - toDate = LocalDateTime.MAX; - } - while (iterator.hasNext()) { - Event currEvent = iterator.next(); - if (DateUtil.floorDate(currEvent.getStartDate()).compareTo(fromDate) >= 0 && - DateUtil.floorDate(currEvent.getStartDate()).compareTo(toDate) <= 0) { - eventByRange.add(currEvent); - } - } - return eventByRange; - } - - /** - * Filter a list of event with a given name list - * - * @param events - * list of events to be used for filtering - * @param itemNameList - * list of name keyword entered by user , to be used for match event name - * @return list of events - * @@author Tiong YaoCong A0139922Y - */ - public List getEventByName(List events, HashSet itemNameList, HashSet tagNameList) { - ArrayList eventByName = new ArrayList(); - Iterator eventIterator = events.iterator(); - Iterator eventNameIterator = itemNameList.iterator(); - Iterator tagNameIterator = tagNameList.iterator(); - while (eventIterator.hasNext()) { - Event currEvent = eventIterator.next(); - String currEventName = currEvent.getName().toLowerCase(); - ArrayList currEventTagList = currEvent.getTagList(); - while(eventNameIterator.hasNext() || tagNameIterator.hasNext()) { - String currentMatchingNameString = ""; - String currentMatchingTagNameString = ""; - - try { - currentMatchingNameString = eventNameIterator.next().toLowerCase(); - } catch (NoSuchElementException e) { - currentMatchingNameString = null; - } - - try { - currentMatchingTagNameString = tagNameIterator.next().toLowerCase(); - } catch (NoSuchElementException e) { - currentMatchingTagNameString = null; - } - - if (currentMatchingNameString != null && currentMatchingTagNameString != null) { - if (currEventName.contains(currentMatchingNameString) || currEventTagList.contains(currentMatchingTagNameString)){ - eventByName.add(currEvent); - } - } else if (currentMatchingNameString != null) { - if (currEventName.contains(currentMatchingNameString)) { - eventByName.add(currEvent); - } - } else { - if (currEventTagList.contains(currentMatchingTagNameString)) { - eventByName.add(currEvent); - } - } - } - tagNameIterator = tagNameList.iterator(); - eventNameIterator = itemNameList.iterator(); - } - return eventByName; - } } From 3aff7cb8b0eccadc8fd556943aec81adc74c0ea5 Mon Sep 17 00:00:00 2001 From: louietyj Date: Sun, 6 Nov 2016 05:52:27 +0800 Subject: [PATCH 2/2] Remove unused imports --- src/main/java/seedu/todo/models/TodoListDB.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/seedu/todo/models/TodoListDB.java b/src/main/java/seedu/todo/models/TodoListDB.java index 777a0eb1d24a..1310274e8c9f 100644 --- a/src/main/java/seedu/todo/models/TodoListDB.java +++ b/src/main/java/seedu/todo/models/TodoListDB.java @@ -4,12 +4,10 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.NoSuchElementException; import java.util.Set; import seedu.todo.commons.exceptions.CannotRedoException;