/*
- * 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
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;
)
@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")
@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
@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
*/
/**
* Constructor for title and names
* <p>
- * @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) {
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;
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
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;
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());