Skip to content

Commit

Permalink
[#169] Addressbook::addTag() is not used (#179)
Browse files Browse the repository at this point in the history
Let's remove the following methods that are no longer used, 
including other related code that are made redundant by 
their removal.
* Addressbook#addTag()
* Addressbook#containsTag()
* Addressbook#removeTag()
* UniqueTagList#add()
* UniqueTagList#remove()
  • Loading branch information
damithc authored Feb 20, 2017
2 parents 7492790 + a6cc952 commit 4f5b987
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 147 deletions.
41 changes: 0 additions & 41 deletions src/seedu/addressbook/data/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import seedu.addressbook.data.person.UniquePersonList.PersonNotFoundException;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.data.tag.UniqueTagList;
import seedu.addressbook.data.tag.UniqueTagList.DuplicateTagException;
import seedu.addressbook.data.tag.UniqueTagList.TagNotFoundException;

/**
* Represents the entire address book. Contains the data of the address book.
Expand Down Expand Up @@ -85,29 +83,13 @@ public void addPerson(Person toAdd) throws DuplicatePersonException {
syncTagsWithMasterList(toAdd);
}

/**
* Adds a tag to the list of tags present in the address book.
*
* @throws DuplicateTagException if an equivalent tag already exists.
*/
public void addTag(Tag toAdd) throws DuplicateTagException {
allTags.add(toAdd);
}

/**
* Returns true if an equivalent person exists in the address book.
*/
public boolean containsPerson(ReadOnlyPerson key) {
return allPersons.contains(key);
}

/**
* Returns true if an equivalent person exists in the address book.
*/
public boolean containsTag(Tag key) {
return allTags.contains(key);
}

/**
* Removes the equivalent person from the address book.
*
Expand All @@ -117,29 +99,6 @@ public void removePerson(ReadOnlyPerson toRemove) throws PersonNotFoundException
allPersons.remove(toRemove);
}

/**
* Removes the equivalent Tag from the address book.
* The Tag will also be removed from any Person in the address book who has that tag.
*
* @throws TagNotFoundException if no such Tag could be found.
*/
public void removeTag(Tag toRemove) throws TagNotFoundException {
removeTagFromAllPersons(toRemove);
allTags.remove(toRemove);
}

private void removeTagFromAllPersons(Tag toRemove) throws TagNotFoundException {
for (Person person : allPersons) {
UniqueTagList personTagList = person.getTags();

if (personTagList.contains(toRemove)) {
personTagList.remove(toRemove);
}

person.setTags(personTagList);
}
}

/**
* Clears all persons and tags from the address book.
*/
Expand Down
30 changes: 0 additions & 30 deletions src/seedu/addressbook/data/tag/UniqueTagList.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ protected DuplicateTagException() {
}
}

/**
* Signals that an operation targeting a specified Tag in the list would fail because
* there is no such matching Tag in the list.
*/
public static class TagNotFoundException extends Exception {}

private final List<Tag> internalList = new ArrayList<>();

/**
Expand Down Expand Up @@ -93,18 +87,6 @@ public boolean contains(Tag toCheck) {
return internalList.contains(toCheck);
}

/**
* Adds a Tag to the list.
*
* @throws DuplicateTagException if the Tag to add is a duplicate of an existing Tag in the list.
*/
public void add(Tag toAdd) throws DuplicateTagException {
if (contains(toAdd)) {
throw new DuplicateTagException();
}
internalList.add(toAdd);
}

/**
* Adds all the given tags to this list.
*
Expand All @@ -129,18 +111,6 @@ public void mergeFrom(UniqueTagList tags) {
}
}

/**
* Removes the equivalent Tag from the list.
*
* @throws TagNotFoundException if no such Tag could be found in the list.
*/
public void remove(Tag toRemove) throws TagNotFoundException {
final boolean tagFoundAndDeleted = internalList.remove(toRemove);
if (!tagFoundAndDeleted) {
throw new TagNotFoundException();
}
}

/**
* Clears all tags in list.
*/
Expand Down
79 changes: 3 additions & 76 deletions test/java/seedu/addressbook/data/AddressBookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import seedu.addressbook.data.person.UniquePersonList.PersonNotFoundException;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.data.tag.UniqueTagList;
import seedu.addressbook.data.tag.UniqueTagList.DuplicateTagException;
import seedu.addressbook.data.tag.UniqueTagList.TagNotFoundException;

