From 9b1c4124b5703f8c377f0c453b6ab101979ec77c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 20 Apr 2017 00:17:46 +0200 Subject: [PATCH] cellphone is history, now there is mobile ... ;-) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../jcontacts/contact/gender/Gender.java | 1 + .../jcontacts/contact/gender/GenderUtils.java | 1 + .../jcontacts/contact/utils/ContactUtils.java | 116 +++++++++--------- 3 files changed, 60 insertions(+), 58 deletions(-) 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 */ -- 2.39.5