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

[W6.4H][W09-B1] Wee Jia Sheng Richardson #761

Open
wants to merge 3 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
10 changes: 9 additions & 1 deletion src/seedu/addressbook/data/person/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* 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";
Expand Down Expand Up @@ -55,4 +55,12 @@ public int hashCode() {
public boolean isPrivate() {
return isPrivate;
}

@Override
public String getPrintableString() {
if (isPrivate) {
return null;
}
return "Address" + value;
}
}
10 changes: 9 additions & 1 deletion src/seedu/addressbook/data/person/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* 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 =
Expand Down Expand Up @@ -58,4 +58,12 @@ public int hashCode() {
public boolean isPrivate() {
return isPrivate;
}

@Override
public String getPrintableString() {
if (isPrivate) {
return null;
}
return "Email: " + value;
}
}
6 changes: 5 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 alphanumeric characters";
Expand Down Expand Up @@ -61,4 +61,8 @@ public int hashCode() {
return fullName.hashCode();
}

@Override
public String getPrintableString() {
return "Name: " + fullName;
}
}
10 changes: 9 additions & 1 deletion src/seedu/addressbook/data/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* 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";
Expand Down Expand Up @@ -56,4 +56,12 @@ public int hashCode() {
public boolean isPrivate() {
return isPrivate;
}

@Override
public String getPrintableString() {
if (isPrivate) {
return null;
}
return "Phone: " + value;
}
}
12 changes: 12 additions & 0 deletions src/seedu/addressbook/data/person/Printable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package seedu.addressbook.data.person;

/**
* A printable interface for Name, Phone, Email and Address in the addressbook.
*/
public interface Printable {
/**
* The returned String is a representation of the object.
* e.g. Name: John Smith, Phone: 12349862
*/
String getPrintableString();
}
22 changes: 12 additions & 10 deletions src/seedu/addressbook/data/person/ReadOnlyPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,22 @@ default String getAsTextShowAll() {
*/
default String getAsTextHidePrivate() {
final StringBuilder builder = new StringBuilder();
builder.append(getName());
if (!getPhone().isPrivate()) {
builder.append(" Phone: ").append(getPhone());
}
if (!getEmail().isPrivate()) {
builder.append(" Email: ").append(getEmail());
}
if (!getAddress().isPrivate()) {
builder.append(" Address: ").append(getAddress());
}
builder.append(getPrintableString(getName(), getPhone(), getEmail(), getAddress()));
builder.append(" Tags: ");
for (Tag tag : getTags()) {
builder.append(tag);
}
return builder.toString();
}

/**
* Returns a concatenated version of the printable strings of each object.
*/
default String getPrintableString(Printable... printables){
final StringBuilder builder = new StringBuilder();
for (Printable print : printables){
builder.append(print.getPrintableString());
}
return builder.toString();
}
}