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