Skip to content

Commit

Permalink
Integrate the activity model into address book
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjulianl committed Oct 3, 2021
1 parent a65588a commit 640c260
Show file tree
Hide file tree
Showing 26 changed files with 677 additions and 49 deletions.
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@

<!-- Checks that every public method (excluding getters, setters and constructors) has a header comment. -->
<module name="JavadocMethod">
<property name="allowedAnnotations" value="Override, Test, BeforeAll, BeforeEach, AfterAll, AfterEach, Subscribe"/>
<property name="allowedAnnotations" value="TempDir, Override, Test, BeforeAll, BeforeEach, AfterAll, AfterEach, Subscribe"/>
<property name="scope" value="public"/>
<property name="validateThrows" value="false"/>
<property name="allowMissingParamTags" value="true"/>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gomedic/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void init() throws Exception {

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

initLogging(config);
Expand Down
57 changes: 54 additions & 3 deletions src/main/java/gomedic/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import static java.util.Objects.requireNonNull;

import java.util.List;
import java.util.Objects;

import gomedic.model.activity.Activity;
import gomedic.model.activity.UniqueActivityList;
import gomedic.model.person.Person;
import gomedic.model.person.UniquePersonList;
import javafx.collections.ObservableList;
Expand All @@ -15,6 +18,7 @@
public class AddressBook implements ReadOnlyAddressBook {

private final UniquePersonList persons;
private final UniqueActivityList activities;

/*
* The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication
Expand All @@ -26,6 +30,7 @@ public class AddressBook implements ReadOnlyAddressBook {

{
persons = new UniquePersonList();
activities = new UniqueActivityList();
}

public AddressBook() {
Expand All @@ -49,13 +54,22 @@ public void setPersons(List<Person> persons) {
this.persons.setPersons(persons);
}

/**
* Replaces the contents of the person list with {@code activities}.
* {@code persons} must not contain duplicate and conflicting activities.
*/
public void setActivities(List<Activity> activities) {
this.activities.setActivities(activities);
}

/**
* Resets the existing data of this {@code AddressBook} with {@code newData}.
*/
public void resetData(ReadOnlyAddressBook newData) {
requireNonNull(newData);

setPersons(newData.getPersonList());
setActivities(newData.getActivityList());
}

//// person-level operations
Expand All @@ -68,6 +82,14 @@ public boolean hasPerson(Person person) {
return persons.contains(person);
}

/**
* Returns true if an activity with the same id as {@code activities} exists in the address book.
*/
public boolean hasActivity(Activity activity) {
requireNonNull(activity);
return activities.contains(activity);
}

/**
* Adds a person to the address book.
* The person must not already exist in the address book.
Expand All @@ -76,6 +98,14 @@ public void addPerson(Person p) {
persons.add(p);
}

/**
* Adds an activity to the address book.
* The activity must not be duplicate and conflicting.
*/
public void addActivity(Activity a) {
activities.add(a);
}

/**
* Replaces the given person {@code target} in the list with {@code editedPerson}.
* {@code target} must exist in the address book.
Expand All @@ -95,11 +125,21 @@ public void removePerson(Person key) {
persons.remove(key);
}

/**
* Remove the activity based on the id.
* Therefore, regardless whether the activity has different titles/fields,
* as long as the id is the same, it would be treated as equal.
*/
public void removeActivity(Activity activity) {
activities.remove(activity);
}

//// util methods

@Override
public String toString() {
return persons.asUnmodifiableObservableList().size() + " persons";
return persons.asUnmodifiableObservableList().size() + " persons; "
+ activities.asUnmodifiableObservableList().size() + " activities";
// TODO: refine later
}

Expand All @@ -108,15 +148,26 @@ public ObservableList<Person> getPersonList() {
return persons.asUnmodifiableObservableList();
}

@Override
public ObservableList<Activity> getActivityList() {
return activities.asUnmodifiableObservableList();
}

@Override
public ObservableList<Activity> getActivityListSortedStartTime() {
return activities.asUnmodifiableSortedList();
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddressBook // instanceof handles nulls
&& persons.equals(((AddressBook) other).persons));
&& persons.equals(((AddressBook) other).persons)
&& activities.equals(((AddressBook) other).activities));
}

