forked from CS2103AUG2017-W14-B2/main
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca7f205
commit 0874d45
Showing
1 changed file
with
59 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 |
---|---|---|
@@ -1,4 +1,63 @@ | ||
package seedu.address.model.person; | ||
|
||
import seedu.address.commons.exceptions.IllegalValueException; | ||
|
||
/** | ||
* Represents a Person's display picture in the address book | ||
* Guarantees: immutable; is valid as declared in (@Link #isValidImage(String)) | ||
*/ | ||
public class Photo { | ||
public static final String MESSAGE_PHOTO_CONSTRAINTS = | ||
"Person's photo should be in jpeg and be of 340px x 453px dimension"; | ||
|
||
/* | ||
* The first character of the address must not be a whitespace, | ||
* otherwise " " (a blank string) becomes a valid input. | ||
*/ | ||
public static final String PHOTO_VALIDATION_REGEX = "[^\\s].*"; //Yet to update | ||
|
||
public final String value; | ||
|
||
/** | ||
* Validates given photo. | ||
* | ||
* @throws IllegalValueException if given photo string is invalid. | ||
*/ | ||
public Photo(String address) throws IllegalValueException { | ||
if (address == null) { | ||
address = "data/default.jpeg"; //Give a default profile picture | ||
} else { | ||
address = address.trim(); | ||
} | ||
/*if (!isValidPhoto(address)) { | ||
throw new IllegalValueException(MESSAGE_PHOTO_CONSTRAINTS); | ||
} | ||
*/ | ||
this.value = address; | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid person email. | ||
*/ | ||
public static boolean isValidPhoto(String test) { | ||
return test.matches(PHOTO_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(); | ||
} | ||
|
||
} |