From 9c2d035493376d4e0ff49a3b8a75aac6fb3fc76e Mon Sep 17 00:00:00 2001 From: Qiu Haohao Date: Wed, 7 Mar 2018 12:47:45 +0800 Subject: [PATCH 1/2] Add getPrintableString to all Printable --- src/seedu/addressbook/data/person/Address.java | 8 +++++++- src/seedu/addressbook/data/person/Email.java | 8 +++++++- src/seedu/addressbook/data/person/Name.java | 7 ++++++- src/seedu/addressbook/data/person/Phone.java | 8 +++++++- src/seedu/addressbook/data/person/Printable.java | 5 +++++ 5 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 src/seedu/addressbook/data/person/Printable.java diff --git a/src/seedu/addressbook/data/person/Address.java b/src/seedu/addressbook/data/person/Address.java index 8ac726444..bf454b064 100644 --- a/src/seedu/addressbook/data/person/Address.java +++ b/src/seedu/addressbook/data/person/Address.java @@ -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 = ".+"; + public static final String PRINTABLE_HEADER = "Address: "; public final String value; private boolean isPrivate; @@ -55,4 +56,9 @@ public int hashCode() { public boolean isPrivate() { return isPrivate; } + + @Override + public String getPrintableString(){ + return PRINTABLE_HEADER + toString(); + } } \ No newline at end of file diff --git a/src/seedu/addressbook/data/person/Email.java b/src/seedu/addressbook/data/person/Email.java index c946f1eb3..cc3d652f5 100644 --- a/src/seedu/addressbook/data/person/Email.java +++ b/src/seedu/addressbook/data/person/Email.java @@ -6,12 +6,13 @@ * 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 = "valid@e.mail"; 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 PRINTABLE_HEADER = "Email: "; public final String value; private boolean isPrivate; @@ -58,4 +59,9 @@ public int hashCode() { public boolean isPrivate() { return isPrivate; } + + @Override + public String getPrintableString(){ + return PRINTABLE_HEADER + toString(); + } } \ No newline at end of file diff --git a/src/seedu/addressbook/data/person/Name.java b/src/seedu/addressbook/data/person/Name.java index 487b7ad9c..255e73feb 100644 --- a/src/seedu/addressbook/data/person/Name.java +++ b/src/seedu/addressbook/data/person/Name.java @@ -9,11 +9,12 @@ * 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"; public static final String NAME_VALIDATION_REGEX = "[\\p{Alnum} ]+"; + public static final String PRINTABLE_HEADER = "Name: "; public final String fullName; @@ -61,4 +62,8 @@ public int hashCode() { return fullName.hashCode(); } + @Override + public String getPrintableString(){ + return PRINTABLE_HEADER + toString(); + } } diff --git a/src/seedu/addressbook/data/person/Phone.java b/src/seedu/addressbook/data/person/Phone.java index b5a556de4..1dbc42536 100644 --- a/src/seedu/addressbook/data/person/Phone.java +++ b/src/seedu/addressbook/data/person/Phone.java @@ -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+"; + public static final String PRINTABLE_HEADER = "Phone: "; public final String value; private boolean isPrivate; @@ -56,4 +57,9 @@ public int hashCode() { public boolean isPrivate() { return isPrivate; } + + @Override + public String getPrintableString(){ + return PRINTABLE_HEADER + toString(); + } } diff --git a/src/seedu/addressbook/data/person/Printable.java b/src/seedu/addressbook/data/person/Printable.java new file mode 100644 index 000000000..2fbd7560b --- /dev/null +++ b/src/seedu/addressbook/data/person/Printable.java @@ -0,0 +1,5 @@ +package seedu.addressbook.data.person; + +public interface Printable { + String getPrintableString(); +} From 38a393a6b2f8363beb40a0d5db09f4c17ecc373e Mon Sep 17 00:00:00 2001 From: Qiu Haohao Date: Wed, 7 Mar 2018 12:48:23 +0800 Subject: [PATCH 2/2] Added variadic getPrintableString to ReadOnlyPerson --- src/seedu/addressbook/data/person/ReadOnlyPerson.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/seedu/addressbook/data/person/ReadOnlyPerson.java b/src/seedu/addressbook/data/person/ReadOnlyPerson.java index f3678da99..eb3b61193 100644 --- a/src/seedu/addressbook/data/person/ReadOnlyPerson.java +++ b/src/seedu/addressbook/data/person/ReadOnlyPerson.java @@ -82,4 +82,12 @@ default String getAsTextHidePrivate() { } return builder.toString(); } + + default String getPrintableString(Printable... printables){ + String concatenated = ""; + for (Printable p : printables){ + concatenated += p.getPrintableString(); + } + return concatenated; + } }