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.text.MessageFormat;
20 import java.util.Objects;
21 import org.mxchange.addressbook.BaseFrameworkSystem;
22 import org.mxchange.addressbook.client.Client;
27 * @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 () {
119 * Check if contacts are same or throw an exception
121 * @param object Other possible contact class
122 * @return Whether both contacts are same
123 * @todo Needs a lot improvements
126 public boolean equals (final Object object) {
128 if (!(object instanceof BaseContact)) {
131 } else if (!(object instanceof Contact)) {
132 // Not correct interface
137 Contact contact = (Contact) object;
139 // Now test some data @todo Definedly needs improvement
140 return ((this.getGender().equals(contact.getGender()))
141 && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))
142 && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
148 * @return the birthday
150 public String getBirthday () {
151 return this.birthday;
157 * @return the cellphoneNumber
159 public String getCellphoneNumber () {
160 return this.cellphoneNumber;
168 public String getCity () {
175 * @param city the city to set
177 private void setCity (final String city) {
184 * @return the comment
186 public String getComment () {
193 * @param comment the comment to set
195 private void setComment (final String comment) {
196 this.comment = comment;
202 * @return the companyName
204 public String getCompanyName () {
205 return this.companyName;
211 * @param companyName the companyName to set
213 private void setCompanyName (final String companyName) {
214 this.companyName = companyName;
220 * @return the countryCode
222 public String getCountryCode () {
223 return this.countryCode;
229 * @param countryCode the countryCode to set
231 private void setCountryCode (final String countryCode) {
232 this.countryCode = countryCode;
236 * "Serializes" this object into a CSV string (this time with semicolons)
238 * @return "CSV-serialized" version of the stored data
240 public String getCsvStringFromStoreableObject () {
242 this.getLogger().trace("CALLED!"); //NOI18N
245 String csvString = String.format(
246 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"",
248 this.getGender().getDatabaseValue(),
250 this.getFamilyName(),
251 this.getCompanyName(),
255 this.getCountryCode(),
256 this.getPhoneNumber(),
258 this.getCellphoneNumber(),
259 this.getEmailAddress(),
271 * @return the emailAddress
273 public String getEmailAddress () {
274 return this.emailAddress;
280 * @param emailAddress the emailAddress to set
282 private void setEmailAddress (final String emailAddress) {
283 this.emailAddress = emailAddress;
289 * @return the familyName
291 public String getFamilyName () {
292 return this.familyName;
298 * @param familyName the familyName to set
300 private void setFamilyName (final String familyName) {
301 this.familyName = familyName;
307 * @return the faxNumber
309 public String getFaxNumber () {
310 return this.faxNumber;
316 * @param faxNumber the faxNumber to set
318 private void setFaxNumber (final String faxNumber) {
319 this.faxNumber = faxNumber;
323 * Gender of the contact
327 public Gender getGender () {
332 * Gender of the contact
334 * @param gender the gender to set
336 private void setGender (final Gender gender) {
337 this.gender = gender;
343 * @return the houseNumber
345 public int getHouseNumber () {
346 return this.houseNumber;
352 * @return the phoneNumber
354 public String getPhoneNumber () {
355 return this.phoneNumber;
363 public String getStreet () {
370 * @param street the street to set
372 protected final void setStreet (final String street) {
373 this.street = street;
379 * @return the surname
381 public final String getSurname () {
386 * Some "getter" for a translated/human-readable gender
388 * @return gender Human-readable gender
390 public String getTranslatedGender () {
392 String translated = null;
395 switch (this.getGender()) {
404 case COMPANY: // "Company"
405 translated = "Firma";
408 default: // Unsupported
409 this.getLogger().error("Gender " + this.getGender() + " not supported.");
420 * @return the zipCode
422 public final long getZipCode () {
429 * @param zipCode the zipCode to set
431 protected final void setZipCode (final long zipCode) {
432 this.zipCode = zipCode;
436 public int hashCode () {
437 // Validate gender instance
438 assert (this.getGender() instanceof Gender) : "gender is not set.";
441 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
442 hash = 79 * hash + this.getGender().hashCode();
443 hash = 79 * hash + Objects.hashCode(this.getSurname());
448 * Checks whether the contact is user's own data
452 public final boolean isOwnContact () {
453 return this.ownContact;
457 * Shows this contact to the user
459 * @param client Client instance to use
461 public void show (final Client client) {
463 this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N
465 // The client must be set
466 if (client == null) {
468 throw new NullPointerException("client is null");
471 // Display name "box"
472 client.displayNameBox((Contact) this);
474 // Display address "box"
475 client.displayAddressBox((Contact) this);
477 // Display other data "box"
478 client.displayOtherDataBox((Contact) this);
482 * Updates address data in this Contact instance
484 * @param street Street
485 * @param zipCode ZIP code
487 * @param countryCode Country code
489 public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {
491 this.getLogger().trace(MessageFormat.format("street={0},zipCode={1},city={2},countryCode={3} - CALLED!", street, zipCode, city, countryCode)); //NOI18N
494 if (street != null) {
495 this.setStreet(street);
498 this.setZipCode(zipCode);
503 if (countryCode != null) {
504 this.setCountryCode(countryCode);
508 this.getLogger().trace("EXIT!"); //NOI18N
512 * Updates name data in this Contact instance
514 * @param gender Gender (M, F, C)
515 * @param surname Surname
516 * @param familyName Family name
517 * @param companyName Company name
519 public void updateNameData (final Gender gender, final String surname, final String familyName, final String companyName) {
521 this.getLogger().trace(MessageFormat.format("gender={0},surname={1},familyName={2},companyName={3} - CALLED!", gender, surname, familyName, companyName)); //NOI18N
524 this.setGender(gender);
526 if (surname != null) {
527 this.setSurname(surname);
529 if (familyName != null) {
530 this.setFamilyName(familyName);
532 if (companyName != null) {
533 this.setCompanyName(companyName);
537 this.getLogger().trace("EXIT!"); //NOI18N
541 * Updates other data in this Contact instance
543 * @param phoneNumber Phone number
544 * @param cellphoneNumber Cellphone number
545 * @param faxNumber Fax number
546 * @param emailAddress Email address
547 * @param birthday Birth day
548 * @param comment Comments
550 public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {
552 this.getLogger().trace(MessageFormat.format("phoneNumber={0},cellphoneNumber={1}faxNumber={2},emailAddress={3},birthday={4},comment={5} - CALLED!", phoneNumber, cellphoneNumber, faxNumber, emailAddress, birthday, comment)); //NOI18N
555 if (phoneNumber != null) {
556 this.setPhoneNumber(phoneNumber);
558 if (cellphoneNumber != null) {
559 this.setCellphoneNumber(cellphoneNumber);
561 if (faxNumber != null) {
562 this.setFaxNumber(faxNumber);
564 if (emailAddress != null) {
565 this.setEmailAddress(emailAddress);
567 if (birthday != null) {
568 this.setBirthday(birthday);
570 if (comment != null) {
571 this.setComment(comment);
575 this.getLogger().trace("EXIT!"); //NOI18N
579 * Enables the flag "own data" which signals that this contact is the user's
582 protected final void enableFlagOwnContact () {
583 this.ownContact = true;
589 * @param surname the surname to set
591 protected final void setSurname (final String surname) {
592 this.surname = surname;
598 * @param phoneNumber the phoneNumber to set
600 protected final void setPhoneNumber (final String phoneNumber) {
601 this.phoneNumber = phoneNumber;
607 * @param houseNumber the houseNumber to set
609 protected final void setHouseNumber (final int houseNumber) {
610 this.houseNumber = houseNumber;
616 * @param cellphoneNumber the cellphoneNumber to set
618 protected final void setCellphoneNumber (final String cellphoneNumber) {
619 this.cellphoneNumber = cellphoneNumber;
625 * @param birthday the birthday to set
627 protected final void setBirthday (final String birthday) {
628 this.birthday = birthday;
632 * Checks if given boolean field is available and set to same value
634 * @param columnName Column name to check
635 * @param bool Boolean value
636 * @return Whether all conditions are met
638 public boolean isValueEqual (final String columnName, final boolean bool) {
640 this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool));
642 // Convert column name to field name
643 String methodName = this.convertColumnNameToGetterMethod(columnName, true);
646 this.getLogger().debug(MessageFormat.format("field={0}", methodName));
648 // Init class instance
649 boolean value = this.getBooleanField(this, "BaseContact", methodName);
652 this.getLogger().debug(MessageFormat.format("value={0}", value));
655 boolean isFound = (bool == value);
658 this.getLogger().trace("isFound=" + isFound + " - EXIT!");