From: Roland Häder Date: Thu, 21 Apr 2016 15:59:07 +0000 (+0200) Subject: added utils class for contacts X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=aca4147a282f267fc8f419bd6cbd4759b362c5ff;p=jcontacts-core.git added utils class for contacts --- diff --git a/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java b/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java new file mode 100644 index 0000000..db2d6cc --- /dev/null +++ b/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontacts.contact.utils; + +import java.text.MessageFormat; +import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcore.BaseFrameworkSystem; +import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber; +import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; +import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; + +/** + * Utilities for contacts + *

+ * @author Roland Haeder + */ +public class ContactUtils extends BaseFrameworkSystem { + + public static void updateCellPhoneNumber (final Contact contact, final MobileProvider cellphoneProvider, final Long cellphoneNumber) { + // Is there a cellphone number? + if (contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) { + // Debug message + System.out.println(MessageFormat.format("updateCellPhoneNumber: cellPhoneId={0}", contact.getContactCellphoneNumber().getPhoneId())); //NOI18N + + // Is provider null? + if (null == cellphoneProvider) { + // Remove instance + contact.setContactCellphoneNumber(null); + } else { + // Yes, then update as well + contact.getContactCellphoneNumber().setCellphoneProvider(cellphoneProvider); + contact.getContactCellphoneNumber().setPhoneNumber(cellphoneNumber); + } + } else if ((cellphoneProvider instanceof MobileProvider) && (cellphoneNumber > 0)) { + // Create new instance + DialableCellphoneNumber cellphone = new CellphoneNumber(cellphoneProvider, cellphoneNumber); + } + } + + /** + * Private constructor for utilities + */ + private ContactUtils () { + } + +}