Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1718S2#82 from CS2103JAN2018-F14-B2/F…
Browse files Browse the repository at this point in the history
…ixedStorageIssues_28032018

Fixed Storage and Tagging Issues
  • Loading branch information
Aquarinte authored Mar 28, 2018
2 parents 047462c + 1ae8b65 commit db6baf8
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public String toString() {
return "number of persons " + data.getPersonList().size()
+ ", number of tags " + data.getTagList().size()
+ ", number of appointments " + data.getAppointmentList().size()
+ ", number of pet patients " + data.getPetPatientList().size()
+ ", number of pet patient tags " + data.getPetPatientTagList().size();
+ ", number of pet patients " + data.getPetPatientList().size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public AddCommand createNewOwnerPetAppt(String ownerInfo, String petInfo, String
public AddCommand createNewApptforExistingOwnerAndPet(String apptInfo, String ownerNric, String petName)
throws ParseException {
Appointment appt = parseAppointment(apptInfo);
return new AddCommand(appt, new Nric(ownerNric), new PetPatientName(petName));
return new AddCommand(appt, new Nric(ownerNric.trim()), new PetPatientName(petName.trim()));
}

/**
Expand Down
52 changes: 9 additions & 43 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public class AddressBook implements ReadOnlyAddressBook {
private final UniquePersonList persons;
private final UniqueTagList tags;
private final UniqueAppointmentList appointments;
private final UniqueTagList appointmentTags;
private final UniquePetPatientList petPatients;
private final UniqueTagList petPatientTags;

/*
* The 'unusual' code block below is an non-static initialization block, sometimes used to avoid duplication
Expand All @@ -47,9 +45,7 @@ public class AddressBook implements ReadOnlyAddressBook {
persons = new UniquePersonList();
tags = new UniqueTagList();
appointments = new UniqueAppointmentList();
appointmentTags = new UniqueTagList();
petPatients = new UniquePetPatientList();
petPatientTags = new UniqueTagList();
}

public AddressBook() {
Expand Down Expand Up @@ -77,18 +73,10 @@ public void setAppointments(List<Appointment> appointments) throws DuplicateAppo
this.appointments.setAppointments(appointments);
}

public void setAppointmentTags(Set<Tag> appointmentTags) {
this.appointmentTags.setTags(appointmentTags);
}

public void setPetPatients(List<PetPatient> petPatients) throws DuplicatePetPatientException {
this.petPatients.setPetPatients(petPatients);
}

public void setPetPatientTags(Set<Tag> petPatientTags) {
this.petPatientTags.setTags(petPatientTags);
}

/**
* Resets the existing data of this {@code AddressBook} with {@code newData}.
*/
Expand All @@ -105,7 +93,7 @@ public void resetData(ReadOnlyAddressBook newData) {
throw new AssertionError("AddressBooks should not have duplicate persons");
}

setAppointmentTags(new HashSet<>(newData.getAppointmentTagList()));
setTags(new HashSet<>(newData.getTagList()));
List<Appointment> syncedAppointmentList = newData.getAppointmentList().stream()
.map(this::syncWithAppointmentMasterTagList)
.collect(Collectors.toList());
Expand All @@ -115,7 +103,7 @@ public void resetData(ReadOnlyAddressBook newData) {
throw new AssertionError("AddressBook should not have appointments on the same slot");
}

setPetPatientTags(new HashSet<>(newData.getPetPatientTagList()));
setTags(new HashSet<>(newData.getTagList()));
List<PetPatient> syncedPetPatientList = newData.getPetPatientList().stream()
.map(this::syncWithMasterTagList)
.collect(Collectors.toList());
Expand Down Expand Up @@ -225,7 +213,7 @@ private Person syncWithMasterTagList(Person person) {
*/
private PetPatient syncWithMasterTagList (PetPatient petPatient) {
final UniqueTagList currentPetPatientTags = new UniqueTagList(petPatient.getTags());
petPatientTags.mergeFrom(currentPetPatientTags);
tags.mergeFrom(currentPetPatientTags);

// Create map with values = tag object references in the master list
// used for checking person tag references
Expand Down Expand Up @@ -287,8 +275,8 @@ public boolean removePerson(Person key) throws PersonNotFoundException {

/**
* Adds a pet patient to the address book.
* Also checks the new pet patient's tags and updates {@link #petPatientTags} with any new tags found,
* and updates the Tag objects in the pet patient to point to those in {@link #petPatientTags}.
* Also checks the new pet patient's tags and updates {@link #tags} with any new tags found,
* and updates the Tag objects in the pet patient to point to those in {@link #tags}.
*
* @throws DuplicatePetPatientException if an equivalent person already exists.
*/
Expand All @@ -303,14 +291,6 @@ public void addTag(Tag t) throws UniqueTagList.DuplicateTagException {
tags.add(t);
}

public void addPetPatientTag(Tag t) throws UniqueTagList.DuplicateTagException {
petPatientTags.add(t);
}

public void addAppointmentTag(Tag t) throws UniqueTagList.DuplicateTagException {
appointmentTags.add(t);
}

/**
* Removes {@code tag} from {@code person} with that tag this {@code AddressBook}.
*
Expand Down Expand Up @@ -355,11 +335,9 @@ public void removeTag(Tag tag) {
@Override
public String toString() {
return persons.asObservableList().size() + " persons, "
+ tags.asObservableList().size() + " tags, "
+ appointments.asObservableList().size() + " appointments, "
+ appointmentTags.asObservableList().size() + " appointment tags, "
+ petPatients.asObservableList().size() + " pet patients, "
+ petPatientTags.asObservableList().size() + " pet patient tags";
+ appointments.asObservableList().size() + " appointments, "
+ tags.asObservableList().size() + " tags";
// TODO: refine later
}

Expand All @@ -378,36 +356,24 @@ public ObservableList<Appointment> getAppointmentList() {
return appointments.asObservableList();
}

@Override
public ObservableList<Tag> getAppointmentTagList() {
return appointmentTags.asObservableList();
}

@Override
public ObservableList<PetPatient> getPetPatientList() {
return petPatients.asObservableList();
}

@Override
public ObservableList<Tag> getPetPatientTagList() {
return petPatientTags.asObservableList();
}

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

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(persons, tags, appointments, appointmentTags, petPatients, petPatientTags);
return Objects.hash(persons, appointments, petPatients, tags);
}
}
14 changes: 0 additions & 14 deletions src/main/java/seedu/address/model/ReadOnlyAddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,10 @@ public interface ReadOnlyAddressBook {
*/
ObservableList<Appointment> getAppointmentList();

/**
* Returns an unmodifiable view of the appointment tag list.
* This list will not contain any duplicate appointment tags.
*/
ObservableList<Tag> getAppointmentTagList();

/**
* Returns an unmodifiable view of the pet patient list.
* This list will not contain any duplicate pet patients.
*/
ObservableList<PetPatient> getPetPatientList();

/**
* Returns an unmodifiable view of the pet patient tags list.
* This list will not contain any duplicate pet patient tags.
*/
ObservableList<Tag> getPetPatientTagList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class XmlSerializableAddressBook {
private List<XmlAdaptedAppointment> appointments;
@XmlElement
private List<XmlAdaptedPetPatient> petPatients;
@XmlElement
private List<XmlAdaptedTag> petPatientTags;

/**
* Creates an empty XmlSerializableAddressBook.
Expand All @@ -37,7 +35,6 @@ public XmlSerializableAddressBook() {
tags = new ArrayList<>();
appointments = new ArrayList<>();
petPatients = new ArrayList<>();
petPatientTags = new ArrayList<>();
}

/**
Expand All @@ -53,8 +50,6 @@ public XmlSerializableAddressBook(ReadOnlyAddressBook src) {
.collect(Collectors.toList()));
petPatients.addAll(src.getPetPatientList().stream().map(XmlAdaptedPetPatient::new)
.collect(Collectors.toList()));
petPatientTags.addAll(src.getPetPatientTagList().stream().map(XmlAdaptedTag::new)
.collect(Collectors.toList()));
}

/**
Expand All @@ -77,9 +72,6 @@ public AddressBook toModelType() throws IllegalValueException {
for (XmlAdaptedPetPatient pp : petPatients) {
addressBook.addPetPatient(pp.toModelType());
}
for (XmlAdaptedTag pt : petPatientTags) {
addressBook.addPetPatientTag(pt.toModelType());
}
return addressBook;
}

Expand All @@ -97,7 +89,6 @@ public boolean equals(Object other) {
return persons.equals(otherAb.persons)
&& tags.equals(otherAb.tags)
&& appointments.equals(otherAb.appointments)
&& petPatients.equals(otherAb.petPatients)
&& petPatientTags.equals(otherAb.petPatientTags);
&& petPatients.equals(otherAb.petPatients);
}
}
11 changes: 0 additions & 11 deletions src/test/java/seedu/address/model/AddressBookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void constructor() {
assertEquals(Collections.emptyList(), addressBook.getPersonList());
assertEquals(Collections.emptyList(), addressBook.getTagList());
assertEquals(Collections.emptyList(), addressBook.getAppointmentList());
assertEquals(Collections.emptyList(), addressBook.getAppointmentTagList());
}

@Test
Expand Down Expand Up @@ -142,20 +141,10 @@ public ObservableList<Appointment> getAppointmentList() {
return appointments;
}

@Override
public ObservableList<Tag> getAppointmentTagList() {
return appointmentTags;
}

@Override
public ObservableList<PetPatient> getPetPatientList() {
return petPatients;
}

@Override
public ObservableList<Tag> getPetPatientTagList() {
return petPatientTags;
}
}

}
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/testutil/TypicalPetPatients.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TypicalPetPatients {
.withColour("Brown and White")
.withBloodType("O")
.withOwnerNric(TypicalPersons.BOB.getNric().toString())
.withTags("Injured").build();
.withTags(new String[]{}).build();

public static final PetPatient JEWEL = new PetPatientBuilder()
.withName("Jewel")
Expand All @@ -23,7 +23,7 @@ public class TypicalPetPatients {
.withColour("Calico")
.withBloodType("AB")
.withOwnerNric(TypicalPersons.ALICE.getNric().toString())
.withTags(new String[]{}).build();
.withTags("Depression", "Test").build();

private TypicalPetPatients() {}
}

0 comments on commit db6baf8

Please sign in to comment.