From a1d9fe04554183a0d0fcc564b3877199abd0a54b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 20 Oct 2022 19:11:46 +0200 Subject: [PATCH] Continued: - The Country instance is required (not null) so it needs to be part of this constructor --- .../jcontacts/model/contact/UserContact.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/org/mxchange/jcontacts/model/contact/UserContact.java b/src/org/mxchange/jcontacts/model/contact/UserContact.java index ea92d27..8f89373 100644 --- a/src/org/mxchange/jcontacts/model/contact/UserContact.java +++ b/src/org/mxchange/jcontacts/model/contact/UserContact.java @@ -16,6 +16,7 @@ */ package org.mxchange.jcontacts.model.contact; +import java.text.MessageFormat; import java.util.Date; import java.util.Objects; import javax.persistence.Basic; @@ -41,9 +42,9 @@ import org.apache.commons.lang3.StringUtils; import org.mxchange.jcontacts.model.contact.title.PersonalTitle; import org.mxchange.jcoreutils.comparable.ComparableUtils; import org.mxchange.jcoreutils.number.SafeNumberUtils; -import org.mxchange.jcountry.model.utils.CountryUtils; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jcountry.model.data.CountryData; +import org.mxchange.jcountry.model.utils.CountryUtils; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber; import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; @@ -231,8 +232,9 @@ public class UserContact implements Contact { * @param contactPersonalTitle Personal title * @param contactFirstName First name * @param contactFamilyName Family name + * @param contactCountry Country instance */ - public UserContact (final PersonalTitle contactPersonalTitle, final String contactFirstName, final String contactFamilyName) { + public UserContact (final PersonalTitle contactPersonalTitle, final String contactFirstName, final String contactFamilyName, final Country contactCountry) { // Invoke default constructor this(); @@ -252,12 +254,22 @@ public class UserContact implements Contact { } else if (contactFamilyName.isEmpty()) { // Throw IAE throw new IllegalArgumentException("contactFamilyName is empty"); //NOI18N + } else if (null == contactCountry) { + // Throw NPE + throw new NullPointerException("contactCountry is null"); //NOI18N + } else if (contactCountry.getCountryId() == null) { + // Throw it again + throw new NullPointerException("contactCountry.countryId is null"); //NOI18N + } else if (contactCountry.getCountryId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("contactCountry.countryId={0} is not valid", contactCountry.getCountryId())); //NOI18N } // Set all this.contactPersonalTitle = contactPersonalTitle; this.contactFirstName = contactFirstName; this.contactFamilyName = contactFamilyName; + this.contactCountry = contactCountry; } @Override -- 2.39.5