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;
78 * Gender code of the contact: - M = Mr. (male) - F = Mrs. (female) - C =
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 (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() == 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 String csvString = String.format(
245 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",
249 this.getFamilyName(),
250 this.getCompanyName(),
254 this.getCountryCode(),
255 this.getPhoneNumber(),
257 this.getCellphoneNumber(),
258 this.getEmailAddress(),
270 * @return the emailAddress
272 public String getEmailAddress () {
273 return this.emailAddress;
279 * @param emailAddress the emailAddress to set
281 private void setEmailAddress (final String emailAddress) {
282 this.emailAddress = emailAddress;
288 * @return the familyName
290 public String getFamilyName () {
291 return this.familyName;
297 * @param familyName the familyName to set
299 private void setFamilyName (final String familyName) {
300 this.familyName = familyName;
306 * @return the faxNumber
308 public String getFaxNumber () {
309 return this.faxNumber;
315 * @param faxNumber the faxNumber to set
317 private void setFaxNumber (final String faxNumber) {
318 this.faxNumber = faxNumber;
322 * Gender of the contact
326 public char getGender () {
331 * Gender of the contact
333 * @param gender the gender to set
335 private void setGender (final char gender) {
336 this.gender = gender;
342 * @return the houseNumber
344 public int getHouseNumber () {
345 return this.houseNumber;
351 * @return the phoneNumber
353 public String getPhoneNumber () {
354 return this.phoneNumber;
362 public String getStreet () {
369 * @param street the street to set
371 protected final void setStreet (final String street) {
372 this.street = street;
378 * @return the surname
380 public final String getSurname () {
385 * Some "getter" for a translated/human-readable gender
387 * @return gender Human-readable gender
389 public String getTranslatedGender () {
391 String translated = null;
394 switch (this.getGender()) {
403 case 'C': // "Company"
404 translated = "Firma";
407 default: // Unsupported
408 this.getLogger().error("Gender " + this.getGender() + " not supported.");
419 * @return the zipCode
421 public final long getZipCode () {
428 * @param zipCode the zipCode to set
430 protected final void setZipCode (final long zipCode) {
431 this.zipCode = zipCode;
435 public int hashCode () {
437 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
438 hash = 79 * hash + this.getGender();
439 hash = 79 * hash + Objects.hashCode(this.getSurname());
444 * Checks whether the contact is user's own data
448 public final boolean isOwnContact () {
449 return this.ownContact;
453 * Shows this contact to the user
455 * @param client Client instance to use
457 public void show (final Client client) {
458 // Display name "box"
459 client.displayNameBox((Contact) this);
461 // Display address "box"
462 client.displayAddressBox((Contact) this);
464 // Display other data "box"
465 client.displayOtherDataBox((Contact) this);
469 * Updates address data in this Contact instance
471 * @param street Street
472 * @param zipCode ZIP code
474 * @param countryCode Country code
476 public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {
478 if (street != null) {
479 this.setStreet(street);
482 this.setZipCode(zipCode);
487 if (countryCode != null) {
488 this.setCountryCode(countryCode);
493 * Updates name data in this Contact instance
495 * @param gender Gender (M, F, C)
496 * @param surname Surname
497 * @param familyName Family name
498 * @param companyName Company name
500 public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) {
502 this.setGender(gender);
503 if (surname != null) {
504 this.setSurname(surname);
506 if (familyName != null) {
507 this.setFamilyName(familyName);
509 if (companyName != null) {
510 this.setCompanyName(companyName);
515 * Updates other data in this Contact instance
517 * @param phoneNumber Phone number
518 * @param cellphoneNumber Cellphone number
519 * @param faxNumber Fax number
520 * @param emailAddress Email address
521 * @param birthday Birth day
522 * @param comment Comments
524 public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {
526 if (phoneNumber != null) {
527 this.setPhoneNumber(phoneNumber);
529 if (cellphoneNumber != null) {
530 this.setCellphoneNumber(cellphoneNumber);
532 if (faxNumber != null) {
533 this.setFaxNumber(faxNumber);
535 if (emailAddress != null) {
536 this.setEmailAddress(emailAddress);
538 if (birthday != null) {
539 this.setBirthday(birthday);
541 if (comment != null) {
542 this.setComment(comment);
547 * Enables the flag "own data" which signals that this contact is the user's
550 protected final void enableFlagOwnContact () {
551 this.ownContact = true;
557 * @param surname the surname to set
559 protected final void setSurname (final String surname) {
560 this.surname = surname;
566 * @param phoneNumber the phoneNumber to set
568 protected final void setPhoneNumber (final String phoneNumber) {
569 this.phoneNumber = phoneNumber;
575 * @param houseNumber the houseNumber to set
577 protected final void setHouseNumber (final int houseNumber) {
578 this.houseNumber = houseNumber;
584 * @param cellphoneNumber the cellphoneNumber to set
586 protected final void setCellphoneNumber (final String cellphoneNumber) {
587 this.cellphoneNumber = cellphoneNumber;
593 * @param birthday the birthday to set
595 protected final void setBirthday (final String birthday) {
596 this.birthday = birthday;