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
} 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
* @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
}\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