2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jcore.model.contact;
19 import java.text.MessageFormat;
20 import java.util.Objects;
21 import org.mxchange.jcore.BaseFrameworkSystem;
22 import org.mxchange.jcore.client.Client;
23 import org.mxchange.jcore.model.contact.gender.Gender;
26 * A general contact class which should only be extended.
28 * @author Roland Haeder
31 public abstract class BaseContact extends BaseFrameworkSystem implements Contact, Comparable<Contact> {
36 private Long contactId;
41 private String birthday;
46 private String cellphoneNumber;
56 private String comment;
61 private String companyName;
66 private String countryCode;
71 private String emailAddress;
76 private String familyName;
81 private String faxNumber;
86 private String firstName;
91 private Gender gender;
96 private Long houseNumber;
99 * Flag whether this contact is user's own data
101 private boolean ownContact;
106 private String phoneNumber;
111 private String street;
116 private Long zipCode;
119 * No instances should be created of this class. Better extend this class
120 * and provide proper constructors.
122 protected BaseContact () {
124 this.gender = Gender.UNKNOWN;
128 * Check if contacts are same or throw an exception
130 * @param object Other possible contact class
131 * @return Whether both contacts are same
132 * TODO Needs a lot improvements
135 public boolean equals (final Object object) {
137 if (!(object instanceof BaseContact)) {
140 } else if (!(object instanceof Contact)) {
141 // Not correct interface
146 Contact contact = (Contact) object;
148 // Now test some data TODO Definedly needs improvement
149 return ((this.getGender().equals(contact.getGender()))
150 && (this.getFirstName().toLowerCase().equals(contact.getFirstName().toLowerCase()))
151 && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
157 * @return the birthday
160 public String getBirthday () {
161 return this.birthday;
167 * @param birthday the birthday to set
170 public void setBirthday (final String birthday) {
171 this.birthday = birthday;
177 * @return the cellphoneNumber
180 public String getCellphoneNumber () {
181 return this.cellphoneNumber;
187 * @param cellphoneNumber the cellphoneNumber to set
190 public void setCellphoneNumber (final String cellphoneNumber) {
191 this.cellphoneNumber = cellphoneNumber;
200 public String getCity () {
207 * @param city the city to set
210 public void setCity (final String city) {
217 * @return the comment
220 public String getComment () {
227 * @param comment the comment to set
230 public void setComment (final String comment) {
231 this.comment = comment;
237 * @return the companyName
240 public String getCompanyName () {
241 return this.companyName;
247 * @param companyName the companyName to set
250 public void setCompanyName (final String companyName) {
251 this.companyName = companyName;
256 * @return the contactId
259 public Long getContactId () {
260 return this.contactId;
265 * @param contactId the contactId to set
268 public void setContactId (final Long contactId) {
269 this.contactId = contactId;
275 * @return the countryCode
278 public String getCountryCode () {
279 return this.countryCode;
285 * @param countryCode the countryCode to set
288 public void setCountryCode (final String countryCode) {
289 this.countryCode = countryCode;
295 * @return the emailAddress
298 public String getEmailAddress () {
299 return this.emailAddress;
305 * @param emailAddress the emailAddress to set
308 public void setEmailAddress (final String emailAddress) {
309 this.emailAddress = emailAddress;
315 * @return the familyName
318 public String getFamilyName () {
319 //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!");
320 return this.familyName;
326 * @param familyName the familyName to set
329 public void setFamilyName (final String familyName) {
330 /* NOISY-DEBUG: */ this.getLogger().trace(MessageFormat.format("familyName={0} - CALLED!", familyName)); //NOI18N
331 this.familyName = familyName;
337 * @return the faxNumber
340 public String getFaxNumber () {
341 return this.faxNumber;
347 * @param faxNumber the faxNumber to set
350 public void setFaxNumber (final String faxNumber) {
351 this.faxNumber = faxNumber;
357 * @return the firstName
360 public String getFirstName () {
361 return this.firstName;
367 * @param firstName the firstName to set
370 public void setFirstName (final String firstName) {
371 this.firstName = firstName;
375 * Gender of the contact
380 public Gender getGender () {
385 * Gender of the contact
387 * @param gender the gender to set
390 public void setGender (final Gender gender) {
391 this.gender = gender;
397 * @return the houseNumber
400 public Long getHouseNumber () {
401 return this.houseNumber;
407 * @param houseNumber the houseNumber to set
410 public void setHouseNumber (final Long houseNumber) {
411 this.houseNumber = houseNumber;
417 * @return the phoneNumber
420 public String getPhoneNumber () {
421 return this.phoneNumber;
427 * @param phoneNumber the phoneNumber to set
430 public void setPhoneNumber (final String phoneNumber) {
431 this.phoneNumber = phoneNumber;
440 public String getStreet () {
447 * @param street the street to set
450 public void setStreet (final String street) {
451 this.street = street;
455 * Some "getter" for a translated/human-readable gender
457 * @return gender Human-readable gender
460 public String getTranslatedGender () {
462 String translated = this.getMessageStringFromKey(this.getGender().getMessageKey());
471 * @return the zipCode
474 public Long getZipCode () {
481 * @param zipCode the zipCode to set
484 public void setZipCode (final Long zipCode) {
485 this.zipCode = zipCode;
489 public int hashCode () {
490 // Validate gender instance
491 assert (this.getGender() instanceof Gender) : "gender is not set."; //NOI18N
494 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
495 hash = 79 * hash + this.getGender().hashCode();
496 hash = 79 * hash + Objects.hashCode(this.getFirstName());
501 * Checks whether the contact is user's own data
506 public boolean isOwnContact () {
507 return this.ownContact;
511 * Shows this contact to the user
513 * @param client Client instance to use
516 public void show (final Client client) {
518 this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N
520 // The client must be set
521 if (null == client) {
523 throw new NullPointerException("client is null"); //NOI18N
526 // Display name "box"
527 client.displayNameBox(this);
529 // Display address "box"
530 client.displayAddressBox(this);
532 // Display other data "box"
533 client.displayOtherDataBox(this);
537 * Enables the flag "own data" which signals that this contact is the user's
540 protected void enableFlagOwnContact () {
541 this.ownContact = true;
545 * Compares two contacts with each other
547 * @param contact Contact comparator
548 * @return Comparison value
551 public int compareTo (final Contact contact) {
553 this.getLogger().trace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
555 // contact should not be null
556 if (null == contact) {
557 throw new NullPointerException("contact is null"); //NOI18N
561 this.getLogger().debug(MessageFormat.format("this.id={0},contact.id={1}", this.getContactId(), contact.getContactId())); //NOI18N
563 // Is the contactId the same?
564 if (Objects.equals(this.getContactId(), contact.getContactId())) {
565 // Same contactId, means same contact
567 } else if (this.getContactId() > contact.getContactId()) {
568 // This contactId is larger than compared to
572 // The other contactId is larger