forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from RuijianLu/branch-AddComments
Add comment class for enabling adding comments to customers later
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package seedu.address.model.person; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
/** | ||
* Represents a Person's comment the user made in the address book. | ||
*/ | ||
public class Comment { | ||
|
||
public static final String MESSAGE_CONSTRAINTS = | ||
"comments should only contain alphanumeric characters and spaces, and it should not be blank"; | ||
|
||
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; | ||
public final String fullComment; | ||
|
||
/** | ||
* Constructs a {@code Comment}. | ||
* | ||
* @param comment A valid comment. | ||
*/ | ||
public Comment(String comment) { | ||
requireNonNull(comment); | ||
checkArgument(isValidComment(comment), MESSAGE_CONSTRAINTS); | ||
fullComment = comment; | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid comment. | ||
*/ | ||
public static boolean isValidComment(String test) { | ||
return test.matches(VALIDATION_REGEX); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return fullComment; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof Name)) { | ||
return false; | ||
} | ||
|
||
Name otherName = (Name) other; | ||
return fullComment.equals(otherName.fullName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return fullComment.hashCode(); | ||
} | ||
|
||
} |