From ccbed893e19fd4c77fc683f7a0d0e8214b8f1045 Mon Sep 17 00:00:00 2001 From: sq <19shuqi@gmail.com> Date: Sun, 2 Jul 2017 00:20:13 +0800 Subject: [PATCH 1/2] created Taggging class --- src/seedu/addressbook/data/AddressBook.java | 26 ++++++++++++++++ src/seedu/addressbook/data/person/Person.java | 1 + src/seedu/addressbook/data/tag/Tagging.java | 30 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/seedu/addressbook/data/tag/Tagging.java diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index a99a92f9f..38b41f52f 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -1,5 +1,6 @@ package seedu.addressbook.data; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -11,6 +12,7 @@ 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.Tagging; import seedu.addressbook.data.tag.UniqueTagList; /** @@ -24,6 +26,7 @@ public class AddressBook { private final UniquePersonList allPersons; private final UniqueTagList allTags; // can contain tags not attached to any person + private ArrayList allTagging; /** * Creates an empty address book. @@ -31,6 +34,7 @@ public class AddressBook { public AddressBook() { allPersons = new UniquePersonList(); allTags = new UniqueTagList(); + allTagging = new ArrayList(); } /** @@ -70,6 +74,26 @@ private void syncTagsWithMasterList(Person person) { } person.setTags(new UniqueTagList(commonTagReferences)); } + /** + * Ensures that every tag in this person is included in main Tagging List as added Tags + * @param person + */ + private void updateAddedTags(Person person) { + String add = "+"; + final UniqueTagList personTags = person.getTags(); + Set tagList= personTags.toSet(); + for ( Tag tag: tagList ) { + allTagging.add( new Tagging(tag, add, person) ); + } + } + private void updateDeletedTags(ReadOnlyPerson person) { + String delete = "-"; + final UniqueTagList personTags = person.getTags(); + Set tagList= personTags.toSet(); + for ( Tag tag: tagList ) { + allTagging.add( new Tagging(tag, delete, person) ); + } + } /** * Adds a person to the address book. @@ -81,6 +105,7 @@ private void syncTagsWithMasterList(Person person) { public void addPerson(Person toAdd) throws DuplicatePersonException { allPersons.add(toAdd); syncTagsWithMasterList(toAdd); + updateAddedTags(toAdd); } /** @@ -96,6 +121,7 @@ public boolean containsPerson(ReadOnlyPerson key) { * @throws PersonNotFoundException if no such Person could be found. */ public void removePerson(ReadOnlyPerson toRemove) throws PersonNotFoundException { + updateDeletedTags(toRemove); allPersons.remove(toRemove); } diff --git a/src/seedu/addressbook/data/person/Person.java b/src/seedu/addressbook/data/person/Person.java index 86561474e..e281c2e02 100644 --- a/src/seedu/addressbook/data/person/Person.java +++ b/src/seedu/addressbook/data/person/Person.java @@ -25,6 +25,7 @@ public Person(Name name, Phone phone, Email email, Address address, UniqueTagLis this.email = email; this.address = address; this.tags = new UniqueTagList(tags); // protect internal tags from changes in the arg list + } /** diff --git a/src/seedu/addressbook/data/tag/Tagging.java b/src/seedu/addressbook/data/tag/Tagging.java new file mode 100644 index 000000000..09598244b --- /dev/null +++ b/src/seedu/addressbook/data/tag/Tagging.java @@ -0,0 +1,30 @@ +package seedu.addressbook.data.tag; + +import seedu.addressbook.data.person.Person; +import seedu.addressbook.data.person.ReadOnlyPerson; + +public class Tagging { + private Tag tag; + private String action; + private ReadOnlyPerson person; + private String personName; + + public Tagging(Tag tag, String action, ReadOnlyPerson person2) { + this.tag = tag; + this.action = action; + this.person = person2; + this.personName = this.person.getName().fullName; + } + + public ReadOnlyPerson getPerson() { + return this.person; + } + public String getPersonName() { + return personName; + } + + public String toString() { + return action +" "+personName+" "+tag.toString(); + } + +} From d8850eb39006d774ce86b1ef5312eb114beb8847 Mon Sep 17 00:00:00 2001 From: sq <19shuqi@gmail.com> Date: Mon, 3 Jul 2017 12:56:01 +0800 Subject: [PATCH 2/2] Added Tagging class --- .../addressbook/commands/ExitCommand.java | 18 ++++++++++ src/seedu/addressbook/data/AddressBook.java | 35 ++++++++++--------- src/seedu/addressbook/data/tag/Tagging.java | 7 ++++ 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/seedu/addressbook/commands/ExitCommand.java b/src/seedu/addressbook/commands/ExitCommand.java index 2f280395c..60a5f24d8 100644 --- a/src/seedu/addressbook/commands/ExitCommand.java +++ b/src/seedu/addressbook/commands/ExitCommand.java @@ -1,5 +1,12 @@ package seedu.addressbook.commands; +import java.util.ArrayList; +import java.util.List; + +import seedu.addressbook.data.AddressBook; +import seedu.addressbook.data.person.ReadOnlyPerson; +import seedu.addressbook.data.tag.Tagging; + /** * Terminates the program. */ @@ -13,10 +20,21 @@ public class ExitCommand extends Command { @Override public CommandResult execute() { + printTagging(); return new CommandResult(MESSAGE_EXIT_ACKNOWEDGEMENT); } public static boolean isExit(Command command) { return command instanceof ExitCommand; // instanceof returns false if it is null } + + /** + * Print list of tags added or deleted each person + */ + public void printTagging() { + ArrayList allTagging = addressBook.getAllTagging(); + for ( Tagging tagging : allTagging) { + System.out.println(tagging.toString()); + } + } } diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index 38b41f52f..1be04f8c1 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -75,25 +75,22 @@ private void syncTagsWithMasterList(Person person) { person.setTags(new UniqueTagList(commonTagReferences)); } /** - * Ensures that every tag in this person is included in main Tagging List as added Tags + * Update Tags added for each person + * @param tag * @param person */ - private void updateAddedTags(Person person) { - String add = "+"; - final UniqueTagList personTags = person.getTags(); - Set tagList= personTags.toSet(); - for ( Tag tag: tagList ) { - allTagging.add( new Tagging(tag, add, person) ); - } + private void updateAddedTags (Tag tag, ReadOnlyPerson person) { + allTagging.add(new Tagging(tag, "+", person)); } - private void updateDeletedTags(ReadOnlyPerson person) { - String delete = "-"; - final UniqueTagList personTags = person.getTags(); - Set tagList= personTags.toSet(); - for ( Tag tag: tagList ) { - allTagging.add( new Tagging(tag, delete, person) ); - } + /** + * Update Tags deleted for each person + * @param tag + * @param person + */ + private void updateDeletedTags (Tag tag, ReadOnlyPerson person) { + allTagging.add(new Tagging(tag, "-", person)); } + /** * Adds a person to the address book. @@ -105,7 +102,6 @@ private void updateDeletedTags(ReadOnlyPerson person) { public void addPerson(Person toAdd) throws DuplicatePersonException { allPersons.add(toAdd); syncTagsWithMasterList(toAdd); - updateAddedTags(toAdd); } /** @@ -121,7 +117,6 @@ public boolean containsPerson(ReadOnlyPerson key) { * @throws PersonNotFoundException if no such Person could be found. */ public void removePerson(ReadOnlyPerson toRemove) throws PersonNotFoundException { - updateDeletedTags(toRemove); allPersons.remove(toRemove); } @@ -146,6 +141,12 @@ public UniquePersonList getAllPersons() { public UniqueTagList getAllTags() { return new UniqueTagList(allTags); } + /** + * Returns a new ArrayList of all Tagging in the address book at the time if the call + */ + public ArrayList getAllTagging() { + return new ArrayList(allTagging); + } @Override public boolean equals(Object other) { diff --git a/src/seedu/addressbook/data/tag/Tagging.java b/src/seedu/addressbook/data/tag/Tagging.java index 09598244b..670232929 100644 --- a/src/seedu/addressbook/data/tag/Tagging.java +++ b/src/seedu/addressbook/data/tag/Tagging.java @@ -3,6 +3,11 @@ import seedu.addressbook.data.person.Person; import seedu.addressbook.data.person.ReadOnlyPerson; +/** + * Association class representing an addition/deletion of Tags for the person + * @author shuqi + * + */ public class Tagging { private Tag tag; private String action; @@ -19,6 +24,8 @@ public Tagging(Tag tag, String action, ReadOnlyPerson person2) { public ReadOnlyPerson getPerson() { return this.person; } + + // get Name of person that Tags was added/deleted public String getPersonName() { return personName; }