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

[T4A1][T01-T3] Teo Shu Qi #91

Open
wants to merge 2 commits 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
9 changes: 8 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 LABEL = "ADDRESS: ";

public final String value;
private boolean isPrivate;
Expand All @@ -35,6 +37,11 @@ public Address(String address, boolean isPrivate) throws IllegalValueException {
public static boolean isValidAddress(String test) {
return test.matches(ADDRESS_VALIDATION_REGEX);
}

@Override
public String getPrintableString() {
return LABEL + this.toString();
}

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.


@Override
public String toString() {
Expand Down
9 changes: 8 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 LABEL = "EMAIL: ";

public final String value;
private boolean isPrivate;
Expand All @@ -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() {
Expand Down
10 changes: 9 additions & 1 deletion src/seedu/addressbook/data/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
* 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 static final String LABEL = "NAME: ";

public final String fullName;

/**
Expand All @@ -35,6 +38,11 @@ public Name(String name) throws IllegalValueException {
public static boolean isValidName(String test) {
return test.matches(NAME_VALIDATION_REGEX);
}

@Override
public String getPrintableString() {
return LABEL + this.toString();
}

/**
* Retrieves a listing of every word in the name, in order.
Expand Down
17 changes: 17 additions & 0 deletions src/seedu/addressbook/data/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,22 @@ public int hashCode() {
public String toString() {
return getAsTextShowAll();
}

private String addDetailToDetailsString(String details, String detail) {

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

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

You can remove @return and write Returns ... as the description.

*/
private String getPrintableString(Printable ... printable) {
String details = "";
for ( Printable detail :printable) {

Choose a reason for hiding this comment

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

Pay attention to the white space.

addDetailToDetailsString(details, detail.getPrintableString());

Choose a reason for hiding this comment

The 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;
}

}
9 changes: 8 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 LABEL = "PHONE: ";

public final String value;
private boolean isPrivate;
Expand All @@ -35,6 +37,11 @@ public Phone(String phone, boolean isPrivate) throws IllegalValueException {
public static boolean isValidPhone(String test) {
return test.matches(PHONE_VALIDATION_REGEX);
}

@Override
public String getPrintableString() {
return LABEL + this.toString();
}

@Override
public String toString() {
Expand Down
16 changes: 16 additions & 0 deletions src/seedu/addressbook/data/person/Printable.java
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 = "";

Choose a reason for hiding this comment

The 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();

}
2 changes: 1 addition & 1 deletion src/seedu/addressbook/ui/TextUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -168,5 +169,4 @@ private static String getIndexedListForViewing(List<String> listItems) {
private static String getIndexedListItem(int visibleIndex, String listItem) {
return String.format(MESSAGE_INDEXED_LIST_ITEM, visibleIndex, listItem);
}

}