]> git.mxchange.org Git - jcontacts-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 20 Oct 2022 17:11:46 +0000 (19:11 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 20 Oct 2022 17:11:46 +0000 (19:11 +0200)
- The Country instance is required (not null) so it needs to be part of this
  constructor

src/org/mxchange/jcontacts/model/contact/UserContact.java

index ea92d271b7dde6082ea41a7d1212d80fffe943ab..8f89373fa90b24019aa551ee70eed2c29e318b10 100644 (file)
@@ -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