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
create customer class #61
Changes from 8 commits
6b6f261
27b80dd
275378e
315aa10
10f6951
4535c24
23ed7ae
8c3039a
acd9665
5172ef7
e5e2308
83c9f1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package seedu.address.model.customer; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
/** | ||
* Represents a Customer's phone number in the address book. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidContactNumber(String)} | ||
*/ | ||
public class ContactNumber { | ||
|
||
|
||
public static final String MESSAGE_CONSTRAINTS = | ||
"ContactNumber numbers should only contain numbers, and it should be at least 3 digits long"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. contact number should be 8 numbers instead i think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
public static final String VALIDATION_REGEX = "\\d{3,}"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be \d{8,} |
||
public final String value; | ||
|
||
/** | ||
* Constructs a {@code ContactNumber}. | ||
* | ||
* @param contactNumber A valid contactNumber number. | ||
*/ | ||
public ContactNumber(String contactNumber) { | ||
requireNonNull(contactNumber); | ||
checkArgument(isValidContactNumber(contactNumber), MESSAGE_CONSTRAINTS); | ||
value = contactNumber; | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid phone number. | ||
*/ | ||
public static boolean isValidContactNumber(String test) { | ||
return test.matches(VALIDATION_REGEX); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ContactNumber // instanceof handles nulls | ||
&& value.equals(((ContactNumber) other).value)); // state check | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package seedu.address.model.customer; | ||
|
||
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Represents a Customer in the address book. | ||
* Guarantees: details are present and not null, field values are validated, immutable. | ||
*/ | ||
public class Customer implements Cloneable { | ||
|
||
// Identity fields | ||
private final Name name; | ||
private final ContactNumber contactNumber; | ||
private final Email email; | ||
|
||
// Data fields | ||
private final Set<Tag> tags = new HashSet<>(); | ||
|
||
/** | ||
* Every field must be present and not null. | ||
*/ | ||
public Customer(Name name, ContactNumber contactNumber, Email email, Set<Tag> tags) { | ||
requireAllNonNull(name, contactNumber, email, tags); | ||
this.name = name; | ||
this.contactNumber = contactNumber; | ||
this.email = email; | ||
this.tags.addAll(tags); | ||
} | ||
|
||
public Name getName() { | ||
return name; | ||
} | ||
|
||
public ContactNumber getContactNumber() { | ||
return contactNumber; | ||
} | ||
|
||
public Email getEmail() { | ||
return email; | ||
} | ||
|
||
/** | ||
* Returns an immutable tag set, which throws {@code UnsupportedOperationException} | ||
* if modification is attempted. | ||
*/ | ||
public Set<Tag> getTags() { | ||
return Collections.unmodifiableSet(tags); | ||
} | ||
|
||
/** | ||
* Returns true if both persons of the same name have at least one other identity field that is the same. | ||
EugeneTeu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* This defines a weaker notion of equality between two persons. | ||
*/ | ||
public boolean isSameCustomer(Customer otherCustomer) { | ||
if (otherCustomer == this) { | ||
return true; | ||
} | ||
|
||
return otherCustomer != null | ||
&& otherCustomer.getName().equals(getName()) | ||
&& (otherCustomer.getContactNumber().equals(getContactNumber()) | ||
|| otherCustomer.getEmail().equals(getEmail())); | ||
} | ||
|
||
/** | ||
* Returns true if both customers have the same identity and data fields. | ||
* This defines a stronger notion of equality between two persons. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. javadoc comment change to customers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
*/ | ||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
if (!(other instanceof Customer)) { | ||
return false; | ||
} | ||
|
||
Customer otherCustomer = (Customer) other; | ||
return otherCustomer.getName().equals(getName()) | ||
&& otherCustomer.getContactNumber().equals(getContactNumber()) | ||
&& otherCustomer.getEmail().equals(getEmail()) | ||
&& otherCustomer.getTags().equals(getTags()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
// use this method for custom fields hashing instead of implementing your own | ||
return Objects.hash(name, contactNumber, email, tags); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder builder = new StringBuilder(); | ||
builder.append(getName()) | ||
.append(" ContactNumber: ") | ||
.append(getContactNumber()) | ||
.append(" Email: ") | ||
.append(getEmail()) | ||
.append(" Tags: "); | ||
getTags().forEach(builder::append); | ||
return builder.toString(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package seedu.address.model.customer; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
/** | ||
* Represents a Customer's email in the address book. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidEmail(String)} | ||
*/ | ||
public class Email { | ||
|
||
private static final String SPECIAL_CHARACTERS = "!#$%&'*+/=?`{|}~^.-"; | ||
public static final String MESSAGE_CONSTRAINTS = "Emails should be of the format local-part@domain " | ||
+ "and adhere to the following constraints:\n" | ||
+ "1. The local-part should only contain alphanumeric characters and these special characters, excluding " | ||
+ "the parentheses, (" + SPECIAL_CHARACTERS + ") .\n" | ||
+ "2. This is followed by a '@' and then a domain name. " | ||
+ "The domain name must:\n" | ||
+ " - be at least 2 characters long\n" | ||
+ " - start and end with alphanumeric characters\n" | ||
+ " - consist of alphanumeric characters, a period or a hyphen for the characters in between, if any."; | ||
// alphanumeric and special characters | ||
private static final String LOCAL_PART_REGEX = "^[\\w" + SPECIAL_CHARACTERS + "]+"; | ||
private static final String DOMAIN_FIRST_CHARACTER_REGEX = "[^\\W_]"; // alphanumeric characters except underscore | ||
private static final String DOMAIN_MIDDLE_REGEX = "[a-zA-Z0-9.-]*"; // alphanumeric, period and hyphen | ||
private static final String DOMAIN_LAST_CHARACTER_REGEX = "[^\\W_]$"; | ||
public static final String VALIDATION_REGEX = LOCAL_PART_REGEX + "@" | ||
+ DOMAIN_FIRST_CHARACTER_REGEX + DOMAIN_MIDDLE_REGEX + DOMAIN_LAST_CHARACTER_REGEX; | ||
|
||
public final String value; | ||
|
||
/** | ||
* Constructs an {@code Email}. | ||
* | ||
* @param email A valid email address. | ||
*/ | ||
public Email(String email) { | ||
requireNonNull(email); | ||
checkArgument(isValidEmail(email), MESSAGE_CONSTRAINTS); | ||
value = email; | ||
} | ||
|
||
/** | ||
* Returns if a given string is a valid email. | ||
*/ | ||
public static boolean isValidEmail(String test) { | ||
return test.matches(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 | ||
&& value.equals(((Email) other).value)); // state check | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package seedu.address.model.customer; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
/** | ||
* Represents a Customer's name in the address book. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidName(String)} | ||
*/ | ||
public class Name { | ||
|
||
public static final String MESSAGE_CONSTRAINTS = | ||
"Names should only contain alphanumeric characters and spaces, and it should not be blank"; | ||
|
||
/* | ||
* The first character of the address must not be a whitespace, | ||
* otherwise " " (a blank string) becomes a valid input. | ||
*/ | ||
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; | ||
|
||
public final String fullName; | ||
|
||
/** | ||
* Constructs a {@code Name}. | ||
* | ||
* @param name A valid name. | ||
*/ | ||
public Name(String name) { | ||
requireNonNull(name); | ||
checkArgument(isValidName(name), MESSAGE_CONSTRAINTS); | ||
fullName = name; | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid name. | ||
*/ | ||
public static boolean isValidName(String test) { | ||
return test.matches(VALIDATION_REGEX); | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return fullName; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof Name // instanceof handles nulls | ||
&& fullName.equals(((Name) other).fullName)); // state check | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return fullName.hashCode(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package seedu.address.model.customer; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import seedu.address.commons.util.StringUtil; | ||
|
||
/** | ||
* Tests that a {@code Person}'s {@code Name} matches any of the keywords given. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be Customer instead of Person |
||
*/ | ||
public class NameContainsKeywordsPredicate implements Predicate<Customer> { | ||
private final List<String> keywords; | ||
|
||
public NameContainsKeywordsPredicate(List<String> keywords) { | ||
this.keywords = keywords; | ||
} | ||
|
||
@Override | ||
public boolean test(Customer customer) { | ||
return keywords.stream() | ||
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(customer.getName().fullName, keyword)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof NameContainsKeywordsPredicate // instanceof handles nulls | ||
&& keywords.equals(((NameContainsKeywordsPredicate) other).keywords)); // state check | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will have to modify in the end, I'll just leave it for now