Skip to content

Commit

Permalink
Refactor Birthday parsing and fix inaccurate javadoc headers
Browse files Browse the repository at this point in the history
  • Loading branch information
zhekaiii committed Mar 17, 2024
1 parent e010a0c commit 7b4a3d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,14 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
}

/**
* Parses {@code Optional<String> birthday} into a {@code Optional<LocalDate>}.
* Parses {@code String birthday} into a {@code Birthday}.
*/
public static Birthday parseBirthday(String birthday) throws ParseException {
requireNonNull(birthday);
return new Birthday(birthday);
birthday = birthday == null ? "" : birthday;
String trimmedBirthday = birthday.trim();
if (!Birthday.isValidBirthday(trimmedBirthday)) {
throw new ParseException(Birthday.BIRTHDAY_CONSTRAINTS);
}
return new Birthday(trimmedBirthday);
}
}
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/model/person/Birthday.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

import java.time.LocalDate;
Expand All @@ -26,7 +27,7 @@ public class Birthday {
* @param birthday A valid birthday, or an empty string.
*/
public Birthday(String birthday) {
birthday = birthday == null ? "" : birthday;
requireNonNull(birthday);
if (birthday.isBlank()) {
this.birthday = null;
return;
Expand All @@ -37,7 +38,7 @@ public Birthday(String birthday) {


/**
* Returns true if a given string is a valid name.
* Returns true if a given string is a valid birthday.
*/
public static boolean isValidBirthday(String test) {
if (test == null || test.isBlank()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/storage/JsonAdaptedPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public Person toModelType() throws IllegalValueException {
if (!Birthday.isValidBirthday(birthday)) {
throw new IllegalValueException(Birthday.BIRTHDAY_CONSTRAINTS);
}
final Birthday modelBirthday = new Birthday(birthday);
final Birthday modelBirthday = new Birthday(Optional.ofNullable(birthday).orElse(""));

return new Person(modelName, modelPhone, modelEmail, modelAddress, modelRemark, modelTags, modelBirthday);
}
Expand Down

0 comments on commit 7b4a3d9

Please sign in to comment.