From 6fa8c02d7ef77e4ea4fc5edf1cafb13229aa0dd8 Mon Sep 17 00:00:00 2001 From: "DESKTOP-IAIBR9Q\\Rahumath Marini" Date: Mon, 3 Jul 2017 13:29:14 +0800 Subject: [PATCH] Create a printable interface class and implement the method on other class --- src/seedu/addressbook/data/person/Address.java | 8 +++++++- src/seedu/addressbook/data/person/Email.java | 8 +++++++- src/seedu/addressbook/data/person/Name.java | 8 +++++++- src/seedu/addressbook/data/person/Phone.java | 8 +++++++- src/seedu/addressbook/data/person/Printable.java | 5 +++++ src/seedu/addressbook/ui/TextUi.java | 10 ++++++++++ 6 files changed, 43 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 131d71b46..1deb8649b 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"; @@ -56,4 +56,10 @@ public int hashCode() { public boolean isPrivate() { return isPrivate; } + + @Override + public String getPrintableString() { + String print = "Address: " + this.value; + return print; + } } diff --git a/src/seedu/addressbook/data/person/Email.java b/src/seedu/addressbook/data/person/Email.java index ad623b5b8..4335c5d97 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() { + String print = "Email: " + this.value; + return print; + } } diff --git a/src/seedu/addressbook/data/person/Name.java b/src/seedu/addressbook/data/person/Name.java index d1d271414..c5d242b76 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 alphabetic characters"; @@ -60,4 +60,10 @@ public int hashCode() { return fullName.hashCode(); } + @Override + public String getPrintableString() { + String print = "Name: " + this.fullName; + return print; + } + } diff --git a/src/seedu/addressbook/data/person/Phone.java b/src/seedu/addressbook/data/person/Phone.java index 431a7a882..c497dc97a 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() { + String print = "Phone: " + this.value; + return print; + } } diff --git a/src/seedu/addressbook/data/person/Printable.java b/src/seedu/addressbook/data/person/Printable.java new file mode 100644 index 000000000..4c0a7ca24 --- /dev/null +++ b/src/seedu/addressbook/data/person/Printable.java @@ -0,0 +1,5 @@ +package seedu.addressbook.data.person; + +public interface Printable { + String getPrintableString(); +} diff --git a/src/seedu/addressbook/ui/TextUi.java b/src/seedu/addressbook/ui/TextUi.java index d30371c70..b9efd10a3 100644 --- a/src/seedu/addressbook/ui/TextUi.java +++ b/src/seedu/addressbook/ui/TextUi.java @@ -14,6 +14,7 @@ import java.util.Scanner; import seedu.addressbook.commands.CommandResult; +import seedu.addressbook.data.person.Printable; import seedu.addressbook.data.person.ReadOnlyPerson; /** @@ -168,5 +169,14 @@ private static String getIndexedListForViewing(List listItems) { private static String getIndexedListItem(int visibleIndex, String listItem) { return String.format(MESSAGE_INDEXED_LIST_ITEM, visibleIndex, listItem); } + + private static String getPrintableString(Printable... printables){ + String string = ""; + for(Printable printable : printables){ + string += printable.getPrintableString() + " "; + } + return string; + + } }