From 2029b22bbfadb0d7d5b0bd5782c6fbd10149e08c Mon Sep 17 00:00:00 2001 From: McNaBry Date: Wed, 18 Oct 2023 21:46:37 +0800 Subject: [PATCH] Change oid field to optional --- .../java/seedu/address/model/person/Recruiter.java | 7 ++++--- .../seedu/address/storage/JsonAdaptedContact.java | 6 ++++-- src/main/java/seedu/address/ui/ContactCard.java | 13 +++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Recruiter.java b/src/main/java/seedu/address/model/person/Recruiter.java index 72d878dd338..c77c8763873 100644 --- a/src/main/java/seedu/address/model/person/Recruiter.java +++ b/src/main/java/seedu/address/model/person/Recruiter.java @@ -1,6 +1,7 @@ package seedu.address.model.person; import java.util.Objects; +import java.util.Optional; import java.util.Set; import seedu.address.commons.util.ToStringBuilder; @@ -12,17 +13,17 @@ */ public class Recruiter extends Contact { - private final Id oid; + private final Optional oid; /** * Every field except oid must be present and not null. */ public Recruiter(Name name, Id id, Phone phone, Email email, Url url, Address address, Set tags, Id oid) { super(name, id, phone, email, url, address, tags); - this.oid = oid; + this.oid = Optional.ofNullable(oid); } - public Id getOrganizationId() { + public Optional getOrganizationId() { return oid; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedContact.java b/src/main/java/seedu/address/storage/JsonAdaptedContact.java index 868d764b37b..3e17f1a5987 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedContact.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedContact.java @@ -78,10 +78,12 @@ public JsonAdaptedContact(Contact source) { position = ((Organization) source).getPosition().jobPosition; oid = ""; } else if (source.getType() == Type.RECRUITER) { + Recruiter recruiter = (Recruiter) source; status = ""; position = ""; - Id tmp = ((Recruiter) source).getOrganizationId(); - oid = tmp == null ? null : tmp.value; + oid = recruiter.getOrganizationId() + .map(oid -> oid.value) + .orElse(null); } type = source.getType().toString(); diff --git a/src/main/java/seedu/address/ui/ContactCard.java b/src/main/java/seedu/address/ui/ContactCard.java index 7148574e103..70c85b5ea8f 100644 --- a/src/main/java/seedu/address/ui/ContactCard.java +++ b/src/main/java/seedu/address/ui/ContactCard.java @@ -1,6 +1,7 @@ package seedu.address.ui; import java.util.Comparator; +import java.util.Optional; import java.util.function.Supplier; import javafx.fxml.FXML; @@ -97,14 +98,14 @@ public ContactCard(Contact contact, int displayedIndex) { case RECRUITER: { Recruiter recruiter = (Recruiter) contact; - final Id linkedOrgId = recruiter.getOrganizationId(); + final Optional linkedOrgId = recruiter.getOrganizationId(); setVboxInnerLabelText( - linkedParentOrganization, () -> linkedOrgId == null - ? null - : String.format( - "from %s (%s)", "organization" /* TODO: Use org name instead */, linkedOrgId.value - ) + linkedParentOrganization, () -> linkedOrgId.map(oid -> + String.format( + "from %s (%s)", "organization" /* TODO: Use org name instead */, oid.value + )) + .orElse(null) ); cardPaneInnerVbox.getChildren().removeAll(status, position); break;