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

Move all logic in LogicManager to model #140

Merged
merged 2 commits into from
Oct 26, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 7 additions & 19 deletions src/main/java/trackitnus/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.nio.file.Path;
import java.time.LocalDate;
import java.util.function.Predicate;
import java.util.logging.Logger;

import javafx.collections.ObservableList;
Expand All @@ -19,7 +18,6 @@
import trackitnus.model.commons.Code;
import trackitnus.model.contact.Contact;
import trackitnus.model.lesson.Lesson;
import trackitnus.model.lesson.LessonWeekday;
import trackitnus.model.module.Module;
import trackitnus.model.task.Task;
import trackitnus.storage.Storage;
Expand Down Expand Up @@ -92,46 +90,36 @@ public ObservableList<Lesson> getFilteredLessonList() {
// All functions should only generate new predicates and use the corresponding getFilteredList to return
@Override
public ObservableList<Lesson> getUpcomingLessons() {
model.sortLesson();
model.updateFilteredLessonList(Model.PREDICATE_SHOW_ALL_LESSONS);
return model.getFilteredLessonList();
return model.getUpcomingLessons();
}

@Override
public ObservableList<Lesson> getDayUpcomingLessons(LocalDate date) {
LessonWeekday weekday = LessonWeekday.getLessonWeekDay(date);
Predicate<Lesson> predicate = lesson -> (lesson.getWeekday().equals(weekday));
ObservableList<Lesson> allUpcomingLessons = getUpcomingLessons();
return allUpcomingLessons.filtered(predicate);
return model.getDayUpcomingLessons(date);
}

@Override
public ObservableList<Lesson> getModuleLessons(Code code) {
Predicate<Lesson> predicate = lesson -> (lesson.getCode().equals(code));
model.updateFilteredLessonList(predicate);
return model.getFilteredLessonList();
return model.getModuleLessons(code);
}

@Override
public ObservableList<Task> getModuleTasks(Code code) {
Predicate<Task> p = task -> task.belongsToModule(code);
model.updateFilteredTaskList(p);
return model.getFilteredTaskList();
return model.getModuleTasks(code);
}

@Override
public ObservableList<Task> getUpcomingTasks() {
model.updateFilteredTaskList(Model.PREDICATE_SHOW_ALL_TASKS);
return model.getFilteredTaskList();
return model.getUpcomingTasks();
}

@Override
public ObservableList<Task> getDayUpcomingTasks(LocalDate date) {
Predicate<Task> p = task -> task.getDate().equals(date);
return model.getFilteredTaskList().filtered(p);
return model.getDayUpcomingTasks(date);
}

//--------------------------------END of V1.3's new functions--------------------------------

@Override
public Path getTrackIterFilePath() {
return model.getTrackIterFilePath();
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/trackitnus/model/Model.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package trackitnus.model;

import java.nio.file.Path;
import java.time.LocalDate;
import java.util.Optional;
import java.util.function.Predicate;

Expand Down Expand Up @@ -230,6 +231,44 @@ public interface Model {
*/
ObservableList<Lesson> getFilteredLessonList();

//--------------------------------START of V1.3's new functions--------------------------------

/**
* @return the list of all lessons that will take place on and up to a week after the current day
*/
ObservableList<Lesson> getUpcomingLessons();

/**
* @param date The date to query
* @return all lessons happens on that date
*/
ObservableList<Lesson> getDayUpcomingLessons(LocalDate date);

/**
* @param code The module code to query
* @return the list of lesson for a specific module
*/
ObservableList<Lesson> getModuleLessons(Code code);

/**
* @param code The module code to query
* @return the list of task for a specific module
*/
ObservableList<Task> getModuleTasks(Code code);

/**
* @return the list of all tasks
*/
ObservableList<Task> getUpcomingTasks();

/**
* @param date The date to query
* @return the list of all tasks that take place on the specified date
*/
ObservableList<Task> getDayUpcomingTasks(LocalDate date);

//--------------------------------END of V1.3's new functions--------------------------------

/**
* Updates the filter of the filtered lesson list to filter by the given {@code predicate}.
*
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/trackitnus/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;

import java.nio.file.Path;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
Expand All @@ -19,6 +20,7 @@
import trackitnus.model.commons.Code;
import trackitnus.model.contact.Contact;
import trackitnus.model.lesson.Lesson;
import trackitnus.model.lesson.LessonWeekday;
import trackitnus.model.lesson.Type;
import trackitnus.model.module.Module;
import trackitnus.model.task.Task;
Expand Down Expand Up @@ -283,6 +285,50 @@ public ObservableList<Lesson> getFilteredLessonList() {
return filteredLessons;
}

//--------------------------------START of V1.3's new functions--------------------------------
// TODO:
// All the current functions are just dummy implementations
// All functions should only generate new predicates and use the corresponding getFilteredList to return
@Override
public ObservableList<Lesson> getUpcomingLessons() {
sortLesson();
updateFilteredLessonList(PREDICATE_SHOW_ALL_LESSONS);
return getFilteredLessonList();
}

@Override
public ObservableList<Lesson> getDayUpcomingLessons(LocalDate date) {
LessonWeekday weekday = LessonWeekday.getLessonWeekDay(date);
Predicate<Lesson> predicate = lesson -> (lesson.getWeekday().equals(weekday));
return getUpcomingLessons().filtered(predicate);
}

@Override
public ObservableList<Lesson> getModuleLessons(Code code) {
Predicate<Lesson> predicate = lesson -> (lesson.getCode().equals(code));
updateFilteredLessonList(predicate);
return getFilteredLessonList();
}

@Override
public ObservableList<Task> getModuleTasks(Code code) {
Predicate<Task> p = task -> task.belongsToModule(code);
updateFilteredTaskList(p);
return getFilteredTaskList();
}

@Override
public ObservableList<Task> getUpcomingTasks() {
updateFilteredTaskList(Model.PREDICATE_SHOW_ALL_TASKS);
return getFilteredTaskList();
}

@Override
public ObservableList<Task> getDayUpcomingTasks(LocalDate date) {
Predicate<Task> p = task -> task.getDate().equals(date);
return getFilteredTaskList().filtered(p);
}

@Override
public void updateFilteredLessonList(Predicate<Lesson> predicate) {
requireNonNull(predicate);
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/trackitnus/testutil/ModelStub.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package trackitnus.testutil;

import java.nio.file.Path;
import java.time.LocalDate;
import java.util.Optional;
import java.util.function.Predicate;

Expand Down Expand Up @@ -181,6 +182,36 @@ public ObservableList<Lesson> getFilteredLessonList() {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Lesson> getUpcomingLessons() {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Lesson> getDayUpcomingLessons(LocalDate date) {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Lesson> getModuleLessons(Code code) {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Task> getModuleTasks(Code code) {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Task> getUpcomingTasks() {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Task> getDayUpcomingTasks(LocalDate date) {
throw new AssertionError("This method should not be called.");
}

@Override
public void updateFilteredLessonList(Predicate<Lesson> predicate) {
throw new AssertionError("This method should not be called.");
Expand Down