]> git.mxchange.org Git - jaddressbook-lib.git/blob - Addressbook/src/org/mxchange/addressbook/contact/BaseContact.java
Bah, bad bad NetBeans. Why the f**k does it need to have a sub directory??? Why not...
[jaddressbook-lib.git] / Addressbook / src / org / mxchange / addressbook / contact / BaseContact.java
1 /*\r
2  * Copyright (C) 2015 Roland Haeder\r
3  *\r
4  * This program is free software: you can redistribute it and/or modify\r
5  * it under the terms of the GNU General Public License as published by\r
6  * the Free Software Foundation, either version 3 of the License, or\r
7  * (at your option) any later version.\r
8  *\r
9  * This program is distributed in the hope that it will be useful,\r
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12  * GNU General Public License for more details.\r
13  *\r
14  * You should have received a copy of the GNU General Public License\r
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
16  */\r
17 package org.mxchange.addressbook.contact;\r
18 \r
19 import java.util.Objects;\r
20 import org.mxchange.addressbook.BaseFrameworkSystem;\r
21 import org.mxchange.addressbook.client.Client;\r
22 \r
23 /**\r
24  * A general contact\r
25  *\r
26  * @author Roland Haeder\r
27  * @version 0.0\r
28  * @since 0.0\r
29  */\r
30 public class BaseContact extends BaseFrameworkSystem {\r
31     /**\r
32      * Amount of columns\r
33      */\r
34     public static final int COLUMN_COUNT = 14;\r
35 \r
36     /**\r
37      * Birth day\r
38      */\r
39     private String birthday;\r
40 \r
41     /**\r
42      * Cellphone number\r
43      */\r
44     private String cellphoneNumber;\r
45 \r
46     /**\r
47      * City\r
48      */\r
49     private String city;\r
50 \r
51     /**\r
52      * Optional comments\r
53      */\r
54     private String comment;\r
55 \r
56     /**\r
57      * Companyname\r
58      */\r
59     private String companyName;\r
60 \r
61     /**\r
62      * Country code\r
63      */\r
64     private String countryCode;\r
65 \r
66     /**\r
67      * Email address\r
68      */\r
69     private String emailAddress;\r
70 \r
71     /**\r
72      * Family name\r
73      */\r
74     private String familyName;\r
75 \r
76     /**\r
77      * Fax number\r
78      */\r
79     private String faxNumber;\r
80 \r
81     /**\r
82      * Gender code of the contact: - M = Mr. (male) - F = Mrs. (female) - C =\r
83      * Company\r
84      */\r
85     private char gender;\r
86 \r
87     /**\r
88      * House number\r
89      */\r
90     private int houseNumber;\r
91 \r
92     /**\r
93      * Marker whether this contact is user's own data\r
94      */\r
95     private boolean ownContact;\r
96 \r
97     /**\r
98      * Phone number\r
99      */\r
100     private String phoneNumber;\r
101 \r
102     /**\r
103      * Street\r
104      */\r
105     private String street;\r
106 \r
107     /**\r
108      * Surname\r
109      */\r
110     private String surname;\r
111 \r
112     /**\r
113      * ZIP code\r
114      */\r
115     private long zipCode;\r
116 \r
117     /**\r
118      * No instances can be created of this class\r
119      */\r
120     protected BaseContact () {\r
121         super();\r
122     }\r
123 \r
124     /**\r
125      * Check if contacts are same or throw an exception\r
126      *\r
127      * @param object Other possible contact class\r
128      * @return Whether both contacts are same\r
129      * @todo Needs a lot improvements\r
130      */\r
131     @Override\r
132     public boolean equals (Object object) {\r
133         // Is it same type?\r
134         if (!(object instanceof BaseContact)) {\r
135             // Not equal types\r
136             return false;\r
137         } else if (!(object instanceof Contact)) {\r
138             // Not correct interface\r
139             return false;\r
140         }\r
141 \r
142         // Try to cast\r
143         Contact contact = (Contact) object;\r
144         \r
145         // Now test some data @todo Definedly needs improvement\r
146         return ((this.getGender() == contact.getGender())\r
147                 && (this.getSurname().toLowerCase().equals(contact.getSurname().toLowerCase()))\r
148                 && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));\r
149     }\r
150 \r
151     /**\r
152      * Birth day\r
153      *\r
154      * @return the birthday\r
155      */\r
156     public String getBirthday () {\r
157         return this.birthday;\r
158     }\r
159 \r
160     /**\r
161      * Birth day\r
162      *\r
163      * @param birthday the birthday to set\r
164      */\r
165     public void setBirthday (final String birthday) {\r
166         this.birthday = birthday;\r
167     }\r
168 \r
169     /**\r
170      * Cellphone number\r
171      *\r
172      * @return the cellphoneNumber\r
173      */\r
174     public String getCellphoneNumber () {\r
175         return this.cellphoneNumber;\r
176     }\r
177 \r
178     /**\r
179      * Cellphone number\r
180      *\r
181      * @param cellphoneNumber the cellphoneNumber to set\r
182      */\r
183     public void setCellphoneNumber (final String cellphoneNumber) {\r
184         this.cellphoneNumber = cellphoneNumber;\r
185     }\r
186 \r
187     /**\r
188      * City\r
189      *\r
190      * @return the city\r
191      */\r
192     public String getCity () {\r
193         return this.city;\r
194     }\r
195 \r
196     /**\r
197      * City\r
198      *\r
199      * @param city the city to set\r
200      */\r
201     public void setCity (final String city) {\r
202         this.city = city;\r
203     }\r
204 \r
205     /**\r
206      * Comments\r
207      *\r
208      * @return the comment\r
209      */\r
210     public String getComment () {\r
211         return this.comment;\r
212     }\r
213 \r
214     /**\r
215      * Comments\r
216      *\r
217      * @param comment the comment to set\r
218      */\r
219     public void setComment (final String comment) {\r
220         this.comment = comment;\r
221     }\r
222 \r
223     /**\r
224      * Companyname\r
225      *\r
226      * @return the companyName\r
227      */\r
228     public String getCompanyName () {\r
229         return this.companyName;\r
230     }\r
231 \r
232     /**\r
233      * Companyname\r
234      *\r
235      * @param companyName the companyName to set\r
236      */\r
237     public void setCompanyName (final String companyName) {\r
238         this.companyName = companyName;\r
239     }\r
240 \r
241     /**\r
242      * Country code\r
243      *\r
244      * @return the countryCode\r
245      */\r
246     public String getCountryCode () {\r
247         return this.countryCode;\r
248     }\r
249 \r
250     /**\r
251      * Country code\r
252      *\r
253      * @param countryCode the countryCode to set\r
254      */\r
255     public void setCountryCode (final String countryCode) {\r
256         this.countryCode = countryCode;\r
257     }\r
258 \r
259     /**\r
260      * "Serializes" this object into a CSV string (this time with semicolons)\r
261      *\r
262      * @return "CSV-serialized" version of the stored data\r
263      */\r
264     public String getCsvStringFromStoreableObject () {\r
265         // Get all together\r
266         String csvString = String.format(\r
267                 "\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\"\n",\r
268                 this.isOwnContact(),\r
269                 this.getGender(),\r
270                 this.getSurname(),\r
271                 this.getFamilyName(),\r
272                 this.getCompanyName(),\r
273                 this.getStreet(),\r
274                 this.getZipCode(),\r
275                 this.getCity(),\r
276                 this.getCountryCode(),\r
277                 this.getPhoneNumber(),\r
278                 this.getFaxNumber(),\r
279                 this.getCellphoneNumber(),\r
280                 this.getEmailAddress(),\r
281                 this.getBirthday(),\r
282                 this.getComment()\r
283         );\r
284         \r
285         // Then return it\r
286         return csvString;\r
287     }\r
288 \r
289     /**\r
290      * Email address\r
291      *\r
292      * @return the emailAddress\r
293      */\r
294     public String getEmailAddress () {\r
295         return this.emailAddress;\r
296     }\r
297 \r
298     /**\r
299      * Email address\r
300      *\r
301      * @param emailAddress the emailAddress to set\r
302      */\r
303     public void setEmailAddress (final String emailAddress) {\r
304         this.emailAddress = emailAddress;\r
305     }\r
306 \r
307     /**\r
308      * Family name\r
309      *\r
310      * @return the familyName\r
311      */\r
312     public String getFamilyName () {\r
313         return this.familyName;\r
314     }\r
315 \r
316     /**\r
317      * Family name\r
318      *\r
319      * @param familyName the familyName to set\r
320      */\r
321     public void setFamilyName (final String familyName) {\r
322         this.familyName = familyName;\r
323     }\r
324 \r
325     /**\r
326      * Fax number\r
327      *\r
328      * @return the faxNumber\r
329      */\r
330     public String getFaxNumber () {\r
331         return this.faxNumber;\r
332     }\r
333 \r
334     /**\r
335      * Fax number\r
336      *\r
337      * @param faxNumber the faxNumber to set\r
338      */\r
339     public void setFaxNumber (final String faxNumber) {\r
340         this.faxNumber = faxNumber;\r
341     }\r
342 \r
343     /**\r
344      * Gender of the contact\r
345      *\r
346      * @return the gender\r
347      */\r
348     public char getGender () {\r
349         return this.gender;\r
350     }\r
351 \r
352     /**\r
353      * Gender of the contact\r
354      *\r
355      * @param gender the gender to set\r
356      */\r
357     public void setGender (final char gender) {\r
358         this.gender = gender;\r
359     }\r
360 \r
361     /**\r
362      * House number\r
363      *\r
364      * @return the houseNumber\r
365      */\r
366     public int getHouseNumber () {\r
367         return this.houseNumber;\r
368     }\r
369 \r
370     /**\r
371      * House number\r
372      *\r
373      * @param houseNumber the houseNumber to set\r
374      */\r
375     public void setHouseNumber (final int houseNumber) {\r
376         this.houseNumber = houseNumber;\r
377     }\r
378 \r
379     /**\r
380      * Phone number\r
381      *\r
382      * @return the phoneNumber\r
383      */\r
384     public String getPhoneNumber () {\r
385         return this.phoneNumber;\r
386     }\r
387 \r
388     /**\r
389      * Phone number\r
390      *\r
391      * @param phoneNumber the phoneNumber to set\r
392      */\r
393     public void setPhoneNumber (final String phoneNumber) {\r
394         this.phoneNumber = phoneNumber;\r
395     }\r
396 \r
397     /**\r
398      * Street\r
399      *\r
400      * @return the street\r
401      */\r
402     public String getStreet () {\r
403         return this.street;\r
404     }\r
405 \r
406     /**\r
407      * Street\r
408      *\r
409      * @param street the street to set\r
410      */\r
411     public void setStreet (final String street) {\r
412         this.street = street;\r
413     }\r
414 \r
415     /**\r
416      * Surname\r
417      *\r
418      * @return the surname\r
419      */\r
420     public String getSurname () {\r
421         return this.surname;\r
422     }\r
423 \r
424     /**\r
425      * Surname\r
426      *\r
427      * @param surname the surname to set\r
428      */\r
429     public void setSurname (final String surname) {\r
430         this.surname = surname;\r
431     }\r
432 \r
433     /**\r
434      * Some "getter" for a translated/human-readable gender\r
435      * @return gender Human-readable gender\r
436      */\r
437     public String getTranslatedGender () {\r
438         // Default init\r
439         String translated = null;\r
440 \r
441         // "Translate" it\r
442         switch (this.getGender()) {\r
443             case 'M': // Mr.\r
444                 translated = "Herr";\r
445                 break;\r
446 \r
447             case 'F': // Mrs.\r
448                 translated = "Frau";\r
449                 break;\r
450 \r
451             case 'C': // "Company"\r
452                 translated = "Firma";\r
453                 break;\r
454 \r
455             default: // Unsupported\r
456                 this.getLogger().error("Gender " + this.getGender() + " not supported.");\r
457                 break;\r
458         }\r
459 \r
460         // Return it\r
461         return translated;\r
462     }\r
463 \r
464     /**\r
465      * ZIP code\r
466      *\r
467      * @return the zipCode\r
468      */\r
469     public long getZipCode () {\r
470         return this.zipCode;\r
471     }\r
472 \r
473     /**\r
474      * ZIP code\r
475      *\r
476      * @param zipCode the zipCode to set\r
477      */\r
478     public void setZipCode (final long zipCode) {\r
479         this.zipCode = zipCode;\r
480     }\r
481 \r
482     @Override\r
483     public int hashCode () {\r
484         int hash = 7;\r
485         hash = 79 * hash + Objects.hashCode(this.getFamilyName());\r
486         hash = 79 * hash + this.getGender();\r
487         hash = 79 * hash + Objects.hashCode(this.getSurname());\r
488         return hash;\r
489     }\r
490 \r
491     /**\r
492      * Checks whether the contact is user's own data\r
493      *\r
494      * @return Own data?\r
495      */\r
496     public boolean isOwnContact () {\r
497         return this.ownContact;\r
498     }\r
499 \r
500     /**\r
501      * Shows this contact to the user\r
502      *\r
503      * @param client Client instance to use\r
504      */\r
505     public void show (final Client client) {\r
506         // Display name "box"\r
507         client.displayNameBox((Contact) this);\r
508 \r
509         // Display address "box"\r
510         client.displayAddressBox((Contact) this);\r
511 \r
512         // Display other data "box"\r
513         client.displayOtherDataBox((Contact) this);\r
514     }\r
515 \r
516     /**\r
517      * Updates address data in this Contact instance\r
518      *\r
519      * @param street Street\r
520      * @param zipCode ZIP code\r
521      * @param city City\r
522      * @param countryCode Country code\r
523      */\r
524     public void updateAddressData (final String street, final long zipCode, final String city, final String countryCode) {\r
525         // Set all\r
526         if (street != null) {\r
527             this.setStreet(street);\r
528         }\r
529         if (zipCode > 0) {\r
530             this.setZipCode(zipCode);\r
531         }\r
532         if (city != null) {\r
533             this.setCity(city);\r
534         }\r
535         if (countryCode != null) {\r
536             this.setCountryCode(countryCode);\r
537         }\r
538     }\r
539 \r
540     /**\r
541      * Updates name data in this Contact instance\r
542      * @param gender Gender (M, F, C)\r
543      * @param surname Surname\r
544      * @param familyName Family name\r
545      * @param companyName Company name\r
546      */\r
547     public void updateNameData (final char gender, final String surname, final String familyName, final String companyName) {\r
548         // Set all\r
549         this.setGender(gender);\r
550         if (surname != null) {\r
551             this.setSurname(surname);\r
552         }\r
553         if (familyName != null) {\r
554             this.setFamilyName(familyName);\r
555         }\r
556         if (companyName != null) {\r
557             this.setCompanyName(companyName);\r
558         }\r
559     }\r
560 \r
561     /**\r
562      * Updates other data in this Contact instance\r
563      * \r
564      * @param phoneNumber Phone number\r
565      * @param cellphoneNumber Cellphone number\r
566      * @param faxNumber Fax number\r
567      * @param emailAddress Email address\r
568      * @param birthday Birth day\r
569      * @param comment Comments\r
570      */\r
571     public void updateOtherData (final String phoneNumber, final String cellphoneNumber, final String faxNumber, final String emailAddress, final String birthday, final String comment) {\r
572         // Set all\r
573         if (phoneNumber != null) {\r
574             this.setPhoneNumber(phoneNumber);\r
575         }\r
576         if (cellphoneNumber != null) {\r
577             this.setCellphoneNumber(cellphoneNumber);\r
578         }\r
579         if (faxNumber != null) {\r
580             this.setFaxNumber(faxNumber);\r
581         }\r
582         if (emailAddress != null) {\r
583             this.setEmailAddress(emailAddress);\r
584         }\r
585         if (birthday != null) {\r
586             this.setBirthday(birthday);\r
587         }\r
588         if (comment != null) {\r
589             this.setComment(comment);\r
590         }\r
591     }\r
592 \r
593     /**\r
594      * Enables the flag "own data" which signals that this contact is the user's\r
595      * own data.\r
596      */\r
597     protected void enableFlagOwnContact () {\r
598         this.ownContact = true;\r
599     }\r
600 }\r