From 5890820c21afa3bb6af1cfb93f6ad11f61160acb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 27 May 2016 10:54:27 +0200 Subject: [PATCH] Continued: - added house number extension (e.g. 123a and 'a' is the extension) - equals/hashCode() did not really check for object-equality, it checked only for contact-equality which is not the same - sorted members --- .../mxchange/jcontacts/contact/Contact.java | 15 +++ .../jcontacts/contact/UserContact.java | 105 +++++++++++++----- 2 files changed, 92 insertions(+), 28 deletions(-) diff --git a/src/org/mxchange/jcontacts/contact/Contact.java b/src/org/mxchange/jcontacts/contact/Contact.java index 0832aed..5a0489e 100644 --- a/src/org/mxchange/jcontacts/contact/Contact.java +++ b/src/org/mxchange/jcontacts/contact/Contact.java @@ -207,6 +207,21 @@ public interface Contact extends Serializable { */ void setContactGender (final Gender gender); + /** + * Getter for house number extension, example: 123a 'a' is then the + * extension and 123 is the house number. + *

+ * @return House number extension + */ + String getContactHouseNumberExtension (); + + /** + * Setter for house number extension + *

+ * @param contactHouseNumberExtension House number extension + */ + void setContactHouseNumberExtension (final String contactHouseNumberExtension); + /** * House number *

diff --git a/src/org/mxchange/jcontacts/contact/UserContact.java b/src/org/mxchange/jcontacts/contact/UserContact.java index fe17b21..3312c8f 100644 --- a/src/org/mxchange/jcontacts/contact/UserContact.java +++ b/src/org/mxchange/jcontacts/contact/UserContact.java @@ -162,9 +162,15 @@ public class UserContact implements Contact { * 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 */ @@ -252,9 +258,13 @@ public class UserContact implements 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()); @@ -273,37 +283,46 @@ public class UserContact implements Contact { @Override public boolean equals (final Object object) { - // Is it same type? - if (null == object) { - // Is null + if (this == object) { + return true; + } else if (null == object) { return false; - } else if (!(object instanceof UserContact)) { - // Not equal types + } 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 @@ -431,6 +450,16 @@ public class UserContact implements Contact { 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; @@ -441,11 +470,6 @@ public class UserContact implements Contact { this.contactId = contactId; } - @Override - public void setContactOwnContact (final Boolean contactOwnContact) { - this.contactOwnContact = contactOwnContact; - } - @Override public DialableLandLineNumber getContactLandLineNumber () { return this.contactPhoneNumber; @@ -456,6 +480,11 @@ public class UserContact implements Contact { this.contactPhoneNumber = contactPhoneNumber; } + @Override + public void setContactOwnContact (final Boolean contactOwnContact) { + this.contactOwnContact = contactOwnContact; + } + @Override public String getContactStreet () { return this.contactStreet; @@ -498,6 +527,26 @@ public class UserContact implements Contact { this.contactZipCode = contactZipCode; } + @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; -- 2.39.5