diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index 844bcd8146d..448b9b304f1 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -12,6 +12,7 @@ import seedu.address.model.group.Group; import seedu.address.model.group.Lesson; import seedu.address.model.group.Student; +import seedu.address.model.group.StudentInfo; import seedu.address.model.person.Person; /** @@ -69,15 +70,20 @@ public interface Logic { ObservableList getFilteredGroupList(); /** - * Returns an unmodifiable view of the filtered list of Students from a group. + * Returns an unmodifiable view of the filtered list of students from a group. */ ObservableList getStudentList(); /** - * Returns an unmodifiable view of the list of lesson from a group. + * Returns an unmodifiable view of the filtered list of lesson from a group. */ ObservableList getLessonList(); + /** + * Returns an unmodifiable view of the filtered list of students info from a group-lesson. + */ + ObservableList getFilteredStudentInfoList(); + /** * Returns the user prefs' serenity file path. */ diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 652b43799a4..57cae40b364 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -18,6 +18,7 @@ import seedu.address.model.group.Group; import seedu.address.model.group.Lesson; import seedu.address.model.group.Student; +import seedu.address.model.group.StudentInfo; import seedu.address.model.person.Person; import seedu.address.storage.Storage; @@ -85,6 +86,8 @@ public void setGuiSettings(GuiSettings guiSettings) { model.setGuiSettings(guiSettings); } + // ========== Serenity ========== + @Override public ReadOnlySerenity getSerenity() { return model.getSerenity(); @@ -105,6 +108,11 @@ public ObservableList getLessonList() { return model.getLessonList(); } + @Override + public ObservableList getFilteredStudentInfoList() { + return model.getStudentInfoList(); + } + @Override public Path getSerenityFilePath() { return model.getSerenityFilePath(); diff --git a/src/main/java/seedu/address/logic/commands/ViewLsnCommand.java b/src/main/java/seedu/address/logic/commands/ViewLsnCommand.java index e59a83ba579..160867df3bf 100644 --- a/src/main/java/seedu/address/logic/commands/ViewLsnCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewLsnCommand.java @@ -36,13 +36,13 @@ private String getMessage(Model model) { ? Messages.MESSAGE_LESSON_EMPTY : String.format(Messages.MESSAGE_LESSON_LISTED_OVERVIEW, model.getFilteredGroupList().get(0).getName(), - model.getLessonList()); + model.getFilteredLessonList().get(0).getName()); } @Override public CommandResult execute(Model model) { requireNonNull(model); - model.updateFilteredGroupList(grpPredicate); + model.updateFilteredLessonList(lsnPredicate); return new CommandResult(this.getMessage(model)); } diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index cd8d1d9354c..1eb5b026092 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -8,6 +8,7 @@ import seedu.address.model.group.Group; import seedu.address.model.group.Lesson; import seedu.address.model.group.Student; +import seedu.address.model.group.StudentInfo; import seedu.address.model.person.Person; /** @@ -95,6 +96,8 @@ public interface Model { */ void updateFilteredPersonList(Predicate predicate); + // ========== Serenity ========== + /** * Returns the user prefs' serenity file path. */ @@ -137,18 +140,46 @@ public interface Model { */ void updateStudentList(); - /** * Updates the lesson list to filter when changing to another group of interest. */ - public void updateLessonList(); + void updateLessonList(); + + /** + * Updates the filter of the filtered group list to filter by the given {@code predicate}. + * + * @throws NullPointerException if {@code predicate} is null. + */ + void updateFilteredLessonList(Predicate predicate); + + /** + * Updates the student info list to filter when changing to another lesson of interest. + */ + void updateStudentInfoList(); /** - * Returns an unmodifiable view of the filtered group list + * Returns an unmodifiable view of the filtered group list. */ ObservableList getFilteredGroupList(); + /** + * Returns an unmodifiable view of the student list. + */ ObservableList getStudentList(); + /** + * Returns an unmodifiable view of the lesson list. + */ ObservableList getLessonList(); + + /** + * Returns an unmodifiable view of the filtered lesson list. + */ + ObservableList getFilteredLessonList(); + + /** + * Returns an unmodifiable view of the student info list + */ + ObservableList getStudentInfoList(); + } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 35ae1b6c06a..ccffd1cff41 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -11,11 +11,7 @@ import javafx.collections.transformation.FilteredList; import seedu.address.commons.core.GuiSettings; import seedu.address.commons.core.LogsCenter; -import seedu.address.model.group.Group; -import seedu.address.model.group.Lesson; -import seedu.address.model.group.Student; -import seedu.address.model.group.UniqueLessonList; -import seedu.address.model.group.UniqueStudentList; +import seedu.address.model.group.*; import seedu.address.model.person.Person; /** @@ -26,13 +22,15 @@ public class ModelManager implements Model { private static final Logger logger = LogsCenter.getLogger(ModelManager.class); private final AddressBook addressBook; - private final Serenity serenity; private final UserPrefs userPrefs; - private final FilteredList filteredPersons; + + private final Serenity serenity; private final FilteredList filteredGroups; private final ArrayObservableList students; private final ArrayObservableList lessons; + private final FilteredList filteredLessons; + private final ArrayObservableList studentsInfo; /** * Initializes a ModelManager with the given addressBook, userPrefs and serenity. @@ -47,13 +45,15 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs + " and serenity " + serenity); this.addressBook = new AddressBook(addressBook); - this.serenity = new Serenity(serenity); this.userPrefs = new UserPrefs(userPrefs); + this.serenity = new Serenity(serenity); filteredPersons = new FilteredList<>(this.addressBook.getPersonList()); filteredGroups = new FilteredList<>(this.serenity.getGroupList()); students = new ArrayObservableList<>(new UniqueStudentList().asUnmodifiableObservableList()); - lessons = new ArrayObservableList<>(new UniqueLessonList().asUnmodifiableObservableList()); + lessons = new ArrayObservableList<>(new UniqueLessonList().asUnmodifiableObservableList()); + filteredLessons = new FilteredList<>(new UniqueLessonList().asUnmodifiableObservableList()); + studentsInfo = new ArrayObservableList<>(new UniqueStudentInfoList().asUnmodifiableObservableList()); } /** @@ -66,20 +66,22 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs logger.fine("Initializing with address book: " + addressBook + " and user prefs " + userPrefs); this.addressBook = new AddressBook(addressBook); - this.serenity = new Serenity(); this.userPrefs = new UserPrefs(userPrefs); + this.serenity = new Serenity(); filteredPersons = new FilteredList<>(this.addressBook.getPersonList()); filteredGroups = new FilteredList<>(this.serenity.getGroupList()); students = new ArrayObservableList<>(new UniqueStudentList().asUnmodifiableObservableList()); - lessons = new ArrayObservableList<>(new UniqueLessonList().asUnmodifiableObservableList()); + lessons = new ArrayObservableList<>(new UniqueLessonList().asUnmodifiableObservableList()); + filteredLessons = new FilteredList<>(new UniqueLessonList().asUnmodifiableObservableList()); + studentsInfo = new ArrayObservableList<>(new UniqueStudentInfoList().asUnmodifiableObservableList()); } public ModelManager() { this(new AddressBook(), new UserPrefs(), new Serenity()); } - //=========== UserPrefs ================================================================================== + // =========== UserPrefs ================================================================================== @Override public void setUserPrefs(ReadOnlyUserPrefs userPrefs) { @@ -103,7 +105,7 @@ public void setGuiSettings(GuiSettings guiSettings) { userPrefs.setGuiSettings(guiSettings); } - //=========== AddressBook ================================================================================ + // =========== AddressBook ================================================================================ @Override public Path getAddressBookFilePath() { @@ -149,7 +151,7 @@ public void setPerson(Person target, Person editedPerson) { addressBook.setPerson(target, editedPerson); } - //=========== Serenity ================================================================================ + // =========== Serenity ================================================================================ @Override public Path getSerenityFilePath() { @@ -206,6 +208,20 @@ public void updateLessonList() { } } + @Override + public void updateFilteredLessonList(Predicate predicate) { + requireAllNonNull(predicate); + this.filteredLessons.setPredicate(predicate); + updateStudentInfoList(); + } + + @Override + public void updateStudentInfoList() { + if (!filteredGroups.isEmpty() || !lessons.isEmpty()) { + this.studentsInfo.setAll(this.lessons.get(0).getStudentsInfoAsUnmodifiableObservableList()); + } + } + @Override public ObservableList getFilteredGroupList() { return filteredGroups; @@ -221,6 +237,16 @@ public ObservableList getLessonList() { return lessons; } + @Override + public ObservableList getFilteredLessonList() { + return lessons; + } + + @Override + public ObservableList getStudentInfoList() { + return studentsInfo; + } + //=========== Filtered Person List Accessors ============================================================= /** diff --git a/src/main/java/seedu/address/model/group/Lesson.java b/src/main/java/seedu/address/model/group/Lesson.java index b30f7582065..9eab9a409d7 100644 --- a/src/main/java/seedu/address/model/group/Lesson.java +++ b/src/main/java/seedu/address/model/group/Lesson.java @@ -1,5 +1,7 @@ package seedu.address.model.group; +import javafx.collections.ObservableList; + import static seedu.address.commons.util.AppUtil.checkArgument; import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; @@ -14,6 +16,7 @@ public class Lesson { public static final String NAME_CONSTRAINT = "Class name cannot be empty"; public static final String STUDENTS_INFO_CONSTRAINT = "Students information cannot be empty"; + private final String name; private final UniqueStudentInfoList studentsInfo; @@ -34,17 +37,20 @@ boolean isValidName(String name) { return name.length() > 0; } - public UniqueStudentInfoList getStudentsInfo() { - return studentsInfo; + public String getName() { + return name; } boolean isValidStudentInfo(UniqueStudentInfoList studentsInfo) { return studentsInfo.size() > 0; } + public UniqueStudentInfoList getStudentsInfo() { + return studentsInfo; + } - public String getName() { - return name; + public ObservableList getStudentsInfoAsUnmodifiableObservableList() { + return studentsInfo.asUnmodifiableObservableList(); } @Override diff --git a/src/main/java/seedu/address/model/group/UniqueStudentInfoList.java b/src/main/java/seedu/address/model/group/UniqueStudentInfoList.java index d033357d8ab..4828235e184 100644 --- a/src/main/java/seedu/address/model/group/UniqueStudentInfoList.java +++ b/src/main/java/seedu/address/model/group/UniqueStudentInfoList.java @@ -3,18 +3,18 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; import seedu.address.model.group.exceptions.DuplicateGroupException; -import seedu.address.model.group.exceptions.GroupNotFoundException; +import seedu.address.model.group.exceptions.DuplicateStudentInfoException; +import seedu.address.model.group.exceptions.StudentInfoNotFoundException; import java.util.Iterator; import java.util.List; -import java.util.Set; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; /** - * A list of Lessons that enforces uniqueness between its elements and does not allow nulls. - * A Lesson is considered unique by comparing using {@code Lesson#equal(Object)}. + * A list of Students Info that enforces uniqueness between its elements and does not allow nulls. + * A Student Info is considered unique by comparing using {@code StudentInfo#equal(Object)}. */ public class UniqueStudentInfoList implements Iterable { @@ -36,7 +36,7 @@ public boolean contains(StudentInfo toCheck) { public void add(StudentInfo toAdd) { requireNonNull(toAdd); if (contains(toAdd)) { - throw new DuplicateGroupException(); + throw new DuplicateStudentInfoException(); } internalList.add(toAdd); } @@ -55,11 +55,11 @@ public void setStudentInfo(StudentInfo target, StudentInfo editedStudentInfo) { int index = internalList.indexOf(target); if (index == -1) { - throw new GroupNotFoundException(); + throw new StudentInfoNotFoundException(); } if (!target.equals(editedStudentInfo) && contains(editedStudentInfo)) { - throw new DuplicateGroupException(); + throw new DuplicateStudentInfoException(); } internalList.set(index, editedStudentInfo); @@ -68,10 +68,10 @@ public void setStudentInfo(StudentInfo target, StudentInfo editedStudentInfo) { /** * Removes the equivalent student info from the list. The student info must exist in the list. */ - public void remove(Group toRemove) { + public void remove(StudentInfo toRemove) { requireNonNull(toRemove); if (!internalList.remove(toRemove)) { - throw new GroupNotFoundException(); + throw new StudentInfoNotFoundException(); } } @@ -81,16 +81,16 @@ public void setStudentInfo(UniqueStudentInfoList replacement) { } /** - * Replaces the contents of this list with {@code studentInfos}. - * {@code studentInfos} must not contain duplicate student infos. + * Replaces the contents of this list with {@code studentsInfo}. + * {@code studentsInfo} must not contain duplicate students info. */ - public void setStudentInfo(List studentInfos) { - requireAllNonNull(studentInfos); - if (!studentInfosAreUnique(studentInfos)) { + public void setStudentInfo(List studentsInfo) { + requireAllNonNull(studentsInfo); + if (!studentsInfoAreUnique(studentsInfo)) { throw new DuplicateGroupException(); } - internalList.setAll(studentInfos); + internalList.setAll(studentsInfo); } /** @@ -108,7 +108,7 @@ public Iterator iterator() { @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof UniqueGroupList // instanceof handles nulls + || (other instanceof UniqueStudentInfoList // instanceof handles nulls && internalList.equals(((UniqueStudentInfoList) other).internalList)); } @@ -118,12 +118,12 @@ public int hashCode() { } /** - * Returns true if {@code studentInfos} contains only unique student infos. + * Returns true if {@code studentsInfo} contains only unique students info. */ - private boolean studentInfosAreUnique(List studentInfos) { - for (int i = 0; i < studentInfos.size() - 1; i++) { - for (int j = i + 1; j < studentInfos.size(); j++) { - if (studentInfos.get(i).equals(studentInfos.get(j))) { + private boolean studentsInfoAreUnique(List studentsInfo) { + for (int i = 0; i < studentsInfo.size() - 1; i++) { + for (int j = i + 1; j < studentsInfo.size(); j++) { + if (studentsInfo.get(i).equals(studentsInfo.get(j))) { return false; } } diff --git a/src/main/java/seedu/address/model/group/exceptions/DuplicateStudentException.java b/src/main/java/seedu/address/model/group/exceptions/DuplicateStudentException.java index b4f81760740..e0593c59606 100644 --- a/src/main/java/seedu/address/model/group/exceptions/DuplicateStudentException.java +++ b/src/main/java/seedu/address/model/group/exceptions/DuplicateStudentException.java @@ -9,4 +9,5 @@ public class DuplicateStudentException extends RuntimeException { public DuplicateStudentException() { super("Operation would result in duplicate Student!"); } + } diff --git a/src/main/java/seedu/address/model/group/exceptions/DuplicateStudentInfoException.java b/src/main/java/seedu/address/model/group/exceptions/DuplicateStudentInfoException.java new file mode 100644 index 00000000000..7fb996c9060 --- /dev/null +++ b/src/main/java/seedu/address/model/group/exceptions/DuplicateStudentInfoException.java @@ -0,0 +1,13 @@ +package seedu.address.model.group.exceptions; + +/** + * Signals that the operation will result in duplicate Student Info + * (Student Info are considered duplicates if they have the same student identity). + */ +public class DuplicateStudentInfoException extends RuntimeException { + + public DuplicateStudentInfoException() { + super("Operation would result in duplicate Student Info!"); + } + +} diff --git a/src/main/java/seedu/address/model/group/exceptions/StudentInfoNotFoundException.java b/src/main/java/seedu/address/model/group/exceptions/StudentInfoNotFoundException.java new file mode 100644 index 00000000000..deb779cddf2 --- /dev/null +++ b/src/main/java/seedu/address/model/group/exceptions/StudentInfoNotFoundException.java @@ -0,0 +1,8 @@ +package seedu.address.model.group.exceptions; + +/** + * Signals that the operation is unable to find the specified student info. + */ +public class StudentInfoNotFoundException extends RuntimeException { + +} diff --git a/src/main/java/seedu/address/model/group/exceptions/StudentNotFoundException.java b/src/main/java/seedu/address/model/group/exceptions/StudentNotFoundException.java index aef4cdeaa31..3a6f9e6d8f0 100644 --- a/src/main/java/seedu/address/model/group/exceptions/StudentNotFoundException.java +++ b/src/main/java/seedu/address/model/group/exceptions/StudentNotFoundException.java @@ -1,7 +1,7 @@ package seedu.address.model.group.exceptions; /** - * Signals that the operation is unable to find the specified group. + * Signals that the operation is unable to find the specified student. */ public class StudentNotFoundException extends RuntimeException {