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 public static final int COLUMN_COUNT = 14;
\r
39 private String birthday;
\r
44 private String cellphoneNumber;
\r
49 private String city;
\r
54 private String comment;
\r
59 private String companyName;
\r
64 private String countryCode;
\r
69 private String emailAddress;
\r
74 private String familyName;
\r
79 private String faxNumber;
\r
82 * Gender code of the contact: - M = Mr. (male) - F = Mrs. (female) - C =
\r
85 private char gender;
\r
90 private int houseNumber;
\r
93 * Marker whether this contact is user's own data
\r
95 private boolean ownContact;
\r
100 private String phoneNumber;
\r
105 private String street;
\r
110 private String surname;
\r
115 private long zipCode;
\r
118 * No instances can be created of this class
\r
120 protected BaseContact () {
\r
125 * Check if contacts are same or throw an exception
\r
127 * @param object Other possible contact class
\r
128 * @return Whether both contacts are same
\r
129 * @todo Needs a lot improvements
\r
132 public boolean equals (Object object) {
\r
133 // Is it same type?
\r
134 if (!(object instanceof BaseContact)) {
\r
137 } else if (!(object instanceof Contact)) {
\r
138 // Not correct interface
\r
143 Contact contact = (Contact) object;
\r
145 // Now test some data @todo Definedly needs improvement
\r
146 return ((this.getGender() == contact.getGender())
\r
147 && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))
\r
148 && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
\r
154 * @return the birthday
\r
156 public String getBirthday () {
\r
157 return this.birthday;
\r
163 * @param birthday the birthday to set
\r
165 public void setBirthday (final String birthday) {
\r
166 this.birthday = birthday;
\r
172 * @return the cellphoneNumber
\r
174 public String getCellphoneNumber () {
\r
175 return this.cellphoneNumber;
\r
181 * @param cellphoneNumber the cellphoneNumber to set
\r
183 public void setCellphoneNumber (final String cellphoneNumber) {
\r
184 this.cellphoneNumber = cellphoneNumber;
\r
192 public String getCity () {
\r
199 * @param city the city to set
\r
201 public void setCity (final String city) {
\r
208 * @return the comment
\r
210 public String getComment () {
\r
211 return this.comment;
\r
217 * @param comment the comment to set
\r
219 public void setComment (final String comment) {
\r
220 this.comment = comment;
\r
226 * @return the companyName
\r
228 public String getCompanyName () {
\r
229 return this.companyName;
\r
235 * @param companyName the companyName to set
\r
237 public void setCompanyName (final String companyName) {
\r
238 this.companyName = companyName;
\r
244 * @return the countryCode
\r
246 public String getCountryCode () {
\r
247 return this.countryCode;
\r
253 * @param countryCode the countryCode to set
\r
255 public void setCountryCode (final String countryCode) {
\r
256 this.countryCode = countryCode;
\r
260 * "Serializes" this object into a CSV string (this time with semicolons)
\r
262 * @return "CSV-serialized" version of the stored data
\r
264 public String getCsvStringFromStoreableObject () {
\r
265 // Get all together
\r
266 String csvString = String.format(
\r
267 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",
\r
268 this.isOwnContact(),
\r
271 this.getFamilyName(),
\r
272 this.getCompanyName(),
\r
276 this.getCountryCode(),
\r
277 this.getPhoneNumber(),
\r
278 this.getFaxNumber(),
\r
279 this.getCellphoneNumber(),
\r
280 this.getEmailAddress(),
\r
281 this.getBirthday(),
\r
292 * @return the emailAddress
\r
294 public String getEmailAddress () {
\r
295 return this.emailAddress;
\r
301 * @param emailAddress the emailAddress to set
\r
303 public void setEmailAddress (final String emailAddress) {
\r
304 this.emailAddress = emailAddress;
\r
310 * @return the familyName
\r
312 public String getFamilyName () {
\r
313 return this.familyName;
\r
319 * @param familyName the familyName to set
\r
321 public void setFamilyName (final String familyName) {
\r
322 this.familyName = familyName;
\r
328 * @return the faxNumber
\r
330 public String getFaxNumber () {
\r
331 return this.faxNumber;
\r
337 * @param faxNumber the faxNumber to set
\r
339 public void setFaxNumber (final String faxNumber) {
\r
340 this.faxNumber = faxNumber;
\r
344 * Gender of the contact
\r
346 * @return the gender
\r
348 public char getGender () {
\r
349 return this.gender;
\r
353 * Gender of the contact
\r
355 * @param gender the gender to set
\r
357 public void setGender (final char gender) {
\r
358 this.gender = gender;
\r
364 * @return the houseNumber
\r
366 public int getHouseNumber () {
\r
367 return this.houseNumber;
\r
373 * @param houseNumber the houseNumber to set
\r
375 public void setHouseNumber (final int houseNumber) {
\r
376 this.houseNumber = houseNumber;
\r
382 * @return the phoneNumber
\r
384 public String getPhoneNumber () {
\r
385 return this.phoneNumber;
\r
391 * @param phoneNumber the phoneNumber to set
\r
393 public void setPhoneNumber (final String phoneNumber) {
\r
394 this.phoneNumber = phoneNumber;
\r
400 * @return the street
\r
402 public String getStreet () {
\r
403 return this.street;
\r
409 * @param street the street to set
\r
411 public void setStreet (final String street) {
\r
412 this.street = street;
\r
418 * @return the surname
\r
420 public String getSurname () {
\r
421 return this.surname;
\r
427 * @param surname the surname to set
\r
429 public void setSurname (final String surname) {
\r
430 this.surname = surname;
\r
434 * Some "getter" for a translated/human-readable gender
\r
435 * @return gender Human-readable gender
\r
437 public String getTranslatedGender () {
\r
439 String translated = null;
\r
442 switch (this.getGender()) {
\r
444 translated = "Herr";
\r
448 translated = "Frau";
\r
451 case 'C': // "Company"
\r
452 translated = "Firma";
\r
455 default: // Unsupported
\r
456 this.getLogger().error("Gender " + this.getGender() + " not supported.");
\r
467 * @return the zipCode
\r
469 public long getZipCode () {
\r
470 return this.zipCode;
\r
476 * @param zipCode the zipCode to set
\r
478 public void setZipCode (final long zipCode) {
\r
479 this.zipCode = zipCode;
\r
483 public int hashCode () {
\r
485 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
\r
486 hash = 79 * hash + this.getGender();
\r
487 hash = 79 * hash + Objects.hashCode(this.getSurname());
\r
492 * Checks whether the contact is user's own data
\r
494 * @return Own data?
\r
496 public boolean isOwnContact () {
\r
497 return this.ownContact;
\r
501 * Shows this contact to the user
\r
503 * @param client Client instance to use
\r
505 public void show (final Client client) {
\r
506 // Display name "box"
\r
507 client.displayNameBox((Contact) this);
\r
509 // Display address "box"
\r
510 client.displayAddressBox((Contact) this);
\r
512 // Display other data "box"
\r
513 client.displayOtherDataBox((Contact) this);
\r
517 * Updates address data in this Contact instance
\r
519 * @param street Street
\r
520 * @param zipCode ZIP code
\r
522 * @param countryCode Country code
\r
524 public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {
\r
526 if (street != null) {
\r
527 this.setStreet(street);
\r
530 this.setZipCode(zipCode);
\r
532 if (city != null) {
\r
533 this.setCity(city);
\r
535 if (countryCode != null) {
\r
536 this.setCountryCode(countryCode);
\r
541 * Updates name data in this Contact instance
\r
542 * @param gender Gender (M, F, C)
\r
543 * @param surname Surname
\r
544 * @param familyName Family name
\r
545 * @param companyName Company name
\r
547 public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) {
\r
549 this.setGender(gender);
\r
550 if (surname != null) {
\r
551 this.setSurname(surname);
\r
553 if (familyName != null) {
\r
554 this.setFamilyName(familyName);
\r
556 if (companyName != null) {
\r
557 this.setCompanyName(companyName);
\r
562 * Updates other data in this Contact instance
\r
564 * @param phoneNumber Phone number
\r
565 * @param cellphoneNumber Cellphone number
\r
566 * @param faxNumber Fax number
\r
567 * @param emailAddress Email address
\r
568 * @param birthday Birth day
\r
569 * @param comment Comments
\r
571 public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {
\r
573 if (phoneNumber != null) {
\r
574 this.setPhoneNumber(phoneNumber);
\r
576 if (cellphoneNumber != null) {
\r
577 this.setCellphoneNumber(cellphoneNumber);
\r
579 if (faxNumber != null) {
\r
580 this.setFaxNumber(faxNumber);
\r
582 if (emailAddress != null) {
\r
583 this.setEmailAddress(emailAddress);
\r
585 if (birthday != null) {
\r
586 this.setBirthday(birthday);
\r
588 if (comment != null) {
\r
589 this.setComment(comment);
\r
594 * Enables the flag "own data" which signals that this contact is the user's
\r
597 protected void enableFlagOwnContact () {
\r
598 this.ownContact = true;
\r