]> git.mxchange.org Git - jbonuscard-lib.git/blob - Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java
Introduced Gender enum which replaces the old char
[jbonuscard-lib.git] / Addressbook / src / org / mxchange / addressbook / 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.addressbook.contact;
18
19 import java.util.Objects;
20 import org.mxchange.addressbook.BaseFrameworkSystem;
21 import org.mxchange.addressbook.client.Client;
22
23 /**
24  * A general contact
25  *
26  * @author Roland Haeder
27  * @version 0.0
28  * @since 0.0
29  */
30 public class BaseContact extends BaseFrameworkSystem {
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                 super();
117         }
118
119         /**
120          * Check if contacts are same or throw an exception
121          *
122          * @param object Other possible contact class
123          * @return Whether both contacts are same
124          * @todo Needs a lot improvements
125          */
126         @Override
127         public boolean equals (Object object) {
128                 // Is it same type?
129                 if (!(object instanceof BaseContact)) {
130                         // Not equal types
131                         return false;
132                 } else if (!(object instanceof Contact)) {
133                         // Not correct interface
134                         return false;
135                 }
136
137                 // Try to cast
138                 Contact contact = (Contact) object;
139
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())));
144         }
145
146         /**
147          * Birth day
148          *
149          * @return the birthday
150          */
151         public String getBirthday () {
152                 return this.birthday;
153         }
154
155         /**
156          * Cellphone number
157          *
158          * @return the cellphoneNumber
159          */
160         public String getCellphoneNumber () {
161                 return this.cellphoneNumber;
162         }
163
164         /**
165          * City
166          *
167          * @return the city
168          */
169         public String getCity () {
170                 return this.city;
171         }
172
173         /**
174          * City
175          *
176          * @param city the city to set
177          */
178         private void setCity (final String city) {
179                 this.city = city;
180         }
181
182         /**
183          * Comments
184          *
185          * @return the comment
186          */
187         public String getComment () {
188                 return this.comment;
189         }
190
191         /**
192          * Comments
193          *
194          * @param comment the comment to set
195          */
196         private void setComment (final String comment) {
197                 this.comment = comment;
198         }
199
200         /**
201          * Companyname
202          *
203          * @return the companyName
204          */
205         public String getCompanyName () {
206                 return this.companyName;
207         }
208
209         /**
210          * Companyname
211          *
212          * @param companyName the companyName to set
213          */
214         private void setCompanyName (final String companyName) {
215                 this.companyName = companyName;
216         }
217
218         /**
219          * Country code
220          *
221          * @return the countryCode
222          */
223         public String getCountryCode () {
224                 return this.countryCode;
225         }
226
227         /**
228          * Country code
229          *
230          * @param countryCode the countryCode to set
231          */
232         private void setCountryCode (final String countryCode) {
233                 this.countryCode = countryCode;
234         }
235
236         /**
237          * "Serializes" this object into a CSV string (this time with semicolons)
238          *
239          * @return "CSV-serialized" version of the stored data
240          */
241         public String getCsvStringFromStoreableObject () {
242                 // Get all together
243                 String csvString = String.format(
244                                 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",
245                                 this.isOwnContact(),
246                                 this.getGender().getDatabaseValue(),
247                                 this.getSurname(),
248                                 this.getFamilyName(),
249                                 this.getCompanyName(),
250                                 this.getStreet(),
251                                 this.getZipCode(),
252                                 this.getCity(),
253                                 this.getCountryCode(),
254                                 this.getPhoneNumber(),
255                                 this.getFaxNumber(),
256                                 this.getCellphoneNumber(),
257                                 this.getEmailAddress(),
258                                 this.getBirthday(),
259                                 this.getComment()
260                 );
261
262                 // Then return it
263                 return csvString;
264         }
265
266         /**
267          * Email address
268          *
269          * @return the emailAddress
270          */
271         public String getEmailAddress () {
272                 return this.emailAddress;
273         }
274
275         /**
276          * Email address
277          *
278          * @param emailAddress the emailAddress to set
279          */
280         private void setEmailAddress (final String emailAddress) {
281                 this.emailAddress = emailAddress;
282         }
283
284         /**
285          * Family name
286          *
287          * @return the familyName
288          */
289         public String getFamilyName () {
290                 return this.familyName;
291         }
292
293         /**
294          * Family name
295          *
296          * @param familyName the familyName to set
297          */
298         private void setFamilyName (final String familyName) {
299                 this.familyName = familyName;
300         }
301
302         /**
303          * Fax number
304          *
305          * @return the faxNumber
306          */
307         public String getFaxNumber () {
308                 return this.faxNumber;
309         }
310
311         /**
312          * Fax number
313          *
314          * @param faxNumber the faxNumber to set
315          */
316         private void setFaxNumber (final String faxNumber) {
317                 this.faxNumber = faxNumber;
318         }
319
320         /**
321          * Gender of the contact
322          *
323          * @return the gender
324          */
325         public Gender getGender () {
326                 return this.gender;
327         }
328
329         /**
330          * Gender of the contact
331          *
332          * @param gender the gender to set
333          */
334         private void setGender (final Gender gender) {
335                 this.gender = gender;
336         }
337
338         /**
339          * House number
340          *
341          * @return the houseNumber
342          */
343         public int getHouseNumber () {
344                 return this.houseNumber;
345         }
346
347         /**
348          * Phone number
349          *
350          * @return the phoneNumber
351          */
352         public String getPhoneNumber () {
353                 return this.phoneNumber;
354         }
355
356         /**
357          * Street
358          *
359          * @return the street
360          */
361         public String getStreet () {
362                 return this.street;
363         }
364
365         /**
366          * Street
367          *
368          * @param street the street to set
369          */
370         protected final void setStreet (final String street) {
371                 this.street = street;
372         }
373
374         /**
375          * Surname
376          *
377          * @return the surname
378          */
379         public final String getSurname () {
380                 return this.surname;
381         }
382
383         /**
384          * Some "getter" for a translated/human-readable gender
385          *
386          * @return gender Human-readable gender
387          */
388         public String getTranslatedGender () {
389                 // Default init
390                 String translated = null;
391
392                 // "Translate" it
393                 switch (this.getGender()) {
394                         case MALE: // Mr.
395                                 translated = "Herr";
396                                 break;
397
398                         case FEMALE: // Mrs.
399                                 translated = "Frau";
400                                 break;
401
402                         case COMPANY: // "Company"
403                                 translated = "Firma";
404                                 break;
405
406                         default: // Unsupported
407                                 this.getLogger().error("Gender " + this.getGender() + " not supported.");
408                                 break;
409                 }
410
411                 // Return it
412                 return translated;
413         }
414
415         /**
416          * ZIP code
417          *
418          * @return the zipCode
419          */
420         public final long getZipCode () {
421                 return this.zipCode;
422         }
423
424         /**
425          * ZIP code
426          *
427          * @param zipCode the zipCode to set
428          */
429         protected final void setZipCode (final long zipCode) {
430                 this.zipCode = zipCode;
431         }
432
433         @Override
434         public int hashCode () {
435                 int hash = 7;
436                 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
437                 hash = 79 * hash + this.getGender().hashCode();
438                 hash = 79 * hash + Objects.hashCode(this.getSurname());
439                 return hash;
440         }
441
442         /**
443          * Checks whether the contact is user's own data
444          *
445          * @return Own data?
446          */
447         public final boolean isOwnContact () {
448                 return this.ownContact;
449         }
450
451         /**
452          * Shows this contact to the user
453          *
454          * @param client Client instance to use
455          */
456         public void show (final Client client) {
457                 // Display name "box"
458                 client.displayNameBox((Contact) this);
459
460                 // Display address "box"
461                 client.displayAddressBox((Contact) this);
462
463                 // Display other data "box"
464                 client.displayOtherDataBox((Contact) this);
465         }
466
467         /**
468          * Updates address data in this Contact instance
469          *
470          * @param street Street
471          * @param zipCode ZIP code
472          * @param city City
473          * @param countryCode Country code
474          */
475         public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {
476                 // Set all
477                 if (street != null) {
478                         this.setStreet(street);
479                 }
480                 if (zipCode > 0) {
481                         this.setZipCode(zipCode);
482                 }
483                 if (city != null) {
484                         this.setCity(city);
485                 }
486                 if (countryCode != null) {
487                         this.setCountryCode(countryCode);
488                 }
489         }
490
491         /**
492          * Updates name data in this Contact instance
493          *
494          * @param gender Gender (M, F, C)
495          * @param surname Surname
496          * @param familyName Family name
497          * @param companyName Company name
498          */
499         public void updateNameData (final Gender gender, final String surname, final String familyName, final String companyName) {
500                 // Set all
501                 this.setGender(gender);
502
503                 if (surname != null) {
504                         this.setSurname(surname);
505                 }
506                 if (familyName != null) {
507                         this.setFamilyName(familyName);
508                 }
509                 if (companyName != null) {
510                         this.setCompanyName(companyName);
511                 }
512         }
513
514         /**
515          * Updates other data in this Contact instance
516          *
517          * @param phoneNumber Phone number
518          * @param cellphoneNumber Cellphone number
519          * @param faxNumber Fax number
520          * @param emailAddress Email address
521          * @param birthday Birth day
522          * @param comment Comments
523          */
524         public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {
525                 // Set all
526                 if (phoneNumber != null) {
527                         this.setPhoneNumber(phoneNumber);
528                 }
529                 if (cellphoneNumber != null) {
530                         this.setCellphoneNumber(cellphoneNumber);
531                 }
532                 if (faxNumber != null) {
533                         this.setFaxNumber(faxNumber);
534                 }
535                 if (emailAddress != null) {
536                         this.setEmailAddress(emailAddress);
537                 }
538                 if (birthday != null) {
539                         this.setBirthday(birthday);
540                 }
541                 if (comment != null) {
542                         this.setComment(comment);
543                 }
544         }
545
546         /**
547          * Enables the flag "own data" which signals that this contact is the user's
548          * own data.
549          */
550         protected final void enableFlagOwnContact () {
551                 this.ownContact = true;
552         }
553
554         /**
555          * Surname
556          *
557          * @param surname the surname to set
558          */
559         protected final void setSurname (final String surname) {
560                 this.surname = surname;
561         }
562
563         /**
564          * Phone number
565          *
566          * @param phoneNumber the phoneNumber to set
567          */
568         protected final void setPhoneNumber (final String phoneNumber) {
569                 this.phoneNumber = phoneNumber;
570         }
571
572         /**
573          * House number
574          *
575          * @param houseNumber the houseNumber to set
576          */
577         protected final void setHouseNumber (final int houseNumber) {
578                 this.houseNumber = houseNumber;
579         }
580
581         /**
582          * Cellphone number
583          *
584          * @param cellphoneNumber the cellphoneNumber to set
585          */
586         protected final void setCellphoneNumber (final String cellphoneNumber) {
587                 this.cellphoneNumber = cellphoneNumber;
588         }
589
590         /**
591          * Birth day
592          *
593          * @param birthday the birthday to set
594          */
595         protected final void setBirthday (final String birthday) {
596                 this.birthday = birthday;
597         }
598 }