X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Fjcontacts%2Fmodel%2Fcontact%2FUserContact.java;h=3015382921f91550f989f39152d6cf83843b726b;hb=7df4118c9b2349af841c0d43d96fa1400084c7d4;hp=e885716de54a62ac98ce4609ed0da64f46f3e72d;hpb=7e6d77d5868c8d5fa5a38f109698654a51383182;p=jcontacts-core.git diff --git a/src/org/mxchange/jcontacts/model/contact/UserContact.java b/src/org/mxchange/jcontacts/model/contact/UserContact.java index e885716..3015382 100644 --- a/src/org/mxchange/jcontacts/model/contact/UserContact.java +++ b/src/org/mxchange/jcontacts/model/contact/UserContact.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Free Software Foundation + * Copyright (C) 2016 - 2020 Free Software Foundation * * 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 @@ -37,7 +37,10 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.apache.commons.lang3.StringUtils; import org.mxchange.jcontacts.model.contact.title.PersonalTitle; +import org.mxchange.jcoreutils.Comparables; +import org.mxchange.jcoreutils.SafeNumberUtils; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jcountry.model.data.CountryData; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; @@ -65,11 +68,7 @@ import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; ) @NamedQueries ( { - @NamedQuery (name = "AllContacts", query = "SELECT c FROM contacts AS c ORDER BY c.contactId ASC"), - @NamedQuery (name = "AllContactEmailAddresses", query = "SELECT c.contactEmailAddress FROM contacts AS c ORDER BY c.contactId ASC"), - @NamedQuery (name = "AllContactsByCellphone", query = "SELECT c FROM contacts AS c WHERE c.contactMobileNumber = :mobileNumber ORDER BY c.contactId ASC"), - @NamedQuery (name = "SearchContact", query = "SELECT c FROM contacts AS c WHERE c = :contact"), - @NamedQuery (name = "SearchContactByEmailAddress", query = "SELECT c FROM contacts AS c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:emailAddress)") + @NamedQuery (name = "AllContacts", query = "SELECT c FROM contacts AS c ORDER BY c.contactId ASC") } ) @SuppressWarnings ("PersistenceUnitPresent") @@ -108,19 +107,26 @@ public class UserContact implements Contact { @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false) private Country contactCountry; + /** + * Email address + */ + @Column (name = "contact_email_address", length = 100, unique = true) + private String contactEmailAddress; + /** * When the contact has been created */ @Basic (optional = false) @Temporal (TemporalType.TIMESTAMP) - @Column (name = "contact_created", nullable = false) - private Date contactCreated; + @Column (name = "contact_entry_created", nullable = false) + private Date contactEntryCreated; /** - * Email address + * When the contact has been updated */ - @Column (name = "contact_email_address", length = 100, unique = true) - private String contactEmailAddress; + @Temporal (TemporalType.TIMESTAMP) + @Column (name = "contact_entry_updated") + private Date contactEntryUpdated; /** * Family name @@ -204,13 +210,6 @@ public class UserContact implements Contact { @Column (name = "contact_title") private String contactTitle; - /** - * When the contact has been updated - */ - @Temporal (TemporalType.TIMESTAMP) - @Column (name = "contact_updated") - private Date contactUpdated; - /** * ZIP code */ @@ -228,20 +227,81 @@ public class UserContact implements Contact { /** * Constructor for title and names *

- * @param contactTitle Personal title - * @param contactFirstName First name - * @param contactFamilyName Family name + * @param contactPersonalTitle Personal title + * @param contactFirstName First name + * @param contactFamilyName Family name */ - public UserContact (final PersonalTitle contactTitle, final String contactFirstName, final String contactFamilyName) { - // Call default constructor + public UserContact (final PersonalTitle contactPersonalTitle, final String contactFirstName, final String contactFamilyName) { + // Invoke default constructor this(); + // Are all parameter set? + if (null == contactFamilyName) { + // Throw NPE + throw new NullPointerException("contactFamilyName is null"); //NOI18N + } else if (contactFamilyName.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("contactFamilyName is empty"); //NOI18N + } else if (null == contactFirstName) { + // Throw NPE + throw new NullPointerException("contactFirstName is null"); //NOI18N + } else if (contactFirstName.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("contactFirstName is empty"); //NOI18N + } else if (null == contactPersonalTitle) { + // Throw NPE + throw new NullPointerException("contactPersonalTitle is null"); //NOI18N + } + // Set all - this.contactPersonalTitle = contactTitle; + this.contactPersonalTitle = contactPersonalTitle; this.contactFirstName = contactFirstName; this.contactFamilyName = contactFamilyName; } + @Override + public int compareTo (final Contact contact) { + // Checkparameter and return 0 if equal + if (null == contact) { + // Should not happen + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.equals(this)) { + // Same object + return 0; + } + + // Init comparators + final int comparators[] = { + // First check country + this.getContactCountry().compareTo(contact.getContactCountry()), + // ... then ZIP code + SafeNumberUtils.compare(this.getContactZipCode(), contact.getContactZipCode()), + // ... and city + StringUtils.compare(this.getContactCity(), contact.getContactCity()), + // ... street name + StringUtils.compareIgnoreCase(this.getContactStreet(), contact.getContactStreet()), + // ... house number + SafeNumberUtils.compare(this.getContactHouseNumber(), contact.getContactHouseNumber()), + // ... extension + StringUtils.compareIgnoreCase(this.getContactHouseNumberExtension(), contact.getContactHouseNumberExtension()), + // ... now it is sure that address is different/same, continue with personal title + this.getContactPersonalTitle().compareTo(contact.getContactPersonalTitle()), + // ... academical title + StringUtils.compareIgnoreCase(this.getContactTitle(), contact.getContactTitle()), + // .. family name is next ... + this.getContactFamilyName().compareToIgnoreCase(contact.getContactFamilyName()), + // .. first name is second ... + this.getContactFirstName().compareToIgnoreCase(contact.getContactFirstName()), + // ... next is email address + StringUtils.compareIgnoreCase(this.getContactEmailAddress(), contact.getContactEmailAddress()),}; + + // Check all values + final int comparison = Comparables.checkAll(comparators); + + // Return value + return comparison; + } + @Override public boolean equals (final Object object) { if (this == object) { @@ -257,9 +317,7 @@ public class UserContact implements Contact { final Contact other = (Contact) object; - if (!Objects.equals(this.getContactId(), other.getContactId())) { - return false; - } else if (!Objects.equals(this.getContactCity(), other.getContactCity())) { + if (!Objects.equals(this.getContactCity(), other.getContactCity())) { return false; } else if (!Objects.equals(this.getContactEmailAddress(), other.getContactEmailAddress())) { return false; @@ -328,26 +386,38 @@ public class UserContact implements Contact { this.contactCountry = contactCountry; } + @Override + public String getContactEmailAddress () { + return this.contactEmailAddress; + } + + @Override + public void setContactEmailAddress (final String contactEmailAddress) { + this.contactEmailAddress = contactEmailAddress; + } + @Override @SuppressWarnings ("ReturnOfDateField") - public Date getContactCreated () { - return this.contactCreated; + public Date getContactEntryCreated () { + return this.contactEntryCreated; } @Override @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setContactCreated (final Date contactCreated) { - this.contactCreated = contactCreated; + public void setContactEntryCreated (final Date contactEntryCreated) { + this.contactEntryCreated = contactEntryCreated; } @Override - public String getContactEmailAddress () { - return this.contactEmailAddress; + @SuppressWarnings ("ReturnOfDateField") + public Date getContactEntryUpdated () { + return this.contactEntryUpdated; } @Override - public void setContactEmailAddress (final String contactEmailAddress) { - this.contactEmailAddress = contactEmailAddress; + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setContactEntryUpdated (final Date contactEntryUpdated) { + this.contactEntryUpdated = contactEntryUpdated; } @Override @@ -466,18 +536,6 @@ public class UserContact implements Contact { this.contactTitle = contactTitle; } - @Override - @SuppressWarnings ("ReturnOfDateField") - public Date getContactUpdated () { - return this.contactUpdated; - } - - @Override - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setContactUpdated (final Date contactUpdated) { - this.contactUpdated = contactUpdated; - } - @Override public Integer getContactZipCode () { return this.contactZipCode; @@ -501,7 +559,6 @@ public class UserContact implements Contact { hash = 29 * hash + Objects.hashCode(this.getContactPersonalTitle()); hash = 29 * hash + Objects.hashCode(this.getContactHouseNumber()); hash = 29 * hash + Objects.hashCode(this.getContactHouseNumberExtension()); - hash = 29 * hash + Objects.hashCode(this.getContactId()); hash = 29 * hash + Objects.hashCode(this.getContactStreet()); hash = 29 * hash + Objects.hashCode(this.getContactTitle());