From fc2c7b31a30410707128a3c71f4bd268b64ae75d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 22 Apr 2016 10:56:44 +0200 Subject: [PATCH] Added method updateFaxNumber() to add/update/delete fax number --- .../jcontacts/contact/utils/ContactUtils.java | 61 ++++++++++++++++++- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java b/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java index 11ae89e..3718069 100644 --- a/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java +++ b/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java @@ -21,6 +21,8 @@ import org.mxchange.jcore.BaseFrameworkSystem; import org.mxchange.jcountry.data.Country; import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber; import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.fax.FaxNumber; import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; @@ -71,6 +73,59 @@ public class ContactUtils extends BaseFrameworkSystem { } else if ((cellphoneProvider instanceof MobileProvider) && (cellphoneNumber > 0)) { // Create new instance DialableCellphoneNumber cellphone = new CellphoneNumber(cellphoneProvider, cellphoneNumber); + + // Set it in contact + contact.setContactCellphoneNumber(cellphone); + } + + // 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 faxAreaCode Updated fax area code or null + * @param faxNumber Updated fax number + *

+ * @return Whether the fax number has been unlinked in contact object + */ + public static boolean updateFaxNumber (final Contact contact, final Country faxCountry, final Integer faxAreaCode, final Long faxNumber) { + // At least contact must be valid + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } + + // Default is not unlinked + boolean isUnlinked = false; + + // Is there a fax instance? + if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { + // Found existing fax number, remove it? + if ((null == faxCountry) || (null == faxAreaCode) || (null == faxNumber)) { + // Remove existing instance + contact.setContactFaxNumber(null); + + // Mark it as being removed + isUnlinked = true; + } else { + // Set all data + contact.getContactFaxNumber().setPhoneCountry(faxCountry); + contact.getContactFaxNumber().setPhoneAreaCode(faxAreaCode); + contact.getContactFaxNumber().setPhoneNumber(faxNumber); + } + } else if ((faxCountry instanceof Country) && (faxAreaCode > 0) && (faxNumber > 0)) { + // Set new land-line number + DialableFaxNumber fax = new FaxNumber(faxCountry, faxAreaCode, faxNumber); + + // Set it in contact + contact.setContactFaxNumber(fax); } // Return status @@ -88,7 +143,7 @@ public class ContactUtils extends BaseFrameworkSystem { * @param phoneAreaCode New phone's area code (or old) * @param phoneNumber New phone number (or old) *

- * @return Whether the land-line has been unlinked in contact object + * @return Whether the land-line number has been unlinked in contact object */ public static boolean updateLandLineNumber (final Contact contact, final Country phoneCountry, final Integer phoneAreaCode, final Long phoneNumber) { // At least contact must be valid @@ -117,10 +172,10 @@ public class ContactUtils extends BaseFrameworkSystem { } } else if ((phoneCountry instanceof Country) && (phoneAreaCode > 0) && (phoneNumber > 0)) { // Set new land-line number - DialableLandLineNumber landLineNumber = new LandLineNumber(phoneCountry, phoneAreaCode, phoneNumber); + DialableLandLineNumber landLine = new LandLineNumber(phoneCountry, phoneAreaCode, phoneNumber); // Set it in contact - contact.setContactLandLineNumber(landLineNumber); + contact.setContactLandLineNumber(landLine); } // Return status -- 2.39.5