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 long zipCode;
\r
113 * No instances can be created of this class
\r
115 protected BaseContact () {
\r
120 * Check if contacts are same or throw an exception
\r
122 * @param object Other possible contact class
\r
123 * @return Whether both contacts are same
\r
124 * @todo Needs a lot improvements
\r
127 public boolean equals (Object object) {
\r
128 // Is it same type?
\r
129 if (!(object instanceof BaseContact)) {
\r
132 } else if (!(object instanceof Contact)) {
\r
133 // Not correct interface
\r
138 Contact contact = (Contact) object;
\r
140 // Now test some data @todo Definedly needs improvement
\r
141 return ((this.getGender() == contact.getGender())
\r
142 && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))
\r
143 && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
\r
149 * @return the birthday
\r
151 public String getBirthday () {
\r
152 return this.birthday;
\r
158 * @param birthday the birthday to set
\r
160 public void setBirthday (final String birthday) {
\r
161 this.birthday = birthday;
\r
167 * @return the cellphoneNumber
\r
169 public String getCellphoneNumber () {
\r
170 return this.cellphoneNumber;
\r
176 * @param cellphoneNumber the cellphoneNumber to set
\r
178 public void setCellphoneNumber (final String cellphoneNumber) {
\r
179 this.cellphoneNumber = cellphoneNumber;
\r
187 public String getCity () {
\r
194 * @param city the city to set
\r
196 public void setCity (final String city) {
\r
203 * @return the comment
\r
205 public String getComment () {
\r
206 return this.comment;
\r
212 * @param comment the comment to set
\r
214 public void setComment (final String comment) {
\r
215 this.comment = comment;
\r
221 * @return the companyName
\r
223 public String getCompanyName () {
\r
224 return this.companyName;
\r
230 * @param companyName the companyName to set
\r
232 public void setCompanyName (final String companyName) {
\r
233 this.companyName = companyName;
\r
239 * @return the countryCode
\r
241 public String getCountryCode () {
\r
242 return this.countryCode;
\r
248 * @param countryCode the countryCode to set
\r
250 public void setCountryCode (final String countryCode) {
\r
251 this.countryCode = countryCode;
\r
255 * "Serializes" this object into a CSV string (this time with semicolons)
\r
257 * @return "CSV-serialized" version of the stored data
\r
259 public String getCsvStringFromStoreableObject () {
\r
260 // Get all together
\r
261 String csvString = String.format(
\r
262 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",
\r
263 this.isOwnContact(),
\r
266 this.getFamilyName(),
\r
267 this.getCompanyName(),
\r
271 this.getCountryCode(),
\r
272 this.getPhoneNumber(),
\r
273 this.getFaxNumber(),
\r
274 this.getCellphoneNumber(),
\r
275 this.getEmailAddress(),
\r
276 this.getBirthday(),
\r
287 * @return the emailAddress
\r
289 public String getEmailAddress () {
\r
290 return this.emailAddress;
\r
296 * @param emailAddress the emailAddress to set
\r
298 public void setEmailAddress (final String emailAddress) {
\r
299 this.emailAddress = emailAddress;
\r
305 * @return the familyName
\r
307 public String getFamilyName () {
\r
308 return this.familyName;
\r
314 * @param familyName the familyName to set
\r
316 public void setFamilyName (final String familyName) {
\r
317 this.familyName = familyName;
\r
323 * @return the faxNumber
\r
325 public String getFaxNumber () {
\r
326 return this.faxNumber;
\r
332 * @param faxNumber the faxNumber to set
\r
334 public void setFaxNumber (final String faxNumber) {
\r
335 this.faxNumber = faxNumber;
\r
339 * Gender of the contact
\r
341 * @return the gender
\r
343 public char getGender () {
\r
344 return this.gender;
\r
348 * Gender of the contact
\r
350 * @param gender the gender to set
\r
352 public void setGender (final char gender) {
\r
353 this.gender = gender;
\r
359 * @return the houseNumber
\r
361 public int getHouseNumber () {
\r
362 return this.houseNumber;
\r
368 * @param houseNumber the houseNumber to set
\r
370 public void setHouseNumber (final int houseNumber) {
\r
371 this.houseNumber = houseNumber;
\r
377 * @return the phoneNumber
\r
379 public String getPhoneNumber () {
\r
380 return this.phoneNumber;
\r
386 * @param phoneNumber the phoneNumber to set
\r
388 public void setPhoneNumber (final String phoneNumber) {
\r
389 this.phoneNumber = phoneNumber;
\r
395 * @return the street
\r
397 public String getStreet () {
\r
398 return this.street;
\r
404 * @param street the street to set
\r
406 public void setStreet (final String street) {
\r
407 this.street = street;
\r
413 * @return the surname
\r
415 public String getSurname () {
\r
416 return this.surname;
\r
422 * @param surname the surname to set
\r
424 public void setSurname (final String surname) {
\r
425 this.surname = surname;
\r
429 * Some "getter" for a translated/human-readable gender
\r
430 * @return gender Human-readable gender
\r
432 public String getTranslatedGender () {
\r
434 String translated = null;
\r
437 switch (this.getGender()) {
\r
439 translated = "Herr";
\r
443 translated = "Frau";
\r
446 case 'C': // "Company"
\r
447 translated = "Firma";
\r
450 default: // Unsupported
\r
451 this.getLogger().error("Gender " + this.getGender() + " not supported.");
\r
462 * @return the zipCode
\r
464 public long getZipCode () {
\r
465 return this.zipCode;
\r
471 * @param zipCode the zipCode to set
\r
473 public void setZipCode (final long zipCode) {
\r
474 this.zipCode = zipCode;
\r
478 public int hashCode () {
\r
480 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
\r
481 hash = 79 * hash + this.getGender();
\r
482 hash = 79 * hash + Objects.hashCode(this.getSurname());
\r
487 * Checks whether the contact is user's own data
\r
489 * @return Own data?
\r
491 public boolean isOwnContact () {
\r
492 return this.ownContact;
\r
496 * Shows this contact to the user
\r
498 * @param client Client instance to use
\r
500 public void show (final Client client) {
\r
501 // Display name "box"
\r
502 client.displayNameBox((Contact) this);
\r
504 // Display address "box"
\r
505 client.displayAddressBox((Contact) this);
\r
507 // Display other data "box"
\r
508 client.displayOtherDataBox((Contact) this);
\r
512 * Updates address data in this Contact instance
\r
514 * @param street Street
\r
515 * @param zipCode ZIP code
\r
517 * @param countryCode Country code
\r
519 public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {
\r
521 if (street != null) {
\r
522 this.setStreet(street);
\r
525 this.setZipCode(zipCode);
\r
527 if (city != null) {
\r
528 this.setCity(city);
\r
530 if (countryCode != null) {
\r
531 this.setCountryCode(countryCode);
\r
536 * Updates name data in this Contact instance
\r
537 * @param gender Gender (M, F, C)
\r
538 * @param surname Surname
\r
539 * @param familyName Family name
\r
540 * @param companyName Company name
\r
542 public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) {
\r
544 this.setGender(gender);
\r
545 if (surname != null) {
\r
546 this.setSurname(surname);
\r
548 if (familyName != null) {
\r
549 this.setFamilyName(familyName);
\r
551 if (companyName != null) {
\r
552 this.setCompanyName(companyName);
\r
557 * Updates other data in this Contact instance
\r
559 * @param phoneNumber Phone number
\r
560 * @param cellphoneNumber Cellphone number
\r
561 * @param faxNumber Fax number
\r
562 * @param emailAddress Email address
\r
563 * @param birthday Birth day
\r
564 * @param comment Comments
\r
566 public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {
\r
568 if (phoneNumber != null) {
\r
569 this.setPhoneNumber(phoneNumber);
\r
571 if (cellphoneNumber != null) {
\r
572 this.setCellphoneNumber(cellphoneNumber);
\r
574 if (faxNumber != null) {
\r
575 this.setFaxNumber(faxNumber);
\r
577 if (emailAddress != null) {
\r
578 this.setEmailAddress(emailAddress);
\r
580 if (birthday != null) {
\r
581 this.setBirthday(birthday);
\r
583 if (comment != null) {
\r
584 this.setComment(comment);
\r
589 * Enables the flag "own data" which signals that this contact is the user's
\r
592 protected void enableFlagOwnContact () {
\r
593 this.ownContact = true;
\r