From 416bee92751427cc46095a206144328edf7bef9a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 23 Jun 2017 20:15:26 +0200 Subject: [PATCH] Continued a bit: - moved copyAll() away from POJO to utils class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../mxchange/jcontacts/contact/Contact.java | 7 --- .../contact/{utils => }/ContactUtils.java | 44 ++++++++++++++++++- .../jcontacts/contact/UserContact.java | 33 -------------- 3 files changed, 42 insertions(+), 42 deletions(-) rename src/org/mxchange/jcontacts/contact/{utils => }/ContactUtils.java (82%) diff --git a/src/org/mxchange/jcontacts/contact/Contact.java b/src/org/mxchange/jcontacts/contact/Contact.java index 649fd82..47381e2 100644 --- a/src/org/mxchange/jcontacts/contact/Contact.java +++ b/src/org/mxchange/jcontacts/contact/Contact.java @@ -32,13 +32,6 @@ import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; */ public interface Contact extends Serializable { - /** - * Copies all attributes from other contact object to this - *

- * @param contact Source instance - */ - void copyAll (final Contact contact); - /** * Birth day *

diff --git a/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java b/src/org/mxchange/jcontacts/contact/ContactUtils.java similarity index 82% rename from src/org/mxchange/jcontacts/contact/utils/ContactUtils.java rename to src/org/mxchange/jcontacts/contact/ContactUtils.java index 1f4f02e..7cc6f12 100644 --- a/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java +++ b/src/org/mxchange/jcontacts/contact/ContactUtils.java @@ -14,11 +14,10 @@ * 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; +package org.mxchange.jcontacts.contact; import java.io.Serializable; import java.util.Objects; -import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcountry.data.Country; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.phonenumbers.fax.FaxNumber; @@ -40,6 +39,47 @@ public class ContactUtils implements Serializable { */ private static final long serialVersionUID = 26_785_734_719_670L; + /** + * Copies all attributes from other contact object to this + *

+ * @param sourceContact Source instance + * @param targetContact Target instance + */ + public static void copyAll (final Contact sourceContact, final Contact targetContact) { + // Contact should be valid + if (null == sourceContact) { + // Throw NPE + throw new NullPointerException("sourceContact is null"); //NOI18N + } else if (null == targetContact) { + // Throw NPE + throw new NullPointerException("targetContact is null"); //NOI18N + } + + // Copy all: + // - base data + targetContact.setContactPersonalTitle(sourceContact.getContactPersonalTitle()); + targetContact.setContactTitle(sourceContact.getContactTitle()); + targetContact.setContactFirstName(sourceContact.getContactFirstName()); + targetContact.setContactFamilyName(sourceContact.getContactFamilyName()); + targetContact.setContactStreet(sourceContact.getContactStreet()); + targetContact.setContactHouseNumber(sourceContact.getContactHouseNumber()); + targetContact.setContactHouseNumberExtension(sourceContact.getContactHouseNumberExtension()); + targetContact.setContactZipCode(sourceContact.getContactZipCode()); + targetContact.setContactCity(sourceContact.getContactCity()); + targetContact.setContactCountry(sourceContact.getContactCountry()); + + // - phone, fax, email + targetContact.setContactLandLineNumber(sourceContact.getContactLandLineNumber()); + targetContact.setContactFaxNumber(sourceContact.getContactFaxNumber()); + targetContact.setContactMobileNumber(sourceContact.getContactMobileNumber()); + + // - other data + targetContact.setContactBirthday(sourceContact.getContactBirthday()); + targetContact.setContactComment(sourceContact.getContactComment()); + targetContact.setContactCreated(sourceContact.getContactCreated()); + targetContact.setContactUpdated(sourceContact.getContactUpdated()); + } + /** * Checks whether both contacts are same, but ignoring id number. If you * want to include id number in comparison, better use Objects.equals() as diff --git a/src/org/mxchange/jcontacts/contact/UserContact.java b/src/org/mxchange/jcontacts/contact/UserContact.java index 29a2c7b..b3e0c0b 100644 --- a/src/org/mxchange/jcontacts/contact/UserContact.java +++ b/src/org/mxchange/jcontacts/contact/UserContact.java @@ -247,39 +247,6 @@ public class UserContact implements Contact { this.contactFamilyName = contactFamilyName; } - @Override - public void copyAll (final Contact contact) { - // Contact should be valid - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } - - // Copy all: - // - base data - this.setContactPersonalTitle(contact.getContactPersonalTitle()); - this.setContactTitle(contact.getContactTitle()); - this.setContactFirstName(contact.getContactFirstName()); - this.setContactFamilyName(contact.getContactFamilyName()); - this.setContactStreet(contact.getContactStreet()); - this.setContactHouseNumber(contact.getContactHouseNumber()); - this.setContactHouseNumberExtension(contact.getContactHouseNumberExtension()); - this.setContactZipCode(contact.getContactZipCode()); - this.setContactCity(contact.getContactCity()); - this.setContactCountry(contact.getContactCountry()); - - // - phone, fax, email - this.setContactLandLineNumber(contact.getContactLandLineNumber()); - this.setContactFaxNumber(contact.getContactFaxNumber()); - this.setContactMobileNumber(contact.getContactMobileNumber()); - - // - other data - this.setContactBirthday(contact.getContactBirthday()); - this.setContactComment(contact.getContactComment()); - this.setContactCreated(contact.getContactCreated()); - this.setContactUpdated(contact.getContactUpdated()); - } - @Override public boolean equals (final Object object) { if (this == object) { -- 2.39.5