diff --git a/src/seedu/addressbook/data/person/Address.java b/src/seedu/addressbook/data/person/Address.java index 8ac726444..ea74854fb 100644 --- a/src/seedu/addressbook/data/person/Address.java +++ b/src/seedu/addressbook/data/person/Address.java @@ -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"; @@ -55,4 +55,10 @@ public int hashCode() { public boolean isPrivate() { return isPrivate; } + + @Override + public String getPrintableString() { + return "Address: " + this.value; + } + } \ 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..b82cabe40 100644 --- a/src/seedu/addressbook/data/person/Email.java +++ b/src/seedu/addressbook/data/person/Email.java @@ -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 = "valid@e.mail"; public static final String MESSAGE_EMAIL_CONSTRAINTS = @@ -58,4 +58,10 @@ public int hashCode() { public boolean isPrivate() { return isPrivate; } + + @Override + public String getPrintableString() { + return "Email: " + this.value; + } + } \ 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..5225ea806 100644 --- a/src/seedu/addressbook/data/person/Name.java +++ b/src/seedu/addressbook/data/person/Name.java @@ -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"; @@ -61,4 +61,9 @@ public int hashCode() { return fullName.hashCode(); } + @Override + public String getPrintableString() { + return "Name: " + this.fullName; + } + } diff --git a/src/seedu/addressbook/data/person/Person.java b/src/seedu/addressbook/data/person/Person.java index cf6211841..45993d055 100644 --- a/src/seedu/addressbook/data/person/Person.java +++ b/src/seedu/addressbook/data/person/Person.java @@ -3,6 +3,7 @@ import seedu.addressbook.data.tag.UniqueTagList; import java.util.Objects; +import java.util.StringJoiner; /** * Represents a Person in the address book. @@ -84,4 +85,15 @@ public String toString() { return getAsTextShowAll(); } + /** + * Returns a concatenated version of the printable strings of each object. + */ + public String getPrintableString(Printable... printables){ + StringJoiner joiner = new StringJoiner(" "); + for (Printable p: printables) { + joiner.add(p.getPrintableString()); + } + return joiner.toString(); + } + } diff --git a/src/seedu/addressbook/data/person/Phone.java b/src/seedu/addressbook/data/person/Phone.java index b5a556de4..e2b96fb8b 100644 --- a/src/seedu/addressbook/data/person/Phone.java +++ b/src/seedu/addressbook/data/person/Phone.java @@ -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"; @@ -56,4 +56,10 @@ public int hashCode() { public boolean isPrivate() { return isPrivate; } + + @Override + public String getPrintableString() { + return "Phone: " + this.value; + } + } diff --git a/src/seedu/addressbook/data/person/Printable.java b/src/seedu/addressbook/data/person/Printable.java new file mode 100644 index 000000000..49446a663 --- /dev/null +++ b/src/seedu/addressbook/data/person/Printable.java @@ -0,0 +1,10 @@ +package seedu.addressbook.data.person; + +/** + * An interface for printable string representation of person's data in the addressbook. + */ +public interface Printable { + + String getPrintableString(); + +}