@Override
public int hashCode() {
return persons.hashCode();
return Objects.hash(persons, activities);
}
}
4 changes: 2 additions & 2 deletions src/main/java/gomedic/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public void setGuiSettings(GuiSettings guiSettings) {

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

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

//=========== AddressBook ================================================================================
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/gomedic/model/ReadOnlyAddressBook.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gomedic.model;

import gomedic.model.activity.Activity;
import gomedic.model.person.Person;
import javafx.collections.ObservableList;

Expand All @@ -14,4 +15,15 @@ public interface ReadOnlyAddressBook {
*/
ObservableList<Person> getPersonList();

/**
* Returns an unmodifiable view of the activity list.
* Guarantee: This list will not contain any conflicting and duplicate activity.
*/
ObservableList<Activity> getActivityList();

/**
* Returns a sorted list by start time.
* Guarantee: This list will not contain any conflicting and duplicate activity.
*/
ObservableList<Activity> getActivityListSortedStartTime();
}
3 changes: 2 additions & 1 deletion src/main/java/gomedic/model/ReadOnlyUserPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface ReadOnlyUserPrefs {

GuiSettings getGuiSettings();

Path getAddressBookFilePath();
Path getAddressBookPersonFilePath();

Path getAddressBookActivityFilePath();
}
32 changes: 18 additions & 14 deletions src/main/java/gomedic/model/UserPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
*/
public class UserPrefs implements ReadOnlyUserPrefs {

private final Path addressBookActivityFilePath = Paths.get("data", "activities.json");
private Path addressBookPersonFilePath = Paths.get("data", "persons.json");
private GuiSettings guiSettings = new GuiSettings();
private Path addressBookFilePath = Paths.get("data", "addressbook.json");

/**
* Creates a {@code UserPrefs} with default values.
Expand All @@ -36,7 +37,7 @@ public UserPrefs(ReadOnlyUserPrefs userPrefs) {
public void resetData(ReadOnlyUserPrefs newUserPrefs) {
requireNonNull(newUserPrefs);
setGuiSettings(newUserPrefs.getGuiSettings());
setAddressBookFilePath(newUserPrefs.getAddressBookFilePath());
setAddressBookPersonFilePath(newUserPrefs.getAddressBookPersonFilePath());
}

public GuiSettings getGuiSettings() {
Expand All @@ -48,13 +49,19 @@ public void setGuiSettings(GuiSettings guiSettings) {
this.guiSettings = guiSettings;
}

public Path getAddressBookFilePath() {
return addressBookFilePath;
@Override
public Path getAddressBookPersonFilePath() {
return addressBookPersonFilePath;
}

public void setAddressBookFilePath(Path addressBookFilePath) {
requireNonNull(addressBookFilePath);
this.addressBookFilePath = addressBookFilePath;
public void setAddressBookPersonFilePath(Path addressBookPersonFilePath) {
requireNonNull(addressBookPersonFilePath);
this.addressBookPersonFilePath = addressBookPersonFilePath;
}

@Override
public Path getAddressBookActivityFilePath() {
return addressBookActivityFilePath;
}

@Override
Expand All @@ -69,20 +76,17 @@ public boolean equals(Object other) {
UserPrefs o = (UserPrefs) other;

return guiSettings.equals(o.guiSettings)
&& addressBookFilePath.equals(o.addressBookFilePath);
&& addressBookPersonFilePath.equals(o.addressBookPersonFilePath);
}

@Override
public int hashCode() {
return Objects.hash(guiSettings, addressBookFilePath);
return Objects.hash(guiSettings, addressBookPersonFilePath);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Gui Settings : " + guiSettings);
sb.append("\nLocal data file location : " + addressBookFilePath);
return sb.toString();
return "Gui Settings : " + guiSettings
+ "\nLocal data file location : " + addressBookPersonFilePath;
}

}
Loading

0 comments on commit 640c260

Please sign in to comment.