]> git.mxchange.org Git - jcore.git/blob - src/org/mxchange/jcore/contact/BaseContact.java
Made all data-setter public, Gender is fine to be set publicly.
[jcore.git] / src / org / mxchange / jcore / contact / BaseContact.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jcore.contact;
18
19 import java.text.MessageFormat;
20 import java.util.Objects;
21 import org.mxchange.jcore.BaseFrameworkSystem;
22 import org.mxchange.jcore.client.Client;
23
24 /**
25  * A general contact
26  *
27  * @author Roland Haeder
28  * @version 0.0
29  */
30 public class BaseContact extends BaseFrameworkSystem implements Contact {
31
32         /**
33          * Birth day
34          */
35         private String birthday;
36
37         /**
38          * Cellphone number
39          */
40         private String cellphoneNumber;
41
42         /**
43          * City
44          */
45         private String city;
46
47         /**
48          * Optional comments
49          */
50         private String comment;
51
52         /**
53          * Companyname
54          */
55         private String companyName;
56
57         /**
58          * Country code
59          */
60         private String countryCode;
61
62         /**
63          * Email address
64          */
65         private String emailAddress;
66
67         /**
68          * Family name
69          */
70         private String familyName;
71
72         /**
73          * Fax number
74          */
75         private String faxNumber;
76
77         /**
78          * Gender instance
79          */
80         private Gender gender;
81
82         /**
83          * House number
84          */
85         private int houseNumber;
86
87         /**
88          * Marker whether this contact is user's own data
89          */
90         private boolean ownContact;
91
92         /**
93          * Phone number
94          */
95         private String phoneNumber;
96
97         /**
98          * Street
99          */
100         private String street;
101
102         /**
103          * Surname
104          */
105         private String surname;
106
107         /**
108          * ZIP code
109          */
110         private long zipCode;
111
112         /**
113          * No instances can be created of this class
114          */
115         protected BaseContact () {
116         }
117
118         /**
119          * Check if contacts are same or throw an exception
120          *
121          * @param object Other possible contact class
122          * @return Whether both contacts are same
123          * @todo Needs a lot improvements
124          */
125         @Override
126         public boolean equals (final Object object) {
127                 // Is it same type?
128                 if (!(object instanceof BaseContact)) {
129                         // Not equal types
130                         return false;
131                 } else if (!(object instanceof Contact)) {
132                         // Not correct interface
133                         return false;
134                 }
135
136                 // Try to cast
137                 Contact contact = (Contact) object;
138
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())));
143         }
144
145         /**
146          * Birth day
147          *
148          * @return the birthday
149          */
150         @Override
151         public String getBirthday () {
152                 return this.birthday;
153         }
154
155         /**
156          * Cellphone number
157          *
158          * @return the cellphoneNumber
159          */
160         @Override
161         public String getCellphoneNumber () {
162                 return this.cellphoneNumber;
163         }
164
165         /**
166          * City
167          *
168          * @return the city
169          */
170         @Override
171         public String getCity () {
172                 return this.city;
173         }
174
175         /**
176          * City
177          *
178          * @param city the city to set
179          */
180         @Override
181         public final void setCity (final String city) {
182                 this.city = city;
183         }
184
185         /**
186          * Comments
187          *
188          * @return the comment
189          */
190         @Override
191         public String getComment () {
192                 return this.comment;
193         }
194
195         /**
196          * Comments
197          *
198          * @param comment the comment to set
199          */
200         @Override
201         public final void setComment (final String comment) {
202                 this.comment = comment;
203         }
204
205         /**
206          * Companyname
207          *
208          * @return the companyName
209          */
210         @Override
211         public String getCompanyName () {
212                 return this.companyName;
213         }
214
215         /**
216          * Companyname
217          *
218          * @param companyName the companyName to set
219          */
220         @Override
221         public final void setCompanyName (final String companyName) {
222                 this.companyName = companyName;
223         }
224
225         /**
226          * Country code
227          *
228          * @return the countryCode
229          */
230         @Override
231         public String getCountryCode () {
232                 return this.countryCode;
233         }
234
235         /**
236          * Country code
237          *
238          * @param countryCode the countryCode to set
239          */
240         @Override
241         public final void setCountryCode (final String countryCode) {
242                 this.countryCode = countryCode;
243         }
244
245         /**
246          * "Serializes" this object into a CSV string (this time with semicolons)
247          *
248          * @return "CSV-serialized" version of the stored data
249          * @deprecated Don't use this anymore
250          */
251         @Deprecated
252         public String getCsvStringFromStoreableObject () {
253                 // Trace message
254                 this.getLogger().trace("CALLED!"); //NOI18N
255
256                 // Get all together
257                 String csvString = String.format(
258                                 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"", //NOI18N
259                                 this.isOwnContact(),
260                                 this.getGender().getDatabaseValue(),
261                                 this.getSurname(),
262                                 this.getFamilyName(),
263                                 this.getCompanyName(),
264                                 this.getStreet(),
265                                 this.getZipCode(),
266                                 this.getCity(),
267                                 this.getCountryCode(),
268                                 this.getPhoneNumber(),
269                                 this.getFaxNumber(),
270                                 this.getCellphoneNumber(),
271                                 this.getEmailAddress(),
272                                 this.getBirthday(),
273                                 this.getComment()
274                 );
275
276                 // Then return it
277                 return csvString;
278         }
279
280         /**
281          * Email address
282          *
283          * @return the emailAddress
284          */
285         @Override
286         public String getEmailAddress () {
287                 return this.emailAddress;
288         }
289
290         /**
291          * Email address
292          *
293          * @param emailAddress the emailAddress to set
294          */
295         @Override
296         public final void setEmailAddress (final String emailAddress) {
297                 this.emailAddress = emailAddress;
298         }
299
300         /**
301          * Family name
302          *
303          * @return the familyName
304          */
305         @Override
306         public String getFamilyName () {
307                 return this.familyName;
308         }
309
310         /**
311          * Family name
312          *
313          * @param familyName the familyName to set
314          */
315         @Override
316         public final void setFamilyName (final String familyName) {
317                 this.familyName = familyName;
318         }
319
320         /**
321          * Fax number
322          *
323          * @return the faxNumber
324          */
325         @Override
326         public String getFaxNumber () {
327                 return this.faxNumber;
328         }
329
330         /**
331          * Fax number
332          *
333          * @param faxNumber the faxNumber to set
334          */
335         @Override
336         public final void setFaxNumber (final String faxNumber) {
337                 this.faxNumber = faxNumber;
338         }
339
340         /**
341          * Gender of the contact
342          *
343          * @return the gender
344          */
345         @Override
346         public Gender getGender () {
347                 return this.gender;
348         }
349
350         /**
351          * Gender of the contact
352          *
353          * @param gender the gender to set
354          */
355         @Override
356         public final void setGender (final Gender gender) {
357                 this.gender = gender;
358         }
359
360         /**
361          * House number
362          *
363          * @return the houseNumber
364          */
365         @Override
366         public int getHouseNumber () {
367                 return this.houseNumber;
368         }
369
370         /**
371          * Phone number
372          *
373          * @return the phoneNumber
374          */
375         @Override
376         public String getPhoneNumber () {
377                 return this.phoneNumber;
378         }
379
380         /**
381          * Street
382          *
383          * @return the street
384          */
385         @Override
386         public String getStreet () {
387                 return this.street;
388         }
389
390         /**
391          * Street
392          *
393          * @param street the street to set
394          */
395         @Override
396         public final void setStreet (final String street) {
397                 this.street = street;
398         }
399
400         /**
401          * Surname
402          *
403          * @return the surname
404          */
405         @Override
406         public final String getSurname () {
407                 return this.surname;
408         }
409
410         /**
411          * Some "getter" for a translated/human-readable gender
412          *
413          * @return gender Human-readable gender
414          */
415         @Override
416         public String getTranslatedGender () {
417                 // "Translate" it
418                 String translated = this.getBundle().getString(this.getGender().getMessageKey());
419
420                 // Return it
421                 return translated;
422         }
423
424         /**
425          * ZIP code
426          *
427          * @return the zipCode
428          */
429         @Override
430         public final long getZipCode () {
431                 return this.zipCode;
432         }
433
434         /**
435          * ZIP code
436          *
437          * @param zipCode the zipCode to set
438          */
439         @Override
440         public final void setZipCode (final long zipCode) {
441                 this.zipCode = zipCode;
442         }
443
444         @Override
445         public int hashCode () {
446                 // Validate gender instance
447                 assert (this.getGender() instanceof Gender) : "gender is not set.";
448
449                 int hash = 7;
450                 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
451                 hash = 79 * hash + this.getGender().hashCode();
452                 hash = 79 * hash + Objects.hashCode(this.getSurname());
453                 return hash;
454         }
455
456         /**
457          * Checks whether the contact is user's own data
458          *
459          * @return Own data?
460          */
461         @Override
462         public final boolean isOwnContact () {
463                 return this.ownContact;
464         }
465
466         /**
467          * Shows this contact to the user
468          *
469          * @param client Client instance to use
470          */
471         @Override
472         public void show (final Client client) {
473                 // Trace message
474                 this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N
475
476                 // The client must be set
477                 if (client == null) {
478                         // Not set
479                         throw new NullPointerException("client is null");
480                 }
481
482                 // Display name "box"
483                 client.displayNameBox(this);
484
485                 // Display address "box"
486                 client.displayAddressBox(this);
487
488                 // Display other data "box"
489                 client.displayOtherDataBox(this);
490         }
491
492         /**
493          * Enables the flag "own data" which signals that this contact is the user's
494          * own data.
495          */
496         protected final void enableFlagOwnContact () {
497                 this.ownContact = true;
498         }
499
500         /**
501          * Surname
502          *
503          * @param surname the surname to set
504          */
505         @Override
506         public final void setSurname (final String surname) {
507                 this.surname = surname;
508         }
509
510         /**
511          * Phone number
512          *
513          * @param phoneNumber the phoneNumber to set
514          */
515         @Override
516         public final void setPhoneNumber (final String phoneNumber) {
517                 this.phoneNumber = phoneNumber;
518         }
519
520         /**
521          * House number
522          *
523          * @param houseNumber the houseNumber to set
524          */
525         public final void setHouseNumber (final int houseNumber) {
526                 this.houseNumber = houseNumber;
527         }
528
529         /**
530          * Cellphone number
531          *
532          * @param cellphoneNumber the cellphoneNumber to set
533          */
534         @Override
535         public final void setCellphoneNumber (final String cellphoneNumber) {
536                 this.cellphoneNumber = cellphoneNumber;
537         }
538
539         /**
540          * Birth day
541          *
542          * @param birthday the birthday to set
543          */
544         @Override
545         public final void setBirthday (final String birthday) {
546                 this.birthday = birthday;
547         }
548
549         /**
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.
552          *
553          * @param columnName Column name
554          * @return Value from field
555          */
556         @Override
557         public Object getValueFromColumn (final String columnName) {
558                 // Trace message
559                 this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName));
560                 
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);
565                 }
566                 
567                 // Convert column name to field name
568                 String methodName = this.convertColumnNameToGetterMethod(columnName, false);
569                 
570                 // Debug message
571                 this.getLogger().debug(MessageFormat.format("field={0}", methodName));
572                 
573                 // Get field
574                 Object value = this.getField(this, "BaseContact", methodName);
575                 
576                 // Trace message
577                 this.getLogger().trace("value=" + value + " - EXIT!");
578                 
579                 // Return it
580                 return value;
581         }
582
583         /**
584          * Checks if given boolean field is available and set to same value
585          *
586          * @param columnName Column name to check
587          * @param bool Boolean value
588          * @return Whether all conditions are met
589          */
590         @Override
591         public boolean isValueEqual (final String columnName, final boolean bool) {
592                 // Trace message
593                 this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool));
594                 
595                 // Convert column name to field name
596                 String methodName = this.convertColumnNameToGetterMethod(columnName, true);
597                 
598                 // Debug message
599                 this.getLogger().debug(MessageFormat.format("field={0}", methodName));
600                 
601                 // Init class instance
602                 boolean value = this.getBooleanField(this, "BaseContact", methodName);
603                 
604                 // Debug message
605                 this.getLogger().debug(MessageFormat.format("value={0}", value));
606                 
607                 // Compare it
608                 boolean isFound = (bool == value);
609                 
610                 // Trace message
611                 this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound));
612                 
613                 // Return result
614                 return isFound;
615         }
616 }