]> git.mxchange.org Git - jcore.git/blob - src/org/mxchange/jcore/model/contact/BaseContact.java
0fb4d495b8e1ab51a6dedf0f90e0c245caf20127
[jcore.git] / src / org / mxchange / jcore / model / 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.jcore.model.contact;
18
19 import java.sql.Timestamp;
20 import java.util.Objects;
21 import org.mxchange.jcore.client.Client;
22 import org.mxchange.jcore.model.contact.gender.Gender;
23
24 /**
25  * A general contact class which should only be extended.
26  *
27  * @author Roland Haeder<roland@mxchange.org>
28  * @version 0.0
29  */
30 public class BaseContact implements Contact, Comparable<Contact> {
31         /**
32          * Serial number
33          */
34         private static final long serialVersionUID = 58_744_284_981_863L;
35
36         /**
37          * When the contact has been created
38          */
39         private Timestamp created;
40
41         /**
42          * Id number
43          */
44         private Long id;
45
46         /**
47          * Birth day
48          */
49         private String birthday;
50
51         /**
52          * Cellphone number
53          */
54         private String cellphoneNumber;
55
56         /**
57          * City
58          */
59         private String city;
60
61         /**
62          * Optional comments
63          */
64         private String comment;
65
66         /**
67          * Company name
68          */
69         private String companyName;
70
71         /**
72          * Country code
73          */
74         private String countryCode;
75
76         /**
77          * Email address
78          */
79         private String emailAddress;
80
81         /**
82          * Family name
83          */
84         private String familyName;
85
86         /**
87          * Fax number
88          */
89         private String faxNumber;
90
91         /**
92          * First name
93          */
94         private String firstName;
95
96         /**
97          * Gender instance
98          */
99         private Gender gender;
100
101         /**
102          * House number
103          */
104         private Long houseNumber;
105
106         /**
107          * Flag whether this contact is user's own data
108          */
109         private boolean ownContact;
110
111         /**
112          * Phone number
113          */
114         private String phoneNumber;
115
116         /**
117          * Street
118          */
119         private String street;
120
121         /**
122          * When the contact has been updated
123          */
124         private Timestamp updated;
125
126         /**
127          * ZIP code
128          */
129         private Long zipCode;
130
131         /**
132          * No instances should be created of this class. Better extend this class
133          * and provide proper constructors.
134          */
135         protected BaseContact () {
136                 // Fake gender
137                 this.gender = Gender.UNKNOWN;
138         }
139
140         /**
141          * Check if contacts are same or throw an exception
142          *
143          * @param object Other possible contact class
144          * @return Whether both contacts are same
145          * TODO Needs a lot improvements
146          */
147         @Override
148         public boolean equals (final Object object) {
149                 // Is it same type?
150                 if (!(object instanceof BaseContact)) {
151                         // Not equal types
152                         return false;
153                 } else if (!(object instanceof Contact)) {
154                         // Not correct interface
155                         return false;
156                 }
157
158                 // Try to cast
159                 Contact contact = (Contact) object;
160
161                 // Now test some data TODO Definedly needs improvement
162                 return ((this.getGender().equals(contact.getGender()))
163                                 && (this.getFirstName().toLowerCase().equals(contact.getFirstName().toLowerCase()))
164                                 && (this.getFamilyName().toLowerCase().equals(contact.getFamilyName().toLowerCase())));
165         }
166
167         /**
168          * Birth day
169          *
170          * @return the birthday
171          */
172         @Override
173         public String getBirthday () {
174                 return this.birthday;
175         }
176
177         /**
178          * Birth day
179          *
180          * @param birthday the birthday to set
181          */
182         @Override
183         public void setBirthday (final String birthday) {
184                 this.birthday = birthday;
185         }
186
187         /**
188          * Cellphone number
189          *
190          * @return the cellphoneNumber
191          */
192         @Override
193         public String getCellphoneNumber () {
194                 return this.cellphoneNumber;
195         }
196
197         /**
198          * Cellphone number
199          *
200          * @param cellphoneNumber the cellphoneNumber to set
201          */
202         @Override
203         public void setCellphoneNumber (final String cellphoneNumber) {
204                 this.cellphoneNumber = cellphoneNumber;
205         }
206
207         /**
208          * City
209          *
210          * @return the city
211          */
212         @Override
213         public String getCity () {
214                 return this.city;
215         }
216
217         /**
218          * City
219          *
220          * @param city the city to set
221          */
222         @Override
223         public void setCity (final String city) {
224                 this.city = city;
225         }
226
227         /**
228          * Comments
229          *
230          * @return the comment
231          */
232         @Override
233         public String getComment () {
234                 return this.comment;
235         }
236
237         /**
238          * Comments
239          *
240          * @param comment the comment to set
241          */
242         @Override
243         public void setComment (final String comment) {
244                 this.comment = comment;
245         }
246
247         /**
248          * Company name
249          *
250          * @return the companyName
251          */
252         @Override
253         public String getCompanyName () {
254                 return this.companyName;
255         }
256
257         /**
258          * Company name
259          *
260          * @param companyName the companyName to set
261          */
262         @Override
263         public void setCompanyName (final String companyName) {
264                 this.companyName = companyName;
265         }
266
267         @Override
268         public Timestamp getCreated () {
269                 return this.created;
270         }
271
272         @Override
273         public void setCreated (final Timestamp created) {
274                 this.created = created;
275         }
276
277         /**
278          * Id number
279          * @return the id
280          */
281         @Override
282         public Long getId () {
283                 return this.id;
284         }
285
286         /**
287          * Id number
288          * @param id the id to set
289          */
290         @Override
291         public void setId (final Long id) {
292                 this.id = id;
293         }
294
295         /**
296          * Country code
297          *
298          * @return the countryCode
299          */
300         @Override
301         public String getCountryCode () {
302                 return this.countryCode;
303         }
304
305         /**
306          * Country code
307          *
308          * @param countryCode the countryCode to set
309          */
310         @Override
311         public void setCountryCode (final String countryCode) {
312                 this.countryCode = countryCode;
313         }
314
315         /**
316          * Email address
317          *
318          * @return the emailAddress
319          */
320         @Override
321         public String getEmailAddress () {
322                 return this.emailAddress;
323         }
324
325         /**
326          * Email address
327          *
328          * @param emailAddress the emailAddress to set
329          */
330         @Override
331         public void setEmailAddress (final String emailAddress) {
332                 this.emailAddress = emailAddress;
333         }
334
335         /**
336          * Family name
337          *
338          * @return the familyName
339          */
340         @Override
341         public String getFamilyName () {
342                 //* NOISY-DEBUG: */ this.getLogger().trace("CALLED!");
343                 return this.familyName;
344         }
345
346         /**
347          * Family name
348          *
349          * @param familyName the familyName to set
350          */
351         @Override
352         public void setFamilyName (final String familyName) {
353                 this.familyName = familyName;
354         }
355
356         /**
357          * Fax number
358          *
359          * @return the faxNumber
360          */
361         @Override
362         public String getFaxNumber () {
363                 return this.faxNumber;
364         }
365
366         /**
367          * Fax number
368          *
369          * @param faxNumber the faxNumber to set
370          */
371         @Override
372         public void setFaxNumber (final String faxNumber) {
373                 this.faxNumber = faxNumber;
374         }
375
376         /**
377          * First name
378          *
379          * @return the firstName
380          */
381         @Override
382         public String getFirstName () {
383                 return this.firstName;
384         }
385
386         /**
387          * First name
388          *
389          * @param firstName the firstName to set
390          */
391         @Override
392         public void setFirstName (final String firstName) {
393                 this.firstName = firstName;
394         }
395
396         /**
397          * Gender of the contact
398          *
399          * @return the gender
400          */
401         @Override
402         public Gender getGender () {
403                 return this.gender;
404         }
405
406         /**
407          * Gender of the contact
408          *
409          * @param gender the gender to set
410          */
411         @Override
412         public void setGender (final Gender gender) {
413                 this.gender = gender;
414         }
415
416         /**
417          * House number
418          *
419          * @return the houseNumber
420          */
421         @Override
422         public Long getHouseNumber () {
423                 return this.houseNumber;
424         }
425
426         /**
427          * House number
428          *
429          * @param houseNumber the houseNumber to set
430          */
431         @Override
432         public void setHouseNumber (final Long houseNumber) {
433                 this.houseNumber = houseNumber;
434         }
435
436         /**
437          * Phone number
438          *
439          * @return the phoneNumber
440          */
441         @Override
442         public String getPhoneNumber () {
443                 return this.phoneNumber;
444         }
445
446         /**
447          * Phone number
448          *
449          * @param phoneNumber the phoneNumber to set
450          */
451         @Override
452         public void setPhoneNumber (final String phoneNumber) {
453                 this.phoneNumber = phoneNumber;
454         }
455
456         /**
457          * Street
458          *
459          * @return the street
460          */
461         @Override
462         public String getStreet () {
463                 return this.street;
464         }
465
466         /**
467          * Street
468          *
469          * @param street the street to set
470          */
471         @Override
472         public void setStreet (final String street) {
473                 this.street = street;
474         }
475
476         @Override
477         public Timestamp getUpdated () {
478                 return this.updated;
479         }
480
481         @Override
482         public void setUpdated (final Timestamp updated) {
483                 this.updated = updated;
484         }
485
486         /**
487          * ZIP code
488          *
489          * @return the zipCode
490          */
491         @Override
492         public Long getZipCode () {
493                 return this.zipCode;
494         }
495
496         /**
497          * ZIP code
498          *
499          * @param zipCode the zipCode to set
500          */
501         @Override
502         public void setZipCode (final Long zipCode) {
503                 this.zipCode = zipCode;
504         }
505
506         @Override
507         public int hashCode () {
508                 // Validate gender instance
509                 assert (this.getGender() instanceof Gender) : "gender is not set."; //NOI18N
510
511                 int hash = 7;
512                 hash = 79 * hash + Objects.hashCode(this.getFamilyName());
513                 hash = 79 * hash + this.getGender().hashCode();
514                 hash = 79 * hash + Objects.hashCode(this.getFirstName());
515                 return hash;
516         }
517
518         /**
519          * Checks whether the contact is user's own data
520          *
521          * @return Own data?
522          */
523         @Override
524         public boolean isOwnContact () {
525                 return this.ownContact;
526         }
527
528         /**
529          * Shows this contact to the user
530          *
531          * @param client Client instance to use
532          * TODO: Maybe needs to be moved to other class
533          */
534         public void show (final Client client) {
535                 // The client must be set
536                 if (null == client) {
537                         // Not set
538                         throw new NullPointerException("client is null"); //NOI18N
539                 }
540
541                 // Display name "box"
542                 client.displayNameBox(this);
543
544                 // Display address "box"
545                 client.displayAddressBox(this);
546
547                 // Display other data "box"
548                 client.displayOtherDataBox(this);
549         }
550
551         @Override
552         public void setOwnContact (final Boolean ownContact) {
553                 this.ownContact = ownContact;
554         }
555
556         /**
557          * Compares two contacts with each other
558          *
559          * @param contact Contact comparator
560          * @return Comparison value
561          */
562         @Override
563         public int compareTo (final Contact contact) {
564                 // contact should not be null
565                 if (null == contact) {
566                         throw new NullPointerException("contact is null"); //NOI18N
567                 }
568
569                 // Is the id the same?
570                 if (Objects.equals(this.getId(), contact.getId())) {
571                         // Same id, means same contact
572                         return 0;
573                 } else if (this.getId() > contact.getId()) {
574                         // This id is larger than compared to
575                         return -1;
576                 }
577
578                 // The other id is larger
579                 return 1;
580         }
581 }