diff --git a/docs/Diagrams.pptx b/docs/Diagrams.pptx index ccecb39ad..bcacbc41b 100644 Binary files a/docs/Diagrams.pptx and b/docs/Diagrams.pptx differ diff --git a/docs/LearningOutcomes.adoc b/docs/LearningOutcomes.adoc index f97d0b502..627b294e4 100644 --- a/docs/LearningOutcomes.adoc +++ b/docs/LearningOutcomes.adoc @@ -150,7 +150,7 @@ e.g. `Main.VERSION`, `Name.EXAMPLE`, `Utils.isAnyNull(...)` * Convert the `Parser::parseCommand(...)` method (i.e. the `parseCommand()` method of the `Parser` class) to a class-level method. Note how this method can be either class-level or instance-level. -* Note how the `setTags` method of the `Person` class cannot be converted to a class-level method. +* Note how some instance-level methods, such as the `setTags` method of the `Person` class, cannot be converted to a class-level method. * Add an instance-level member `int sequenceNumber` and a class-level variable `int nextSequenceNumber` to the `Person` class. Using these two variables, ensure that each `Person` object has a unique sequence number that indicates the order in which `Person` objects were created. e.g. @@ -168,8 +168,8 @@ Note the following examples of _composition_ (filled diamond): [cols="<,<",options="header",] |================================================= |Whole |Parts -|`AddressBook` |`UniquePersonList` `UniqueTagList` -|`Person` |`Name` `Phone` `Email` `Address` +|`AddressBook` |`UniquePersonList` +|`Person` |`Name` `Phone` `Email` `Address` `Tag` |================================================= Contrast with these examples of _aggregration_ (empty diamond): @@ -178,7 +178,6 @@ Contrast with these examples of _aggregration_ (empty diamond): |============================ |Container |Contained |`UniquePersonList` |`Person` -|`UuniqueTagList` |`Tag` |============================ === References diff --git a/docs/images/TaggingClass.png b/docs/images/TaggingClass.png index c6acc1450..603b82e44 100644 Binary files a/docs/images/TaggingClass.png and b/docs/images/TaggingClass.png differ diff --git a/docs/images/TaggingsInTagging.png b/docs/images/TaggingsInTagging.png index b1460db01..31110481d 100644 Binary files a/docs/images/TaggingsInTagging.png and b/docs/images/TaggingsInTagging.png differ diff --git a/docs/images/mainClassDiagram.png b/docs/images/mainClassDiagram.png index 344408fea..eb1cbbc97 100644 Binary files a/docs/images/mainClassDiagram.png and b/docs/images/mainClassDiagram.png differ diff --git a/src/seedu/addressbook/commands/AddCommand.java b/src/seedu/addressbook/commands/AddCommand.java index 7f27791e7..ac307f1b2 100644 --- a/src/seedu/addressbook/commands/AddCommand.java +++ b/src/seedu/addressbook/commands/AddCommand.java @@ -12,7 +12,6 @@ import seedu.addressbook.data.person.ReadOnlyPerson; import seedu.addressbook.data.person.UniquePersonList; import seedu.addressbook.data.tag.Tag; -import seedu.addressbook.data.tag.UniqueTagList; /** * Adds a person to the address book. @@ -51,7 +50,7 @@ public AddCommand(String name, new Phone(phone, isPhonePrivate), new Email(email, isEmailPrivate), new Address(address, isAddressPrivate), - new UniqueTagList(tagSet) + tagSet ); } diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index a99a92f9f..537d35c89 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -1,86 +1,41 @@ package seedu.addressbook.data; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - import seedu.addressbook.data.person.Person; import seedu.addressbook.data.person.ReadOnlyPerson; import seedu.addressbook.data.person.UniquePersonList; import seedu.addressbook.data.person.UniquePersonList.DuplicatePersonException; import seedu.addressbook.data.person.UniquePersonList.PersonNotFoundException; -import seedu.addressbook.data.tag.Tag; -import seedu.addressbook.data.tag.UniqueTagList; /** * Represents the entire address book. Contains the data of the address book. - * - * Guarantees: - * - Every tag found in every person will also be found in the tag list. - * - The tags in each person point to tag objects in the master list. (== equality) */ public class AddressBook { private final UniquePersonList allPersons; - private final UniqueTagList allTags; // can contain tags not attached to any person /** * Creates an empty address book. */ public AddressBook() { allPersons = new UniquePersonList(); - allTags = new UniqueTagList(); } /** * Constructs an address book with the given data. - * Also updates the tag list with any missing tags found in any person. * * @param persons external changes to this will not affect this address book - * @param tags external changes to this will not affect this address book */ - public AddressBook(UniquePersonList persons, UniqueTagList tags) { + public AddressBook(UniquePersonList persons) { this.allPersons = new UniquePersonList(persons); - this.allTags = new UniqueTagList(tags); - for (Person p : allPersons) { - syncTagsWithMasterList(p); - } - } - - /** - * Ensures that every tag in this person: - * - exists in the master list {@link #allTags} - * - points to a Tag object in the master list - */ - private void syncTagsWithMasterList(Person person) { - final UniqueTagList personTags = person.getTags(); - allTags.mergeFrom(personTags); - - // Create map with values = tag object references in the master list - final Map masterTagObjects = new HashMap<>(); - for (Tag tag : allTags) { - masterTagObjects.put(tag, tag); - } - - // Rebuild the list of person tags using references from the master list - final Set commonTagReferences = new HashSet<>(); - for (Tag tag : personTags) { - commonTagReferences.add(masterTagObjects.get(tag)); - } - person.setTags(new UniqueTagList(commonTagReferences)); } /** * Adds a person to the address book. - * Also checks the new person's tags and updates {@link #allTags} with any new tags found, - * and updates the Tag objects in the person to point to those in {@link #allTags}. * * @throws DuplicatePersonException if an equivalent person already exists. */ public void addPerson(Person toAdd) throws DuplicatePersonException { allPersons.add(toAdd); - syncTagsWithMasterList(toAdd); } /** @@ -104,7 +59,6 @@ public void removePerson(ReadOnlyPerson toRemove) throws PersonNotFoundException */ public void clear() { allPersons.clear(); - allTags.clear(); } /** @@ -114,18 +68,10 @@ public UniquePersonList getAllPersons() { return new UniquePersonList(allPersons); } - /** - * Returns a new UniqueTagList of all tags in the address book at the time of the call. - */ - public UniqueTagList getAllTags() { - return new UniqueTagList(allTags); - } - @Override public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof AddressBook // instanceof handles nulls - && this.allPersons.equals(((AddressBook) other).allPersons) - && this.allTags.equals(((AddressBook) other).allTags)); + && this.allPersons.equals(((AddressBook) other).allPersons)); } } diff --git a/src/seedu/addressbook/data/person/Person.java b/src/seedu/addressbook/data/person/Person.java index 86561474e..64551c7fe 100644 --- a/src/seedu/addressbook/data/person/Person.java +++ b/src/seedu/addressbook/data/person/Person.java @@ -1,8 +1,10 @@ package seedu.addressbook.data.person; -import seedu.addressbook.data.tag.UniqueTagList; - +import java.util.HashSet; import java.util.Objects; +import java.util.Set; + +import seedu.addressbook.data.tag.Tag; /** * Represents a Person in the address book. @@ -15,16 +17,17 @@ public class Person implements ReadOnlyPerson { private Email email; private Address address; - private final UniqueTagList tags; + private final Set tags = new HashSet<>(); + /** * Assumption: Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, UniqueTagList tags) { + public Person(Name name, Phone phone, Email email, Address address, Set tags) { this.name = name; this.phone = phone; this.email = email; this.address = address; - this.tags = new UniqueTagList(tags); // protect internal tags from changes in the arg list + this.tags.addAll(tags); } /** @@ -55,15 +58,16 @@ public Address getAddress() { } @Override - public UniqueTagList getTags() { - return new UniqueTagList(tags); + public Set getTags() { + return new HashSet<>(tags); } /** - * Replaces this person's tags with the tags in the argument tag list. + * Replaces this person's tags with the tags in the argument tag set. */ - public void setTags(UniqueTagList replacement) { - tags.setTags(replacement); + public void setTags(Set replacement) { + tags.clear(); + tags.addAll(replacement); } @Override diff --git a/src/seedu/addressbook/data/person/ReadOnlyPerson.java b/src/seedu/addressbook/data/person/ReadOnlyPerson.java index 611e93557..1493f0a2b 100644 --- a/src/seedu/addressbook/data/person/ReadOnlyPerson.java +++ b/src/seedu/addressbook/data/person/ReadOnlyPerson.java @@ -1,7 +1,8 @@ package seedu.addressbook.data.person; +import java.util.Set; + import seedu.addressbook.data.tag.Tag; -import seedu.addressbook.data.tag.UniqueTagList; /** * A read-only immutable interface for a Person in the addressbook. @@ -15,10 +16,10 @@ public interface ReadOnlyPerson { Address getAddress(); /** - * Returns a new TagList that is a deep copy of the internal TagList, - * changes on the returned list will not affect the person's internal tags. + * Returns a new TagSet that is a deep copy of the internal TagSet, + * changes on the returned set will not affect the person's internal tags. */ - UniqueTagList getTags(); + Set getTags(); /** * Returns true if both persons have the same identity fields (name and telephone). diff --git a/src/seedu/addressbook/data/tag/UniqueTagList.java b/src/seedu/addressbook/data/tag/UniqueTagList.java deleted file mode 100644 index b3a2cf615..000000000 --- a/src/seedu/addressbook/data/tag/UniqueTagList.java +++ /dev/null @@ -1,141 +0,0 @@ -package seedu.addressbook.data.tag; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import seedu.addressbook.common.Utils; -import seedu.addressbook.data.exception.DuplicateDataException; - - -/** - * A list of tags. Does not allow nulls or duplicates. - * - * @see Tag#equals(Object) - * @see Utils#elementsAreUnique(Collection) - */ -public class UniqueTagList implements Iterable { - - /** - * Signals that an operation would have violated the 'no duplicates' property of the list. - */ - public static class DuplicateTagException extends DuplicateDataException { - protected DuplicateTagException() { - super("Operation would result in duplicate tags"); - } - } - - private final List internalList = new ArrayList<>(); - - /** - * Constructs an empty TagList. - */ - public UniqueTagList() {} - - /** - * Constructs a tag list with the given tags. - */ - public UniqueTagList(Tag... tags) throws DuplicateTagException { - final List initialTags = Arrays.asList(tags); - if (!Utils.elementsAreUnique(initialTags)) { - throw new DuplicateTagException(); - } - internalList.addAll(initialTags); - } - - /** - * Constructs a tag list with the given tags. - */ - public UniqueTagList(Collection tags) throws DuplicateTagException { - if (!Utils.elementsAreUnique(tags)) { - throw new DuplicateTagException(); - } - internalList.addAll(tags); - } - - /** - * Constructs a tag list with the given tags. - */ - public UniqueTagList(Set tags) { - internalList.addAll(tags); - } - - /** - * Constructs a shallow copy of the given tag list. - */ - public UniqueTagList(UniqueTagList source) { - internalList.addAll(source.internalList); - } - - /** - * Returns a new Set that is a deep copy of all tags in this list. - * This set is mutable and change-insulated against the internal list. - */ - public Set toSet() { - return new HashSet<>(internalList); - } - - /** - * Returns true if the list contains an equivalent Tag as the given argument. - */ - public boolean contains(Tag toCheck) { - return internalList.contains(toCheck); - } - - /** - * Adds all the given tags to this list. - * - * @throws DuplicateTagException if the argument tag list contains tag(s) that already exist in this list. - */ - public void addAll(UniqueTagList tags) throws DuplicateTagException { - if (!Collections.disjoint(this.internalList, tags.internalList)) { - throw new DuplicateTagException(); - } - this.internalList.addAll(tags.internalList); - } - - /** - * Adds every tag from the argument list that does not yet exist in this list. - */ - public void mergeFrom(UniqueTagList tags) { - final Set alreadyInside = this.toSet(); - for (Tag tag : tags) { - if (!alreadyInside.contains(tag)) { - internalList.add(tag); - } - } - } - - /** - * Clears all tags in list. - */ - public void clear() { - internalList.clear(); - } - - /** - * Replaces the Tags in this list with those in the argument tag list. - */ - public void setTags(UniqueTagList replacement) { - this.internalList.clear(); - this.internalList.addAll(replacement.internalList); - } - - @Override - public Iterator iterator() { - return internalList.iterator(); - } - - @Override - public boolean equals(Object other) { - return other == this // short circuit if same object - || (other instanceof UniqueTagList // instanceof handles nulls - && this.internalList.equals(((UniqueTagList) other).internalList)); - } - -} diff --git a/src/seedu/addressbook/storage/jaxb/AdaptedAddressBook.java b/src/seedu/addressbook/storage/jaxb/AdaptedAddressBook.java index 538ba33d8..8fcab82fb 100644 --- a/src/seedu/addressbook/storage/jaxb/AdaptedAddressBook.java +++ b/src/seedu/addressbook/storage/jaxb/AdaptedAddressBook.java @@ -2,8 +2,6 @@ import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; -import seedu.addressbook.data.tag.Tag; -import seedu.addressbook.data.tag.UniqueTagList; import seedu.addressbook.data.person.Person; import seedu.addressbook.data.person.ReadOnlyPerson; import seedu.addressbook.data.person.UniquePersonList; @@ -21,8 +19,6 @@ public class AdaptedAddressBook { @XmlElement private List persons = new ArrayList<>(); - @XmlElement - private List tags = new ArrayList<>(); /** * No-arg constructor for JAXB use. @@ -36,13 +32,9 @@ public AdaptedAddressBook() {} */ public AdaptedAddressBook(AddressBook source) { persons = new ArrayList<>(); - tags = new ArrayList<>(); for (ReadOnlyPerson person : source.getAllPersons()) { persons.add(new AdaptedPerson(person)); } - for (Tag tag : source.getAllTags()) { - tags.add(new AdaptedTag(tag)); - } } @@ -55,11 +47,6 @@ public AdaptedAddressBook(AddressBook source) { * so we check for that. */ public boolean isAnyRequiredFieldMissing() { - for (AdaptedTag tag : tags) { - if (tag.isAnyRequiredFieldMissing()) { - return true; - } - } for (AdaptedPerson person : persons) { if (person.isAnyRequiredFieldMissing()) { return true; @@ -74,14 +61,10 @@ public boolean isAnyRequiredFieldMissing() { * @throws IllegalValueException if there were any data constraints violated in the adapted person */ public AddressBook toModelType() throws IllegalValueException { - final List tagList = new ArrayList<>(); final List personList = new ArrayList<>(); - for (AdaptedTag tag : tags) { - tagList.add(tag.toModelType()); - } for (AdaptedPerson person : persons) { personList.add(person.toModelType()); } - return new AddressBook(new UniquePersonList(personList), new UniqueTagList(tagList)); + return new AddressBook(new UniquePersonList(personList)); } } diff --git a/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java b/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java index 62808638a..4ade0ccbf 100644 --- a/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java +++ b/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java @@ -1,7 +1,9 @@ package seedu.addressbook.storage.jaxb; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; @@ -16,7 +18,6 @@ import seedu.addressbook.data.person.Phone; import seedu.addressbook.data.person.ReadOnlyPerson; import seedu.addressbook.data.tag.Tag; -import seedu.addressbook.data.tag.UniqueTagList; /** * JAXB-friendly adapted person data holder class. @@ -99,7 +100,7 @@ public boolean isAnyRequiredFieldMissing() { * @throws IllegalValueException if there were any data constraints violated in the adapted person */ public Person toModelType() throws IllegalValueException { - final List personTags = new ArrayList<>(); + final Set personTags = new HashSet<>(); for (AdaptedTag tag : tagged) { personTags.add(tag.toModelType()); } @@ -107,7 +108,6 @@ public Person toModelType() throws IllegalValueException { final Phone phone = new Phone(this.phone.value, this.phone.isPrivate); final Email email = new Email(this.email.value, this.email.isPrivate); final Address address = new Address(this.address.value, this.address.isPrivate); - final UniqueTagList tags = new UniqueTagList(personTags); - return new Person(name, phone, email, address, tags); + return new Person(name, phone, email, address, personTags); } } diff --git a/test/data/StorageFileTest/ValidData.xml b/test/data/StorageFileTest/ValidData.xml index 968fccfdc..fc6b00df6 100644 --- a/test/data/StorageFileTest/ValidData.xml +++ b/test/data/StorageFileTest/ValidData.xml @@ -14,6 +14,4 @@ friend criminal - friend - criminal diff --git a/test/java/seedu/addressbook/commands/AddCommandTest.java b/test/java/seedu/addressbook/commands/AddCommandTest.java index fd870a62e..461017710 100644 --- a/test/java/seedu/addressbook/commands/AddCommandTest.java +++ b/test/java/seedu/addressbook/commands/AddCommandTest.java @@ -26,14 +26,14 @@ public class AddCommandTest { private static final List EMPTY_PERSON_LIST = Collections.emptyList(); - private static final Set EMPTY_STRING_LIST = Collections.emptySet(); + private static final Set EMPTY_STRING_SET = Collections.emptySet(); @Test public void addCommand_invalidName_throwsException() { final String[] invalidNames = { "", " ", "[]\\[;]" }; for (String name : invalidNames) { assertConstructingInvalidAddCmdThrowsException(name, Phone.EXAMPLE, true, Email.EXAMPLE, false, - Address.EXAMPLE, true, EMPTY_STRING_LIST); + Address.EXAMPLE, true, EMPTY_STRING_SET); } } @@ -42,7 +42,7 @@ public void addCommand_invalidPhone_throwsException() { final String[] invalidNumbers = { "", " ", "1234-5678", "[]\\[;]", "abc", "a123", "+651234" }; for (String number : invalidNumbers) { assertConstructingInvalidAddCmdThrowsException(Name.EXAMPLE, number, false, Email.EXAMPLE, true, - Address.EXAMPLE, false, EMPTY_STRING_LIST); + Address.EXAMPLE, false, EMPTY_STRING_SET); } } @@ -52,7 +52,7 @@ public void addCommand_invalidEmail_throwsException() { "@invalid@email", "invalid@email!", "!invalid@email" }; for (String email : invalidEmails) { assertConstructingInvalidAddCmdThrowsException(Name.EXAMPLE, Phone.EXAMPLE, false, email, false, - Address.EXAMPLE, false, EMPTY_STRING_LIST); + Address.EXAMPLE, false, EMPTY_STRING_SET); } } @@ -61,7 +61,7 @@ public void addCommand_invalidAddress_throwsException() { final String[] invalidAddresses = { "", " " }; for (String address : invalidAddresses) { assertConstructingInvalidAddCmdThrowsException(Name.EXAMPLE, Phone.EXAMPLE, true, Email.EXAMPLE, - true, address, true, EMPTY_STRING_LIST); + true, address, true, EMPTY_STRING_SET); } } @@ -98,7 +98,7 @@ private void assertConstructingInvalidAddCmdThrowsException(String name, String @Test public void addCommand_validData_correctlyConstructed() throws Exception { AddCommand command = new AddCommand(Name.EXAMPLE, Phone.EXAMPLE, true, Email.EXAMPLE, false, - Address.EXAMPLE, true, EMPTY_STRING_LIST); + Address.EXAMPLE, true, EMPTY_STRING_SET); ReadOnlyPerson p = command.getPerson(); // TODO: add comparison of tags to person.equals and equality methods to diff --git a/test/java/seedu/addressbook/commands/DeleteCommandTest.java b/test/java/seedu/addressbook/commands/DeleteCommandTest.java index 0e5ab80d9..02a77b0c2 100644 --- a/test/java/seedu/addressbook/commands/DeleteCommandTest.java +++ b/test/java/seedu/addressbook/commands/DeleteCommandTest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertEquals; +import java.util.Collections; import java.util.List; import org.junit.Before; @@ -17,7 +18,6 @@ import seedu.addressbook.data.person.Phone; import seedu.addressbook.data.person.ReadOnlyPerson; import seedu.addressbook.data.person.UniquePersonList.PersonNotFoundException; -import seedu.addressbook.data.tag.UniqueTagList; import seedu.addressbook.ui.TextUi; import seedu.addressbook.util.TestUtil; @@ -33,14 +33,14 @@ public class DeleteCommandTest { @Before public void setUp() throws Exception { Person johnDoe = new Person(new Name("John Doe"), new Phone("61234567", false), - new Email("john@doe.com", false), new Address("395C Ben Road", false), new UniqueTagList()); + new Email("john@doe.com", false), new Address("395C Ben Road", false), Collections.emptySet()); Person janeDoe = new Person(new Name("Jane Doe"), new Phone("91234567", false), - new Email("jane@doe.com", false), new Address("33G Ohm Road", false), new UniqueTagList()); + new Email("jane@doe.com", false), new Address("33G Ohm Road", false), Collections.emptySet()); Person samDoe = new Person(new Name("Sam Doe"), new Phone("63345566", false), - new Email("sam@doe.com", false), new Address("55G Abc Road", false), new UniqueTagList()); + new Email("sam@doe.com", false), new Address("55G Abc Road", false), Collections.emptySet()); Person davidGrant = new Person(new Name("David Grant"), new Phone("61121122", false), new Email("david@grant.com", false), new Address("44H Define Road", false), - new UniqueTagList()); + Collections.emptySet()); emptyAddressBook = TestUtil.createAddressBook(); addressBook = TestUtil.createAddressBook(johnDoe, janeDoe, davidGrant, samDoe); @@ -65,7 +65,7 @@ public void execute_noPersonDisplayed_returnsInvalidIndexMessage() { public void execute_targetPersonNotInAddressBook_returnsPersonNotFoundMessage() throws IllegalValueException { Person notInAddressBookPerson = new Person(new Name("Not In Book"), new Phone("63331444", false), - new Email("notin@book.com", false), new Address("156D Grant Road", false), new UniqueTagList()); + new Email("notin@book.com", false), new Address("156D Grant Road", false), Collections.emptySet()); List listWithPersonNotInAddressBook = TestUtil.createList(notInAddressBookPerson); assertDeletionFailsDueToNoSuchPerson(1, addressBook, listWithPersonNotInAddressBook); diff --git a/test/java/seedu/addressbook/commands/ViewCommandTest.java b/test/java/seedu/addressbook/commands/ViewCommandTest.java index 3408463c1..f2e4d420a 100644 --- a/test/java/seedu/addressbook/commands/ViewCommandTest.java +++ b/test/java/seedu/addressbook/commands/ViewCommandTest.java @@ -18,7 +18,6 @@ import seedu.addressbook.data.person.Person; import seedu.addressbook.data.person.Phone; import seedu.addressbook.data.person.ReadOnlyPerson; -import seedu.addressbook.data.tag.UniqueTagList; import seedu.addressbook.util.TestUtil; import seedu.addressbook.util.TypicalPersons; @@ -50,7 +49,7 @@ public void execute_personNotInAddressBook_returnsPersonNotInAddressBookMessage( new Phone("123", true), new Email("some@hey.go", true), new Address("nus", false), - new UniqueTagList(Collections.emptySet())); + Collections.emptySet()); List listWithExtraPerson = new ArrayList(listWithAllTypicalPersons); listWithExtraPerson.add(stranger); diff --git a/test/java/seedu/addressbook/data/AddressBookTest.java b/test/java/seedu/addressbook/data/AddressBookTest.java index 79808d80b..193229774 100644 --- a/test/java/seedu/addressbook/data/AddressBookTest.java +++ b/test/java/seedu/addressbook/data/AddressBookTest.java @@ -6,6 +6,10 @@ import static seedu.addressbook.util.TestUtil.isEmpty; import static seedu.addressbook.util.TestUtil.isIdentical; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; + import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -20,7 +24,6 @@ import seedu.addressbook.data.person.UniquePersonList.DuplicatePersonException; import seedu.addressbook.data.person.UniquePersonList.PersonNotFoundException; import seedu.addressbook.data.tag.Tag; -import seedu.addressbook.data.tag.UniqueTagList; public class AddressBookTest { private Tag tagPrizeWinner; @@ -48,75 +51,39 @@ public void setUp() throws Exception { new Phone("91235468", false), new Email("alice@nushackers.org", false), new Address("8 Computing Drive, Singapore", false), - new UniqueTagList(tagMathematician)); + Collections.singleton(tagMathematician)); bobChaplin = new Person(new Name("Bob Chaplin"), new Phone("94321500", false), new Email("bob@nusgreyhats.org", false), new Address("9 Computing Drive", false), - new UniqueTagList(tagMathematician)); + Collections.singleton(tagMathematician)); charlieDouglas = new Person(new Name("Charlie Douglas"), new Phone("98751365", false), new Email("charlie@nusgdg.org", false), new Address("10 Science Drive", false), - new UniqueTagList(tagScientist)); + Collections.singleton(tagScientist)); davidElliot = new Person(new Name("David Elliot"), new Phone("84512575", false), new Email("douglas@nuscomputing.com", false), new Address("11 Arts Link", false), - new UniqueTagList(tagEconomist, tagPrizeWinner)); + new HashSet<>(Arrays.asList(tagEconomist, tagPrizeWinner))); emptyAddressBook = new AddressBook(); - defaultAddressBook = new AddressBook(new UniquePersonList(aliceBetsy, bobChaplin), - new UniqueTagList(tagMathematician, tagScientist)); + defaultAddressBook = new AddressBook(new UniquePersonList(aliceBetsy, bobChaplin)); } @Rule public ExpectedException thrown = ExpectedException.none(); - @Test - public void addPerson_emptyAddressBook() throws Exception { - emptyAddressBook.addPerson(bobChaplin); - emptyAddressBook.addPerson(charlieDouglas); - - UniqueTagList expectedTagList = new UniqueTagList(tagMathematician, tagScientist); - assertTrue(isIdentical(expectedTagList, emptyAddressBook.getAllTags())); - - assertTrue(isTagObjectInAddressBookList(tagMathematician, emptyAddressBook)); - assertTrue(isTagObjectInAddressBookList(tagScientist, emptyAddressBook)); - - } - - @Test - public void addPerson_someTagsNotInTagList() throws Exception { - assertFalse(isTagObjectInAddressBookList(tagEconomist, defaultAddressBook)); - assertFalse(isTagObjectInAddressBookList(tagPrizeWinner, defaultAddressBook)); - defaultAddressBook.addPerson(davidElliot); - assertTrue(isTagObjectInAddressBookList(tagEconomist, defaultAddressBook)); - assertTrue(isTagObjectInAddressBookList(tagPrizeWinner, defaultAddressBook)); - } - @Test public void addPerson_personAlreadyInList_throwsDuplicatePersonException() throws Exception { thrown.expect(DuplicatePersonException.class); defaultAddressBook.addPerson(aliceBetsy); } - @Test - public void addPerson_personAlreadyInListButHasTagNotInList_tagNotAdded() throws Exception { - aliceBetsy.setTags(new UniqueTagList(tagMathematician, tagPrizeWinner)); - - try { - defaultAddressBook.addPerson(aliceBetsy); - } catch (DuplicatePersonException e) { - // ignore expected exception - } - - assertFalse(isTagObjectInAddressBookList(tagPrizeWinner, defaultAddressBook)); - } - @Test public void containsPerson() throws Exception { UniquePersonList personsWhoShouldBeIn = new UniquePersonList(aliceBetsy, bobChaplin); @@ -155,11 +122,10 @@ public void removePerson_personNotExists_throwsPersonNotFoundException() throws } @Test - public void clear() throws Exception { + public void clear() { defaultAddressBook.clear(); assertTrue(isEmpty(defaultAddressBook.getAllPersons())); - assertTrue(isEmpty(defaultAddressBook.getAllTags())); } @Test @@ -169,24 +135,4 @@ public void getAllPersons() throws Exception { assertTrue(isIdentical(allPersons, personsToCheck)); } - - @Test - public void getAllTags() throws Exception { - UniqueTagList allTags = defaultAddressBook.getAllTags(); - UniqueTagList tagsToCheck = new UniqueTagList(tagMathematician, tagScientist); - - assertTrue(isIdentical(allTags, tagsToCheck)); - } - - /** - * Returns true if the given Tag object is found in the tag list of the given AddressBook. - */ - private boolean isTagObjectInAddressBookList(Tag tagToCheck, AddressBook addressBook) { - for (Tag tag : addressBook.getAllTags()) { - if (tag == tagToCheck) { - return true; - } - } - return false; - } } diff --git a/test/java/seedu/addressbook/parser/ParserTest.java b/test/java/seedu/addressbook/parser/ParserTest.java index 03e692997..8b7259950 100644 --- a/test/java/seedu/addressbook/parser/ParserTest.java +++ b/test/java/seedu/addressbook/parser/ParserTest.java @@ -31,7 +31,6 @@ import seedu.addressbook.data.person.Phone; import seedu.addressbook.data.person.ReadOnlyPerson; import seedu.addressbook.data.tag.Tag; -import seedu.addressbook.data.tag.UniqueTagList; public class ParserTest { @@ -276,7 +275,7 @@ private static Person generateTestPerson() { new Phone(Phone.EXAMPLE, true), new Email(Email.EXAMPLE, false), new Address(Address.EXAMPLE, true), - new UniqueTagList(new Tag("tag1"), new Tag("tag2"), new Tag("tag3")) + new HashSet<>(Arrays.asList(new Tag("tag1"), new Tag ("tag2"), new Tag("tag3"))) ); } catch (IllegalValueException ive) { throw new RuntimeException("test person data should be valid by definition"); diff --git a/test/java/seedu/addressbook/storage/StorageFileTest.java b/test/java/seedu/addressbook/storage/StorageFileTest.java index f61abdabd..73af385d6 100644 --- a/test/java/seedu/addressbook/storage/StorageFileTest.java +++ b/test/java/seedu/addressbook/storage/StorageFileTest.java @@ -3,7 +3,9 @@ import static org.junit.Assert.assertEquals; import java.nio.file.Paths; +import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import org.junit.Rule; import org.junit.Test; @@ -18,7 +20,6 @@ import seedu.addressbook.data.person.Person; import seedu.addressbook.data.person.Phone; import seedu.addressbook.data.tag.Tag; -import seedu.addressbook.data.tag.UniqueTagList; import seedu.addressbook.storage.StorageFile.StorageOperationException; import static seedu.addressbook.util.TestUtil.assertTextFilesEqual; import static seedu.addressbook.util.TestUtil.assertFileDoesNotExist; @@ -113,12 +114,12 @@ private AddressBook getTestAddressBook() throws Exception { new Phone("98765432", false), new Email("johnd@gmail.com", false), new Address("John street, block 123, #01-01", false), - new UniqueTagList(Collections.emptySet()))); + Collections.emptySet())); ab.addPerson(new Person(new Name("Betsy Crowe"), new Phone("1234567", true), new Email("betsycrowe@gmail.com", false), new Address("Newgate Prison", true), - new UniqueTagList(new Tag("friend"), new Tag("criminal")))); + new HashSet<>(Arrays.asList(new Tag("friend"), new Tag("criminal"))))); return ab; } } diff --git a/test/java/seedu/addressbook/util/TestUtil.java b/test/java/seedu/addressbook/util/TestUtil.java index 919f517f2..b286bb4bd 100644 --- a/test/java/seedu/addressbook/util/TestUtil.java +++ b/test/java/seedu/addressbook/util/TestUtil.java @@ -10,10 +10,9 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.HashSet; +import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.Set; import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; @@ -23,10 +22,7 @@ import seedu.addressbook.data.person.Person; import seedu.addressbook.data.person.Phone; import seedu.addressbook.data.person.ReadOnlyPerson; -import seedu.addressbook.data.person.UniquePersonList; import seedu.addressbook.data.person.UniquePersonList.DuplicatePersonException; -import seedu.addressbook.data.tag.Tag; -import seedu.addressbook.data.tag.UniqueTagList; public class TestUtil { /** @@ -64,7 +60,7 @@ public static List createList(Person...persons) { * of Persons and Tags. The Persons and Tags are not cloned. */ public static AddressBook clone(AddressBook addressBook) { - return new AddressBook(addressBook.getAllPersons(), addressBook.getAllTags()); + return new AddressBook(addressBook.getAllPersons()); } /** @@ -111,25 +107,13 @@ public static int getSize(Iterable it) { public static Person generateTestPerson() { try { return new Person(new Name(Name.EXAMPLE), new Phone(Phone.EXAMPLE, false), - new Email(Email.EXAMPLE, true), new Address(Address.EXAMPLE, false), new UniqueTagList()); + new Email(Email.EXAMPLE, true), new Address(Address.EXAMPLE, false), Collections.emptySet()); } catch (IllegalValueException e) { fail("test person data should be valid by definition"); return null; } } - public static UniqueTagList getAllTags(UniquePersonList persons) { - Set combinedTagList = new HashSet(); - - for (Person person : persons) { - for (Tag tag : person.getTags()) { - combinedTagList.add(tag); - } - } - - return new UniqueTagList(combinedTagList); - } - /** * Asserts whether the text in the two given files are the same. Ignores any * differences in line endings diff --git a/test/java/seedu/addressbook/util/TypicalPersons.java b/test/java/seedu/addressbook/util/TypicalPersons.java index 7c03f6fa5..cd3a3f819 100644 --- a/test/java/seedu/addressbook/util/TypicalPersons.java +++ b/test/java/seedu/addressbook/util/TypicalPersons.java @@ -1,5 +1,7 @@ package seedu.addressbook.util; +import java.util.Collections; + import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; import seedu.addressbook.data.person.Address; @@ -8,7 +10,6 @@ import seedu.addressbook.data.person.Person; import seedu.addressbook.data.person.Phone; import seedu.addressbook.data.tag.Tag; -import seedu.addressbook.data.tag.UniqueTagList; /** * Class to generate typical test persons @@ -20,13 +21,13 @@ public class TypicalPersons { public TypicalPersons() { try { amy = new Person(new Name("Amy Buck"), new Phone("91119111", false), new Email("ab@gmail.com", false), - new Address("1 Clementi Road", false), new UniqueTagList()); + new Address("1 Clementi Road", false), Collections.emptySet()); bill = new Person(new Name("Bill Clint"), new Phone("92229222", false), new Email("bc@gmail.com", false), - new Address("2 Clementi Road", true), new UniqueTagList()); + new Address("2 Clementi Road", true), Collections.emptySet()); candy = new Person(new Name("Candy Destiny"), new Phone("93339333", true), - new Email("cd@gmail.com", false), new Address("3 Clementi Road", true), new UniqueTagList()); + new Email("cd@gmail.com", false), new Address("3 Clementi Road", true), Collections.emptySet()); dan = new Person(new Name("Dan Smith"), new Phone("1234556", true), new Email("ss@tt.com", true), - new Address("NUS", true), new UniqueTagList(new Tag("Test"))); + new Address("NUS", true), Collections.singleton(new Tag("test"))); } catch (IllegalValueException e) { e.printStackTrace(); assert false : "not possible";