Skip to content

Commit

Permalink
Merge branch 'AY2324S2-CS2103T-T13-2:master' into branch-userguide
Browse files Browse the repository at this point in the history
  • Loading branch information
SherwynNg authored Apr 15, 2024
2 parents 3d32fe8 + 21e8fed commit 26bad3e
Show file tree
Hide file tree
Showing 42 changed files with 936 additions and 204 deletions.
6 changes: 3 additions & 3 deletions docs/tutorials/TracingCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Recall from the User Guide that the `edit` command has the format: `edit INDEX [
try {
//We can deduce that the previous line of code modifies model in some way
// since it's being stored here.
storage.saveAddressBook(model.getAddressBook());
storage.saveInternBook(model.getAddressBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
Expand Down Expand Up @@ -226,10 +226,10 @@ Recall from the User Guide that the `edit` command has the format: `edit INDEX [

<box type="tip" seamless>

**Intellij Tip:** When trying to step into a statement such as `storage.saveAddressBook(model.getAddressBook())` which contains multiple method calls, Intellij will let you choose (by clicking) which one you want to step into.
**Intellij Tip:** When trying to step into a statement such as `storage.saveInternBook(model.getAddressBook())` which contains multiple method calls, Intellij will let you choose (by clicking) which one you want to step into.
</box>

1. As you step through the code inside the `Storage` component, you will eventually arrive at the `JsonAddressBook#saveAddressBook()` method which calls the `JsonSerializableAddressBook` constructor, to create an object that can be _serialized_ (i.e., stored in storage medium) in JSON format. That constructor is given below (with added line breaks for easier readability):
1. As you step through the code inside the `Storage` component, you will eventually arrive at the `JsonAddressBook#saveInternBook()` method which calls the `JsonSerializableAddressBook` constructor, to create an object that can be _serialized_ (i.e., stored in storage medium) in JSON format. That constructor is given below (with added line breaks for easier readability):

**`JsonSerializableAddressBook` constructor:**
```java
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.UserPrefs;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.storage.AddressBookStorage;
import seedu.address.storage.JsonAddressBookStorage;
import seedu.address.storage.InternBookStorage;
import seedu.address.storage.JsonInternBookStorage;
import seedu.address.storage.JsonUserPrefsStorage;
import seedu.address.storage.Storage;
import seedu.address.storage.StorageManager;
Expand Down Expand Up @@ -57,8 +57,8 @@ public void init() throws Exception {

UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath());
UserPrefs userPrefs = initPrefs(userPrefsStorage);
AddressBookStorage addressBookStorage = new JsonAddressBookStorage(userPrefs.getAddressBookFilePath());
storage = new StorageManager(addressBookStorage, userPrefsStorage);
InternBookStorage internBookStorage = new JsonInternBookStorage(userPrefs.getAddressBookFilePath());
storage = new StorageManager(internBookStorage, userPrefsStorage);

model = initModelManager(storage, userPrefs);

Expand All @@ -73,19 +73,19 @@ public void init() throws Exception {
* or an empty address book will be used instead if errors occur when reading {@code storage}'s address book.
*/
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
logger.info("Using data file : " + storage.getAddressBookFilePath());
logger.info("Using data file : " + storage.getInternBookFilePath());

Optional<ReadOnlyInternBook> addressBookOptional;
ReadOnlyInternBook initialData;
try {
addressBookOptional = storage.readAddressBook();
addressBookOptional = storage.readInternBook();
if (!addressBookOptional.isPresent()) {
logger.info("Creating a new data file " + storage.getAddressBookFilePath()
logger.info("Creating a new data file " + storage.getInternBookFilePath()
+ " populated with a sample AddressBook.");
}
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
} catch (DataLoadingException e) {
logger.warning("Data file at " + storage.getAddressBookFilePath() + " could not be loaded."
logger.warning("Data file at " + storage.getInternBookFilePath() + " could not be loaded."
+ " Will be starting with an empty AddressBook.");
initialData = new InternBook();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface Logic {
/**
* Returns the AddressBook.
*
* @see seedu.address.model.Model#getAddressBook()
* @see seedu.address.model.Model#getInternBook()
*/
ReadOnlyInternBook getAddressBook();

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
commandResult = command.execute(model);

try {
storage.saveAddressBook(model.getAddressBook());
storage.saveInternBook(model.getInternBook());
} catch (AccessDeniedException e) {
throw new CommandException(String.format(FILE_OPS_PERMISSION_ERROR_FORMAT, e.getMessage()), e);
} catch (IOException ioe) {
Expand All @@ -64,7 +64,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE

@Override
public ReadOnlyInternBook getAddressBook() {
return model.getAddressBook();
return model.getInternBook();
}

@Override
Expand All @@ -79,7 +79,7 @@ public ObservableList<Company> getFilteredCompaniesRemindersList() {

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
return model.getInternBookFilePath();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ClearCommand extends Command {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.setAddressBook(new InternBook());
model.setInternBook(new InternBook());
return new CommandResult(MESSAGE_SUCCESS);
}
}
26 changes: 13 additions & 13 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,45 +51,45 @@ public interface Model {
boolean getReminderStatus();

/**
* Returns the user prefs' address book file path.
* Returns the user prefs' intern book file path.
*/
Path getAddressBookFilePath();
Path getInternBookFilePath();

/**
* Sets the user prefs' address book file path.
* Sets the user prefs' intern book file path.
*/
void setAddressBookFilePath(Path addressBookFilePath);
void setInternBookFilePath(Path internBookFilePath);

/**
* Replaces address book data with the data in {@code addressBook}.
* Replaces intern book data with the data in {@code internBook}.
*/
void setAddressBook(ReadOnlyInternBook addressBook);
void setInternBook(ReadOnlyInternBook internBook);

/** Returns the AddressBook */
ReadOnlyInternBook getAddressBook();
/** Returns the InternBook */
ReadOnlyInternBook getInternBook();

/**
* Returns true if a company with the same identity as {@code company} exists in the address book.
* Returns true if a company with the same identity as {@code company} exists in the intern book.
*/
boolean hasCompany(Company company);

/**
* Deletes the given company.
* The company must exist in the address book.
* The company must exist in the intern book.
*/
void deleteCompany(Company target);

/**
* Adds the given company.
* {@code company} must not already exist in the address book.
* {@code company} must not already exist in the intern book.
*/
void addCompany(Company company);

/**
* Replaces the given company {@code target} with {@code editedCompany}.
* {@code target} must exist in the address book.
* {@code target} must exist in the intern book.
* The company identity of {@code editedCompany} must not be the same as another existing company
* in the address book.
* in the intern book.
*/
void setCompany(Company target, Company editedCompany);

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,25 @@ public void setGuiSettings(GuiSettings guiSettings) {
}

@Override
public Path getAddressBookFilePath() {
public Path getInternBookFilePath() {
return userPrefs.getAddressBookFilePath();
}

@Override
public void setAddressBookFilePath(Path addressBookFilePath) {
requireNonNull(addressBookFilePath);
userPrefs.setAddressBookFilePath(addressBookFilePath);
public void setInternBookFilePath(Path internBookFilePath) {
requireNonNull(internBookFilePath);
userPrefs.setAddressBookFilePath(internBookFilePath);
}

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

@Override
public void setAddressBook(ReadOnlyInternBook addressBook) {
this.internBook.resetData(addressBook);
public void setInternBook(ReadOnlyInternBook internBook) {
this.internBook.resetData(internBook);
}

@Override
public ReadOnlyInternBook getAddressBook() {
public ReadOnlyInternBook getInternBook() {
return internBook;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/company/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Phone(String phone) {
/**
* Constructs a {@code Phone}.
*/
public Phone() {
private Phone() {
value = null;
}

Expand Down Expand Up @@ -87,6 +87,6 @@ public int hashCode() {
}

public boolean isPhonePresent() {
return !(this == DEFAULT_PHONE);
return !(this.equals(DEFAULT_PHONE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@
/**
* Represents a storage for {@link InternBook}.
*/
public interface AddressBookStorage {
public interface InternBookStorage {

/**
* Returns the file path of the data file.
*/
Path getAddressBookFilePath();
Path getInternBookFilePath();

/**
* Returns AddressBook data as a {@link ReadOnlyInternBook}.
* Returns InternBook data as a {@link ReadOnlyInternBook}.
* Returns {@code Optional.empty()} if storage file is not found.
*
* @throws DataLoadingException if loading the data from storage failed.
*/
Optional<ReadOnlyInternBook> readAddressBook() throws DataLoadingException;
Optional<ReadOnlyInternBook> readInternBook() throws DataLoadingException;

/**
* @see #getAddressBookFilePath()
* @see #getInternBookFilePath()
*/
Optional<ReadOnlyInternBook> readAddressBook(Path filePath) throws DataLoadingException;
Optional<ReadOnlyInternBook> readInternBook(Path filePath) throws DataLoadingException;

/**
* Saves the given {@link ReadOnlyInternBook} to the storage.
* @param addressBook cannot be null.
* @param internBook cannot be null.
* @throws IOException if there was any problem writing to the file.
*/
void saveAddressBook(ReadOnlyInternBook addressBook) throws IOException;
void saveInternBook(ReadOnlyInternBook internBook) throws IOException;

/**
* @see #saveAddressBook(ReadOnlyInternBook)
* @see #saveInternBook(ReadOnlyInternBook)
*/
void saveAddressBook(ReadOnlyInternBook addressBook, Path filePath) throws IOException;
void saveInternBook(ReadOnlyInternBook addressBook, Path filePath) throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@
/**
* A class to access AddressBook data stored as a json file on the hard disk.
*/
public class JsonAddressBookStorage implements AddressBookStorage {
public class JsonInternBookStorage implements InternBookStorage {

private static final Logger logger = LogsCenter.getLogger(JsonAddressBookStorage.class);
private static final Logger logger = LogsCenter.getLogger(JsonInternBookStorage.class);

private Path filePath;

public JsonAddressBookStorage(Path filePath) {
public JsonInternBookStorage(Path filePath) {
this.filePath = filePath;
}

public Path getAddressBookFilePath() {
public Path getInternBookFilePath() {
return filePath;
}

@Override
public Optional<ReadOnlyInternBook> readAddressBook() throws DataLoadingException {
return readAddressBook(filePath);
public Optional<ReadOnlyInternBook> readInternBook() throws DataLoadingException {
return readInternBook(filePath);
}

/**
* Similar to {@link #readAddressBook()}.
* Similar to {@link #readInternBook()}.
*
* @param filePath location of the data. Cannot be null.
* @throws DataLoadingException if loading the data from storage failed.
*/
public Optional<ReadOnlyInternBook> readAddressBook(Path filePath) throws DataLoadingException {
public Optional<ReadOnlyInternBook> readInternBook(Path filePath) throws DataLoadingException {
requireNonNull(filePath);

Optional<JsonSerializableInternBook> jsonAddressBook = JsonUtil.readJsonFile(
Expand All @@ -60,16 +60,16 @@ public Optional<ReadOnlyInternBook> readAddressBook(Path filePath) throws DataLo
}

@Override
public void saveAddressBook(ReadOnlyInternBook addressBook) throws IOException {
saveAddressBook(addressBook, filePath);
public void saveInternBook(ReadOnlyInternBook internBook) throws IOException {
saveInternBook(internBook, filePath);
}

/**
* Similar to {@link #saveAddressBook(ReadOnlyInternBook)}.
* Similar to {@link #saveInternBook(ReadOnlyInternBook)}.
*
* @param filePath location of the data. Cannot be null.
*/
public void saveAddressBook(ReadOnlyInternBook addressBook, Path filePath) throws IOException {
public void saveInternBook(ReadOnlyInternBook addressBook, Path filePath) throws IOException {
requireNonNull(addressBook);
requireNonNull(filePath);

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/storage/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* API of the Storage component
*/
public interface Storage extends AddressBookStorage, UserPrefsStorage {
public interface Storage extends InternBookStorage, UserPrefsStorage {

@Override
Optional<UserPrefs> readUserPrefs() throws DataLoadingException;
Expand All @@ -21,12 +21,12 @@ public interface Storage extends AddressBookStorage, UserPrefsStorage {
void saveUserPrefs(ReadOnlyUserPrefs userPrefs) throws IOException;

@Override
Path getAddressBookFilePath();
Path getInternBookFilePath();

@Override
Optional<ReadOnlyInternBook> readAddressBook() throws DataLoadingException;
Optional<ReadOnlyInternBook> readInternBook() throws DataLoadingException;

@Override
void saveAddressBook(ReadOnlyInternBook addressBook) throws IOException;
void saveInternBook(ReadOnlyInternBook internBook) throws IOException;

}
Loading

0 comments on commit 26bad3e

Please sign in to comment.