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][T15-B3] Jason Manson-Hing #952

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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ test/localrun.bat
# Gradle build files
.gradle/
build/

*.DS_Store
8 changes: 8 additions & 0 deletions src/seedu/addressbook/commands/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package seedu.addressbook.commands;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import seedu.addressbook.data.AddressBook;
import seedu.addressbook.data.Tagging;
import seedu.addressbook.data.exception.IllegalValueException;
import seedu.addressbook.data.person.Address;
import seedu.addressbook.data.person.Email;
Expand Down Expand Up @@ -67,6 +70,11 @@ public ReadOnlyPerson getPerson() {
public CommandResult execute() {
try {
addressBook.addPerson(toAdd);
if (toAdd.getTags() != null) {
for (Tag tag : toAdd.getTags()) {
AddressBook.addSessionsTaggingEvent(new Tagging(toAdd, tag, Tagging.OperationType.ADDITION));
}
}
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
} catch (UniquePersonList.DuplicatePersonException dpe) {
return new CommandResult(MESSAGE_DUPLICATE_PERSON);
Expand Down
10 changes: 9 additions & 1 deletion src/seedu/addressbook/commands/ExitCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package seedu.addressbook.commands;

import seedu.addressbook.data.Tagging;

import java.util.ArrayList;

/**
* Terminates the program.
*/
Expand All @@ -13,7 +17,11 @@ public class ExitCommand extends Command {

@Override
public CommandResult execute() {
return new CommandResult(MESSAGE_EXIT_ACKNOWEDGEMENT);
StringBuilder sessionTaggings = new StringBuilder();
for (Tagging taggingEvent : addressBook.getSessionsTaggings()) {
sessionTaggings.append(taggingEvent.toString()).append("\n");
}
return new CommandResult(sessionTaggings + MESSAGE_EXIT_ACKNOWEDGEMENT);
}

public static boolean isExit(Command command) {
Expand Down
18 changes: 18 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 @@ -22,6 +23,7 @@
*/
public class AddressBook {

private static ArrayList<Tagging> sessionTaggings; // list of tagging actions performed in a session
private final UniquePersonList allPersons;
private final UniqueTagList allTags; // can contain tags not attached to any person

Expand All @@ -31,6 +33,7 @@ public class AddressBook {
public AddressBook() {
allPersons = new UniquePersonList();
allTags = new UniqueTagList();
sessionTaggings = new ArrayList<>();
}

/**
Expand All @@ -43,6 +46,7 @@ public AddressBook() {
public AddressBook(UniquePersonList persons, UniqueTagList tags) {
this.allPersons = new UniquePersonList(persons);
this.allTags = new UniqueTagList(tags);
this.sessionTaggings = new ArrayList<>();
for (Person p : allPersons) {
syncTagsWithMasterList(p);
}
Expand Down Expand Up @@ -121,6 +125,20 @@ public UniqueTagList getAllTags() {
return new UniqueTagList(allTags);
}

/**
* Returns an ArrayList of all tagging events triggered in the session at the time of the call.
*/
public ArrayList<Tagging> getSessionsTaggings() {
return this.sessionTaggings;
}

/**
* Adds a tagging event triggered in the session to the session tagging list.
*/
public static void addSessionsTaggingEvent(Tagging tagInfo) {
sessionTaggings.add(tagInfo);
}

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

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

public class Tagging {

public enum OperationType {
ADDITION, DELETION
}

private final Person person;
private final Tag tag;
private final OperationType operationType;

public Tagging(Person person, Tag tag, OperationType operationType) {
this.person = person;
this.tag = tag;
this.operationType = operationType;
}

@Override
public String toString() {
final String operationSymbol = (operationType == OperationType.ADDITION ? "+ " : "- ");
return operationSymbol + person.getName().toString() + " [" + tag.tagName + "]";
}
}
6 changes: 6 additions & 0 deletions test/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@
|| 0 persons listed!
|| ===================================================
|| Enter command: || [Command entered: exit]
|| + Betsy Choo [secretive]
|| + Charlie Dickson [school]
|| + Charlie Dickson [friends]
|| + Dickson Ee [friends]
|| + Esther Potato [tubers]
|| + Esther Potato [starchy]
|| Exiting Address Book as requested ...
|| ===================================================
|| Good bye!
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ then
fi

# compile the code into the bin folder
javac -cp ../src -Xlint:none -d ../bin ../src/seedu/addressbook/Main.java
javac -cp ../src -Xlint:none -d ../bin --add-modules java.xml.bind ../src/seedu/addressbook/Main.java

# run the program, feed commands from input.txt file and redirect the output to the actual.txt
java -classpath ../bin seedu.addressbook.Main < input.txt > actual.txt
java -classpath ../bin --add-modules java.xml.bind seedu.addressbook.Main < input.txt > actual.txt

# compare the output to the expected output
diff actual.txt expected.txt
Expand Down