X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Fjcontacts%2Fcontact%2FUserContact.java;h=c4f6ba74bb906fd3a7b4ed4756292aeed076e428;hb=f67911d2934adfe8a9b5b4f46753a7a24a0dd513;hp=b1daf29b463fe388f1b192694e929bd5e749fee3;hpb=00498185e1656dd0d4c2b10e0edbe6ac9161d71f;p=jcontacts-core.git diff --git a/src/org/mxchange/jcontacts/contact/UserContact.java b/src/org/mxchange/jcontacts/contact/UserContact.java index b1daf29..c4f6ba7 100644 --- a/src/org/mxchange/jcontacts/contact/UserContact.java +++ b/src/org/mxchange/jcontacts/contact/UserContact.java @@ -19,7 +19,6 @@ package org.mxchange.jcontacts.contact; import java.util.Calendar; import java.util.Date; import java.util.Objects; -import javax.annotation.PostConstruct; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -32,6 +31,8 @@ import javax.persistence.Id; import javax.persistence.Index; import javax.persistence.JoinColumn; import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Temporal; @@ -59,15 +60,20 @@ import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; @Index ( name = "contact_gender", columnList = "contact_gender" - ), - @Index ( - name = "contact_email_address", - unique = true, - columnList = "contact_email_address" ) } ) -public class UserContact implements Contact, Comparable { +@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.contactCellphoneNumber = :cellPhone ORDER BY c.contactId ASC"), + @NamedQuery (name = "SearchContactById", query = "SELECT c FROM contacts AS c WHERE c.contactId = :contactId"), + @NamedQuery (name = "SearchContactByEmailAddress", query = "SELECT c FROM contacts AS c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:emailAddress)") + } +) +@SuppressWarnings ("PersistenceUnitPresent") +public class UserContact implements Contact { /** * Serial number @@ -120,8 +126,7 @@ public class UserContact implements Contact, Comparable { /** * Email address */ - @Basic (optional = false) - @Column (name = "contact_email_address", length = 100, nullable = false) + @Column (name = "contact_email_address", length = 100, unique = true) private String contactEmailAddress; /** @@ -157,15 +162,21 @@ public class UserContact implements Contact, Comparable { * House number */ @Basic (optional = false) - @Column (name = "contact_house_number", length = 5, nullable = false) + @Column (name = "contact_house_number", nullable = false) private Short contactHouseNumber; + /** + * House number extension + */ + @Column (name = "contact_house_number_extension", length = 5) + private String contactHouseNumberExtension; + /** * Id number */ @Id @GeneratedValue (strategy = GenerationType.IDENTITY) - @Column (name = "contact_id", length = 20, nullable = false, updatable = false) + @Column (name = "contact_id", nullable = false, updatable = false) private Long contactId; /** @@ -209,15 +220,23 @@ public class UserContact implements Contact, Comparable { @Column (name = "contact_zip_code", nullable = false, length = 6) private Integer contactZipCode; + /** + * Default constructor + */ + public UserContact () { + // Default is not user's own contact + this.contactOwnContact = Boolean.FALSE; + } + /** * Constructor for contactGender and names *

