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.sql.Timestamp;
20 import java.util.Objects;
21 import org.mxchange.jcore.client.Client;
22 import org.mxchange.jcore.model.contact.gender.Gender;
25 * A general contact class which should only be extended.
27 * @author Roland Haeder<roland@mxchange.org>
30 public class BaseContact implements Contact, Comparable<Contact> {
34 private static final long serialVersionUID = 58_744_284_981_863L;
37 * When the contact has been created
39 private Timestamp created;
49 private String birthday;
54 private String cellphoneNumber;
64 private String comment;
69 private String companyName;
74 private String countryCode;
79 private String emailAddress;
84 private String familyName;
89 private String faxNumber;
94 private String firstName;
99 private Gender gender;
104 private Long houseNumber;
107 * Flag whether this contact is user's own data
109 private boolean ownContact;
114 private String phoneNumber;
119 private String street;
122 * When the contact has been updated
124 private Timestamp updated;
129 private Long zipCode;
132 * No instances should be created of this class. Better extend this class
133 * and provide proper constructors.
135 protected BaseContact () {
137 this.gender = Gender.UNKNOWN;
141 * Check if contacts are same or throw an exception
143 * @param object Other possible contact class
144 * @return Whether both contacts are same
145 * TODO Needs a lot improvements
148 public boolean equals (final Object object) {
150 if (!(object instanceof BaseContact)) {
153 } else if (!(object instanceof Contact)) {
154 // Not correct interface
159 Contact contact = (Contact) object;
161 // Now test some data TODO Definedly needs improvement
162 return ((this.getGender().equals(contact.getGender()))
163 && (this.getFirstName().toLowerCase().equals(contact.getFirstName().toLowerCase()))
164 && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
170 * @return the birthday
173 public String getBirthday () {
174 return this.birthday;
180 * @param birthday the birthday to set
183 public void setBirthday (final String birthday) {
184 this.birthday = birthday;
190 * @return the cellphoneNumber
193 public String getCellphoneNumber () {
194 return this.cellphoneNumber;
200 * @param cellphoneNumber the cellphoneNumber to set
203 public void setCellphoneNumber (final String cellphoneNumber) {
204 this.cellphoneNumber = cellphoneNumber;
213 public String getCity () {
220 * @param city the city to set
223 public void setCity (final String city) {
230 * @return the comment
233 public String getComment () {
240 * @param comment the comment to set
243 public void setComment (final String comment) {
244 this.comment = comment;
250 * @return the companyName
253 public String getCompanyName () {
254 return this.companyName;
260 * @param companyName the companyName to set
263 public void setCompanyName (final String companyName) {
264 this.companyName = companyName;
268 public Timestamp getCreated () {
273 public void setCreated (final Timestamp created) {
274 this.created = created;
282 public Long getId () {
288 * @param id the id to set
291 public void setId (final Long id) {
298 * @return the countryCode
301 public String getCountryCode () {
302 return this.countryCode;
308 * @param countryCode the countryCode to set
311 public void setCountryCode (final String countryCode) {
312 this.countryCode = countryCode;
318 * @return the emailAddress
321 public String getEmailAddress () {
322 return this.emailAddress;
328 * @param emailAddress the emailAddress to set
331 public void setEmailAddress (final String emailAddress) {
332 this.emailAddress = emailAddress;
338 * @return the familyName
341 public String getFamilyName () {
342 //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!");
343 return this.familyName;
349 * @param familyName the familyName to set
352 public void setFamilyName (final String familyName) {
353 this.familyName = familyName;
359 * @return the faxNumber
362 public String getFaxNumber () {
363 return this.faxNumber;
369 * @param faxNumber the faxNumber to set
372 public void setFaxNumber (final String faxNumber) {
373 this.faxNumber = faxNumber;
379 * @return the firstName
382 public String getFirstName () {
383 return this.firstName;
389 * @param firstName the firstName to set
392 public void setFirstName (final String firstName) {
393 this.firstName = firstName;
397 * Gender of the contact
402 public Gender getGender () {
407 * Gender of the contact
409 * @param gender the gender to set
412 public void setGender (final Gender gender) {
413 this.gender = gender;
419 * @return the houseNumber
422 public Long getHouseNumber () {
423 return this.houseNumber;
429 * @param houseNumber the houseNumber to set
432 public void setHouseNumber (final Long houseNumber) {
433 this.houseNumber = houseNumber;
439 * @return the phoneNumber
442 public String getPhoneNumber () {
443 return this.phoneNumber;
449 * @param phoneNumber the phoneNumber to set
452 public void setPhoneNumber (final String phoneNumber) {
453 this.phoneNumber = phoneNumber;
462 public String getStreet () {
469 * @param street the street to set
472 public void setStreet (final String street) {
473 this.street = street;
477 public Timestamp getUpdated () {
482 public void setUpdated (final Timestamp updated) {
483 this.updated = updated;
489 * @return the zipCode
492 public Long getZipCode () {
499 * @param zipCode the zipCode to set
502 public void setZipCode (final Long zipCode) {
503 this.zipCode = zipCode;
507 public int hashCode () {
508 // Validate gender instance
509 assert (this.getGender() instanceof Gender) : "gender is not set."; //NOI18N
512 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
513 hash = 79 * hash + this.getGender().hashCode();
514 hash = 79 * hash + Objects.hashCode(this.getFirstName());
519 * Checks whether the contact is user's own data
524 public boolean isOwnContact () {
525 return this.ownContact;
529 * Shows this contact to the user
531 * @param client Client instance to use
532 * TODO: Maybe needs to be moved to other class
534 public void show (final Client client) {
535 // The client must be set
536 if (null == client) {
538 throw new NullPointerException("client is null"); //NOI18N
541 // Display name "box"
542 client.displayNameBox(this);
544 // Display address "box"
545 client.displayAddressBox(this);
547 // Display other data "box"
548 client.displayOtherDataBox(this);
552 public void setOwnContact (final Boolean ownContact) {
553 this.ownContact = ownContact;
557 * Compares two contacts with each other
559 * @param contact Contact comparator
560 * @return Comparison value
563 public int compareTo (final Contact contact) {
564 // contact should not be null
565 if (null == contact) {
566 throw new NullPointerException("contact is null"); //NOI18N
569 // Is the id the same?
570 if (Objects.equals(this.getId(), contact.getId())) {
571 // Same id, means same contact
573 } else if (this.getId() > contact.getId()) {
574 // This id is larger than compared to
578 // The other id is larger