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