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

[T4A3][T17-B3]Sin Yu Fan #1692

Open
wants to merge 1 commit 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
25 changes: 1 addition & 24 deletions src/seedu/addressbook/data/person/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +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 extends Contact {

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 final String value;
private boolean isPrivate;

/**
* Validates given address.
*
Expand All @@ -35,24 +32,4 @@ public static boolean isValidAddress(String test) {
return test.matches(ADDRESS_VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Address // instanceof handles nulls
&& this.value.equals(((Address) other).value)); // state check
}

@Override
public int hashCode() {
return value.hashCode();
}

public boolean isPrivate() {
return isPrivate;
}
}
33 changes: 33 additions & 0 deletions src/seedu/addressbook/data/person/Contact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package seedu.addressbook.data.person;

import seedu.addressbook.data.exception.IllegalValueException;

public class Contact {

public static String EXAMPLE;

public String value;
protected boolean isPrivate;

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Contact // instanceof handles nulls
&& this.value.equals(((Contact) other).value)); // state check
}

@Override
public int hashCode() {
return value.hashCode();
}

public boolean isPrivate() {
return isPrivate;
}

}
26 changes: 1 addition & 25 deletions src/seedu/addressbook/data/person/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +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 extends Contact {

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 final String value;
private boolean isPrivate;

/**
* Validates given email.
*
Expand All @@ -37,25 +34,4 @@ public static boolean isValidEmail(String test) {
return test.matches(EMAIL_VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Email // instanceof handles nulls
&& this.value.equals(((Email) other).value)); // state check
}

@Override
public int hashCode() {
return value.hashCode();
}


public boolean isPrivate() {
return isPrivate;
}
}
20 changes: 1 addition & 19 deletions src/seedu/addressbook/data/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +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 extends Contact {

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 final String value;
private boolean isPrivate;

/**
* Validates given phone number.
*
Expand All @@ -36,24 +33,9 @@ public static boolean isValidPhone(String test) {
return test.matches(PHONE_VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Phone // instanceof handles nulls
&& this.value.equals(((Phone) other).value)); // state check
}

@Override
public int hashCode() {
Copy link

@bongbongbee bongbongbee Sep 17, 2016

Choose a reason for hiding this comment

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

What's the rationale behind overriding the hashCode() method? Or did you forget to remove this?

return value.hashCode();

Choose a reason for hiding this comment

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

hmm..the value variable does not exist in your Phone class already. Can this class file still compile?

}

public boolean isPrivate() {
return isPrivate;
}
}