diff --git a/src/main/java/seedu/hireme/model/ModelManager.java b/src/main/java/seedu/hireme/model/ModelManager.java index a95e89583a9..c65efe79fcd 100644 --- a/src/main/java/seedu/hireme/model/ModelManager.java +++ b/src/main/java/seedu/hireme/model/ModelManager.java @@ -12,9 +12,10 @@ import seedu.hireme.commons.core.LogsCenter; import seedu.hireme.commons.util.CollectionUtil; - /** * Represents the in-memory model of the address book data. + * + * @param the type of elements in the AddressBook, which extends {@code HireMeComparable} */ public class ModelManager> implements Model { private static final Logger logger = LogsCenter.getLogger(ModelManager.class); @@ -24,50 +25,90 @@ public class ModelManager> implements Model { /** * Initializes a ModelManager with the given addressBook and userPrefs. + * + * @param addressBook The address book containing the application data. + * @param userPrefs The user preferences. */ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs) { CollectionUtil.requireAllNonNull(addressBook, userPrefs); - logger.fine("Initializing with address book: " + addressBook + " and user prefs " + userPrefs); + logger.info("Initializing ModelManager with AddressBook and UserPrefs"); + logger.fine("AddressBook: " + addressBook + ", UserPrefs: " + userPrefs); this.addressBook = new AddressBook<>(addressBook); this.userPrefs = new UserPrefs(userPrefs); filtered = new FilteredList<>(this.addressBook.getList()); + + logger.fine("Filtered list initialized with " + filtered.size() + " items."); } + /** + * Initializes a ModelManager with default values. + */ public ModelManager() { this(new AddressBook<>(), new UserPrefs()); + logger.info("Initialized default ModelManager"); } //=========== UserPrefs ================================================================================== + /** + * Sets the user preferences. + * + * @param userPrefs The new user preferences to be saved. + */ @Override public void setUserPrefs(ReadOnlyUserPrefs userPrefs) { requireNonNull(userPrefs); this.userPrefs.resetData(userPrefs); } + /** + * Gets the user preferences. + * + * @return the {@code ReadOnlyUserPrefs} object. + */ @Override public ReadOnlyUserPrefs getUserPrefs() { return userPrefs; } + /** + * Gets the GUI settings for the application. + * + * @return the current {@code GuiSettings}. + */ @Override public GuiSettings getGuiSettings() { return userPrefs.getGuiSettings(); } + /** + * Sets the GUI settings for the application. + * + * @param guiSettings the new {@code GuiSettings} to be saved. + */ @Override public void setGuiSettings(GuiSettings guiSettings) { requireNonNull(guiSettings); userPrefs.setGuiSettings(guiSettings); } + /** + * Gets the file path to the HireMe data file. + * + * @return the {@code Path} to the HireMe data file. + */ @Override public Path getHireMeFilePath() { return userPrefs.getHireMeFilePath(); } + /** + * Sets the file path to the HireMe data file. + * + * @param hireMeFilePath The new file path to be saved. + */ @Override public void setHireMeFilePath(Path hireMeFilePath) { requireNonNull(hireMeFilePath); @@ -76,27 +117,53 @@ public void setHireMeFilePath(Path hireMeFilePath) { //=========== AddressBook ================================================================================ + /** + * Replaces the address book data with the provided {@code ReadOnlyAddressBook}. + * + * @param addressBook the new address book data. + */ @Override public void setAddressBook(ReadOnlyAddressBook addressBook) { this.addressBook.resetData(addressBook); } + /** + * Gets the current address book. + * + * @return the current {@code ReadOnlyAddressBook}. + */ @Override public ReadOnlyAddressBook getAddressBook() { return addressBook; } + /** + * Checks if the address book contains the specified item. + * + * @param item the item to check. + * @return true if the item exists in the address book, otherwise false. + */ @Override public boolean hasItem(T item) { requireNonNull(item); return addressBook.hasItem(item); } + /** + * Deletes the specified item from the address book. + * + * @param target the item to delete. + */ @Override public void deleteItem(T target) { addressBook.removeItem(target); } + /** + * Adds a new item to the address book. + * + * @param item the item to add. + */ @Override public void addItem(T item) { addressBook.addItem(item); @@ -105,49 +172,61 @@ public void addItem(T item) { updateFilteredList(showAll); } + /** + * Replaces the specified item with the edited item in the address book. + * + * @param target the item to replace. + * @param edited the edited item. + */ @Override public void setItem(T target, T edited) { CollectionUtil.requireAllNonNull(target, edited); - addressBook.setItem(target, edited); } //=========== Filtered List Accessors ============================================================= /** - * Returns an unmodifiable view of the list of items backed by the internal list of - * {@code versionedAddressBook} + * Gets the filtered list of items. + * + * @return an unmodifiable view of the filtered list. */ @Override public ObservableList getFilteredList() { return filtered; } + /** + * Updates the predicate for the filtered list. + * + * @param predicate the new predicate to filter the list. + */ @Override public void updateFilteredList(Predicate predicate) { requireNonNull(predicate); filtered.setPredicate(predicate); } + /** + * Checks if this ModelManager is equal to another object. + * + * @param other the other object to compare with. + * @return true if both objects are equal, otherwise false. + */ @Override public boolean equals(Object other) { - // Check if the objects are the same instance if (other == this) { return true; } - // Check if the other object is an instance of ModelManager and not null if (!(other instanceof ModelManager)) { return false; } - // Cast the other object to ModelManager ModelManager otherModelManager = (ModelManager) other; - // Compare the state of addressBook, userPrefs, and filtered lists return addressBook.equals(otherModelManager.addressBook) && userPrefs.equals(otherModelManager.userPrefs) && filtered.equals(otherModelManager.filtered); } - } diff --git a/src/main/java/seedu/hireme/storage/StorageManager.java b/src/main/java/seedu/hireme/storage/StorageManager.java index d6c4936a7c6..1c3a63840be 100644 --- a/src/main/java/seedu/hireme/storage/StorageManager.java +++ b/src/main/java/seedu/hireme/storage/StorageManager.java @@ -27,53 +27,61 @@ public class StorageManager> implements Storage public StorageManager(AddressBookStorage addressBookStorage, UserPrefsStorage userPrefsStorage) { this.addressBookStorage = addressBookStorage; this.userPrefsStorage = userPrefsStorage; + logger.info("StorageManager initialized with AddressBookStorage and UserPrefsStorage."); } // ================ UserPrefs methods ============================== @Override public Path getUserPrefsFilePath() { + logger.fine("Fetching UserPrefs file path."); return userPrefsStorage.getUserPrefsFilePath(); } @Override public Optional readUserPrefs() throws DataLoadingException { + logger.info("Reading UserPrefs from storage."); return userPrefsStorage.readUserPrefs(); } @Override public void saveUserPrefs(ReadOnlyUserPrefs userPrefs) throws IOException { + logger.info("Saving UserPrefs to storage."); userPrefsStorage.saveUserPrefs(userPrefs); + logger.fine("UserPrefs saved successfully."); } - // ================ AddressBook methods ============================== @Override public Path getAddressBookFilePath() { + logger.fine("Fetching AddressBook file path."); return addressBookStorage.getAddressBookFilePath(); } @Override public Optional> readAddressBook() throws DataLoadingException { + logger.info("Reading AddressBook from default file path."); return readAddressBook(addressBookStorage.getAddressBookFilePath()); } @Override public Optional> readAddressBook(Path filePath) throws DataLoadingException { - logger.fine("Attempting to read data from file: " + filePath); + logger.info("Reading AddressBook from file: " + filePath); return addressBookStorage.readAddressBook(filePath); } @Override public void saveAddressBook(ReadOnlyAddressBook addressBook) throws IOException { + logger.info("Saving AddressBook to default file path."); saveAddressBook(addressBook, addressBookStorage.getAddressBookFilePath()); + logger.fine("AddressBook saved successfully."); } @Override public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws IOException { - logger.fine("Attempting to write to data file: " + filePath); + logger.info("Saving AddressBook to file: " + filePath); addressBookStorage.saveAddressBook(addressBook, filePath); + logger.fine("AddressBook saved successfully to file: " + filePath); } - } diff --git a/src/test/java/seedu/hireme/storage/StorageManagerTest.java b/src/test/java/seedu/hireme/storage/StorageManagerTest.java index 2ca3683ca11..4b70e036d35 100644 --- a/src/test/java/seedu/hireme/storage/StorageManagerTest.java +++ b/src/test/java/seedu/hireme/storage/StorageManagerTest.java @@ -69,4 +69,16 @@ public void getAddressBookFilePath() { assertNotNull(storageManager.getAddressBookFilePath()); } + @Test + public void getUserPrefsFilePath_correctPathReturned() { + // Setup: Ensure that the file path is not null and correct + Path expectedPath = getTempFilePath("prefs"); + + // Act: Get the UserPrefs file path from StorageManager + Path actualPath = storageManager.getUserPrefsFilePath(); + + // Assert: Verify that the path is not null and matches the expected path + assertNotNull(actualPath, "The UserPrefs file path should not be null."); + assertEquals(expectedPath, actualPath, "The UserPrefs file path should match the expected path."); + } }