- * @param contactGender Gender instance - * @param contactFirstName First name + * @param contactGender Gender instance + * @param contactFirstName First name * @param contactFamilyName Family name */ public UserContact (final Gender contactGender, final String contactFirstName, final String contactFamilyName) { - // Call other constructor + // Call default constructor this(); // Set all @@ -226,41 +245,23 @@ public class UserContact implements Contact, Comparable { this.contactFamilyName = contactFamilyName; } - /** - * Default constructor - */ - public UserContact () { - // Default is not user's own contact - this.contactOwnContact = Boolean.FALSE; - } - @Override - public int compareTo (final Contact contact) { - // contact should not be null + public void copyAll (final Contact contact) { + // Contact should be valid if (null == contact) { + // Throw NPE throw new NullPointerException("contact is null"); //NOI18N } - // Is the contactId the same? - if (Objects.equals(this.getContactId(), contact.getContactId())) { - // Same contactId, means same contact - return 0; - } else if (this.getContactId() > contact.getContactId()) { - // This contactId is larger than compared to - return -1; - } - - // The other contactId is larger - return 1; - } - - @Override - public void copyAll (final Contact contact) { // Copy all: // - base data + this.setContactGender(contact.getContactGender()); + 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()); @@ -279,42 +280,56 @@ public class UserContact implements Contact, Comparable { @Override public boolean equals (final Object object) { - // Is it same type? - if (!(object instanceof UserContact)) { - // Not equal types + if (this == object) { + return true; + } else if (null == object) { + return false; + } else if (this.getClass() != object.getClass()) { return false; } else if (!(object instanceof Contact)) { // Not correct interface return false; } - // Try to cast - Contact contact = (Contact) object; + final Contact other = (Contact) object; - // Now test some data TODO Definedly needs improvement - return ((this.getContactGender().equals(contact.getContactGender())) && - (this.getContactFirstName().toLowerCase().equals(contact.getContactFirstName().toLowerCase())) && - (this.getContactFamilyName().toLowerCase().equals(contact.getContactFamilyName().toLowerCase()))); - } - - @Override - public int hashCode () { - // Validate contactGender instance - assert (this.getContactGender() instanceof Gender) : "gender is not set."; //NOI18N + if (!Objects.equals(this.getContactCity(), other.getContactCity())) { + return false; + } else if (!Objects.equals(this.getContactEmailAddress(), other.getContactEmailAddress())) { + return false; + } else if (!Objects.equals(this.getContactFamilyName(), other.getContactFamilyName())) { + return false; + } else if (!Objects.equals(this.getContactFirstName(), other.getContactFirstName())) { + return false; + } else if (!Objects.equals(this.getContactStreet(), other.getContactStreet())) { + return false; + } else if (!Objects.equals(this.getContactTitle(), other.getContactTitle())) { + return false; + } else if (!Objects.equals(this.getContactBirthday(), other.getContactBirthday())) { + return false; + } else if (!Objects.equals(this.getContactCountry(), other.getContactCountry())) { + return false; + } else if (this.getContactGender() != other.getContactGender()) { + return false; + } else if (!Objects.equals(this.getContactHouseNumber(), other.getContactHouseNumber())) { + return false; + } else if (!Objects.equals(this.getContactHouseNumberExtension(), other.getContactHouseNumberExtension())) { + return false; + } else if (!Objects.equals(this.getContactId(), other.getContactId())) { + return false; + } - int hash = 7; - hash = 79 * hash + Objects.hashCode(this.getContactFamilyName()); - hash = 79 * hash + this.getContactGender().hashCode(); - hash = 79 * hash + Objects.hashCode(this.getContactFirstName()); - return hash; + return true; } @Override + @SuppressWarnings ("ReturnOfDateField") public Date getContactBirthday () { return this.contactBirthday; } @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") public void setContactBirthday (final Date contactBirthday) { this.contactBirthday = contactBirthday; } @@ -360,11 +375,13 @@ public class UserContact implements Contact, Comparable { } @Override + @SuppressWarnings ("ReturnOfDateField") public Calendar getContactCreated () { return this.contactCreated; } @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") public void setContactCreated (final Calendar contactCreated) { this.contactCreated = contactCreated; } @@ -430,6 +447,16 @@ public class UserContact implements Contact, Comparable { this.contactHouseNumber = contactHouseNumber; } + @Override + public String getContactHouseNumberExtension () { + return this.contactHouseNumberExtension; + } + + @Override + public void setContactHouseNumberExtension (final String contactHouseNumberExtension) { + this.contactHouseNumberExtension = contactHouseNumberExtension; + } + @Override public Long getContactId () { return this.contactId; @@ -440,11 +467,6 @@ public class UserContact implements Contact, Comparable { this.contactId = contactId; } - @Override - public void setContactOwnContact (final Boolean contactOwnContact) { - this.contactOwnContact = contactOwnContact; - } - @Override public DialableLandLineNumber getContactLandLineNumber () { return this.contactPhoneNumber; @@ -455,6 +477,11 @@ public class UserContact implements Contact, Comparable { this.contactPhoneNumber = contactPhoneNumber; } + @Override + public void setContactOwnContact (final Boolean contactOwnContact) { + this.contactOwnContact = contactOwnContact; + } + @Override public String getContactStreet () { return this.contactStreet; @@ -476,11 +503,13 @@ public class UserContact implements Contact, Comparable { } @Override + @SuppressWarnings ("ReturnOfDateField") public Calendar getContactUpdated () { return this.contactUpdated; } @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") public void setContactUpdated (final Calendar contactUpdated) { this.contactUpdated = contactUpdated; } @@ -495,17 +524,29 @@ public class UserContact implements Contact, Comparable { this.contactZipCode = contactZipCode; } - /** - * Initialization with fake contactGender UNKNOWN - */ - @PostConstruct - public void init () { - // Fake contactGender - this.contactGender = Gender.UNKNOWN; + @Override + public int hashCode () { + int hash = 5; + + hash = 29 * hash + Objects.hashCode(this.getContactBirthday()); + hash = 29 * hash + Objects.hashCode(this.getContactCity()); + hash = 29 * hash + Objects.hashCode(this.getContactCountry()); + hash = 29 * hash + Objects.hashCode(this.getContactEmailAddress()); + hash = 29 * hash + Objects.hashCode(this.getContactFamilyName()); + hash = 29 * hash + Objects.hashCode(this.getContactFirstName()); + hash = 29 * hash + Objects.hashCode(this.getContactGender()); + 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()); + + return hash; } @Override public Boolean isOwnContact () { return this.contactOwnContact; } + }