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 * @param birthday the birthday to set
161 public final void setBirthday (final String birthday) {
162 this.birthday = birthday;
168 * @return the cellphoneNumber
171 public String getCellphoneNumber () {
172 return this.cellphoneNumber;
178 * @param cellphoneNumber the cellphoneNumber to set
181 public final void setCellphoneNumber (final String cellphoneNumber) {
182 this.cellphoneNumber = cellphoneNumber;
191 public String getCity () {
198 * @param city the city to set
201 public final void setCity (final String city) {
208 * @return the comment
211 public String getComment () {
218 * @param comment the comment to set
221 public final void setComment (final String comment) {
222 this.comment = comment;
228 * @return the companyName
231 public String getCompanyName () {
232 return this.companyName;
238 * @param companyName the companyName to set
241 public final void setCompanyName (final String companyName) {
242 this.companyName = companyName;
248 * @return the countryCode
251 public String getCountryCode () {
252 return this.countryCode;
258 * @param countryCode the countryCode to set
261 public final void setCountryCode (final String countryCode) {
262 this.countryCode = countryCode;
266 * "Serializes" this object into a CSV string (this time with semicolons)
268 * @return "CSV-serialized" version of the stored data
269 * @deprecated Don't use this anymore
272 public String getCsvStringFromStoreableObject () {
274 this.getLogger().trace("CALLED!"); //NOI18N
277 String csvString = String.format(
278 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"", //NOI18N
280 this.getGender().getDatabaseValue(),
282 this.getFamilyName(),
283 this.getCompanyName(),
287 this.getCountryCode(),
288 this.getPhoneNumber(),
290 this.getCellphoneNumber(),
291 this.getEmailAddress(),
303 * @return the emailAddress
306 public String getEmailAddress () {
307 return this.emailAddress;
313 * @param emailAddress the emailAddress to set
316 public final void setEmailAddress (final String emailAddress) {
317 this.emailAddress = emailAddress;
323 * @return the familyName
326 public String getFamilyName () {
327 return this.familyName;
333 * @param familyName the familyName to set
336 public final void setFamilyName (final String familyName) {
337 this.familyName = familyName;
343 * @return the faxNumber
346 public String getFaxNumber () {
347 return this.faxNumber;
353 * @param faxNumber the faxNumber to set
356 public final void setFaxNumber (final String faxNumber) {
357 this.faxNumber = faxNumber;
361 * Gender of the contact
366 public Gender getGender () {
371 * Gender of the contact
373 * @param gender the gender to set
376 public final void setGender (final Gender gender) {
377 this.gender = gender;
383 * @return the houseNumber
386 public int getHouseNumber () {
387 return this.houseNumber;
393 * @param houseNumber the houseNumber to set
396 public final void setHouseNumber (final int houseNumber) {
397 this.houseNumber = houseNumber;
403 * @return the phoneNumber
406 public String getPhoneNumber () {
407 return this.phoneNumber;
413 * @param phoneNumber the phoneNumber to set
416 public final void setPhoneNumber (final String phoneNumber) {
417 this.phoneNumber = phoneNumber;
426 public String getStreet () {
433 * @param street the street to set
436 public final void setStreet (final String street) {
437 this.street = street;
443 * @return the surname
446 public final String getSurname () {
453 * @param surname the surname to set
456 public final void setSurname (final String surname) {
457 this.surname = surname;
461 * Some "getter" for a translated/human-readable gender
463 * @return gender Human-readable gender
466 public String getTranslatedGender () {
468 String translated = this.getBundle().getString(this.getGender().getMessageKey());
475 * Some "getter for a value from given column name. This name will be
476 * translated into a method name and then this method is called.
478 * @param columnName Column name
479 * @return Value from field
482 public Object getValueFromColumn (final String columnName) {
484 this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName));
486 // Determine if the given column is boolean
487 if (this.isBooleanField(this, "BaseContact", columnName)) {
488 // Yes, then call other method
489 return this.getBooleanField(this, "BaseContact", columnName);
492 // Convert column name to field name
493 String methodName = this.convertColumnNameToGetterMethod(columnName, false);
496 this.getLogger().debug(MessageFormat.format("field={0}", methodName));
499 Object value = this.getField(this, "BaseContact", methodName);
502 this.getLogger().trace("value=" + value + " - EXIT!");
511 * @return the zipCode
514 public final long getZipCode () {
521 * @param zipCode the zipCode to set
524 public final void setZipCode (final long zipCode) {
525 this.zipCode = zipCode;
529 public int hashCode () {
530 // Validate gender instance
531 assert (this.getGender() instanceof Gender) : "gender is not set.";
534 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
535 hash = 79 * hash + this.getGender().hashCode();
536 hash = 79 * hash + Objects.hashCode(this.getSurname());
541 * Checks whether the contact is user's own data
546 public final boolean isOwnContact () {
547 return this.ownContact;
551 * Checks if given boolean field is available and set to same value
553 * @param columnName Column name to check
554 * @param bool Boolean value
555 * @return Whether all conditions are met
558 public boolean isValueEqual (final String columnName, final boolean bool) {
560 this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool));
562 // Convert column name to field name
563 String methodName = this.convertColumnNameToGetterMethod(columnName, true);
566 this.getLogger().debug(MessageFormat.format("field={0}", methodName));
568 // Init class instance
569 boolean value = this.getBooleanField(this, "BaseContact", methodName);
572 this.getLogger().debug(MessageFormat.format("value={0}", value));
575 boolean isFound = (bool == value);
578 this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound));
585 * Shows this contact to the user
587 * @param client Client instance to use
590 public void show (final Client client) {
592 this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N
594 // The client must be set
595 if (client == null) {
597 throw new NullPointerException("client is null");
600 // Display name "box"
601 client.displayNameBox(this);
603 // Display address "box"
604 client.displayAddressBox(this);
606 // Display other data "box"
607 client.displayOtherDataBox(this);
611 * Enables the flag "own data" which signals that this contact is the user's
614 protected final void enableFlagOwnContact () {
615 this.ownContact = true;