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