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.addressbook.contact;
19 import java.text.MessageFormat;
20 import java.util.Objects;
21 import org.mxchange.addressbook.BaseFrameworkSystem;
22 import org.mxchange.addressbook.client.Client;
27 * @author Roland Haeder
31 public class BaseContact extends BaseFrameworkSystem {
36 private String birthday;
41 private String cellphoneNumber;
51 private String comment;
56 private String companyName;
61 private String countryCode;
66 private String emailAddress;
71 private String familyName;
76 private String faxNumber;
81 private Gender gender;
86 private int houseNumber;
89 * Marker whether this contact is user's own data
91 private boolean ownContact;
96 private String phoneNumber;
101 private String street;
106 private String surname;
111 private long zipCode;
114 * No instances can be created of this class
116 protected BaseContact () {
121 * Check if contacts are same or throw an exception
123 * @param object Other possible contact class
124 * @return Whether both contacts are same
125 * @todo Needs a lot improvements
128 public boolean equals (final Object object) {
130 if (!(object instanceof BaseContact)) {
133 } else if (!(object instanceof Contact)) {
134 // Not correct interface
139 Contact contact = (Contact) object;
141 // Now test some data @todo Definedly needs improvement
142 return ((this.getGender().equals(contact.getGender()))
143 && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))
144 && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
150 * @return the birthday
152 public String getBirthday () {
153 return this.birthday;
159 * @return the cellphoneNumber
161 public String getCellphoneNumber () {
162 return this.cellphoneNumber;
170 public String getCity () {
177 * @param city the city to set
179 private void setCity (final String city) {
186 * @return the comment
188 public String getComment () {
195 * @param comment the comment to set
197 private void setComment (final String comment) {
198 this.comment = comment;
204 * @return the companyName
206 public String getCompanyName () {
207 return this.companyName;
213 * @param companyName the companyName to set
215 private void setCompanyName (final String companyName) {
216 this.companyName = companyName;
222 * @return the countryCode
224 public String getCountryCode () {
225 return this.countryCode;
231 * @param countryCode the countryCode to set
233 private void setCountryCode (final String countryCode) {
234 this.countryCode = countryCode;
238 * "Serializes" this object into a CSV string (this time with semicolons)
240 * @return "CSV-serialized" version of the stored data
242 public String getCsvStringFromStoreableObject () {
244 this.getLogger().trace("CALLED!"); //NOI18N
247 String csvString = String.format(
248 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"",
250 this.getGender().getDatabaseValue(),
252 this.getFamilyName(),
253 this.getCompanyName(),
257 this.getCountryCode(),
258 this.getPhoneNumber(),
260 this.getCellphoneNumber(),
261 this.getEmailAddress(),
273 * @return the emailAddress
275 public String getEmailAddress () {
276 return this.emailAddress;
282 * @param emailAddress the emailAddress to set
284 private void setEmailAddress (final String emailAddress) {
285 this.emailAddress = emailAddress;
291 * @return the familyName
293 public String getFamilyName () {
294 return this.familyName;
300 * @param familyName the familyName to set
302 private void setFamilyName (final String familyName) {
303 this.familyName = familyName;
309 * @return the faxNumber
311 public String getFaxNumber () {
312 return this.faxNumber;
318 * @param faxNumber the faxNumber to set
320 private void setFaxNumber (final String faxNumber) {
321 this.faxNumber = faxNumber;
325 * Gender of the contact
329 public Gender getGender () {
334 * Gender of the contact
336 * @param gender the gender to set
338 private void setGender (final Gender gender) {
339 this.gender = gender;
345 * @return the houseNumber
347 public int getHouseNumber () {
348 return this.houseNumber;
354 * @return the phoneNumber
356 public String getPhoneNumber () {
357 return this.phoneNumber;
365 public String getStreet () {
372 * @param street the street to set
374 protected final void setStreet (final String street) {
375 this.street = street;
381 * @return the surname
383 public final String getSurname () {
388 * Some "getter" for a translated/human-readable gender
390 * @return gender Human-readable gender
392 public String getTranslatedGender () {
394 String translated = null;
397 switch (this.getGender()) {
406 case COMPANY: // "Company"
407 translated = "Firma";
410 default: // Unsupported
411 this.getLogger().error("Gender " + this.getGender() + " not supported.");
422 * @return the zipCode
424 public final long getZipCode () {
431 * @param zipCode the zipCode to set
433 protected final void setZipCode (final long zipCode) {
434 this.zipCode = zipCode;
438 public int hashCode () {
439 // Validate gender instance
440 assert (this.getGender() instanceof Gender) : "gender is not set.";
443 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
444 hash = 79 * hash + this.getGender().hashCode();
445 hash = 79 * hash + Objects.hashCode(this.getSurname());
450 * Checks whether the contact is user's own data
454 public final boolean isOwnContact () {
455 return this.ownContact;
459 * Shows this contact to the user
461 * @param client Client instance to use
463 public void show (final Client client) {
465 this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N
467 // The client must be set
468 if (client == null) {
470 throw new NullPointerException("client is null");
473 // Display name "box"
474 client.displayNameBox((Contact) this);
476 // Display address "box"
477 client.displayAddressBox((Contact) this);
479 // Display other data "box"
480 client.displayOtherDataBox((Contact) this);
484 * Updates address data in this Contact instance
486 * @param street Street
487 * @param zipCode ZIP code
489 * @param countryCode Country code
491 public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {
493 this.getLogger().trace(MessageFormat.format("street={0},zipCode={1},city={2},countryCode={3} - CALLED!", street, zipCode, city, countryCode)); //NOI18N
496 if (street != null) {
497 this.setStreet(street);
500 this.setZipCode(zipCode);
505 if (countryCode != null) {
506 this.setCountryCode(countryCode);
510 this.getLogger().trace("EXIT!"); //NOI18N
514 * Updates name data in this Contact instance
516 * @param gender Gender (M, F, C)
517 * @param surname Surname
518 * @param familyName Family name
519 * @param companyName Company name
521 public void updateNameData (final Gender gender, final String surname, final String familyName, final String companyName) {
523 this.getLogger().trace(MessageFormat.format("gender={0},surname={1},familyName={2},companyName={3} - CALLED!", gender, surname, familyName, companyName)); //NOI18N
526 this.setGender(gender);
528 if (surname != null) {
529 this.setSurname(surname);
531 if (familyName != null) {
532 this.setFamilyName(familyName);
534 if (companyName != null) {
535 this.setCompanyName(companyName);
539 this.getLogger().trace("EXIT!"); //NOI18N
543 * Updates other data in this Contact instance
545 * @param phoneNumber Phone number
546 * @param cellphoneNumber Cellphone number
547 * @param faxNumber Fax number
548 * @param emailAddress Email address
549 * @param birthday Birth day
550 * @param comment Comments
552 public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {
554 this.getLogger().trace(MessageFormat.format("phoneNumber={0},cellphoneNumber={1}faxNumber={2},emailAddress={3},birthday={4},comment={5} - CALLED!", phoneNumber, cellphoneNumber, faxNumber, emailAddress, birthday, comment)); //NOI18N
557 if (phoneNumber != null) {
558 this.setPhoneNumber(phoneNumber);
560 if (cellphoneNumber != null) {
561 this.setCellphoneNumber(cellphoneNumber);
563 if (faxNumber != null) {
564 this.setFaxNumber(faxNumber);
566 if (emailAddress != null) {
567 this.setEmailAddress(emailAddress);
569 if (birthday != null) {
570 this.setBirthday(birthday);
572 if (comment != null) {
573 this.setComment(comment);
577 this.getLogger().trace("EXIT!"); //NOI18N
581 * Enables the flag "own data" which signals that this contact is the user's
584 protected final void enableFlagOwnContact () {
585 this.ownContact = true;
591 * @param surname the surname to set
593 protected final void setSurname (final String surname) {
594 this.surname = surname;
600 * @param phoneNumber the phoneNumber to set
602 protected final void setPhoneNumber (final String phoneNumber) {
603 this.phoneNumber = phoneNumber;
609 * @param houseNumber the houseNumber to set
611 protected final void setHouseNumber (final int houseNumber) {
612 this.houseNumber = houseNumber;
618 * @param cellphoneNumber the cellphoneNumber to set
620 protected final void setCellphoneNumber (final String cellphoneNumber) {
621 this.cellphoneNumber = cellphoneNumber;
627 * @param birthday the birthday to set
629 protected final void setBirthday (final String birthday) {
630 this.birthday = birthday;