Skip to content

Commit

Permalink
Merge pull request #111 from narwhalsilent/branch-fixLoanListOnStartup
Browse files Browse the repository at this point in the history
Implement defensive command access
  • Loading branch information
kjw142857 authored Apr 4, 2024
2 parents 58874f6 + 1a32dd1 commit e66deea
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void init() throws Exception {
storage = new StorageManager(addressBookStorage, userPrefsStorage);

model = initModelManager(storage, userPrefs);
model.updateFilteredLoanList(Model.PREDICATE_SHOW_NO_LOANS);

logic = new LogicManager(model, storage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public CommandResult execute(Model model) throws CommandException {

Person personToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(personToDelete);
model.setToPersonTab();
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_ACTIVE_LOANS;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_LOANS;
import static seedu.address.model.Model.PREDICATE_SHOW_NO_PERSON;
import static seedu.address.model.Model.PREDICATE_SHOW_NO_PERSONS;

import seedu.address.model.Model;

Expand All @@ -22,7 +22,7 @@ public ViewLoansCommand(boolean isShowAllLoans) {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(PREDICATE_SHOW_NO_PERSON);
model.updateFilteredPersonList(PREDICATE_SHOW_NO_PERSONS);
if (isShowAllLoans) {
model.updateFilteredLoanList(PREDICATE_SHOW_ALL_LOANS);
} else {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface Model {
/**
* {@code Predicate} that always evaluates to false
*/
Predicate<Person> PREDICATE_SHOW_NO_PERSON = unused -> false;
Predicate<Person> PREDICATE_SHOW_NO_PERSONS = unused -> false;

/**
* {@code Predicate} that always evaluate to true
Expand All @@ -38,6 +38,11 @@ public interface Model {
*/
Predicate<Loan> PREDICATE_SHOW_ALL_ACTIVE_LOANS = loan -> loan.isActive();

/**
* {@code Predicate} that always evaluates to false
*/
Predicate<Loan> PREDICATE_SHOW_NO_LOANS = unused -> false;

/**
* Replaces user prefs data with the data in {@code userPrefs}.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public void setToPersonTab() {
System.out.println("Method setToPersonTab called inside ModelManager");
this.isLoansTab.setValue(false);
this.isAnalyticsTab.setValue(false);
this.updateFilteredLoanList(PREDICATE_SHOW_NO_LOANS);
this.setIsPersonTab(true);
}

Expand All @@ -247,6 +248,8 @@ public void setIsAnalyticsTab(Boolean isAnalyticsTab) {
if (isAnalyticsTab) {
this.isLoansTab.setValue(false);
this.isPersonTab.setValue(false);
this.updateFilteredPersonList(PREDICATE_SHOW_NO_PERSONS);
this.updateFilteredLoanList(PREDICATE_SHOW_NO_LOANS);
}
this.isAnalyticsTab.setValue(isAnalyticsTab);
}
Expand Down

0 comments on commit e66deea

Please sign in to comment.