Skip to content

Commit

Permalink
Remove UniqueTagList class
Browse files Browse the repository at this point in the history
Many methods in UniqueTagList, such as mergeFrom(UniqueTagList),
were previously used by only the AddressBook for the master tag list.

Since AddressBook does not use a master tag list anymore, all these
methods are no longer necessary. UniqueTagList now only serves to add
complexity to the code base.

Let's remove the UniqueTagList class, and update Person to use a Set
instead for holding its tags instead, since it can only contain unique
elements.
  • Loading branch information
yamidark committed Aug 12, 2018
1 parent 0d22fc5 commit 386ca95
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 196 deletions.
3 changes: 1 addition & 2 deletions src/seedu/addressbook/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import seedu.addressbook.data.exception.IllegalValueException;
import seedu.addressbook.data.person.*;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.data.tag.UniqueTagList;

import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -45,7 +44,7 @@ public AddCommand(String name,
new Phone(phone, isPhonePrivate),
new Email(email, isEmailPrivate),
new Address(address, isAddressPrivate),
new UniqueTagList(tagSet)
tagSet
);
}

Expand Down
23 changes: 13 additions & 10 deletions src/seedu/addressbook/data/person/Person.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,16 +17,16 @@ public class Person implements ReadOnlyPerson {
private Email email;
private Address address;

private final UniqueTagList tags;
private final Set<Tag> 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<Tag> 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);
}

/**
Expand Down Expand Up @@ -55,15 +57,16 @@ public Address getAddress() {
}

@Override
public UniqueTagList getTags() {
return new UniqueTagList(tags);
public Set<Tag> 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 {@code replacement}.
*/
public void setTags(UniqueTagList replacement) {
tags.setTags(replacement);
public void setTags(Set<Tag> replacement) {
tags.clear();
tags.addAll(replacement);
}

@Override
Expand Down
7 changes: 4 additions & 3 deletions src/seedu/addressbook/data/person/ReadOnlyPerson.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,10 +16,10 @@ public interface ReadOnlyPerson {
Address getAddress();

/**
* The returned TagList is a deep copy of the internal TagList,
* The returned {@code Set} is a deep copy of the internal {@code Set},
* changes on the returned list will not affect the person's internal tags.
*/
UniqueTagList getTags();
Set<Tag> getTags();

/**
* Returns true if the values inside this object is same as those of the other (Note: interfaces cannot override .equals)
Expand Down
167 changes: 0 additions & 167 deletions src/seedu/addressbook/data/tag/UniqueTagList.java

This file was deleted.

8 changes: 4 additions & 4 deletions src/seedu/addressbook/storage/jaxb/AdaptedPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import seedu.addressbook.data.exception.IllegalValueException;
import seedu.addressbook.data.person.*;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.data.tag.UniqueTagList;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlValue;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* JAXB-friendly adapted person data holder class.
Expand Down Expand Up @@ -93,15 +94,14 @@ public boolean isAnyRequiredFieldMissing() {
* @throws IllegalValueException if there were any data constraints violated in the adapted person
*/
public Person toModelType() throws IllegalValueException {
final List<Tag> personTags = new ArrayList<>();
final Set<Tag> tags = new HashSet<>();
for (AdaptedTag tag : tagged) {
personTags.add(tag.toModelType());
tags.add(tag.toModelType());
}
final Name name = new Name(this.name);
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);
}
}
9 changes: 4 additions & 5 deletions test/java/seedu/addressbook/logic/LogicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import seedu.addressbook.data.AddressBook;
import seedu.addressbook.data.person.*;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.data.tag.UniqueTagList;
import seedu.addressbook.storage.StorageFile;

import java.util.*;
Expand Down Expand Up @@ -469,7 +468,7 @@ Person adam() throws Exception {
Address privateAddress = new Address("111, alpha street", true);
Tag tag1 = new Tag("tag1");
Tag tag2 = new Tag("tag2");
UniqueTagList tags = new UniqueTagList(tag1, tag2);
Set<Tag> tags = new HashSet<>(Arrays.asList(tag1, tag2));
return new Person(name, privatePhone, email, privateAddress, tags);
}

Expand All @@ -487,7 +486,7 @@ Person generatePerson(int seed, boolean isAllFieldsPrivate) throws Exception {
new Phone("" + Math.abs(seed), isAllFieldsPrivate),
new Email(seed + "@email", isAllFieldsPrivate),
new Address("House of " + seed, isAllFieldsPrivate),
new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1)))
new HashSet<>(Arrays.asList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1))))
);
}

Expand All @@ -502,7 +501,7 @@ String generateAddCommand(Person p) {
cmd.add((p.getEmail().isPrivate() ? "pe/" : "e/") + p.getEmail());
cmd.add((p.getAddress().isPrivate() ? "pa/" : "a/") + p.getAddress());

UniqueTagList tags = p.getTags();
Set<Tag> tags = p.getTags();
for(Tag t: tags){
cmd.add("t/" + t.tagName);
}
Expand Down Expand Up @@ -583,7 +582,7 @@ Person generatePersonWithName(String name) throws Exception {
new Phone("1", false),
new Email("1@email", false),
new Address("House of 1", false),
new UniqueTagList(new Tag("tag"))
Collections.singleton(new Tag("tag"))
);
}
}
Expand Down
3 changes: 1 addition & 2 deletions test/java/seedu/addressbook/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import seedu.addressbook.commands.*;
import seedu.addressbook.data.exception.IllegalValueException;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.data.tag.UniqueTagList;
import seedu.addressbook.data.person.*;

import java.util.Arrays;
Expand Down Expand Up @@ -253,7 +252,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");
Expand Down
8 changes: 5 additions & 3 deletions test/java/seedu/addressbook/storage/StorageFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

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;
import org.junit.rules.ExpectedException;
Expand All @@ -16,7 +19,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;

Expand Down Expand Up @@ -98,12 +100,12 @@ private AddressBook getTestAddressBook() throws Exception {
new Phone("98765432", false),
new Email("[email protected]", 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("[email protected]", 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;
}
}

0 comments on commit 386ca95

Please sign in to comment.