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.util.Objects;
20 import org.mxchange.jcore.client.Client;
21 import org.mxchange.jcore.model.contact.gender.Gender;
24 * A general contact class which should only be extended.
26 * @author Roland Haeder
29 public abstract class BaseContact implements Contact, Comparable<Contact> {
33 private static final long serialVersionUID = 58_744_284_981_863L;
43 private String birthday;
48 private String cellphoneNumber;
58 private String comment;
63 private String companyName;
68 private String countryCode;
73 private String emailAddress;
78 private String familyName;
83 private String faxNumber;
88 private String firstName;
93 private Gender gender;
98 private Long houseNumber;
101 * Flag whether this contact is user's own data
103 private boolean ownContact;
108 private String phoneNumber;
113 private String street;
118 private Long zipCode;
121 * No instances should be created of this class. Better extend this class
122 * and provide proper constructors.
124 protected BaseContact () {
126 this.gender = Gender.UNKNOWN;
130 * Check if contacts are same or throw an exception
132 * @param object Other possible contact class
133 * @return Whether both contacts are same
134 * TODO Needs a lot improvements
137 public boolean equals (final Object object) {
139 if (!(object instanceof BaseContact)) {
142 } else if (!(object instanceof Contact)) {
143 // Not correct interface
148 Contact contact = (Contact) object;
150 // Now test some data TODO Definedly needs improvement
151 return ((this.getGender().equals(contact.getGender()))
152 && (this.getFirstName().toLowerCase().equals(contact.getFirstName().toLowerCase()))
153 && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
159 * @return the birthday
162 public String getBirthday () {
163 return this.birthday;
169 * @param birthday the birthday to set
172 public void setBirthday (final String birthday) {
173 this.birthday = birthday;
179 * @return the cellphoneNumber
182 public String getCellphoneNumber () {
183 return this.cellphoneNumber;
189 * @param cellphoneNumber the cellphoneNumber to set
192 public void setCellphoneNumber (final String cellphoneNumber) {
193 this.cellphoneNumber = cellphoneNumber;
202 public String getCity () {
209 * @param city the city to set
212 public void setCity (final String city) {
219 * @return the comment
222 public String getComment () {
229 * @param comment the comment to set
232 public void setComment (final String comment) {
233 this.comment = comment;
239 * @return the companyName
242 public String getCompanyName () {
243 return this.companyName;
249 * @param companyName the companyName to set
252 public void setCompanyName (final String companyName) {
253 this.companyName = companyName;
261 public Long getId () {
267 * @param id the id to set
270 public void setId (final Long id) {
277 * @return the countryCode
280 public String getCountryCode () {
281 return this.countryCode;
287 * @param countryCode the countryCode to set
290 public void setCountryCode (final String countryCode) {
291 this.countryCode = countryCode;
297 * @return the emailAddress
300 public String getEmailAddress () {
301 return this.emailAddress;
307 * @param emailAddress the emailAddress to set
310 public void setEmailAddress (final String emailAddress) {
311 this.emailAddress = emailAddress;
317 * @return the familyName
320 public String getFamilyName () {
321 //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!");
322 return this.familyName;
328 * @param familyName the familyName to set
331 public void setFamilyName (final String familyName) {
332 this.familyName = familyName;
338 * @return the faxNumber
341 public String getFaxNumber () {
342 return this.faxNumber;
348 * @param faxNumber the faxNumber to set
351 public void setFaxNumber (final String faxNumber) {
352 this.faxNumber = faxNumber;
358 * @return the firstName
361 public String getFirstName () {
362 return this.firstName;
368 * @param firstName the firstName to set
371 public void setFirstName (final String firstName) {
372 this.firstName = firstName;
376 * Gender of the contact
381 public Gender getGender () {
386 * Gender of the contact
388 * @param gender the gender to set
391 public void setGender (final Gender gender) {
392 this.gender = gender;
398 * @return the houseNumber
401 public Long getHouseNumber () {
402 return this.houseNumber;
408 * @param houseNumber the houseNumber to set
411 public void setHouseNumber (final Long houseNumber) {
412 this.houseNumber = houseNumber;
418 * @return the phoneNumber
421 public String getPhoneNumber () {
422 return this.phoneNumber;
428 * @param phoneNumber the phoneNumber to set
431 public void setPhoneNumber (final String phoneNumber) {
432 this.phoneNumber = phoneNumber;
441 public String getStreet () {
448 * @param street the street to set
451 public void setStreet (final String street) {
452 this.street = street;
458 * @return the zipCode
461 public Long getZipCode () {
468 * @param zipCode the zipCode to set
471 public void setZipCode (final Long zipCode) {
472 this.zipCode = zipCode;
476 public int hashCode () {
477 // Validate gender instance
478 assert (this.getGender() instanceof Gender) : "gender is not set."; //NOI18N
481 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
482 hash = 79 * hash + this.getGender().hashCode();
483 hash = 79 * hash + Objects.hashCode(this.getFirstName());
488 * Checks whether the contact is user's own data
493 public boolean isOwnContact () {
494 return this.ownContact;
498 * Shows this contact to the user
500 * @param client Client instance to use
501 * TODO: Maybe needs to be moved to other class
503 public void show (final Client client) {
504 // The client must be set
505 if (null == client) {
507 throw new NullPointerException("client is null"); //NOI18N
510 // Display name "box"
511 client.displayNameBox(this);
513 // Display address "box"
514 client.displayAddressBox(this);
516 // Display other data "box"
517 client.displayOtherDataBox(this);
521 * Enables the flag "own data" which signals that this contact is the user's
524 protected void enableFlagOwnContact () {
525 this.ownContact = true;
529 * Compares two contacts with each other
531 * @param contact Contact comparator
532 * @return Comparison value
535 public int compareTo (final Contact contact) {
536 // contact should not be null
537 if (null == contact) {
538 throw new NullPointerException("contact is null"); //NOI18N
541 // Is the id the same?
542 if (Objects.equals(this.getId(), contact.getId())) {
543 // Same id, means same contact
545 } else if (this.getId() > contact.getId()) {
546 // This id is larger than compared to
550 // The other id is larger