public class AddressBookTest {
private Tag tagPrizeWinner;
Expand Down Expand Up @@ -93,12 +91,9 @@ public void addPerson_emptyAddressBook() throws Exception {

@Test
public void addPerson_someTagsNotInTagList() throws Exception {
assertFalse(defaultAddressBook.containsTag(tagEconomist));
assertFalse(defaultAddressBook.containsTag(tagPrizeWinner));
assertFalse(isTagObjectInAddressBookList(tagEconomist, defaultAddressBook));
assertFalse(isTagObjectInAddressBookList(tagPrizeWinner, defaultAddressBook));
defaultAddressBook.addPerson(davidElliot);
assertTrue(defaultAddressBook.containsTag(tagEconomist));
assertTrue(defaultAddressBook.containsTag(tagPrizeWinner));

assertTrue(isTagObjectInAddressBookList(tagEconomist, defaultAddressBook));
assertTrue(isTagObjectInAddressBookList(tagPrizeWinner, defaultAddressBook));
}
Expand All @@ -119,22 +114,7 @@ public void addPerson_personAlreadyInListButHasTagNotInList_tagNotAdded() throws
// ignore expected exception
}

assertFalse(defaultAddressBook.containsTag(tagPrizeWinner));
}

@Test
public void addTag_tagNotInList_addsNormally() throws Exception {
assertFalse(defaultAddressBook.containsTag(tagEconomist));
defaultAddressBook.addTag(tagEconomist);

UniqueTagList expectedTagsAfterAddition = new UniqueTagList(tagMathematician, tagScientist, tagEconomist);
assertTrue(isIdentical(expectedTagsAfterAddition, defaultAddressBook.getAllTags()));
}

@Test
public void addTag_tagAlreadyInList_throwsDuplicateTagException() throws Exception {
thrown.expect(DuplicateTagException.class);
defaultAddressBook.addTag(tagMathematician);
assertFalse(isTagObjectInAddressBookList(tagPrizeWinner, defaultAddressBook));
}

@Test
Expand All @@ -156,25 +136,6 @@ public void containsPerson() throws Exception {
}
}

@Test
public void containsTag() throws Exception {
UniqueTagList tagsWhichShouldBeIn = new UniqueTagList(tagMathematician, tagScientist);
UniqueTagList tagsWHichShouldNotBeIn = new UniqueTagList(tagEconomist, tagPrizeWinner);

for (Tag tagWhichShouldBeIn : tagsWhichShouldBeIn) {
assertTrue(defaultAddressBook.containsTag(tagWhichShouldBeIn));
}
for (Tag tagWhichShouldNotBeIn : tagsWHichShouldNotBeIn) {
assertFalse(defaultAddressBook.containsTag(tagWhichShouldNotBeIn));
}

UniqueTagList allTags = new UniqueTagList(tagPrizeWinner, tagScientist, tagMathematician, tagEconomist);

for (Tag tag : allTags) {
assertFalse(emptyAddressBook.containsTag(tag));
}
}

@Test
public void removePerson_personExists_removesNormally() throws Exception {
int numberOfPersonsBeforeRemoval = getSize(defaultAddressBook.getAllPersons());
Expand All @@ -193,40 +154,6 @@ public void removePerson_personNotExists_throwsPersonNotFoundException() throws
defaultAddressBook.removePerson(charlieDouglas);
}

@Test
public void removeTag_tagExistsAndUnused_removesNormally() throws Exception {
int numberOfTagsBeforeRemoval = getSize(defaultAddressBook.getAllTags());
defaultAddressBook.removeTag(tagScientist);

assertFalse(defaultAddressBook.containsTag(tagScientist));

int numberOfTagsAfterRemoval = getSize(defaultAddressBook.getAllTags());
assertTrue(numberOfTagsAfterRemoval == numberOfTagsBeforeRemoval - 1);

}

@Test
public void removeTag_tagExistsAndUsed_removesUsedTagFromPersons() throws Exception {
aliceBetsy.setTags(new UniqueTagList(tagMathematician, tagPrizeWinner));
bobChaplin.setTags(new UniqueTagList(tagEconomist));

int numberOfTagsBeforeRemoval = getSize(defaultAddressBook.getAllTags());
defaultAddressBook.removeTag(tagMathematician);

assertTrue(isIdentical(aliceBetsy.getTags(), new UniqueTagList(tagPrizeWinner)));
assertTrue(isIdentical(bobChaplin.getTags(), new UniqueTagList(tagEconomist)));
assertFalse(defaultAddressBook.containsTag(tagMathematician));

int numberOfTagsAfterRemoval = getSize(defaultAddressBook.getAllTags());
assertTrue(numberOfTagsAfterRemoval == numberOfTagsBeforeRemoval - 1);
}

@Test
public void removeTag_tagNotExists_throwsTagNotFoundException() throws Exception {
thrown.expect(TagNotFoundException.class);
defaultAddressBook.removeTag(tagEconomist);
}

@Test
public void clear() throws Exception {
defaultAddressBook.clear();
Expand Down

0 comments on commit 4f5b987

Please sign in to comment.