]> git.mxchange.org Git - jcore.git/blob - src/org/mxchange/jcore/contact/BaseContact.java
Type needs to be long as the parser wants to set long
[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 long 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          * Birth day
157          *
158          * @param birthday the birthday to set
159          */
160         @Override
161         public final void setBirthday (final String birthday) {
162                 this.birthday = birthday;
163         }
164
165         /**
166          * Cellphone number
167          *
168          * @return the cellphoneNumber
169          */
170         @Override
171         public String getCellphoneNumber () {
172                 return this.cellphoneNumber;
173         }
174
175         /**
176          * Cellphone number
177          *
178          * @param cellphoneNumber the cellphoneNumber to set
179          */
180         @Override
181         public final void setCellphoneNumber (final String cellphoneNumber) {
182                 this.cellphoneNumber = cellphoneNumber;
183         }
184
185         /**
186          * City
187          *
188          * @return the city
189          */
190         @Override
191         public String getCity () {
192                 return this.city;
193         }
194
195         /**
196          * City
197          *
198          * @param city the city to set
199          */
200         @Override
201         public final void setCity (final String city) {
202                 this.city = city;
203         }
204
205         /**
206          * Comments
207          *
208          * @return the comment
209          */
210         @Override
211         public String getComment () {
212                 return this.comment;
213         }
214
215         /**
216          * Comments
217          *
218          * @param comment the comment to set
219          */
220         @Override
221         public final void setComment (final String comment) {
222                 this.comment = comment;
223         }
224
225         /**
226          * Companyname
227          *
228          * @return the companyName
229          */
230         @Override
231         public String getCompanyName () {
232                 return this.companyName;
233         }
234
235         /**
236          * Companyname
237          *
238          * @param companyName the companyName to set
239          */
240         @Override
241         public final void setCompanyName (final String companyName) {
242                 this.companyName = companyName;
243         }
244
245         /**
246          * Country code
247          *
248          * @return the countryCode
249          */
250         @Override
251         public String getCountryCode () {
252                 return this.countryCode;
253         }
254
255         /**
256          * Country code
257          *
258          * @param countryCode the countryCode to set
259          */
260         @Override
261         public final void setCountryCode (final String countryCode) {
262                 this.countryCode = countryCode;
263         }
264
265         /**
266          * "Serializes" this object into a CSV string (this time with semicolons)
267          *
268          * @return "CSV-serialized" version of the stored data
269          * @deprecated Don't use this anymore
270          */
271         @Deprecated
272         public String getCsvStringFromStoreableObject () {
273                 // Trace message
274                 this.getLogger().trace("CALLED!"); //NOI18N
275
276                 // Get all together
277                 String csvString = String.format(
278                                 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"", //NOI18N
279                                 this.isOwnContact(),
280                                 this.getGender().getDatabaseValue(),
281                                 this.getSurname(),
282                                 this.getFamilyName(),
283                                 this.getCompanyName(),
284                                 this.getStreet(),
285                                 this.getZipCode(),
286                                 this.getCity(),
287                                 this.getCountryCode(),
288                                 this.getPhoneNumber(),
289                                 this.getFaxNumber(),
290                                 this.getCellphoneNumber(),
291                                 this.getEmailAddress(),
292                                 this.getBirthday(),
293                                 this.getComment()
294                 );
295
296                 // Then return it
297                 return csvString;
298         }
299
300         /**
301          * Email address
302          *
303          * @return the emailAddress
304          */
305         @Override
306         public String getEmailAddress () {
307                 return this.emailAddress;
308         }
309
310         /**
311          * Email address
312          *
313          * @param emailAddress the emailAddress to set
314          */
315         @Override
316         public final void setEmailAddress (final String emailAddress) {
317                 this.emailAddress = emailAddress;
318         }
319
320         /**
321          * Family name
322          *
323          * @return the familyName
324          */
325         @Override
326         public String getFamilyName () {
327                 return this.familyName;
328         }
329
330         /**
331          * Family name
332          *
333          * @param familyName the familyName to set
334          */
335         @Override
336         public final void setFamilyName (final String familyName) {
337                 this.familyName = familyName;
338         }
339
340         /**
341          * Fax number
342          *
343          * @return the faxNumber
344          */
345         @Override
346         public String getFaxNumber () {
347                 return this.faxNumber;
348         }
349
350         /**
351          * Fax number
352          *
353          * @param faxNumber the faxNumber to set
354          */
355         @Override
356         public final void setFaxNumber (final String faxNumber) {
357                 this.faxNumber = faxNumber;
358         }
359
360         /**
361          * Gender of the contact
362          *
363          * @return the gender
364          */
365         @Override
366         public Gender getGender () {
367                 return this.gender;
368         }
369
370         /**
371          * Gender of the contact
372          *
373          * @param gender the gender to set
374          */
375         @Override
376         public final void setGender (final Gender gender) {
377                 this.gender = gender;
378         }
379
380         /**
381          * House number
382          *
383          * @return the houseNumber
384          */
385         @Override
386         public long getHouseNumber () {
387                 return this.houseNumber;
388         }
389
390         /**
391          * House number
392          *
393          * @param houseNumber the houseNumber to set
394          */
395         @Override
396         public final void setHouseNumber (final long houseNumber) {
397                 this.houseNumber = houseNumber;
398         }
399
400         /**
401          * Phone number
402          *
403          * @return the phoneNumber
404          */
405         @Override
406         public String getPhoneNumber () {
407                 return this.phoneNumber;
408         }
409
410         /**
411          * Phone number
412          *
413          * @param phoneNumber the phoneNumber to set
414          */
415         @Override
416         public final void setPhoneNumber (final String phoneNumber) {
417                 this.phoneNumber = phoneNumber;
418         }
419
420         /**
421          * Street
422          *
423          * @return the street
424          */
425         @Override
426         public String getStreet () {
427                 return this.street;
428         }
429
430         /**
431          * Street
432          *
433          * @param street the street to set
434          */
435         @Override
436         public final void setStreet (final String street) {
437                 this.street = street;
438         }
439
440         /**
441          * Surname
442          *
443          * @return the surname
444          */
445         @Override
446         public final String getSurname () {
447                 return this.surname;
448         }
449
450         /**
451          * Surname
452          *
453          * @param surname the surname to set
454          */
455         @Override
456         public final void setSurname (final String surname) {
457                 this.surname = surname;
458         }
459
460         /**
461          * Some "getter" for a translated/human-readable gender
462          *
463          * @return gender Human-readable gender
464          */
465         @Override
466         public String getTranslatedGender () {
467                 // "Translate" it
468                 String translated = this.getBundle().getString(this.getGender().getMessageKey());
469
470                 // Return it
471                 return translated;
472         }
473
474         /**
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.
477          *
478          * @param columnName Column name
479          * @return Value from field
480          */
481         @Override
482         public Object getValueFromColumn (final String columnName) {
483                 // Trace message
484                 this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName));
485                 
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);
490                 }
491                 
492                 // Convert column name to field name
493                 String methodName = this.convertColumnNameToGetterMethod(columnName, false);
494                 
495                 // Debug message
496                 this.getLogger().debug(MessageFormat.format("field={0}", methodName));
497                 
498                 // Get field
499                 Object value = this.getField(this, "BaseContact", methodName);
500                 
501                 // Trace message
502                 this.getLogger().trace("value=" + value + " - EXIT!");
503                 
504                 // Return it
505                 return value;
506         }
507
508         /**
509          * ZIP code
510          *
511          * @return the zipCode
512          */
513         @Override
514         public final long getZipCode () {
515                 return this.zipCode;
516         }
517
518         /**
519          * ZIP code
520          *
521          * @param zipCode the zipCode to set
522          */
523         @Override
524         public final void setZipCode (final long zipCode) {
525                 this.zipCode = zipCode;
526         }
527
528         @Override
529         public int hashCode () {
530                 // Validate gender instance
531                 assert (this.getGender() instanceof Gender) : "gender is not set.";
532
533                 int hash = 7;
534                 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
535                 hash = 79 * hash + this.getGender().hashCode();
536                 hash = 79 * hash + Objects.hashCode(this.getSurname());
537                 return hash;
538         }
539
540         /**
541          * Checks whether the contact is user's own data
542          *
543          * @return Own data?
544          */
545         @Override
546         public final boolean isOwnContact () {
547                 return this.ownContact;
548         }
549
550         /**
551          * Checks if given boolean field is available and set to same value
552          *
553          * @param columnName Column name to check
554          * @param bool Boolean value
555          * @return Whether all conditions are met
556          */
557         @Override
558         public boolean isValueEqual (final String columnName, final boolean bool) {
559                 // Trace message
560                 this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool));
561                 
562                 // Convert column name to field name
563                 String methodName = this.convertColumnNameToGetterMethod(columnName, true);
564                 
565                 // Debug message
566                 this.getLogger().debug(MessageFormat.format("field={0}", methodName));
567                 
568                 // Init class instance
569                 boolean value = this.getBooleanField(this, "BaseContact", methodName);
570                 
571                 // Debug message
572                 this.getLogger().debug(MessageFormat.format("value={0}", value));
573                 
574                 // Compare it
575                 boolean isFound = (bool == value);
576                 
577                 // Trace message
578                 this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound));
579                 
580                 // Return result
581                 return isFound;
582         }
583
584         /**
585          * Shows this contact to the user
586          *
587          * @param client Client instance to use
588          */
589         @Override
590         public void show (final Client client) {
591                 // Trace message
592                 this.getLogger().trace(MessageFormat.format("client={0} - CALLED!", client)); //NOI18N
593                 
594                 // The client must be set
595                 if (client == null) {
596                         // Not set
597                         throw new NullPointerException("client is null");
598                 }
599                 
600                 // Display name "box"
601                 client.displayNameBox(this);
602                 
603                 // Display address "box"
604                 client.displayAddressBox(this);
605                 
606                 // Display other data "box"
607                 client.displayOtherDataBox(this);
608         }
609
610         /**
611          * Enables the flag "own data" which signals that this contact is the user's
612          * own data.
613          */
614         protected final void enableFlagOwnContact () {
615                 this.ownContact = true;
616         }
617 }