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