Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[W8.6b][W15-B1] Add Tagging association class #958

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/seedu/addressbook/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
21 changes: 21 additions & 0 deletions src/seedu/addressbook/data/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;

Expand All @@ -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;

/**
Expand All @@ -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<Tagging> taggings;

/**
* Creates an empty address book.
Expand All @@ -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<Tagging> getTaggings() {
return taggings;
}

/**
* Constructs an address book with the given data.
* Also updates the tag list with any missing tags found in any person.
Expand Down Expand Up @@ -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<>();
}
}
29 changes: 29 additions & 0 deletions src/seedu/addressbook/data/tag/Tagging.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
13 changes: 13 additions & 0 deletions src/seedu/addressbook/ui/TextUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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<Tagging> 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 + " ]");
}
}
}