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
31 public class BaseContact extends BaseFrameworkSystem {
36 private String birthday;
41 private String cellphoneNumber;
51 private String comment;
56 private String companyName;
61 private String countryCode;
66 private String emailAddress;
71 private String familyName;
76 private String faxNumber;
81 private Gender gender;
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 () {
120 * Check if contacts are same or throw an exception
122 * @param object Other possible contact class
123 * @return Whether both contacts are same
124 * @todo Needs a lot improvements
127 public boolean equals (final Object object) {
129 if (!(object instanceof BaseContact)) {
132 } else if (!(object instanceof Contact)) {
133 // Not correct interface
138 Contact contact = (Contact) object;
140 // Now test some data @todo Definedly needs improvement
141 return ((this.getGender().equals(contact.getGender()))
142 && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))
143 && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
149 * @return the birthday
151 public String getBirthday () {
152 return this.birthday;
158 * @return the cellphoneNumber
160 public String getCellphoneNumber () {
161 return this.cellphoneNumber;
169 public String getCity () {
176 * @param city the city to set
178 private void setCity (final String city) {
185 * @return the comment
187 public String getComment () {
194 * @param comment the comment to set
196 private void setComment (final String comment) {
197 this.comment = comment;
203 * @return the companyName
205 public String getCompanyName () {
206 return this.companyName;
212 * @param companyName the companyName to set
214 private void setCompanyName (final String companyName) {
215 this.companyName = companyName;
221 * @return the countryCode
223 public String getCountryCode () {
224 return this.countryCode;
230 * @param countryCode the countryCode to set
232 private void setCountryCode (final String countryCode) {
233 this.countryCode = countryCode;
237 * "Serializes" this object into a CSV string (this time with semicolons)
239 * @return "CSV-serialized" version of the stored data
241 public String getCsvStringFromStoreableObject () {
243 this.getLogger().trace("CALLED!"); //NOI18N
246 String csvString = String.format(
247 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"",
249 this.getGender().getDatabaseValue(),
251 this.getFamilyName(),
252 this.getCompanyName(),
256 this.getCountryCode(),
257 this.getPhoneNumber(),
259 this.getCellphoneNumber(),
260 this.getEmailAddress(),
272 * @return the emailAddress
274 public String getEmailAddress () {
275 return this.emailAddress;
281 * @param emailAddress the emailAddress to set
283 private void setEmailAddress (final String emailAddress) {
284 this.emailAddress = emailAddress;
290 * @return the familyName
292 public String getFamilyName () {
293 return this.familyName;
299 * @param familyName the familyName to set
301 private void setFamilyName (final String familyName) {
302 this.familyName = familyName;
308 * @return the faxNumber
310 public String getFaxNumber () {
311 return this.faxNumber;
317 * @param faxNumber the faxNumber to set
319 private void setFaxNumber (final String faxNumber) {
320 this.faxNumber = faxNumber;
324 * Gender of the contact
328 public Gender getGender () {
333 * Gender of the contact
335 * @param gender the gender to set
337 private void setGender (final Gender gender) {
338 this.gender = gender;
344 * @return the houseNumber
346 public int getHouseNumber () {
347 return this.houseNumber;
353 * @return the phoneNumber
355 public String getPhoneNumber () {
356 return this.phoneNumber;
364 public String getStreet () {
371 * @param street the street to set
373 protected final void setStreet (final String street) {
374 this.street = street;
380 * @return the surname
382 public final String getSurname () {
387 * Some "getter" for a translated/human-readable gender
389 * @return gender Human-readable gender
391 public String getTranslatedGender () {
393 String translated = null;
396 switch (this.getGender()) {
405 case COMPANY: // "Company"
406 translated = "Firma";
409 default: // Unsupported
410 this.getLogger().error("Gender " + this.getGender() + " not supported.");
421 * @return the zipCode
423 public final long getZipCode () {
430 * @param zipCode the zipCode to set
432 protected final void setZipCode (final long zipCode) {
433 this.zipCode = zipCode;
437 public int hashCode () {
438 // Validate gender instance
439 assert (this.getGender() instanceof Gender) : "gender is not set.";
442 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
443 hash = 79 * hash + this.getGender().hashCode();
444 hash = 79 * hash + Objects.hashCode(this.getSurname());
449 * Checks whether the contact is user's own data
453 public final boolean isOwnContact () {
454 return this.ownContact;
458 * Shows this contact to the user
460 * @param client Client instance to use
462 public void show (final Client client) {
464 this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N
466 // The client must be set
467 if (client == null) {
469 throw new NullPointerException("client is null");
472 // Display name "box"
473 client.displayNameBox((Contact) this);
475 // Display address "box"
476 client.displayAddressBox((Contact) this);
478 // Display other data "box"
479 client.displayOtherDataBox((Contact) this);
483 * Updates address data in this Contact instance
485 * @param street Street
486 * @param zipCode ZIP code
488 * @param countryCode Country code
490 public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {
492 this.getLogger().trace(MessageFormat.format("street={0},zipCode={1},city={2},countryCode={3} - CALLED!", street, zipCode, city, countryCode)); //NOI18N
495 if (street != null) {
496 this.setStreet(street);
499 this.setZipCode(zipCode);
504 if (countryCode != null) {
505 this.setCountryCode(countryCode);
509 this.getLogger().trace("EXIT!"); //NOI18N
513 * Updates name data in this Contact instance
515 * @param gender Gender (M, F, C)
516 * @param surname Surname
517 * @param familyName Family name
518 * @param companyName Company name
520 public void updateNameData (final Gender gender, final String surname, final String familyName, final String companyName) {
522 this.getLogger().trace(MessageFormat.format("gender={0},surname={1},familyName={2},companyName={3} - CALLED!", gender, surname, familyName, companyName)); //NOI18N
525 this.setGender(gender);
527 if (surname != null) {
528 this.setSurname(surname);
530 if (familyName != null) {
531 this.setFamilyName(familyName);
533 if (companyName != null) {
534 this.setCompanyName(companyName);
538 this.getLogger().trace("EXIT!"); //NOI18N
542 * Updates other data in this Contact instance
544 * @param phoneNumber Phone number
545 * @param cellphoneNumber Cellphone number
546 * @param faxNumber Fax number
547 * @param emailAddress Email address
548 * @param birthday Birth day
549 * @param comment Comments
551 public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {
553 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
556 if (phoneNumber != null) {
557 this.setPhoneNumber(phoneNumber);
559 if (cellphoneNumber != null) {
560 this.setCellphoneNumber(cellphoneNumber);
562 if (faxNumber != null) {
563 this.setFaxNumber(faxNumber);
565 if (emailAddress != null) {
566 this.setEmailAddress(emailAddress);
568 if (birthday != null) {
569 this.setBirthday(birthday);
571 if (comment != null) {
572 this.setComment(comment);
576 this.getLogger().trace("EXIT!"); //NOI18N
580 * Enables the flag "own data" which signals that this contact is the user's
583 protected final void enableFlagOwnContact () {
584 this.ownContact = true;
590 * @param surname the surname to set
592 protected final void setSurname (final String surname) {
593 this.surname = surname;
599 * @param phoneNumber the phoneNumber to set
601 protected final void setPhoneNumber (final String phoneNumber) {
602 this.phoneNumber = phoneNumber;
608 * @param houseNumber the houseNumber to set
610 protected final void setHouseNumber (final int houseNumber) {
611 this.houseNumber = houseNumber;
617 * @param cellphoneNumber the cellphoneNumber to set
619 protected final void setCellphoneNumber (final String cellphoneNumber) {
620 this.cellphoneNumber = cellphoneNumber;
626 * @param birthday the birthday to set
628 protected final void setBirthday (final String birthday) {
629 this.birthday = birthday;
633 * Checks if given boolean field is available and set to same value
635 * @param columnName Column name to check
636 * @param bool Boolean value
637 * @return Whether all conditions are met
639 public boolean isValueEqual (final String columnName, final boolean bool) {
641 this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool));
643 // Convert column name to field name
644 String methodName = this.convertColumnNameToGetterMethod(columnName, true);
647 this.getLogger().debug(MessageFormat.format("field={0}", methodName));
649 // Init class instance
650 boolean value = this.getBooleanField(this, "BaseContact", methodName);
653 this.getLogger().debug(MessageFormat.format("value={0}", value));
656 boolean isFound = (bool == value);
659 this.getLogger().trace("isFound=" + isFound + " - EXIT!");