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