forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #68 from Shruthiiii03/branch-EmergencyNameCommand
Complete Emergency Contact Name functionality
- Loading branch information
Showing
25 changed files
with
471 additions
and
109 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
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
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
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
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
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
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
66 changes: 66 additions & 0 deletions
66
src/main/java/seedu/address/model/person/EmergencyContactName.java
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,66 @@ | ||
package seedu.address.model.person; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
/** | ||
* Represents a person's emergency contact name in the address book | ||
* The name can be empty or contain only alphanumeric characters and spaces. | ||
*/ | ||
public class EmergencyContactName { | ||
|
||
public static final String MESSAGE_CONSTRAINTS = | ||
"Emergency contact names should only contain alphanumeric characters and spaces, " | ||
+ "and it can be blank if no contact is provided."; | ||
|
||
/** | ||
* The first character of the name 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 an EmergencyContactName | ||
* @param ecName | ||
*/ | ||
public EmergencyContactName(String ecName) { | ||
requireNonNull(ecName); | ||
checkArgument(isValidEmergencyContactName(ecName), MESSAGE_CONSTRAINTS); | ||
fullName = ecName; | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid name. | ||
*/ | ||
public static boolean isValidEmergencyContactName(String name) { | ||
return name != null && (name.isEmpty() || name.matches(VALIDATION_REGEX)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return fullName; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof EmergencyContactName)) { | ||
return false; | ||
} | ||
|
||
EmergencyContactName otherName = (EmergencyContactName) other; | ||
return fullName.equals(otherName.fullName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return fullName.hashCode(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.