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

[T4A4][W10-A3]Li Chengcheng #1073

Open
wants to merge 7 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
15 changes: 13 additions & 2 deletions src/seedu/addressbook/data/person/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
* Represents a Person's address in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidAddress(String)}
*/
public class Address {
public class Address implements Printable{

public static final String EXAMPLE = "123, some street";
public static final String MESSAGE_ADDRESS_CONSTRAINTS = "Person addresses can be in any format";
public static final String ADDRESS_VALIDATION_REGEX = ".+";
private static final String ADDRESS_PRIVATE_STRING = "***";

public final String value;
private boolean isPrivate;
Expand Down Expand Up @@ -56,4 +57,14 @@ public int hashCode() {
public boolean isPrivate() {
return isPrivate;
}
}

@Override
public String getPrintableString() {
if(this.isPrivate()){
return "Address: " + ADDRESS_PRIVATE_STRING;
}
else {
return "Address: "+ this.toString();
}
}
}
15 changes: 13 additions & 2 deletions src/seedu/addressbook/data/person/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
* 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 implements Printable {

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\\.]+";

private static final String EMAIL_PRIVATE_STRING = "***";

public final String value;
private boolean isPrivate;

Expand Down Expand Up @@ -58,4 +59,14 @@ public int hashCode() {
public boolean isPrivate() {
return isPrivate;
}

@Override
public String getPrintableString() {
if(this.isPrivate()){
return "Email: " + EMAIL_PRIVATE_STRING;
}
else {
return "Email: "+ this.toString();
}
}
}
7 changes: 6 additions & 1 deletion src/seedu/addressbook/data/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Represents a Person's name in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidName(String)}
*/
public class Name {
public class Name implements Printable {

public static final String EXAMPLE = "John Doe";
public static final String MESSAGE_NAME_CONSTRAINTS = "Person names should be spaces or alphabetic characters";
Expand Down Expand Up @@ -59,5 +59,10 @@ public boolean equals(Object other) {
public int hashCode() {
return fullName.hashCode();
}

@Override
public String getPrintableString() {
return "Name: "+this.toString();
}

}
13 changes: 12 additions & 1 deletion src/seedu/addressbook/data/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
* Represents a Person's phone number in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidPhone(String)}
*/
public class Phone {
public class Phone implements Printable {

public static final String EXAMPLE = "123456789";
public static final String MESSAGE_PHONE_CONSTRAINTS = "Person phone numbers should only contain numbers";
public static final String PHONE_VALIDATION_REGEX = "\\d+";
private static final String PHONE_PRIVATE_STRING = "***";

public final String value;
private boolean isPrivate;
Expand Down Expand Up @@ -56,4 +57,14 @@ public int hashCode() {
public boolean isPrivate() {
return isPrivate;
}

@Override
public String getPrintableString() {
if(this.isPrivate()){
return "Phone: " + PHONE_PRIVATE_STRING;
}
else {
return "Phone: "+ this.toString();
}
}
}
10 changes: 10 additions & 0 deletions src/seedu/addressbook/data/person/Printable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package seedu.addressbook.data.person;
/**
* A read-only immutable interface for printables in the addressbook.
*/
public interface Printable {
String toString();
default String getPrintableString(){
return this.toString();
}
}
13 changes: 13 additions & 0 deletions test/java/seedu/addressbook/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static seedu.addressbook.common.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.addressbook.common.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX;


public class ParserTest {

private Parser parser;
Expand Down Expand Up @@ -304,4 +305,16 @@ private <T extends Command> T parseAndAssertCommandType(String input, Class<T> e
assertTrue(result.getClass().isAssignableFrom(expectedCommandClass));
return (T) result;
}

/**
* Returns a concatenated version of the printable strings of each object.
*/
String getPrintableString(Printable... printables){
Set<String> allPrintables = new HashSet<String>();
for(Printable p: printables){
allPrintables.add(p.getPrintableString());
}
String concatenatedString = String.join(", ", allPrintables);
return concatenatedString;
}
}