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.util.Objects;
20 import org.mxchange.addressbook.BaseFrameworkSystem;
21 import org.mxchange.addressbook.client.Client;
26 * @author Roland Haeder
30 public class BaseContact extends BaseFrameworkSystem {
35 private String birthday;
40 private String cellphoneNumber;
50 private String comment;
55 private String companyName;
60 private String countryCode;
65 private String emailAddress;
70 private String familyName;
75 private String faxNumber;
80 private Gender gender;
85 private int houseNumber;
88 * Marker whether this contact is user's own data
90 private boolean ownContact;
95 private String phoneNumber;
100 private String street;
105 private String surname;
110 private long zipCode;
113 * No instances can be created of this class
115 protected BaseContact () {
120 * Check if contacts are same or throw an exception
122 * @param object Other possible contact class
123 * @return Whether both contacts are same
124 * @todo Needs a lot improvements
127 public boolean equals (Object object) {
129 if (!(object instanceof BaseContact)) {
132 } else if (!(object instanceof Contact)) {
133 // Not correct interface
138 Contact contact = (Contact) object;
140 // Now test some data @todo Definedly needs improvement
141 return ((this.getGender().equals(contact.getGender()))
142 && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))
143 && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
149 * @return the birthday
151 public String getBirthday () {
152 return this.birthday;
158 * @return the cellphoneNumber
160 public String getCellphoneNumber () {
161 return this.cellphoneNumber;
169 public String getCity () {
176 * @param city the city to set
178 private void setCity (final String city) {
185 * @return the comment
187 public String getComment () {
194 * @param comment the comment to set
196 private void setComment (final String comment) {
197 this.comment = comment;
203 * @return the companyName
205 public String getCompanyName () {
206 return this.companyName;
212 * @param companyName the companyName to set
214 private void setCompanyName (final String companyName) {
215 this.companyName = companyName;
221 * @return the countryCode
223 public String getCountryCode () {
224 return this.countryCode;
230 * @param countryCode the countryCode to set
232 private void setCountryCode (final String countryCode) {
233 this.countryCode = countryCode;
237 * "Serializes" this object into a CSV string (this time with semicolons)
239 * @return "CSV-serialized" version of the stored data
241 public String getCsvStringFromStoreableObject () {
243 String csvString = String.format(
244 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",
246 this.getGender().getDatabaseValue(),
248 this.getFamilyName(),
249 this.getCompanyName(),
253 this.getCountryCode(),
254 this.getPhoneNumber(),
256 this.getCellphoneNumber(),
257 this.getEmailAddress(),
269 * @return the emailAddress
271 public String getEmailAddress () {
272 return this.emailAddress;
278 * @param emailAddress the emailAddress to set
280 private void setEmailAddress (final String emailAddress) {
281 this.emailAddress = emailAddress;
287 * @return the familyName
289 public String getFamilyName () {
290 return this.familyName;
296 * @param familyName the familyName to set
298 private void setFamilyName (final String familyName) {
299 this.familyName = familyName;
305 * @return the faxNumber
307 public String getFaxNumber () {
308 return this.faxNumber;
314 * @param faxNumber the faxNumber to set
316 private void setFaxNumber (final String faxNumber) {
317 this.faxNumber = faxNumber;
321 * Gender of the contact
325 public Gender getGender () {
330 * Gender of the contact
332 * @param gender the gender to set
334 private void setGender (final Gender gender) {
335 this.gender = gender;
341 * @return the houseNumber
343 public int getHouseNumber () {
344 return this.houseNumber;
350 * @return the phoneNumber
352 public String getPhoneNumber () {
353 return this.phoneNumber;
361 public String getStreet () {
368 * @param street the street to set
370 protected final void setStreet (final String street) {
371 this.street = street;
377 * @return the surname
379 public final String getSurname () {
384 * Some "getter" for a translated/human-readable gender
386 * @return gender Human-readable gender
388 public String getTranslatedGender () {
390 String translated = null;
393 switch (this.getGender()) {
402 case COMPANY: // "Company"
403 translated = "Firma";
406 default: // Unsupported
407 this.getLogger().error("Gender " + this.getGender() + " not supported.");
418 * @return the zipCode
420 public final long getZipCode () {
427 * @param zipCode the zipCode to set
429 protected final void setZipCode (final long zipCode) {
430 this.zipCode = zipCode;
434 public int hashCode () {
435 // Validate gender instance
436 assert (this.getGender() instanceof Gender) : "gender is not set.";
439 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
440 hash = 79 * hash + this.getGender().hashCode();
441 hash = 79 * hash + Objects.hashCode(this.getSurname());
446 * Checks whether the contact is user's own data
450 public final boolean isOwnContact () {
451 return this.ownContact;
455 * Shows this contact to the user
457 * @param client Client instance to use
459 public void show (final Client client) {
460 // Display name "box"
461 client.displayNameBox((Contact) this);
463 // Display address "box"
464 client.displayAddressBox((Contact) this);
466 // Display other data "box"
467 client.displayOtherDataBox((Contact) this);
471 * Updates address data in this Contact instance
473 * @param street Street
474 * @param zipCode ZIP code
476 * @param countryCode Country code
478 public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {
480 if (street != null) {
481 this.setStreet(street);
484 this.setZipCode(zipCode);
489 if (countryCode != null) {
490 this.setCountryCode(countryCode);
495 * Updates name data in this Contact instance
497 * @param gender Gender (M, F, C)
498 * @param surname Surname
499 * @param familyName Family name
500 * @param companyName Company name
502 public void updateNameData (final Gender gender, final String surname, final String familyName, final String companyName) {
504 this.setGender(gender);
506 if (surname != null) {
507 this.setSurname(surname);
509 if (familyName != null) {
510 this.setFamilyName(familyName);
512 if (companyName != null) {
513 this.setCompanyName(companyName);
518 * Updates other data in this Contact instance
520 * @param phoneNumber Phone number
521 * @param cellphoneNumber Cellphone number
522 * @param faxNumber Fax number
523 * @param emailAddress Email address
524 * @param birthday Birth day
525 * @param comment Comments
527 public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {
529 if (phoneNumber != null) {
530 this.setPhoneNumber(phoneNumber);
532 if (cellphoneNumber != null) {
533 this.setCellphoneNumber(cellphoneNumber);
535 if (faxNumber != null) {
536 this.setFaxNumber(faxNumber);
538 if (emailAddress != null) {
539 this.setEmailAddress(emailAddress);
541 if (birthday != null) {
542 this.setBirthday(birthday);
544 if (comment != null) {
545 this.setComment(comment);
550 * Enables the flag "own data" which signals that this contact is the user's
553 protected final void enableFlagOwnContact () {
554 this.ownContact = true;
560 * @param surname the surname to set
562 protected final void setSurname (final String surname) {
563 this.surname = surname;
569 * @param phoneNumber the phoneNumber to set
571 protected final void setPhoneNumber (final String phoneNumber) {
572 this.phoneNumber = phoneNumber;
578 * @param houseNumber the houseNumber to set
580 protected final void setHouseNumber (final int houseNumber) {
581 this.houseNumber = houseNumber;
587 * @param cellphoneNumber the cellphoneNumber to set
589 protected final void setCellphoneNumber (final String cellphoneNumber) {
590 this.cellphoneNumber = cellphoneNumber;
596 * @param birthday the birthday to set
598 protected final void setBirthday (final String birthday) {
599 this.birthday = birthday;