X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Fjcontacts%2Fcontact%2FUserContact.java;h=c4f6ba74bb906fd3a7b4ed4756292aeed076e428;hb=f67911d2934adfe8a9b5b4f46753a7a24a0dd513;hp=47554565789d91bf89924f6fbe5d043b7e9e625f;hpb=a4a43cf6db10c0552a783a9899a2824c1657d0b8;p=jcontacts-core.git diff --git a/src/org/mxchange/jcontacts/contact/UserContact.java b/src/org/mxchange/jcontacts/contact/UserContact.java index 4755456..c4f6ba7 100644 --- a/src/org/mxchange/jcontacts/contact/UserContact.java +++ b/src/org/mxchange/jcontacts/contact/UserContact.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Roland Haeder + * Copyright (C) 2016 Roland Haeder * * 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 @@ -19,8 +19,8 @@ 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; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -28,21 +28,52 @@ import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; 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; import javax.persistence.TemporalType; import org.mxchange.jcontacts.contact.gender.Gender; +import org.mxchange.jcountry.data.Country; +import org.mxchange.jcountry.data.CountryData; +import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber; +import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.fax.FaxNumber; +import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; /** - * A general contact class which should only be extended. + * A general contact class which serves as an entity. *
* @author Roland Haeder
- * @param gender Gender instance
- * @param firstName First name
- * @param familyName Family name
- * @param companyName Company name
+ * ZIP code
*/
- public UserContact (final Gender gender, final String firstName, final String familyName, final String companyName) {
- // Set all
- this.gender = gender;
- this.firstName = firstName;
- this.familyName = familyName;
- }
+ @Basic (optional = false)
+ @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;
}
/**
- * Compares two contacts with each other
+ * Constructor for contactGender and names
*
- * @param contact Contact comparator
- * @return Comparison value
+ * @param contactGender Gender instance
+ * @param contactFirstName First name
+ * @param contactFamilyName Family name
*/
- @Override
- public int compareTo (final Contact contact) {
- // contact should not be null
- if (null == contact) {
- throw new NullPointerException("contact is null"); //NOI18N
- }
+ public UserContact (final Gender contactGender, final String contactFirstName, final String contactFamilyName) {
+ // Call default constructor
+ this();
- // 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;
+ // Set all
+ this.contactGender = contactGender;
+ this.contactFirstName = contactFirstName;
+ 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.setFirstName(contact.getFirstName());
- this.setFamilyName(contact.getFamilyName());
- this.setCompanyName(contact.getCompanyName());
- this.setStreet(contact.getStreet());
- this.setZipCode(contact.getZipCode());
- this.setCity(contact.getCity());
- this.setCountryCode(contact.getCountryCode());
+ 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());
// - phone, fax, email
- this.setPhoneNumber(contact.getPhoneNumber());
- this.setFaxNumber(contact.getFaxNumber());
- this.setCellphoneNumber(contact.getCellphoneNumber());
+ this.setContactLandLineNumber(contact.getContactLandLineNumber());
+ this.setContactFaxNumber(contact.getContactFaxNumber());
+ this.setContactCellphoneNumber(contact.getContactCellphoneNumber());
// - other data
- this.setBirthday(contact.getBirthday());
- this.setComment(contact.getComment());
- this.setCreated(contact.getCreated());
- this.setUpdated(contact.getUpdated());
+ this.setContactBirthday(contact.getContactBirthday());
+ this.setContactComment(contact.getContactComment());
+ this.setContactCreated(contact.getContactCreated());
+ this.setContactUpdated(contact.getContactUpdated());
}
- /**
- * Check if contacts are same or throw an exception
- *
- * @param object Other possible contact class
- * @return Whether both contacts are same TODO Needs a lot improvements
- */
@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;
+
+ 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;
+ }
- // Now test some data TODO Definedly needs improvement
- return ((this.getGender().equals(contact.getGender()))
- && (this.getFirstName().toLowerCase().equals(contact.getFirstName().toLowerCase()))
- && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
+ return true;
}
@Override
- public Date getBirthday () {
- return this.birthday;
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getContactBirthday () {
+ return this.contactBirthday;
}
@Override
- public void setBirthday (final Date birthday) {
- this.birthday = birthday;
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setContactBirthday (final Date contactBirthday) {
+ this.contactBirthday = contactBirthday;
}
@Override
- public String getCellphoneNumber () {
- return this.cellphoneNumber;
+ public DialableCellphoneNumber getContactCellphoneNumber () {
+ return this.contactCellphoneNumber;
}
@Override
- public void setCellphoneNumber (final String cellphoneNumber) {
- this.cellphoneNumber = cellphoneNumber;
+ public void setContactCellphoneNumber (final DialableCellphoneNumber contactCellphoneNumber) {
+ this.contactCellphoneNumber = contactCellphoneNumber;
}
@Override
- public String getCity () {
- return this.city;
+ public String getContactCity () {
+ return this.contactCity;
}
@Override
- public void setCity (final String city) {
- this.city = city;
+ public void setContactCity (final String contactCity) {
+ this.contactCity = contactCity;
}
@Override
- public String getComment () {
- return this.comment;
+ public String getContactComment () {
+ return this.contactComment;
}
@Override
- public void setComment (final String comment) {
- this.comment = comment;
+ public void setContactComment (final String contactComment) {
+ this.contactComment = contactComment;
}
@Override
- public String getCompanyName () {
- return this.companyName;
+ public Country getContactCountry () {
+ return this.contactCountry;
}
@Override
- public void setCompanyName (final String companyName) {
- this.companyName = companyName;
+ public void setContactCountry (final Country contactCountry) {
+ this.contactCountry = contactCountry;
}
@Override
- public Long getContactId () {
- return this.contactId;
+ @SuppressWarnings ("ReturnOfDateField")
+ public Calendar getContactCreated () {
+ return this.contactCreated;
}
@Override
- public void setContactId (final Long contactId) {
- this.contactId = contactId;
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setContactCreated (final Calendar contactCreated) {
+ this.contactCreated = contactCreated;
}
@Override
- public String getCountryCode () {
- return this.countryCode;
+ public String getContactEmailAddress () {
+ return this.contactEmailAddress;
}
@Override
- public void setCountryCode (final String countryCode) {
- this.countryCode = countryCode;
+ public void setContactEmailAddress (final String contactEmailAddress) {
+ this.contactEmailAddress = contactEmailAddress;
}
@Override
- public Calendar getCreated () {
- return this.created;
+ public String getContactFamilyName () {
+ //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!");
+ return this.contactFamilyName;
}
@Override
- public void setCreated (final Calendar created) {
- this.created = created;
+ public void setContactFamilyName (final String contactFamilyName) {
+ this.contactFamilyName = contactFamilyName;
}
@Override
- public String getEmailAddress () {
- return this.emailAddress;
+ public DialableFaxNumber getContactFaxNumber () {
+ return this.contactFaxNumber;
}
@Override
- public void setEmailAddress (final String emailAddress) {
- this.emailAddress = emailAddress;
+ public void setContactFaxNumber (final DialableFaxNumber contactFaxNumber) {
+ this.contactFaxNumber = contactFaxNumber;
}
@Override
- public String getFamilyName () {
- //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!");
- return this.familyName;
+ public String getContactFirstName () {
+ return this.contactFirstName;
}
@Override
- public void setFamilyName (final String familyName) {
- this.familyName = familyName;
+ public void setContactFirstName (final String contactFirstName) {
+ this.contactFirstName = contactFirstName;
}
@Override
- public String getFaxNumber () {
- return this.faxNumber;
+ public Gender getContactGender () {
+ return this.contactGender;
}
@Override
- public void setFaxNumber (final String faxNumber) {
- this.faxNumber = faxNumber;
+ public void setContactGender (final Gender contactGender) {
+ this.contactGender = contactGender;
}
@Override
- public String getFirstName () {
- return this.firstName;
+ public Short getContactHouseNumber () {
+ return this.contactHouseNumber;
}
@Override
- public void setFirstName (final String firstName) {
- this.firstName = firstName;
+ public void setContactHouseNumber (final Short contactHouseNumber) {
+ this.contactHouseNumber = contactHouseNumber;
}
@Override
- public Gender getGender () {
- return this.gender;
+ public String getContactHouseNumberExtension () {
+ return this.contactHouseNumberExtension;
}
@Override
- public void setGender (final Gender gender) {
- this.gender = gender;
+ public void setContactHouseNumberExtension (final String contactHouseNumberExtension) {
+ this.contactHouseNumberExtension = contactHouseNumberExtension;
}
@Override
- public Short getHouseNumber () {
- return this.houseNumber;
+ public Long getContactId () {
+ return this.contactId;
}
@Override
- public void setHouseNumber (final Short houseNumber) {
- this.houseNumber = houseNumber;
+ public void setContactId (final Long contactId) {
+ this.contactId = contactId;
}
@Override
- public void setOwnContact (final Boolean ownContact) {
- this.ownContact = ownContact;
+ public DialableLandLineNumber getContactLandLineNumber () {
+ return this.contactPhoneNumber;
}
@Override
- public String getPhoneNumber () {
- return this.phoneNumber;
+ public void setContactLandLineNumber (final DialableLandLineNumber contactPhoneNumber) {
+ this.contactPhoneNumber = contactPhoneNumber;
}
@Override
- public void setPhoneNumber (final String phoneNumber) {
- this.phoneNumber = phoneNumber;
+ public void setContactOwnContact (final Boolean contactOwnContact) {
+ this.contactOwnContact = contactOwnContact;
}
@Override
- public String getStreet () {
- return this.street;
+ public String getContactStreet () {
+ return this.contactStreet;
}
@Override
- public void setStreet (final String street) {
- this.street = street;
+ public void setContactStreet (final String contactStreet) {
+ this.contactStreet = contactStreet;
}
@Override
- public Calendar getUpdated () {
- return this.updated;
+ public String getContactTitle () {
+ return this.contactTitle;
}
@Override
- public void setUpdated (final Calendar updated) {
- this.updated = updated;
+ public void setContactTitle (final String contactTitle) {
+ this.contactTitle = contactTitle;
}
@Override
- public Long getZipCode () {
- return this.zipCode;
+ @SuppressWarnings ("ReturnOfDateField")
+ public Calendar getContactUpdated () {
+ return this.contactUpdated;
}
@Override
- public void setZipCode (final Long zipCode) {
- this.zipCode = zipCode;
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setContactUpdated (final Calendar contactUpdated) {
+ this.contactUpdated = contactUpdated;
}
@Override
- public int hashCode () {
- // Validate gender instance
- assert (this.getGender() instanceof Gender) : "gender is not set."; //NOI18N
+ public Integer getContactZipCode () {
+ return this.contactZipCode;
+ }
- int hash = 7;
- hash = 79 * hash + Objects.hashCode(this.getFamilyName());
- hash = 79 * hash + this.getGender().hashCode();
- hash = 79 * hash + Objects.hashCode(this.getFirstName());
- return hash;
+ @Override
+ public void setContactZipCode (final Integer contactZipCode) {
+ this.contactZipCode = contactZipCode;
}
- /**
- * Initialization with fake gender UNKNOWN
- */
- @PostConstruct
- public void init () {
- // Fake gender
- this.gender = 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.ownContact;
+ return this.contactOwnContact;
}
+
}