-
Notifications
You must be signed in to change notification settings - Fork 10
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
[T4A1][T01-T3] Teo Shu Qi #91
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 LABEL = "EMAIL: "; | ||
|
||
public final String value; | ||
private boolean isPrivate; | ||
|
@@ -36,6 +38,11 @@ public Email(String email, boolean isPrivate) throws IllegalValueException { | |
public static boolean isValidEmail(String test) { | ||
return test.matches(EMAIL_VALIDATION_REGEX); | ||
} | ||
|
||
@Override | ||
public String getPrintableString() { | ||
return LABEL + this.toString(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,5 +83,22 @@ public int hashCode() { | |
public String toString() { | ||
return getAsTextShowAll(); | ||
} | ||
|
||
private String addDetailToDetailsString(String details, String detail) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to create a new method for this. Also the method name is quite confusing. :) |
||
return details +" "+ detail; | ||
} | ||
|
||
/** | ||
* Print out the details of the person requested. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method doesn't print anything. |
||
* @param printable | ||
* @return a concatenated version of the printable strings of each object. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove |
||
*/ | ||
private String getPrintableString(Printable ... printable) { | ||
String details = ""; | ||
for ( Printable detail :printable) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pay attention to the white space. |
||
addDetailToDetailsString(details, detail.getPrintableString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might use java collection method, like String.join or StringBuilder. |
||
} | ||
return details; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package seedu.addressbook.data.person; | ||
|
||
/** | ||
* A read-only immutable interface for a Person Details in the addressbook. | ||
* Implementations should guarantee: details are present and not null, field values are validated. | ||
* | ||
*/ | ||
public interface Printable { | ||
|
||
// Label stating what detail is this detail (e.g. Phone: ) | ||
public static String LABEL = ""; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to define it here. |
||
|
||
// Returns the detail with the labelS | ||
String getPrintableString(); | ||
|
||
} |
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.
Shouldn't you check if it's a private or not? The variable name
LABEL
is too generic.