forked from se-edu/addressbook-level2
-
Notifications
You must be signed in to change notification settings - Fork 104
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
[W5.6][T16-2] Perry Wang Zhiming #191
Open
perrythewang
wants to merge
9
commits into
nusCS2113-AY1819S1:master
Choose a base branch
from
perrythewang:W5.6
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b7dbf84
Applied encapsulation to feedbackToUser class property: changed varia…
perrywzm 5dbe3a0
All instances of accessing private property feedbackToUser of class C…
perrywzm 227398c
Added FindByTag command class to find persons who contain a specified…
perrywzm 8ea5653
Added FindByTag command parsing to input Parser class
perrywzm ffcb8f8
Fixed javadocs for FindByTagCommand
perrywzm 71033a0
Added FindByTag listing to the HelpCommand
perrywzm 6569295
Fixed FindByTagCommand message usage
perrywzm 878cb26
Added JUnit and I/O test cases
perrywzm d4a912d
Added Contact superclass for Address, Email & Phone subclass to inherit
perrywzm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package seedu.addressbook.commands; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import seedu.addressbook.data.person.ReadOnlyPerson; | ||
import seedu.addressbook.data.tag.Tag; | ||
|
||
/** | ||
* Finds and lists all persons in address book who contains the specified tag. | ||
* Keyword matching is not case sensitive. | ||
*/ | ||
public class FindByTagCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "findbytag"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons who contain the " | ||
+ "specified tag (non-case-sensitive) and displays them as a list with index numbers.\n" | ||
+ "Parameters: TAG\n" | ||
+ "Example: " + COMMAND_WORD + " friends"; | ||
|
||
private final String tag; | ||
|
||
public FindByTagCommand(String tag) { | ||
this.tag = tag.trim(); | ||
} | ||
|
||
/** | ||
* Returns the tag to find in this command. | ||
*/ | ||
public String getTag() { | ||
return tag; | ||
} | ||
|
||
@Override | ||
public CommandResult execute() { | ||
final List<ReadOnlyPerson> personsFound = getPersonsWithNameContainingTag(tag); | ||
return new CommandResult(getMessageForPersonListShownSummary(personsFound), personsFound); | ||
} | ||
|
||
/** | ||
* Retrieves all persons in the address book who contain the specified tag. | ||
* | ||
* @param tag for searching | ||
* @return list of persons found | ||
*/ | ||
private List<ReadOnlyPerson> getPersonsWithNameContainingTag(String tag) { | ||
final List<ReadOnlyPerson> matchedPersons = new ArrayList<>(); | ||
for (ReadOnlyPerson person : addressBook.getAllPersons()) { | ||
for (Tag t : person.getTags()) { | ||
if (t.tagName.toLowerCase().equals(tag.toLowerCase())) { | ||
matchedPersons.add(person); | ||
break; | ||
} | ||
} | ||
} | ||
return matchedPersons; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package seedu.addressbook.data.person; | ||
|
||
/** | ||
* Represents a Person's contact | ||
*/ | ||
public class Contact { | ||
public String value; | ||
private boolean isPrivate; | ||
|
||
protected Contact() {} | ||
|
||
public boolean isPrivate() { | ||
return isPrivate; | ||
} | ||
|
||
public void setPrivate(boolean isPrivate) { | ||
this.isPrivate = isPrivate; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,23 +6,20 @@ | |
* Represents a Person's email in the address book. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidEmail(String)} | ||
*/ | ||
public class Email { | ||
public class Email extends Contact { | ||
|
||
public static final String EXAMPLE = "[email protected]"; | ||
public static final String MESSAGE_EMAIL_CONSTRAINTS = | ||
"Person emails should be 2 alphanumeric/period strings separated by '@'"; | ||
public static final String EMAIL_VALIDATION_REGEX = "[\\w\\.]+@[\\w\\.]+"; | ||
|
||
public final String value; | ||
private boolean isPrivate; | ||
|
||
/** | ||
* Validates given email. | ||
* | ||
* @throws IllegalValueException if given email address string is invalid. | ||
*/ | ||
public Email(String email, boolean isPrivate) throws IllegalValueException { | ||
this.isPrivate = isPrivate; | ||
this.setPrivate(isPrivate); | ||
String trimmedEmail = email.trim(); | ||
if (!isValidEmail(trimmedEmail)) { | ||
throw new IllegalValueException(MESSAGE_EMAIL_CONSTRAINTS); | ||
|
@@ -37,25 +34,10 @@ public static boolean isValidEmail(String test) { | |
return test.matches(EMAIL_VALIDATION_REGEX); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof Email // instanceof handles nulls | ||
&& this.value.equals(((Email) other).value)); // state check | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
|
||
|
||
public boolean isPrivate() { | ||
return isPrivate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ | |
|| find: Finds all persons whose names contain any of the specified keywords (case-sensitive) and displays them as a list with index numbers. | ||
|| Parameters: KEYWORD [MORE_KEYWORDS]... | ||
|| Example: find alice bob charlie | ||
|| findbytag: Finds all persons who contain the specified tag (non-case-sensitive) and displays them as a list with index numbers. | ||
|| Parameters: TAG | ||
|| Example: findbytag friends | ||
|| list: Displays all persons in the address book as a list with index numbers. | ||
|| Example: list | ||
|| view: Views the non-private details of the person identified by the index number in the last shown person listing. | ||
|
@@ -233,6 +236,34 @@ | |
|| | ||
|| 2 persons listed! | ||
|| =================================================== | ||
|| Enter command: || [Command entered: findbytag] | ||
|| Invalid command format! | ||
|| findbytag: Finds all persons who contain the specified tag (non-case-sensitive) and displays them as a list with index numbers. | ||
|| Parameters: TAG | ||
|| Example: findbytag friends | ||
|| =================================================== | ||
|| Enter command: || [Command entered: findbytag friends] | ||
|| 1. Charlie Dickson Email: [email protected] Address: 333, gamma street Tags: [school][friends] | ||
|| 2. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] | ||
|| | ||
|| 2 persons listed! | ||
|| =================================================== | ||
|| Enter command: || [Command entered: findbytag FRIENDS] | ||
|| 1. Charlie Dickson Email: [email protected] Address: 333, gamma street Tags: [school][friends] | ||
|| 2. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] | ||
|| | ||
|| 2 persons listed! | ||
|| =================================================== | ||
|| Enter command: || [Command entered: findbytag nobodyhasthistag] | ||
|| | ||
|| 0 persons listed! | ||
|| =================================================== | ||
|| Enter command: || [Command entered: find Charlie Betsy] | ||
|| 1. Betsy Choo Tags: [secretive] | ||
|| 2. Charlie Dickson Email: [email protected] Address: 333, gamma street Tags: [school][friends] | ||
|| | ||
|| 2 persons listed! | ||
|| =================================================== | ||
|| Enter command: || [Command entered: delete] | ||
|| Invalid command format! | ||
|| delete: Deletes the person identified by the index number used in the last person listing. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
equals()
is overriden,hashCode()
also has to be overridden. you may find out why.