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.jcore.contact;
19 import java.text.MessageFormat;
20 import java.util.Objects;
21 import org.mxchange.jcore.BaseFrameworkSystem;
22 import org.mxchange.jcore.client.Client;
27 * @author Roland Haeder
30 public class BaseContact extends BaseFrameworkSystem implements Contact {
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
151 public String getBirthday () {
152 return this.birthday;
158 * @return the cellphoneNumber
161 public String getCellphoneNumber () {
162 return this.cellphoneNumber;
171 public String getCity () {
178 * @param city the city to set
181 public final void setCity (final String city) {
188 * @return the comment
191 public String getComment () {
198 * @param comment the comment to set
201 public final void setComment (final String comment) {
202 this.comment = comment;
208 * @return the companyName
211 public String getCompanyName () {
212 return this.companyName;
218 * @param companyName the companyName to set
221 public final void setCompanyName (final String companyName) {
222 this.companyName = companyName;
228 * @return the countryCode
231 public String getCountryCode () {
232 return this.countryCode;
238 * @param countryCode the countryCode to set
241 public final void setCountryCode (final String countryCode) {
242 this.countryCode = countryCode;
246 * "Serializes" this object into a CSV string (this time with semicolons)
248 * @return "CSV-serialized" version of the stored data
249 * @deprecated Don't use this anymore
252 public String getCsvStringFromStoreableObject () {
254 this.getLogger().trace("CALLED!"); //NOI18N
257 String csvString = String.format(
258 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"", //NOI18N
260 this.getGender().getDatabaseValue(),
262 this.getFamilyName(),
263 this.getCompanyName(),
267 this.getCountryCode(),
268 this.getPhoneNumber(),
270 this.getCellphoneNumber(),
271 this.getEmailAddress(),
283 * @return the emailAddress
286 public String getEmailAddress () {
287 return this.emailAddress;
293 * @param emailAddress the emailAddress to set
296 public final void setEmailAddress (final String emailAddress) {
297 this.emailAddress = emailAddress;
303 * @return the familyName
306 public String getFamilyName () {
307 return this.familyName;
313 * @param familyName the familyName to set
316 public final void setFamilyName (final String familyName) {
317 this.familyName = familyName;
323 * @return the faxNumber
326 public String getFaxNumber () {
327 return this.faxNumber;
333 * @param faxNumber the faxNumber to set
336 public final void setFaxNumber (final String faxNumber) {
337 this.faxNumber = faxNumber;
341 * Gender of the contact
346 public Gender getGender () {
351 * Gender of the contact
353 * @param gender the gender to set
356 public final void setGender (final Gender gender) {
357 this.gender = gender;
363 * @return the houseNumber
366 public int getHouseNumber () {
367 return this.houseNumber;
373 * @return the phoneNumber
376 public String getPhoneNumber () {
377 return this.phoneNumber;
386 public String getStreet () {
393 * @param street the street to set
396 public final void setStreet (final String street) {
397 this.street = street;
403 * @return the surname
406 public final String getSurname () {
411 * Some "getter" for a translated/human-readable gender
413 * @return gender Human-readable gender
416 public String getTranslatedGender () {
418 String translated = this.getBundle().getString(this.getGender().getMessageKey());
427 * @return the zipCode
430 public final long getZipCode () {
437 * @param zipCode the zipCode to set
440 public final void setZipCode (final long zipCode) {
441 this.zipCode = zipCode;
445 public int hashCode () {
446 // Validate gender instance
447 assert (this.getGender() instanceof Gender) : "gender is not set.";
450 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
451 hash = 79 * hash + this.getGender().hashCode();
452 hash = 79 * hash + Objects.hashCode(this.getSurname());
457 * Checks whether the contact is user's own data
462 public final boolean isOwnContact () {
463 return this.ownContact;
467 * Shows this contact to the user
469 * @param client Client instance to use
472 public void show (final Client client) {
474 this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N
476 // The client must be set
477 if (client == null) {
479 throw new NullPointerException("client is null");
482 // Display name "box"
483 client.displayNameBox(this);
485 // Display address "box"
486 client.displayAddressBox(this);
488 // Display other data "box"
489 client.displayOtherDataBox(this);
493 * Enables the flag "own data" which signals that this contact is the user's
496 protected final void enableFlagOwnContact () {
497 this.ownContact = true;
503 * @param surname the surname to set
506 public final void setSurname (final String surname) {
507 this.surname = surname;
513 * @param phoneNumber the phoneNumber to set
516 public final void setPhoneNumber (final String phoneNumber) {
517 this.phoneNumber = phoneNumber;
523 * @param houseNumber the houseNumber to set
525 public final void setHouseNumber (final int houseNumber) {
526 this.houseNumber = houseNumber;
532 * @param cellphoneNumber the cellphoneNumber to set
535 public final void setCellphoneNumber (final String cellphoneNumber) {
536 this.cellphoneNumber = cellphoneNumber;
542 * @param birthday the birthday to set
545 public final void setBirthday (final String birthday) {
546 this.birthday = birthday;
550 * Some "getter for a value from given column name. This name will be
551 * translated into a method name and then this method is called.
553 * @param columnName Column name
554 * @return Value from field
557 public Object getValueFromColumn (final String columnName) {
559 this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName));
561 // Determine if the given column is boolean
562 if (this.isBooleanField(this, "BaseContact", columnName)) {
563 // Yes, then call other method
564 return this.getBooleanField(this, "BaseContact", columnName);
567 // Convert column name to field name
568 String methodName = this.convertColumnNameToGetterMethod(columnName, false);
571 this.getLogger().debug(MessageFormat.format("field={0}", methodName));
574 Object value = this.getField(this, "BaseContact", methodName);
577 this.getLogger().trace("value=" + value + " - EXIT!");
584 * Checks if given boolean field is available and set to same value
586 * @param columnName Column name to check
587 * @param bool Boolean value
588 * @return Whether all conditions are met
591 public boolean isValueEqual (final String columnName, final boolean bool) {
593 this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool));
595 // Convert column name to field name
596 String methodName = this.convertColumnNameToGetterMethod(columnName, true);
599 this.getLogger().debug(MessageFormat.format("field={0}", methodName));
601 // Init class instance
602 boolean value = this.getBooleanField(this, "BaseContact", methodName);
605 this.getLogger().debug(MessageFormat.format("value={0}", value));
608 boolean isFound = (bool == value);
611 this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound));