Skip to content

Commit

Permalink
Add methods to update UniqueStudentInfoList
Browse files Browse the repository at this point in the history
  • Loading branch information
Nijnxw committed Oct 6, 2020
1 parent b343c43 commit a5ea45a
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 47 deletions.
10 changes: 8 additions & 2 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -69,15 +70,20 @@ public interface Logic {
ObservableList<Group> 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<Student> 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<Lesson> getLessonList();

/**
* Returns an unmodifiable view of the filtered list of students info from a group-lesson.
*/
ObservableList<StudentInfo> getFilteredStudentInfoList();

/**
* Returns the user prefs' serenity file path.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -85,6 +86,8 @@ public void setGuiSettings(GuiSettings guiSettings) {
model.setGuiSettings(guiSettings);
}

// ========== Serenity ==========

@Override
public ReadOnlySerenity getSerenity() {
return model.getSerenity();
Expand All @@ -105,6 +108,11 @@ public ObservableList<Lesson> getLessonList() {
return model.getLessonList();
}

@Override
public ObservableList<StudentInfo> getFilteredStudentInfoList() {
return model.getStudentInfoList();
}

@Override
public Path getSerenityFilePath() {
return model.getSerenityFilePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
37 changes: 34 additions & 3 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -95,6 +96,8 @@ public interface Model {
*/
void updateFilteredPersonList(Predicate<Person> predicate);

// ========== Serenity ==========

/**
* Returns the user prefs' serenity file path.
*/
Expand Down Expand Up @@ -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<Lesson> 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<Group> getFilteredGroupList();

/**
* Returns an unmodifiable view of the student list.
*/
ObservableList<Student> getStudentList();

/**
* Returns an unmodifiable view of the lesson list.
*/
ObservableList<Lesson> getLessonList();

/**
* Returns an unmodifiable view of the filtered lesson list.
*/
ObservableList<Lesson> getFilteredLessonList();

/**
* Returns an unmodifiable view of the student info list
*/
ObservableList<StudentInfo> getStudentInfoList();

}
54 changes: 40 additions & 14 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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<Person> filteredPersons;

private final Serenity serenity;
private final FilteredList<Group> filteredGroups;
private final ArrayObservableList<Student> students;
private final ArrayObservableList<Lesson> lessons;
private final FilteredList<Lesson> filteredLessons;
private final ArrayObservableList<StudentInfo> studentsInfo;

/**
* Initializes a ModelManager with the given addressBook, userPrefs and serenity.
Expand All @@ -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());
}

/**
Expand All @@ -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) {
Expand All @@ -103,7 +105,7 @@ public void setGuiSettings(GuiSettings guiSettings) {
userPrefs.setGuiSettings(guiSettings);
}

//=========== AddressBook ================================================================================
// =========== AddressBook ================================================================================

@Override
public Path getAddressBookFilePath() {
Expand Down Expand Up @@ -149,7 +151,7 @@ public void setPerson(Person target, Person editedPerson) {
addressBook.setPerson(target, editedPerson);
}

//=========== Serenity ================================================================================
// =========== Serenity ================================================================================

@Override
public Path getSerenityFilePath() {
Expand Down Expand Up @@ -206,6 +208,20 @@ public void updateLessonList() {
}
}

@Override
public void updateFilteredLessonList(Predicate<Lesson> 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<Group> getFilteredGroupList() {
return filteredGroups;
Expand All @@ -221,6 +237,16 @@ public ObservableList<Lesson> getLessonList() {
return lessons;
}

@Override
public ObservableList<Lesson> getFilteredLessonList() {
return lessons;
}

@Override
public ObservableList<StudentInfo> getStudentInfoList() {
return studentsInfo;
}

//=========== Filtered Person List Accessors =============================================================

/**
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/seedu/address/model/group/Lesson.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;

Expand All @@ -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<StudentInfo> getStudentsInfoAsUnmodifiableObservableList() {
return studentsInfo.asUnmodifiableObservableList();
}

@Override
Expand Down
Loading

0 comments on commit a5ea45a

Please sign in to comment.