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][W14-A4]Lee Jin Shun #1066

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
13 changes: 12 additions & 1 deletion src/seedu/addressbook/data/person/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
* 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 = ".+";
public static final String ADDRESS_PREFIX_STR = "Address: ";
public static final String ACCESS_DENIED = "Access Denied! Private Address!";

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

@Override
public String getPrintableString() {
if(isPrivate){
return ACCESS_DENIED;
} else {
return ADDRESS_PREFIX_STR + toString();
}
}
}
13 changes: 12 additions & 1 deletion src/seedu/addressbook/data/person/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +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\\.]+";
public static final String EMAIL_PREFIX_STR = "Email: ";
public static final String ACCESS_DENIED = "Access Denied! Private Email!";

public final String value;
private boolean isPrivate;
Expand Down Expand Up @@ -58,4 +60,13 @@ public int hashCode() {
public boolean isPrivate() {
return isPrivate;
}

@Override
public String getPrintableString() {
if(isPrivate){
return ACCESS_DENIED;
} else {
return EMAIL_PREFIX_STR + toString();
}
}
}
8 changes: 7 additions & 1 deletion src/seedu/addressbook/data/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
* 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";
public static final String NAME_VALIDATION_REGEX = "[\\p{Alpha} ]+";
public final String fullName;
public static final String NAME_PREFIX_STR = "Name: ";

/**
* Validates given name.
Expand Down Expand Up @@ -60,4 +61,9 @@ public int hashCode() {
return fullName.hashCode();
}

@Override
public String getPrintableString() {
return NAME_PREFIX_STR + toString();
}

}
12 changes: 12 additions & 0 deletions src/seedu/addressbook/data/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,16 @@ public String toString() {
return getAsTextShowAll();
}



@Override
public String getPrintableString(Printable... printable) {
Copy link

Choose a reason for hiding this comment

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

Maybe printables sounds more appropriate here

String printedText = "";
for(Printable element : printable){
printedText += element.getPrintableString() + ", ";
Copy link

Choose a reason for hiding this comment

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

Take note of magic strings.

}
// remove ", " for the last printable element
return printedText.substring(0, printedText.length() - 2);

}
}
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,13 @@
* 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+";
public static final String PHONE_PREFIX_STR = "Phone: ";
public static final String ACCESS_DENIED = "Access Denied! Private Address!";

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

@Override
public String getPrintableString() {
if(isPrivate){
return ACCESS_DENIED;
} else {
return PHONE_PREFIX_STR + toString();
}
}
}
13 changes: 13 additions & 0 deletions src/seedu/addressbook/data/person/Printable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package seedu.addressbook.data.person;

/**
* An interface to help beautify objects to a nicer string representation.
*/
public interface Printable {

/**
* Returns a string of the object in the terms of Name, Phone, Email, Address
* eg. Name: John Smith, Phone: 12349862
*/
String getPrintableString();
}
1 change: 1 addition & 0 deletions src/seedu/addressbook/data/person/ReadOnlyPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface ReadOnlyPerson {
Phone getPhone();
Email getEmail();
Address getAddress();
String getPrintableString(Printable... printable);

/**
* The returned TagList is a deep copy of the internal TagList,
Expand Down