2 * Copyright (C) 2015 Roland Haeder
\r
4 * This program is free software: you can redistribute it and/or modify
\r
5 * it under the terms of the GNU General Public License as published by
\r
6 * the Free Software Foundation, either version 3 of the License, or
\r
7 * (at your option) any later version.
\r
9 * This program is distributed in the hope that it will be useful,
\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License
\r
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
17 package org.mxchange.addressbook.contact;
\r
19 import java.util.Objects;
\r
20 import org.mxchange.addressbook.BaseFrameworkSystem;
\r
21 import org.mxchange.addressbook.client.Client;
\r
26 * @author Roland Haeder
\r
30 public class BaseContact extends BaseFrameworkSystem {
\r
34 private String birthday;
\r
39 private String cellphoneNumber;
\r
44 private String city;
\r
49 private String comment;
\r
54 private String companyName;
\r
59 private String countryCode;
\r
64 private String emailAddress;
\r
69 private String familyName;
\r
74 private String faxNumber;
\r
77 * Gender code of the contact: - M = Mr. (male) - F = Mrs. (female) - C =
\r
80 private char gender;
\r
85 private int houseNumber;
\r
88 * Marker whether this contact is user's own data
\r
90 private boolean ownContact;
\r
95 private String phoneNumber;
\r
100 private String street;
\r
105 private String surname;
\r
110 private int zipCode;
\r
113 * No instances can be created of this class
\r
115 protected BaseContact () {
\r
120 * Enables the flag "own data" which signals that this contact is the user's
\r
123 public void enableFlagOwnContact () {
\r
124 this.ownContact = true;
\r
128 * Check if contacts are same or throw an exception
\r
130 * @param object Other possible contact class
\r
131 * @return Whether both contacts are same
\r
132 * @todo Needs a lot improvements
\r
135 public boolean equals (Object object) {
\r
136 // Is it same type?
\r
137 if (!(object instanceof BaseContact)) {
\r
140 } else if (!(object instanceof Contact)) {
\r
141 // Not correct interface
\r
146 Contact contact = (Contact) object;
\r
148 // Now test some data @todo Definedly needs improvement
\r
149 return ((this.getGender() == contact.getGender())
\r
150 && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))
\r
151 && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
\r
157 * @return the birthday
\r
159 public String getBirthday () {
\r
160 return this.birthday;
\r
166 * @param birthday the birthday to set
\r
168 public void setBirthday (final String birthday) {
\r
169 this.birthday = birthday;
\r
175 * @return the cellphoneNumber
\r
177 public String getCellphoneNumber () {
\r
178 return this.cellphoneNumber;
\r
184 * @param cellphoneNumber the cellphoneNumber to set
\r
186 public void setCellphoneNumber (final String cellphoneNumber) {
\r
187 this.cellphoneNumber = cellphoneNumber;
\r
195 public String getCity () {
\r
202 * @param city the city to set
\r
204 public void setCity (final String city) {
\r
211 * @return the comment
\r
213 public String getComment () {
\r
214 return this.comment;
\r
220 * @param comment the comment to set
\r
222 public void setComment (final String comment) {
\r
223 this.comment = comment;
\r
229 * @return the companyName
\r
231 public String getCompanyName () {
\r
232 return this.companyName;
\r
238 * @param companyName the companyName to set
\r
240 public void setCompanyName (final String companyName) {
\r
241 this.companyName = companyName;
\r
247 * @return the countryCode
\r
249 public String getCountryCode () {
\r
250 return this.countryCode;
\r
256 * @param countryCode the countryCode to set
\r
258 public void setCountryCode (final String countryCode) {
\r
259 this.countryCode = countryCode;
\r
265 * @return the emailAddress
\r
267 public String getEmailAddress () {
\r
268 return this.emailAddress;
\r
274 * @param emailAddress the emailAddress to set
\r
276 public void setEmailAddress (final String emailAddress) {
\r
277 this.emailAddress = emailAddress;
\r
283 * @return the familyName
\r
285 public String getFamilyName () {
\r
286 return this.familyName;
\r
292 * @param familyName the familyName to set
\r
294 public void setFamilyName (final String familyName) {
\r
295 this.familyName = familyName;
\r
301 * @return the faxNumber
\r
303 public String getFaxNumber () {
\r
304 return this.faxNumber;
\r
310 * @param faxNumber the faxNumber to set
\r
312 public void setFaxNumber (final String faxNumber) {
\r
313 this.faxNumber = faxNumber;
\r
317 * Gender of the contact
\r
319 * @return the gender
\r
321 public char getGender () {
\r
322 return this.gender;
\r
326 * Gender of the contact
\r
328 * @param gender the gender to set
\r
330 public void setGender (final char gender) {
\r
331 this.gender = gender;
\r
337 * @return the houseNumber
\r
339 public int getHouseNumber () {
\r
340 return this.houseNumber;
\r
346 * @param houseNumber the houseNumber to set
\r
348 public void setHouseNumber (final int houseNumber) {
\r
349 this.houseNumber = houseNumber;
\r
355 * @return the phoneNumber
\r
357 public String getPhoneNumber () {
\r
358 return this.phoneNumber;
\r
364 * @param phoneNumber the phoneNumber to set
\r
366 public void setPhoneNumber (final String phoneNumber) {
\r
367 this.phoneNumber = phoneNumber;
\r
373 * @return the street
\r
375 public String getStreet () {
\r
376 return this.street;
\r
382 * @param street the street to set
\r
384 public void setStreet (final String street) {
\r
385 this.street = street;
\r
391 * @return the surname
\r
393 public String getSurname () {
\r
394 return this.surname;
\r
400 * @param surname the surname to set
\r
402 public void setSurname (final String surname) {
\r
403 this.surname = surname;
\r
407 * Some "getter" for a translated/human-readable gender
\r
408 * @return gender Human-readable gender
\r
410 public String getTranslatedGender () {
\r
412 String translated = null;
\r
415 switch (this.getGender()) {
\r
417 translated = "Herr";
\r
421 translated = "Frau";
\r
424 case 'C': // "Company"
\r
425 translated = "Firma";
\r
428 default: // Unsupported
\r
429 this.getLogger().error("Gender " + this.getGender() + " not supported.");
\r
440 * @return the zipCode
\r
442 public int getZipCode () {
\r
443 return this.zipCode;
\r
449 * @param zipCode the zipCode to set
\r
451 public void setZipCode (final int zipCode) {
\r
452 this.zipCode = zipCode;
\r
456 public int hashCode () {
\r
458 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
\r
459 hash = 79 * hash + this.getGender();
\r
460 hash = 79 * hash + Objects.hashCode(this.getSurname());
\r
465 * Checks whether the contact is user's own data
\r
467 * @return Own data?
\r
469 public boolean isOwnContact () {
\r
470 return this.ownContact;
\r
474 * Shows this contact to the user
\r
476 * @param client Client instance to use
\r
478 public void show (final Client client) {
\r
479 // Display name "box"
\r
480 client.displayNameBox((Contact) this);
\r
482 // Display address "box"
\r
483 client.displayAddressBox((Contact) this);
\r
485 // Display other data "box"
\r
486 client.displayOtherDataBox((Contact) this);
\r
490 * Updates address data in this Contact instance
\r
492 * @param street Street
\r
493 * @param zipCode ZIP code
\r
495 * @param countryCode Country code
\r
497 public void updateAddressData (final String street, final int zipCode, final String city, final String countryCode) {
\r
499 this.setStreet(street);
\r
500 this.setZipCode(zipCode);
\r
501 this.setCity(city);
\r
502 this.setCountryCode(countryCode);
\r
506 * Updates name data in this Contact instance
\r
507 * @param gender Gender (M, F, C)
\r
508 * @param surname Surname
\r
509 * @param familyName Family name
\r
510 * @param companyName Company name
\r
512 public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) {
\r
514 this.setGender(gender);
\r
515 this.setSurname(surname);
\r
516 this.setFamilyName(familyName);
\r
517 this.setCompanyName(companyName);
\r
521 * Updates other data in this Contact instance
\r
523 * @param phoneNumber Phone number
\r
524 * @param cellphoneNumber Cellphone number
\r
525 * @param faxNumber Fax number
\r
526 * @param emailAddress Email address
\r
527 * @param comment Comments
\r
529 public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String comment) {
\r
531 this.setPhoneNumber(phoneNumber);
\r
532 this.setCellphoneNumber(cellphoneNumber);
\r
533 this.setFaxNumber(faxNumber);
\r
534 this.setEmailAddress(emailAddress);
\r
535 this.setComment(comment);
\r
539 * "Serializes" this object into a CSV string (this time with semicolons)
\r
541 * @return "CSV-serialized" version of the stored data
\r
543 public String getCsvStringFromStoreableObject () {
\r
544 // Get all together
\r
545 String csvString = String.format(
\r
546 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",
\r
549 this.getFamilyName(),
\r
550 this.getCompanyName(),
\r
554 this.getCountryCode(),
\r
555 this.getPhoneNumber(),
\r
556 this.getFaxNumber(),
\r
557 this.getCellphoneNumber(),
\r
558 this.getEmailAddress(),
\r
559 this.getBirthday(),
\r