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.Iterator;
21 import java.util.Objects;
22 import org.mxchange.jcore.BaseFrameworkSystem;
23 import org.mxchange.jcore.client.Client;
28 * @author Roland Haeder
31 public class BaseContact extends BaseFrameworkSystem implements Contact {
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 long houseNumber;
89 * Flag 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
152 public String getBirthday () {
153 return this.birthday;
159 * @param birthday the birthday to set
162 public final void setBirthday (final String birthday) {
163 this.birthday = birthday;
169 * @return the cellphoneNumber
172 public String getCellphoneNumber () {
173 return this.cellphoneNumber;
179 * @param cellphoneNumber the cellphoneNumber to set
182 public final void setCellphoneNumber (final String cellphoneNumber) {
183 this.cellphoneNumber = cellphoneNumber;
192 public String getCity () {
199 * @param city the city to set
202 public final void setCity (final String city) {
209 * @return the comment
212 public String getComment () {
219 * @param comment the comment to set
222 public final void setComment (final String comment) {
223 this.comment = comment;
229 * @return the companyName
232 public String getCompanyName () {
233 return this.companyName;
239 * @param companyName the companyName to set
242 public final void setCompanyName (final String companyName) {
243 this.companyName = companyName;
249 * @return the countryCode
252 public String getCountryCode () {
253 return this.countryCode;
259 * @param countryCode the countryCode to set
262 public final void setCountryCode (final String countryCode) {
263 this.countryCode = countryCode;
267 * "Serializes" this object into a CSV string (this time with semicolons)
269 * @return "CSV-serialized" version of the stored data
270 * @deprecated Don't use this anymore
273 public String getCsvStringFromStoreableObject () {
275 this.getLogger().trace("CALLED!"); //NOI18N
278 String csvString = String.format(
279 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"", //NOI18N
281 this.getGender().getDatabaseValue(),
283 this.getFamilyName(),
284 this.getCompanyName(),
288 this.getCountryCode(),
289 this.getPhoneNumber(),
291 this.getCellphoneNumber(),
292 this.getEmailAddress(),
304 * @return the emailAddress
307 public String getEmailAddress () {
308 return this.emailAddress;
314 * @param emailAddress the emailAddress to set
317 public final void setEmailAddress (final String emailAddress) {
318 this.emailAddress = emailAddress;
324 * @return the familyName
327 public String getFamilyName () {
328 return this.familyName;
334 * @param familyName the familyName to set
337 public final void setFamilyName (final String familyName) {
338 this.familyName = familyName;
344 * @return the faxNumber
347 public String getFaxNumber () {
348 return this.faxNumber;
354 * @param faxNumber the faxNumber to set
357 public final void setFaxNumber (final String faxNumber) {
358 this.faxNumber = faxNumber;
362 * Gender of the contact
367 public Gender getGender () {
372 * Gender of the contact
374 * @param gender the gender to set
377 public final void setGender (final Gender gender) {
378 this.gender = gender;
384 * @return the houseNumber
387 public long getHouseNumber () {
388 return this.houseNumber;
394 * @param houseNumber the houseNumber to set
397 public final void setHouseNumber (final long houseNumber) {
398 this.houseNumber = houseNumber;
404 * @return the phoneNumber
407 public String getPhoneNumber () {
408 return this.phoneNumber;
414 * @param phoneNumber the phoneNumber to set
417 public final void setPhoneNumber (final String phoneNumber) {
418 this.phoneNumber = phoneNumber;
427 public String getStreet () {
434 * @param street the street to set
437 public final void setStreet (final String street) {
438 this.street = street;
444 * @return the surname
447 public final String getSurname () {
454 * @param surname the surname to set
457 public final void setSurname (final String surname) {
458 this.surname = surname;
462 * Some "getter" for a translated/human-readable gender
464 * @return gender Human-readable gender
467 public String getTranslatedGender () {
469 String translated = this.getBundle().getString(this.getGender().getMessageKey());
476 * Some "getter for a value from given column name. This name will be
477 * translated into a method name and then this method is called.
479 * @param columnName Column name
480 * @return Value from field
483 public Object getValueFromColumn (final String columnName) {
485 this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName));
487 // Determine if the given column is boolean
488 if (this.isBooleanField(this, "BaseContact", columnName)) {
489 // Yes, then call other method
490 return this.getBooleanField(this, "BaseContact", columnName);
493 // Convert column name to field name
494 String methodName = this.convertColumnNameToGetterMethod(columnName, false);
497 this.getLogger().debug(MessageFormat.format("field={0}", methodName));
500 Object value = this.getField(this, "BaseContact", methodName);
503 this.getLogger().trace("value=" + value + " - EXIT!");
512 * @return the zipCode
515 public final long getZipCode () {
522 * @param zipCode the zipCode to set
525 public final void setZipCode (final long zipCode) {
526 this.zipCode = zipCode;
530 public int hashCode () {
531 // Validate gender instance
532 assert (this.getGender() instanceof Gender) : "gender is not set.";
535 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
536 hash = 79 * hash + this.getGender().hashCode();
537 hash = 79 * hash + Objects.hashCode(this.getSurname());
542 * Checks whether the contact is user's own data
547 public final boolean isOwnContact () {
548 return this.ownContact;
552 * Checks if given boolean field is available and set to same value
554 * @param columnName Column name to check
555 * @param bool Boolean value
556 * @return Whether all conditions are met
559 public boolean isValueEqual (final String columnName, final boolean bool) {
561 this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool));
563 // Convert column name to field name
564 String methodName = this.convertColumnNameToGetterMethod(columnName, true);
567 this.getLogger().debug(MessageFormat.format("field={0}", methodName));
569 // Init class instance
570 boolean value = this.getBooleanField(this, "BaseContact", methodName);
573 this.getLogger().debug(MessageFormat.format("value={0}", value));
576 boolean isFound = (bool == value);
579 this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound));
586 * Returns an iterator of all values from this object
587 * @return An iterator
590 public Iterator<Object> iterator () {
591 return this.fieldIterator(this, "BaseContact");
595 * Shows this contact to the user
597 * @param client Client instance to use
600 public void show (final Client client) {
602 this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N
604 // The client must be set
605 if (client == null) {
607 throw new NullPointerException("client is null");
610 // Display name "box"
611 client.displayNameBox(this);
613 // Display address "box"
614 client.displayAddressBox(this);
616 // Display other data "box"
617 client.displayOtherDataBox(this);
621 * Enables the flag "own data" which signals that this contact is the user's
624 protected final void enableFlagOwnContact () {
625 this.ownContact = true;