Skip to content

Commit

Permalink
Merge branch 'master' into Check-Javadoc
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
qinxutan committed Mar 19, 2024
2 parents 49e64fd + 1488ea1 commit 204ddd5
Show file tree
Hide file tree
Showing 27 changed files with 443 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ jobs:
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}


7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ task coverage(type: JacocoReport) {
dependencies {
String jUnitVersion = '5.4.0'
String javaFxVersion = '17.0.7'
String mockitoVersion = '5.11.0'

implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
Expand All @@ -61,8 +62,12 @@ dependencies {
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.7.4'

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion

testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion

testImplementation "org.mockito:mockito-core:$mockitoVersion"

testImplementation 'org.testfx:testfx-junit5:4.0.16-alpha'
testImplementation 'org.testfx:testfx-core:4.0.16-alpha'
}

shadowJar {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ public interface Logic {
* Set the user prefs' GUI settings.
*/
void setGuiSettings(GuiSettings guiSettings);
boolean isInitialModuleListPanelDisplayed();
}
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@ public GuiSettings getGuiSettings() {
public void setGuiSettings(GuiSettings guiSettings) {
model.setGuiSettings(guiSettings);
}

@Override
public boolean isInitialModuleListPanelDisplayed() {
// Check if there are any modules in the address book
return !model.getAddressBook().getModuleList().isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public AddClassCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_MODULECODE, PREFIX_TUTORIALCLASS);

if (!arePrefixesPresent(argMultimap, PREFIX_MODULECODE, PREFIX_TUTORIALCLASS)
|| !argMultimap.getPreamble().isEmpty()) {
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddClassCommand.MESSAGE_USAGE));
}

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.ArrayList;
import java.util.List;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.module.ModuleCode;
Expand Down Expand Up @@ -52,13 +53,19 @@ public void setPersons(List<Person> persons) {
this.persons.setPersons(persons);
}

public void setModules(List<ModuleCode> modules) {
requireNonNull(modules);
this.modules.clear();
this.modules.addAll(modules);
}
/**
* Resets the existing data of this {@code AddressBook} with {@code newData}.
*/
public void resetData(ReadOnlyAddressBook newData) {
requireNonNull(newData);

setPersons(newData.getPersonList());
setModules(newData.getModuleList());
}

//// person-level operations
Expand All @@ -82,6 +89,7 @@ public void addPerson(Person p) {
/**
* Returns true if a module with the same identity as {@code module} exists in the address book.
*/
@Override
public boolean hasModule(ModuleCode module) {
requireNonNull(module);
return modules.contains(module);
Expand All @@ -106,6 +114,7 @@ public ModuleCode findModuleFromList(ModuleCode module) {
* Adds a module to the address book.
* The module must not already exist in the address book. (TODO)
*/
@Override
public void addModule(ModuleCode m) {
modules.add(m);
}
Expand Down Expand Up @@ -143,8 +152,9 @@ public ObservableList<Person> getPersonList() {
return persons.asUnmodifiableObservableList();
}

public List<ModuleCode> getModuleList() {
return modules;
@Override
public ObservableList<ModuleCode> getModuleList() {
return FXCollections.observableList(modules);
}

@Override
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
public interface Model {
/** {@code Predicate} that always evaluate to true */
Predicate<Person> PREDICATE_SHOW_ALL_PERSONS = unused -> true;
Predicate<ModuleCode> PREDICATE_SHOW_ALL_MODULES = unused -> true;


/**
* Replaces user prefs data with the data in {@code userPrefs}.
Expand Down Expand Up @@ -57,12 +59,6 @@ public interface Model {
* Returns true if a person with the same identity as {@code person} exists in the address book.
*/
boolean hasPerson(Person person);

/**
* Returns true if a module with the same identity as {@code module} exists in the address book.
*/
boolean hasModule(ModuleCode module);

/**
* Finds the module object from the list if it exists. Else, returns null.
*
Expand Down Expand Up @@ -98,15 +94,17 @@ public interface Model {

/** Returns an unmodifiable view of the filtered person list */
ObservableList<Person> getFilteredPersonList();
ObservableList<ModuleCode> getFilteredModuleList();

/**
* Updates the filter of the filtered person list to filter by the given {@code predicate}.
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredPersonList(Predicate<Person> predicate);

void updateFilteredModuleList(Predicate<ModuleCode> predicate);
/**
* Search for person by a given {@code predicate}.
*/
Person searchPersonByPredicate(Predicate<Person> predicate);

}
26 changes: 18 additions & 8 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ModelManager implements Model {
private final AddressBook addressBook;
private final UserPrefs userPrefs;
private final FilteredList<Person> filteredPersons;
private final FilteredList<ModuleCode> filteredModules;

/**
* Initializes a ModelManager with the given addressBook and userPrefs.
Expand All @@ -36,6 +37,7 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs
this.addressBook = new AddressBook(addressBook);
this.userPrefs = new UserPrefs(userPrefs);
filteredPersons = new FilteredList<>(this.addressBook.getPersonList());
filteredModules = new FilteredList<>(this.addressBook.getModuleList());
}

public ModelManager() {
Expand Down Expand Up @@ -94,13 +96,6 @@ public boolean hasPerson(Person person) {
requireNonNull(person);
return addressBook.hasPerson(person);
}

@Override
public boolean hasModule(ModuleCode module) {
requireNonNull(module);
return addressBook.hasModule(module);
}

@Override
public ModuleCode findModuleFromList(ModuleCode module) {
requireNonNull(module);
Expand Down Expand Up @@ -140,13 +135,29 @@ public ObservableList<Person> getFilteredPersonList() {
return filteredPersons;
}

@Override
public ObservableList<ModuleCode> getFilteredModuleList() {
return filteredModules;
}

@Override
public void updateFilteredPersonList(Predicate<Person> predicate) {
requireNonNull(predicate);
filteredPersons.setPredicate(predicate);
}

@Override
public void updateFilteredModuleList(Predicate<ModuleCode> predicate) {
requireNonNull(predicate);
filteredModules.setPredicate(predicate);
}
/**
* Searches for a person in the list of filtered persons based on the given predicate.
*
* @param predicate The predicate used to filter persons.
* @return The first person that matches the predicate, or {@code null} if no person matches.
* @throws NullPointerException if the predicate is {@code null}.
*/
public Person searchPersonByPredicate(Predicate<Person> predicate) {
requireNonNull(predicate);
return filteredPersons.stream().filter(predicate).findFirst().orElse(null);
Expand All @@ -168,5 +179,4 @@ public boolean equals(Object other) {
&& userPrefs.equals(otherModelManager.userPrefs)
&& filteredPersons.equals(otherModelManager.filteredPersons);
}

}
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/model/ReadOnlyAddressBook.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package seedu.address.model;

import java.util.List;

import javafx.collections.ObservableList;
import seedu.address.model.module.ModuleCode;
import seedu.address.model.person.Person;
Expand All @@ -17,5 +15,7 @@ public interface ReadOnlyAddressBook {
*/
ObservableList<Person> getPersonList();

List<ModuleCode> getModuleList();
ObservableList<ModuleCode> getModuleList();
boolean hasModule(ModuleCode moduleCode);
void addModule(ModuleCode moduleCode);
}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/module/ModuleCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public boolean hasTutorialClass(TutorialClass tutorialClass) {
return false;
}


/**
* List all the tutorial classes under this module.
*
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/seedu/address/model/module/TutorialClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public class TutorialClass {

public final String tutorialName;
private final ArrayList<Person> students;
/**
* Constructs a {@code TutorialClass} with default values.
* Initializes the {@code value} field to an empty string and creates an empty list for {@code students}.
*/
public TutorialClass() {
this.tutorialName = "";
this.students = new ArrayList<>();
}


/**
* A constructor for TutorialClass. Creates an empty tutorial class with no students.
Expand All @@ -49,7 +58,6 @@ public TutorialClass(String tutorialClass, ArrayList<Person> students) {
this.tutorialName = tutorialClass;
this.students = students;
}

/**
* Returns true if a given string is a valid tutorial class code.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.AddressBook;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.module.ModuleCode;
import seedu.address.model.person.Person;

/**
Expand All @@ -20,15 +21,23 @@
class JsonSerializableAddressBook {

public static final String MESSAGE_DUPLICATE_PERSON = "Persons list contains duplicate person(s).";
public static final String MESSAGE_DUPLICATE_MODULE = "Modules list contains duplicate module(s).";

private final List<JsonAdaptedPerson> persons = new ArrayList<>();
private final List<JsonAdaptedModule> modules = new ArrayList<>();

/**
* Constructs a {@code JsonSerializableAddressBook} with the given persons.
*/
@JsonCreator
public JsonSerializableAddressBook(@JsonProperty("persons") List<JsonAdaptedPerson> persons) {
this.persons.addAll(persons);
public JsonSerializableAddressBook(@JsonProperty("persons") List<JsonAdaptedPerson> persons,
@JsonProperty("modules") List<JsonAdaptedModule> modules) {
if (persons != null) {
this.persons.addAll(persons);
}
if (modules != null) {
this.modules.addAll(modules);
}
}

/**
Expand All @@ -38,6 +47,7 @@ public JsonSerializableAddressBook(@JsonProperty("persons") List<JsonAdaptedPers
*/
public JsonSerializableAddressBook(ReadOnlyAddressBook source) {
persons.addAll(source.getPersonList().stream().map(JsonAdaptedPerson::new).collect(Collectors.toList()));
modules.addAll(source.getModuleList().stream().map(JsonAdaptedModule::new).collect(Collectors.toList()));
}

/**
Expand All @@ -54,6 +64,13 @@ public AddressBook toModelType() throws IllegalValueException {
}
addressBook.addPerson(person);
}
for (JsonAdaptedModule jsonAdaptedModule : modules) {
ModuleCode module = jsonAdaptedModule.toModelType();
if (addressBook.hasModule(module)) {
throw new IllegalValueException(MESSAGE_DUPLICATE_MODULE);
}
addressBook.addModule(module);
}
return addressBook;
}

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/seedu/address/storage/StorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,17 @@ public Optional<ReadOnlyAddressBook> readAddressBook() throws DataLoadingExcepti
@Override
public Optional<ReadOnlyAddressBook> readAddressBook(Path filePath) throws DataLoadingException {
logger.fine("Attempting to read data from file: " + filePath);
return addressBookStorage.readAddressBook(filePath);
Optional<ReadOnlyAddressBook> addressBookOptional = addressBookStorage.readAddressBook(filePath);

addressBookOptional.ifPresent(addressBook -> {
addressBook.getModuleList().forEach(moduleCode -> {
if (!addressBook.hasModule(moduleCode)) {
addressBook.addModule(moduleCode);
}
});
});

return addressBookOptional;
}

@Override
Expand Down
Loading

0 comments on commit 204ddd5

Please sign in to comment.