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