From d464b19af853476726289c6508d0f84a3b4ccab6 Mon Sep 17 00:00:00 2001 From: IzHoBX Date: Wed, 14 Mar 2018 10:23:11 +0800 Subject: [PATCH] Add Tagging association class to record each tag add/remove activity --- src/seedu/addressbook/Main.java | 2 ++ src/seedu/addressbook/data/AddressBook.java | 21 +++++++++++++++ src/seedu/addressbook/data/tag/Tagging.java | 29 +++++++++++++++++++++ src/seedu/addressbook/ui/TextUi.java | 13 +++++++++ 4 files changed, 65 insertions(+) create mode 100644 src/seedu/addressbook/data/tag/Tagging.java diff --git a/src/seedu/addressbook/Main.java b/src/seedu/addressbook/Main.java index bc18bed7e..6020f3686 100644 --- a/src/seedu/addressbook/Main.java +++ b/src/seedu/addressbook/Main.java @@ -55,6 +55,7 @@ private void start(String[] launchArgs) { this.ui = new TextUi(); this.storage = initializeStorage(launchArgs); this.addressBook = storage.load(); + addressBook.init(); ui.showWelcomeMessage(VERSION, storage.getPath()); } catch (InvalidStorageFilePathException | StorageOperationException e) { @@ -74,6 +75,7 @@ private void start(String[] launchArgs) { /** Prints the Goodbye message and exits. */ private void exit() { + ui.showAllTaggings(addressBook.getTaggings()); ui.showGoodbyeMessage(); System.exit(0); } diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index a99a92f9f..953d86e4c 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -2,6 +2,7 @@ import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.Map; import java.util.Set; @@ -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 LinkedList taggings; /** * Creates an empty address book. @@ -33,6 +36,17 @@ public AddressBook() { allTags = new UniqueTagList(); } + /** + * Add the details of an add/remove tag operation to tagging + */ + public void addNewTagging(boolean isAdd, Person person, Tag tag) { + taggings.add(new Tagging(isAdd, person, tag)); + } + + public LinkedList getTaggings() { + return taggings; + } + /** * Constructs an address book with the given data. * Also updates the tag list with any missing tags found in any person. @@ -128,4 +142,11 @@ public boolean equals(Object other) { && this.allPersons.equals(((AddressBook) other).allPersons) && this.allTags.equals(((AddressBook) other).allTags)); } + + /** + * Initiate fields for runtime + */ + public void init() { + taggings = new LinkedList<>(); + } } diff --git a/src/seedu/addressbook/data/tag/Tagging.java b/src/seedu/addressbook/data/tag/Tagging.java new file mode 100644 index 000000000..a6c8815b0 --- /dev/null +++ b/src/seedu/addressbook/data/tag/Tagging.java @@ -0,0 +1,29 @@ +package seedu.addressbook.data.tag; + +import seedu.addressbook.data.person.Person; + +/** +* Association class that records each activity of adding and removing tag*/ +public class Tagging { + Tag tag; + Person person; + Boolean isAdd; + + public Tagging(Boolean isAdd, Person person, Tag tag) { + this.isAdd = isAdd; + this.tag = tag; + this.person = person; + } + + public Tag getTag() { + return tag; + } + + public boolean isAdd() { + return isAdd; + } + + public Person getPerson() { + return person; + } +} diff --git a/src/seedu/addressbook/ui/TextUi.java b/src/seedu/addressbook/ui/TextUi.java index d30371c70..667f89c06 100644 --- a/src/seedu/addressbook/ui/TextUi.java +++ b/src/seedu/addressbook/ui/TextUi.java @@ -9,12 +9,14 @@ import java.io.InputStream; import java.io.PrintStream; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.Scanner; import seedu.addressbook.commands.CommandResult; import seedu.addressbook.data.person.ReadOnlyPerson; +import seedu.addressbook.data.tag.Tagging; /** * Text UI of the application. @@ -38,6 +40,8 @@ public class TextUi { /** Format of a comment input line. Comment lines are silently consumed when reading user input. */ private static final String COMMENT_LINE_FORMAT_REGEX = "#.*"; + private static final String ADD_TAGGING_BULLET = "+"; + private static final String REMOVE_TAGGING_BULLET = "-"; private final Scanner in; private final PrintStream out; @@ -169,4 +173,13 @@ private static String getIndexedListItem(int visibleIndex, String listItem) { return String.format(MESSAGE_INDEXED_LIST_ITEM, visibleIndex, listItem); } + public void showAllTaggings(LinkedList taggings) { + for(Tagging t: taggings) { + if(t.isAdd()) + out.print(ADD_TAGGING_BULLET + " "); + else + out.print(REMOVE_TAGGING_BULLET + " "); + out.println(t.getPerson().getName().toString() + " [" + t.getTag().tagName + " ]"); + } + } }