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][W13-B1] Alicia Ho Sor Sian #960

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
16 changes: 16 additions & 0 deletions src/seedu/addressbook/data/AddressBook.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.addressbook.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -24,13 +25,15 @@ public class AddressBook {

private final UniquePersonList allPersons;
private final UniqueTagList allTags; // can contain tags not attached to any person
private final ArrayList<Tagging> allTaggings;

/**
* Creates an empty address book.
*/
public AddressBook() {
allPersons = new UniquePersonList();
allTags = new UniqueTagList();
allTaggings= new ArrayList<>();
}

/**
Expand All @@ -46,6 +49,7 @@ public AddressBook(UniquePersonList persons, UniqueTagList tags) {
for (Person p : allPersons) {
syncTagsWithMasterList(p);
}
allTaggings = new ArrayList<>();
}

/**
Expand Down Expand Up @@ -121,6 +125,18 @@ public UniqueTagList getAllTags() {
return new UniqueTagList(allTags);
}

/**
* Returns message containing all Tagging messages in current session of AddressBook.
*/
public String getAllTaggings() {
StringBuilder builder = new StringBuilder();
for(Tagging t: allTaggings) {
builder.append(t.getTaggingMessage());
builder.append("\n");
}
return builder.toString().trim();
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
Expand Down
42 changes: 42 additions & 0 deletions src/seedu/addressbook/data/Tagging.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package seedu.addressbook.data;

import seedu.addressbook.data.exception.IllegalValueException;
import seedu.addressbook.data.person.Person;
import seedu.addressbook.data.tag.Tag;

/**
* Represents the adding or deleting a Tag to a Person.
*/
public class Tagging {
private static final String DELETE_SYMBOL = "-";
private static final String ADD_SYMBOL = "+";
private static final String MESSAGE_CONSTRAINTS = "Action Executed message can only be \"delete\" or \"add\".";
private static final String DELETE_ACTION = "delete";
private static final String ADD_ACTION = "add";


public final Person person;
public final Tag tag;
public final String actionTaken;

public Tagging (Person person, Tag tag, String actionExecuted) throws IllegalValueException {
this.person = person;
this.tag = tag;
if (actionExecuted.equals(DELETE_ACTION)) {
actionTaken = DELETE_SYMBOL;
}
else if (actionExecuted.equals(ADD_ACTION)) {
actionTaken = ADD_SYMBOL;
}
else {
throw new IllegalValueException(MESSAGE_CONSTRAINTS);
}
}

/**
* Returns Tagging message.
*/
public String getTaggingMessage () {
return actionTaken + " " + person.getName().toString() + " " + tag.toString();
}
}