]> git.mxchange.org Git - jcontacts-core.git/commitdiff
Added method updateFaxNumber() to add/update/delete fax number
authorRoland Häder <roland@mxchange.org>
Fri, 22 Apr 2016 08:56:44 +0000 (10:56 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 22 Apr 2016 08:56:44 +0000 (10:56 +0200)
src/org/mxchange/jcontacts/contact/utils/ContactUtils.java

index 11ae89e4890bdecb8816cef70644a804ace0133e..3718069e547b3e44901dcc9e21343f5a1ecf5a0c 100644 (file)
@@ -21,6 +21,8 @@ import org.mxchange.jcore.BaseFrameworkSystem;
 import org.mxchange.jcountry.data.Country;\r
 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;\r
 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;\r
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;\r
+import org.mxchange.jphone.phonenumbers.fax.FaxNumber;\r
 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;\r
 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;\r
 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;\r
@@ -71,6 +73,59 @@ public class ContactUtils extends BaseFrameworkSystem {
                } else if ((cellphoneProvider instanceof MobileProvider) && (cellphoneNumber > 0)) {\r
                        // Create new instance\r
                        DialableCellphoneNumber cellphone = new CellphoneNumber(cellphoneProvider, cellphoneNumber);\r
+\r
+                       // Set it in contact\r
+                       contact.setContactCellphoneNumber(cellphone);\r
+               }\r
+\r
+               // Return status\r
+               return isUnlinked;\r
+       }\r
+\r
+       /**\r
+        * Updates land-line data in contact instance. This method also removes the\r
+        * land-line instance if no country is selected. A bean (mostly EJB) should\r
+        * then make sure that the land-line entry is being unlinked from contact\r
+        * instance or being removed, if no longer used.\r
+        * <p>\r
+        * @param contact     Contact instance being updated\r
+        * @param faxCountry  Updated fax number or null\r
+        * @param faxAreaCode Updated fax area code or null\r
+        * @param faxNumber   Updated fax number\r
+        * <p>\r
+        * @return Whether the fax number has been unlinked in contact object\r
+        */\r
+       public static boolean updateFaxNumber (final Contact contact, final Country faxCountry, final Integer faxAreaCode, final Long faxNumber) {\r
+               // At least contact must be valid\r
+               if (null == contact) {\r
+                       // Throw NPE\r
+                       throw new NullPointerException("contact is null"); //NOI18N\r
+               }\r
+\r
+               // Default is not unlinked\r
+               boolean isUnlinked = false;\r
+\r
+               // Is there a fax instance?\r
+               if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {\r
+                       // Found existing fax number, remove it?\r
+                       if ((null == faxCountry) || (null == faxAreaCode) || (null == faxNumber)) {\r
+                               // Remove existing instance\r
+                               contact.setContactFaxNumber(null);\r
+\r
+                               // Mark it as being removed\r
+                               isUnlinked = true;\r
+                       } else {\r
+                               // Set all data\r
+                               contact.getContactFaxNumber().setPhoneCountry(faxCountry);\r
+                               contact.getContactFaxNumber().setPhoneAreaCode(faxAreaCode);\r
+                               contact.getContactFaxNumber().setPhoneNumber(faxNumber);\r
+                       }\r
+               } else if ((faxCountry instanceof Country) && (faxAreaCode > 0) && (faxNumber > 0)) {\r
+                       // Set new land-line number\r
+                       DialableFaxNumber fax = new FaxNumber(faxCountry, faxAreaCode, faxNumber);\r
+\r
+                       // Set it in contact\r
+                       contact.setContactFaxNumber(fax);\r
                }\r
 \r
                // Return status\r
@@ -88,7 +143,7 @@ public class ContactUtils extends BaseFrameworkSystem {
         * @param phoneAreaCode New phone's area code (or old)\r
         * @param phoneNumber   New phone number (or old)\r
         * <p>\r
-        * @return Whether the land-line has been unlinked in contact object\r
+        * @return Whether the land-line number has been unlinked in contact object\r
         */\r
        public static boolean updateLandLineNumber (final Contact contact, final Country phoneCountry, final Integer phoneAreaCode, final Long phoneNumber) {\r
                // At least contact must be valid\r
@@ -117,10 +172,10 @@ public class ContactUtils extends BaseFrameworkSystem {
                        }\r
                } else if ((phoneCountry instanceof Country) && (phoneAreaCode > 0) && (phoneNumber > 0)) {\r
                        // Set new land-line number\r
-                       DialableLandLineNumber landLineNumber = new LandLineNumber(phoneCountry, phoneAreaCode, phoneNumber);\r
+                       DialableLandLineNumber landLine = new LandLineNumber(phoneCountry, phoneAreaCode, phoneNumber);\r
 \r
                        // Set it in contact\r
-                       contact.setContactLandLineNumber(landLineNumber);\r
+                       contact.setContactLandLineNumber(landLine);\r
                }\r
 \r
                // Return status\r