Skip to content

Commit

Permalink
Merge pull request #118 from Justinhoejj/master
Browse files Browse the repository at this point in the history
Implement temporary solution for bug fix.
  • Loading branch information
Justinhoejj authored Oct 28, 2021
2 parents a392b92 + 97b54b1 commit 934e164
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,35 +201,39 @@ private static boolean isAfterCurrentMonthday(Birthday birthday) {
}

private void addToBirthdayReminderList(Person personToAdd) {
if (personToAdd.getBirthday().isEmpty()) {
return;
}

int indexToInsert = -1;
MonthDay birthdayToAdd = MonthDay.from(personToAdd.getBirthday().get().birthdate);
PersonBirthdayComparator comparator = new PersonBirthdayComparator();
if (MonthDay.now().isAfter(birthdayToAdd)) {
// BirthdayToAdd has past should inserted from the end of the list
indexToInsert = birthdayReminders.size();
while (indexToInsert > 0
&& comparator.compare(personToAdd, birthdayReminders.get(indexToInsert - 1)) < 0) {
indexToInsert--;
}
}
if (!MonthDay.now().isAfter(birthdayToAdd)) {
// BirthdayToAdd has not past should inserted at the start of the list
indexToInsert = 0;
while (indexToInsert < birthdayReminders.size()
&& comparator.compare(personToAdd, birthdayReminders.get(indexToInsert)) > 0) {
indexToInsert++;
}
}
if (indexToInsert == birthdayReminders.size() && !MonthDay.now().isAfter(birthdayToAdd)) {
// BirthdayToAdd is latest in the list but has not past therefore placed at start of list
birthdayReminders.add(0, personToAdd);
} else {
birthdayReminders.add(indexToInsert, personToAdd);
}
birthdayReminders.clear();
ObservableList<Person> updatedList = generateBirthdayReminderList(this.addressBook);
birthdayReminders.addAll(updatedList);
// Buggy Implementation use brute force for now.
// if (personToAdd.getBirthday().isEmpty()) {
// return;
// }
//
// int indexToInsert = -1;
// MonthDay birthdayToAdd = MonthDay.from(personToAdd.getBirthday().get().birthdate);
// PersonBirthdayComparator comparator = new PersonBirthdayComparator();
// if (MonthDay.now().isAfter(birthdayToAdd)) {
// // BirthdayToAdd has past should inserted from the end of the list
// indexToInsert = birthdayReminders.size();
// while (indexToInsert > 0
// && comparator.compare(personToAdd, birthdayReminders.get(indexToInsert - 1)) < 0) {
// indexToInsert--;
// }
// }
// if (!MonthDay.now().isAfter(birthdayToAdd)) {
// // BirthdayToAdd has not past should inserted at the start of the list
// indexToInsert = 0;
// while (indexToInsert < birthdayReminders.size()
// && comparator.compare(personToAdd, birthdayReminders.get(indexToInsert)) > 0) {
// indexToInsert++;
// }
// }
// if (indexToInsert == birthdayReminders.size() && !MonthDay.now().isAfter(birthdayToAdd)) {
// // BirthdayToAdd is latest in the list but has not past therefore placed at start of list
// birthdayReminders.add(0, personToAdd);
// } else {
// birthdayReminders.add(indexToInsert, personToAdd);
// }
}

@Override
Expand Down

0 comments on commit 934e164

Please sign in to comment.