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 a99a92f9f..1be04f8c1 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,23 @@ private void syncTagsWithMasterList(Person person) { } person.setTags(new UniqueTagList(commonTagReferences)); } + /** + * Update Tags added for each person + * @param tag + * @param person + */ + private void updateAddedTags (Tag tag, ReadOnlyPerson person) { + allTagging.add(new Tagging(tag, "+", 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. @@ -120,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/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..670232929 --- /dev/null +++ b/src/seedu/addressbook/data/tag/Tagging.java @@ -0,0 +1,37 @@ +package seedu.addressbook.data.tag; + +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; + 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; + } + + // get Name of person that Tags was added/deleted + public String getPersonName() { + return personName; + } + + public String toString() { + return action +" "+personName+" "+tag.toString(); + } + +}