]> git.mxchange.org Git - jaddressbook-lib.git/blob - Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java
f03a3c1bdf20c1ded94ccacfb5eb68ceeefbb4d0
[jaddressbook-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 code of the contact: - M = Mr. (male) - F = Mrs. (female) - C =
79          * Company
80          */
81         private char gender;
82
83         /**
84          * House number
85          */
86         private int houseNumber;
87
88         /**
89          * Marker whether this contact is user's own data
90          */
91         private boolean ownContact;
92
93         /**
94          * Phone number
95          */
96         private String phoneNumber;
97
98         /**
99          * Street
100          */
101         private String street;
102
103         /**
104          * Surname
105          */
106         private String surname;
107
108         /**
109          * ZIP code
110          */
111         private long zipCode;
112
113         /**
114          * No instances can be created of this class
115          */
116         protected BaseContact () {
117                 super();
118         }
119
120         /**
121          * Check if contacts are same or throw an exception
122          *
123          * @param object Other possible contact class
124          * @return Whether both contacts are same
125          * @todo Needs a lot improvements
126          */
127         @Override
128         public boolean equals (Object object) {
129                 // Is it same type?
130                 if (!(object instanceof BaseContact)) {
131                         // Not equal types
132                         return false;
133                 } else if (!(object instanceof Contact)) {
134                         // Not correct interface
135                         return false;
136                 }
137
138                 // Try to cast
139                 Contact contact = (Contact) object;
140
141                 // Now test some data @todo Definedly needs improvement
142                 return ((this.getGender() == contact.getGender())
143                                 && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))
144                                 && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
145         }
146
147         /**
148          * Birth day
149          *
150          * @return the birthday
151          */
152         public String getBirthday () {
153                 return this.birthday;
154         }
155
156         /**
157          * Cellphone number
158          *
159          * @return the cellphoneNumber
160          */
161         public String getCellphoneNumber () {
162                 return this.cellphoneNumber;
163         }
164
165         /**
166          * City
167          *
168          * @return the city
169          */
170         public String getCity () {
171                 return this.city;
172         }
173
174         /**
175          * City
176          *
177          * @param city the city to set
178          */
179         private void setCity (final String city) {
180                 this.city = city;
181         }
182
183         /**
184          * Comments
185          *
186          * @return the comment
187          */
188         public String getComment () {
189                 return this.comment;
190         }
191
192         /**
193          * Comments
194          *
195          * @param comment the comment to set
196          */
197         private void setComment (final String comment) {
198                 this.comment = comment;
199         }
200
201         /**
202          * Companyname
203          *
204          * @return the companyName
205          */
206         public String getCompanyName () {
207                 return this.companyName;
208         }
209
210         /**
211          * Companyname
212          *
213          * @param companyName the companyName to set
214          */
215         private void setCompanyName (final String companyName) {
216                 this.companyName = companyName;
217         }
218
219         /**
220          * Country code
221          *
222          * @return the countryCode
223          */
224         public String getCountryCode () {
225                 return this.countryCode;
226         }
227
228         /**
229          * Country code
230          *
231          * @param countryCode the countryCode to set
232          */
233         private void setCountryCode (final String countryCode) {
234                 this.countryCode = countryCode;
235         }
236
237         /**
238          * "Serializes" this object into a CSV string (this time with semicolons)
239          *
240          * @return "CSV-serialized" version of the stored data
241          */
242         public String getCsvStringFromStoreableObject () {
243                 // Get all together
244                 String csvString = String.format(
245                                 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",
246                                 this.isOwnContact(),
247                                 this.getGender(),
248                                 this.getSurname(),
249                                 this.getFamilyName(),
250                                 this.getCompanyName(),
251                                 this.getStreet(),
252                                 this.getZipCode(),
253                                 this.getCity(),
254                                 this.getCountryCode(),
255                                 this.getPhoneNumber(),
256                                 this.getFaxNumber(),
257                                 this.getCellphoneNumber(),
258                                 this.getEmailAddress(),
259                                 this.getBirthday(),
260                                 this.getComment()
261                 );
262
263                 // Then return it
264                 return csvString;
265         }
266
267         /**
268          * Email address
269          *
270          * @return the emailAddress
271          */
272         public String getEmailAddress () {
273                 return this.emailAddress;
274         }
275
276         /**
277          * Email address
278          *
279          * @param emailAddress the emailAddress to set
280          */
281         private void setEmailAddress (final String emailAddress) {
282                 this.emailAddress = emailAddress;
283         }
284
285         /**
286          * Family name
287          *
288          * @return the familyName
289          */
290         public String getFamilyName () {
291                 return this.familyName;
292         }
293
294         /**
295          * Family name
296          *
297          * @param familyName the familyName to set
298          */
299         private void setFamilyName (final String familyName) {
300                 this.familyName = familyName;
301         }
302
303         /**
304          * Fax number
305          *
306          * @return the faxNumber
307          */
308         public String getFaxNumber () {
309                 return this.faxNumber;
310         }
311
312         /**
313          * Fax number
314          *
315          * @param faxNumber the faxNumber to set
316          */
317         private void setFaxNumber (final String faxNumber) {
318                 this.faxNumber = faxNumber;
319         }
320
321         /**
322          * Gender of the contact
323          *
324          * @return the gender
325          */
326         public char getGender () {
327                 return this.gender;
328         }
329
330         /**
331          * Gender of the contact
332          *
333          * @param gender the gender to set
334          */
335         private void setGender (final char gender) {
336                 this.gender = gender;
337         }
338
339         /**
340          * House number
341          *
342          * @return the houseNumber
343          */
344         public int getHouseNumber () {
345                 return this.houseNumber;
346         }
347
348         /**
349          * Phone number
350          *
351          * @return the phoneNumber
352          */
353         public String getPhoneNumber () {
354                 return this.phoneNumber;
355         }
356
357         /**
358          * Street
359          *
360          * @return the street
361          */
362         public String getStreet () {
363                 return this.street;
364         }
365
366         /**
367          * Street
368          *
369          * @param street the street to set
370          */
371         protected final void setStreet (final String street) {
372                 this.street = street;
373         }
374
375         /**
376          * Surname
377          *
378          * @return the surname
379          */
380         public final String getSurname () {
381                 return this.surname;
382         }
383
384         /**
385          * Some "getter" for a translated/human-readable gender
386          *
387          * @return gender Human-readable gender
388          */
389         public String getTranslatedGender () {
390                 // Default init
391                 String translated = null;
392
393                 // "Translate" it
394                 switch (this.getGender()) {
395                         case 'M': // Mr.
396                                 translated = "Herr";
397                                 break;
398
399                         case 'F': // Mrs.
400                                 translated = "Frau";
401                                 break;
402
403                         case 'C': // "Company"
404                                 translated = "Firma";
405                                 break;
406
407                         default: // Unsupported
408                                 this.getLogger().error("Gender " + this.getGender() + " not supported.");
409                                 break;
410                 }
411
412                 // Return it
413                 return translated;
414         }
415
416         /**
417          * ZIP code
418          *
419          * @return the zipCode
420          */
421         public final long getZipCode () {
422                 return this.zipCode;
423         }
424
425         /**
426          * ZIP code
427          *
428          * @param zipCode the zipCode to set
429          */
430         protected final void setZipCode (final long zipCode) {
431                 this.zipCode = zipCode;
432         }
433
434         @Override
435         public int hashCode () {
436                 int hash = 7;
437                 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
438                 hash = 79 * hash + this.getGender();
439                 hash = 79 * hash + Objects.hashCode(this.getSurname());
440                 return hash;
441         }
442
443         /**
444          * Checks whether the contact is user's own data
445          *
446          * @return Own data?
447          */
448         public final boolean isOwnContact () {
449                 return this.ownContact;
450         }
451
452         /**
453          * Shows this contact to the user
454          *
455          * @param client Client instance to use
456          */
457         public void show (final Client client) {
458                 // Display name "box"
459                 client.displayNameBox((Contact) this);
460
461                 // Display address "box"
462                 client.displayAddressBox((Contact) this);
463
464                 // Display other data "box"
465                 client.displayOtherDataBox((Contact) this);
466         }
467
468         /**
469          * Updates address data in this Contact instance
470          *
471          * @param street Street
472          * @param zipCode ZIP code
473          * @param city City
474          * @param countryCode Country code
475          */
476         public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {
477                 // Set all
478                 if (street != null) {
479                         this.setStreet(street);
480                 }
481                 if (zipCode > 0) {
482                         this.setZipCode(zipCode);
483                 }
484                 if (city != null) {
485                         this.setCity(city);
486                 }
487                 if (countryCode != null) {
488                         this.setCountryCode(countryCode);
489                 }
490         }
491
492         /**
493          * Updates name data in this Contact instance
494          *
495          * @param gender Gender (M, F, C)
496          * @param surname Surname
497          * @param familyName Family name
498          * @param companyName Company name
499          */
500         public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) {
501                 // Set all
502                 this.setGender(gender);
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 }