From: Roland Häder Date: Thu, 18 Aug 2016 15:46:59 +0000 (+0200) Subject: Continued a bit: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=43544a1730a5019399f17f7a8ff596e581f75d5d;p=jcontacts-core.git Continued a bit: - if a mobile provider instance is given, but no number, throw an NPE before the JVM detects the null reference - this may look like redundant but it makes the code more clear (and may become handy for unit tests) - renamed cellphone -> mobile --- diff --git a/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java b/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java index 00bfef4..702baea 100644 --- a/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java +++ b/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java @@ -75,31 +75,34 @@ public class ContactUtils implements Serializable { } /** - * Updates cellphone data in contact instance. This method also removes the - * cellphone instance if no provider is selected. A bean (mostly EJB) should - * then make sure that the cellphone entry is being unlinked from contact + * 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 cellphoneProvider New cellphone provider (or old) - * @param cellphoneNumber New cellphone number (or old) + * @param mobileProvider New mobile provider (or old) + * @param mobileNumber New mobile number (or old) *

- * @return Whether the cellphone has been unlinked in contact object + * @return Whether the mobile has been unlinked in contact object */ - public static boolean updateCellPhoneNumber (final Contact contact, final MobileProvider cellphoneProvider, final Long cellphoneNumber) { + 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 cellphone number? + // Is there a mobile number? if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { // Is provider null? - if ((null == cellphoneProvider) || (null == cellphoneNumber) || (cellphoneNumber == 0)) { + if ((null == mobileProvider) || (null == mobileNumber) || (mobileNumber == 0)) { // Remove instance contact.setContactMobileNumber(null); @@ -107,15 +110,15 @@ public class ContactUtils implements Serializable { isUnlinked = true; } else { // Yes, then update as well - contact.getContactMobileNumber().setMobileProvider(cellphoneProvider); - contact.getContactMobileNumber().setPhoneNumber(cellphoneNumber); + contact.getContactMobileNumber().setMobileProvider(mobileProvider); + contact.getContactMobileNumber().setPhoneNumber(mobileNumber); } - } else if ((cellphoneProvider instanceof MobileProvider) && (cellphoneNumber > 0)) { + } else if ((mobileProvider instanceof MobileProvider) && (mobileNumber > 0)) { // Create new instance - DialableMobileNumber cellphone = new MobileNumber(cellphoneProvider, cellphoneNumber); + DialableMobileNumber mobile = new MobileNumber(mobileProvider, mobileNumber); // Set it in contact - contact.setContactMobileNumber(cellphone); + contact.setContactMobileNumber(mobile); } // Return status