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