2 * Copyright (C) 2016 Roland Haeder
\r
4 * This program is free software: you can redistribute it and/or modify
\r
5 * it under the terms of the GNU General Public License as published by
\r
6 * the Free Software Foundation, either version 3 of the License, or
\r
7 * (at your option) any later version.
\r
9 * This program is distributed in the hope that it will be useful,
\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License
\r
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
17 package org.mxchange.jcontacts.contact.utils;
\r
19 import org.mxchange.jcontacts.contact.Contact;
\r
20 import org.mxchange.jcore.BaseFrameworkSystem;
\r
21 import org.mxchange.jcountry.data.Country;
\r
22 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
\r
23 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
\r
24 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
\r
25 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
\r
26 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
\r
29 * Utilities for contacts
\r
31 * @author Roland Haeder<roland@mxchange.org>
\r
33 public class ContactUtils extends BaseFrameworkSystem {
\r
36 * Updates cellphone data in contact instance. This method also removes the
\r
37 * cellphone instance if no provider is selected. A bean (mostly EJB) should
\r
38 * then make sure that the cellphone entry is being unlinked from contact
\r
39 * instance or being removed, if no longer used.
\r
41 * @param contact Contact instance to update
\r
42 * @param cellphoneProvider New cellphone provider (or old)
\r
43 * @param cellphoneNumber New cellphone number (or old)
\r
45 * @return Whether the cellphone has been unlinked in contact object
\r
47 public static boolean updateCellPhoneNumber (final Contact contact, final MobileProvider cellphoneProvider, final Long cellphoneNumber) {
\r
48 // At least contact must be valid
\r
49 if (null == contact) {
\r
51 throw new NullPointerException("contact is null"); //NOI18N
\r
54 // Default is not unlinked
\r
55 boolean isUnlinked = false;
\r
57 // Is there a cellphone number?
\r
58 if (contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) {
\r
59 // Is provider null?
\r
60 if ((null == cellphoneProvider) || (null == cellphoneNumber) || (cellphoneNumber == 0)) {
\r
62 contact.setContactCellphoneNumber(null);
\r
67 // Yes, then update as well
\r
68 contact.getContactCellphoneNumber().setCellphoneProvider(cellphoneProvider);
\r
69 contact.getContactCellphoneNumber().setPhoneNumber(cellphoneNumber);
\r
71 } else if ((cellphoneProvider instanceof MobileProvider) && (cellphoneNumber > 0)) {
\r
72 // Create new instance
\r
73 DialableCellphoneNumber cellphone = new CellphoneNumber(cellphoneProvider, cellphoneNumber);
\r
81 * Updates land-line data in contact instance. This method also removes the
\r
82 * land-line instance if no country is selected. A bean (mostly EJB) should
\r
83 * then make sure that the land-line entry is being unlinked from contact
\r
84 * instance or being removed, if no longer used.
\r
86 * @param contact Contact instance being updated
\r
87 * @param phoneCountry New phone country or old or null
\r
88 * @param phoneAreaCode New phone's area code (or old)
\r
89 * @param phoneNumber New phone number (or old)
\r
91 * @return Whether the land-line has been unlinked in contact object
\r
93 public static boolean updateLandLineNumber (final Contact contact, final Country phoneCountry, final Integer phoneAreaCode, final Long phoneNumber) {
\r
94 // At least contact must be valid
\r
95 if (null == contact) {
\r
97 throw new NullPointerException("contact is null"); //NOI18N
\r
100 // Default is not unlinked
\r
101 boolean isUnlinked = false;
\r
103 // Is there a land-line instance?
\r
104 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
\r
105 // Found existing land-line number, remove it?
\r
106 if ((null == phoneCountry) || (null == phoneAreaCode) || (null == phoneNumber)) {
\r
107 // Remove existing instance
\r
108 contact.setContactLandLineNumber(null);
\r
110 // Mark it as being removed
\r
114 contact.getContactLandLineNumber().setPhoneCountry(phoneCountry);
\r
115 contact.getContactLandLineNumber().setPhoneAreaCode(phoneAreaCode);
\r
116 contact.getContactLandLineNumber().setPhoneNumber(phoneNumber);
\r
118 } else if ((phoneCountry instanceof Country) && (phoneAreaCode > 0) && (phoneNumber > 0)) {
\r
119 // Set new land-line number
\r
120 DialableLandLineNumber landLineNumber = new LandLineNumber(phoneCountry, phoneAreaCode, phoneNumber);
\r
122 // Set it in contact
\r
123 contact.setContactLandLineNumber(landLineNumber);
\r
131 * Private constructor for utilities
\r
133 private ContactUtils () {
\r