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

[T4A2][T01-3] Teo Shu Qi #119

Open
wants to merge 2 commits 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
18 changes: 18 additions & 0 deletions src/seedu/addressbook/commands/ExitCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package seedu.addressbook.commands;

import java.util.ArrayList;
import java.util.List;

import seedu.addressbook.data.AddressBook;
import seedu.addressbook.data.person.ReadOnlyPerson;
import seedu.addressbook.data.tag.Tagging;

/**
* Terminates the program.
*/
Expand All @@ -13,10 +20,21 @@ public class ExitCommand extends Command {

@Override
public CommandResult execute() {
printTagging();
return new CommandResult(MESSAGE_EXIT_ACKNOWEDGEMENT);
}

public static boolean isExit(Command command) {
return command instanceof ExitCommand; // instanceof returns false if it is null
}

/**
* Print list of tags added or deleted each person

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prints

*/
public void printTagging() {
ArrayList<Tagging> allTagging = addressBook.getAllTagging();
for ( Tagging tagging : allTagging) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pay attention to the whitespace

System.out.println(tagging.toString());
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job for writing this method.

}
27 changes: 27 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 @@ -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,13 +26,15 @@ public class AddressBook {

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job for creating the Tagging list here.


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

/**
Expand Down Expand Up @@ -70,6 +74,23 @@ private void syncTagsWithMasterList(Person person) {
}
person.setTags(new UniqueTagList(commonTagReferences));
}
/**
* Update Tags added for each person
* @param tag
* @param person

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better write a short description for each @param

*/
private void updateAddedTags (Tag tag, ReadOnlyPerson person) {
allTagging.add(new Tagging(tag, "+", person));
}
/**
* Update Tags deleted for each person
* @param tag
* @param person
*/
private void updateDeletedTags (Tag tag, ReadOnlyPerson person) {
allTagging.add(new Tagging(tag, "-", person));
}


/**
* Adds a person to the address book.
Expand Down Expand Up @@ -120,6 +141,12 @@ public UniquePersonList getAllPersons() {
public UniqueTagList getAllTags() {
return new UniqueTagList(allTags);
}
/**
* Returns a new ArrayList of all Tagging in the address book at the time if the call

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns latest tagging list or something similar to that is suffice alrady.

*/
public ArrayList<Tagging> getAllTagging() {
return new ArrayList<Tagging>(allTagging);
}

@Override
public boolean equals(Object other) {
Expand Down
1 change: 1 addition & 0 deletions src/seedu/addressbook/data/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public Person(Name name, Phone phone, Email email, Address address, UniqueTagLis
this.email = email;
this.address = address;
this.tags = new UniqueTagList(tags); // protect internal tags from changes in the arg list

}

/**
Expand Down
37 changes: 37 additions & 0 deletions src/seedu/addressbook/data/tag/Tagging.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package seedu.addressbook.data.tag;

import seedu.addressbook.data.person.Person;
import seedu.addressbook.data.person.ReadOnlyPerson;

/**
* Association class representing an addition/deletion of Tags for the person

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more precise description is Represents an adding or removing a Tag to/from a Person.

* @author shuqi
*
*/
public class Tagging {
private Tag tag;
private String action;
private ReadOnlyPerson person;
private String personName;

public Tagging(Tag tag, String action, ReadOnlyPerson person2) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is person2? you better use person

this.tag = tag;
this.action = action;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better create different method for adding/removing a tag.

this.person = person2;
this.personName = this.person.getName().fullName;
}

public ReadOnlyPerson getPerson() {
return this.person;
}

// get Name of person that Tags was added/deleted
public String getPersonName() {
return personName;
}

public String toString() {
return action +" "+personName+" "+tag.toString();
}

}