From: Roland Häder Date: Wed, 19 Apr 2017 22:17:46 +0000 (+0200) Subject: cellphone is history, now there is mobile ... ;-) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9b1c4124b5703f8c377f0c453b6ab101979ec77c;p=jcontacts-core.git cellphone is history, now there is mobile ... ;-) Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jcontacts/contact/gender/Gender.java b/src/org/mxchange/jcontacts/contact/gender/Gender.java index d5ba5a9..0871506 100644 --- a/src/org/mxchange/jcontacts/contact/gender/Gender.java +++ b/src/org/mxchange/jcontacts/contact/gender/Gender.java @@ -151,4 +151,5 @@ public enum Gender implements Serializable { public String getMessageKey () { return this.messageKey; } + } diff --git a/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java b/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java index b126f0f..53d2549 100644 --- a/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java +++ b/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java @@ -65,4 +65,5 @@ public class GenderUtils implements Serializable { */ private GenderUtils () { } + } diff --git a/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java b/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java index 3dbfad5..192b2e7 100644 --- a/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java +++ b/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java @@ -46,7 +46,7 @@ public class ContactUtils implements Serializable { * the equal() method is implemented and checks all fields. *

* @param contact Contact one - * @param other Contact two + * @param other Contact two *

* @return Whether both are the same */ @@ -74,67 +74,16 @@ public class ContactUtils implements Serializable { (Objects.equals(contact.getContactZipCode(), other.getContactZipCode()))); } - /** - * Updates mobile data in contact instance. This method also removes the - * mobile instance if no provider is selected. A bean (mostly EJB) should - * then make sure that the mobile entry is being unlinked from contact - * instance or being removed, if no longer used. - *

- * @param contact Contact instance to update - * @param mobileProvider New mobile provider (or old) - * @param mobileNumber New mobile number (or old) - *

- * @return Whether the mobile has been unlinked in contact object - */ - public static boolean updateCellPhoneNumber (final Contact contact, final MobileProvider mobileProvider, final Long mobileNumber) { - // At least contact must be valid - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if ((mobileProvider instanceof MobileProvider) && (null == mobileNumber)) { - // Mobile provider given, but no number - throw new NullPointerException("mobileNumber is null"); //NOI18N - } - - // Default is not unlinked - boolean isUnlinked = false; - - // Is there a mobile number? - if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { - // Is provider null? - if ((null == mobileProvider) || (null == mobileNumber) || (mobileNumber == 0)) { - // Remove instance - contact.setContactMobileNumber(null); - - // Mark as unlinked - isUnlinked = true; - } else { - // Yes, then update as well - contact.getContactMobileNumber().setMobileProvider(mobileProvider); - contact.getContactMobileNumber().setPhoneNumber(mobileNumber); - } - } else if ((mobileProvider instanceof MobileProvider) && (mobileNumber > 0)) { - // Create new instance - DialableMobileNumber mobile = new MobileNumber(mobileProvider, mobileNumber); - - // Set it in contact - contact.setContactMobileNumber(mobile); - } - - // Return status - return isUnlinked; - } - /** * Updates land-line data in contact instance. This method also removes the * land-line instance if no country is selected. A bean (mostly EJB) should * then make sure that the land-line entry is being unlinked from contact * instance or being removed, if no longer used. *

- * @param contact Contact instance being updated - * @param faxCountry Updated fax number or null + * @param contact Contact instance being updated + * @param faxCountry Updated fax number or null * @param faxAreaCode Updated fax area code or null - * @param faxNumber Updated fax number + * @param faxNumber Updated fax number *

* @return Whether the fax number has been unlinked in contact object */ @@ -181,10 +130,10 @@ public class ContactUtils implements Serializable { * then make sure that the land-line entry is being unlinked from contact * instance or being removed, if no longer used. *

- * @param contact Contact instance being updated - * @param phoneCountry New phone country or old or null + * @param contact Contact instance being updated + * @param phoneCountry New phone country or old or null * @param phoneAreaCode New phone's area code (or old) - * @param phoneNumber New phone number (or old) + * @param phoneNumber New phone number (or old) *

* @return Whether the land-line number has been unlinked in contact object */ @@ -225,6 +174,57 @@ public class ContactUtils implements Serializable { return isUnlinked; } + /** + * Updates mobile data in contact instance. This method also removes the + * mobile instance if no provider is selected. A bean (mostly EJB) should + * then make sure that the mobile entry is being unlinked from contact + * instance or being removed, if no longer used. + *

+ * @param contact Contact instance to update + * @param mobileProvider New mobile provider (or old) + * @param mobileNumber New mobile number (or old) + *

+ * @return Whether the mobile has been unlinked in contact object + */ + public static boolean updateMobileNumber (final Contact contact, final MobileProvider mobileProvider, final Long mobileNumber) { + // At least contact must be valid + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if ((mobileProvider instanceof MobileProvider) && (null == mobileNumber)) { + // Mobile provider given, but no number + throw new NullPointerException("mobileNumber is null"); //NOI18N + } + + // Default is not unlinked + boolean isUnlinked = false; + + // Is there a mobile number? + if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { + // Is provider null? + if ((null == mobileProvider) || (null == mobileNumber) || (mobileNumber == 0)) { + // Remove instance + contact.setContactMobileNumber(null); + + // Mark as unlinked + isUnlinked = true; + } else { + // Yes, then update as well + contact.getContactMobileNumber().setMobileProvider(mobileProvider); + contact.getContactMobileNumber().setPhoneNumber(mobileNumber); + } + } else if ((mobileProvider instanceof MobileProvider) && (mobileNumber > 0)) { + // Create new instance + DialableMobileNumber mobile = new MobileNumber(mobileProvider, mobileNumber); + + // Set it in contact + contact.setContactMobileNumber(mobile); + } + + // Return status + return isUnlinked; + } + /** * Private constructor for utilities */