diff --git a/src/seedu/addressbook/commands/ExitCommand.java b/src/seedu/addressbook/commands/ExitCommand.java index 2f280395c..0ec095d0c 100644 --- a/src/seedu/addressbook/commands/ExitCommand.java +++ b/src/seedu/addressbook/commands/ExitCommand.java @@ -13,6 +13,8 @@ public class ExitCommand extends Command { @Override public CommandResult execute() { + addressBook.printTaggings(); + addressBook.clearTaggings(); return new CommandResult(MESSAGE_EXIT_ACKNOWEDGEMENT); } diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index 6a37d752d..0b4e3927f 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -4,7 +4,10 @@ import seedu.addressbook.data.person.UniquePersonList.*; import seedu.addressbook.data.tag.UniqueTagList; import seedu.addressbook.data.tag.UniqueTagList.*; +import seedu.addressbook.data.tag.Tagging; +import seedu.addressbook.data.tag.Tagging.TaggingType; import seedu.addressbook.data.tag.Tag; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -22,13 +25,14 @@ public class AddressBook { private final UniquePersonList allPersons; private final UniqueTagList allTags; // can contain tags not attached to any person - + private static ArrayList allTaggings; /** * Creates an empty address book. */ public AddressBook() { allPersons = new UniquePersonList(); allTags = new UniqueTagList(); + allTaggings = new ArrayList(); } /** @@ -89,6 +93,17 @@ public void addPerson(Person toAdd) throws DuplicatePersonException { public void addTag(Tag toAdd) throws DuplicateTagException { allTags.add(toAdd); } + + /** + * Adds a tagging to the list of taggings present in the address book + * @param person + * @param tag + * @param taggingType + */ + public void addTagging(Person person, Tag tag, TaggingType taggingType){ + Tagging toAdd = new Tagging(person, tag, taggingType); + allTaggings.add(toAdd); + } /** * Checks if an equivalent person exists in the address book. @@ -123,13 +138,29 @@ public void removeTag(Tag toRemove) throws TagNotFoundException { } /** - * Clears all persons and tags from the address book. + * Clears all persons, tags and taggings from the address book. */ public void clear() { allPersons.clear(); allTags.clear(); + allTaggings.clear(); } - + /** + * Print the list of taggings + */ + public void printTaggings(){ + for(Tagging tagging: allTaggings){ + System.out.println(tagging.toString()); + } + } + + /** + * Clear the list of taggings + */ + public void clearTaggings(){ + allTaggings.clear(); + } + /** * Defensively copied UniquePersonList of all persons in the address book at the time of the call. */ diff --git a/src/seedu/addressbook/data/tag/Tagging.java b/src/seedu/addressbook/data/tag/Tagging.java new file mode 100644 index 000000000..3da020081 --- /dev/null +++ b/src/seedu/addressbook/data/tag/Tagging.java @@ -0,0 +1,59 @@ +package seedu.addressbook.data.tag; +import seedu.addressbook.data.person.Person; +import java.util.ArrayList; +/** + * Association Class + * represent an adding or deleting of a tag + * for a specific person that happened during a specific session + * @author LiChengcheng + * + */ +public class Tagging { + public enum TaggingType {ADD, DELETE}; + + private Person _person; + private Tag _tag; + private TaggingType _taggingType; + + public static final String ADD_TAGGING_EXPRESSION = "+"; + public static final String DELETE_TAGGING_EXPRESSION = "-"; + + public Tagging(Person person, Tag tag, TaggingType taggingType){ + _person = person; + _tag = tag; + _taggingType = taggingType; + } + + /** + * @return the _person + */ + public Person get_person() { + return _person; + } + + /** + * @return the _tag + */ + public Tag get_tag() { + return _tag; + } + + /** + * @return the _taggingType + */ + public TaggingType get_taggingType() { + return _taggingType; + } + + private String getTypeExpression(){ + if(this.get_taggingType().equals(TaggingType.ADD)){ + return ADD_TAGGING_EXPRESSION; + } + return DELETE_TAGGING_EXPRESSION; + } + + public String toString(){ + return this.getTypeExpression()+ " " + this.get_person().getName() + " " + + this.get_tag(); + } +}