From: Roland Häder Date: Sun, 10 Sep 2017 14:42:46 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ba989205464935dfb5c17cb911bfc8f3b616e59b;p=jcontacts-core.git Continued: - moved model-related classes (entities, of course) to own 'model' package Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jcontacts/contact/Contact.java b/src/org/mxchange/jcontacts/contact/Contact.java deleted file mode 100644 index 89e4113..0000000 --- a/src/org/mxchange/jcontacts/contact/Contact.java +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontacts.contact; - -import java.io.Serializable; -import java.util.Calendar; -import java.util.Date; -import org.mxchange.jcontacts.contact.title.PersonalTitle; -import org.mxchange.jcountry.data.Country; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; - -/** - * A general contact POJI - *

- * @author Roland Häder - */ -public interface Contact extends Serializable { - - /** - * Birth day - *

- * @return the birthday - */ - Date getContactBirthday (); - - /** - * Birth day - *

- * @param birthday the birthday to set - */ - void setContactBirthday (final Date birthday); - - /** - * Getter for mobile number - *

- * @return Mobile number - */ - DialableMobileNumber getContactMobileNumber (); - - /** - * Setter for mobile number - *

- * @param mobileNumber Mobile number - */ - void setContactMobileNumber (final DialableMobileNumber mobileNumber); - - /** - * City - *

- * @return the city - */ - String getContactCity (); - - /** - * City - *

- * @param city the city to set - */ - void setContactCity (final String city); - - /** - * Comments - *

- * @return the comment - */ - String getContactComment (); - - /** - * Comments - *

- * @param comment the comment to set - */ - void setContactComment (final String comment); - - /** - * Id number - *

- * @return the contactId - */ - Long getContactId (); - - /** - * Id number - *

- * @param id the contactId to set - */ - void setContactId (final Long id); - - /** - * Country code - *

- * @return the countryCode - */ - Country getContactCountry (); - - /** - * Country code - *

- * @param contactCountry the countryCode to set - */ - void setContactCountry (final Country contactCountry); - - /** - * Getter for "created" timestamp - *

- * @return "created" timestamp - */ - Calendar getContactCreated (); - - /** - * Setter for "created" timestamp - *

- * @param created "created" timestamp - */ - void setContactCreated (final Calendar created); - - /** - * Email address - *

- * @return the emailAddress - */ - String getContactEmailAddress (); - - /** - * Email address - *

- * @param emailAddress the emailAddress to set - */ - void setContactEmailAddress (final String emailAddress); - - /** - * Family name - *

- * @return the familyName - */ - String getContactFamilyName (); - - /** - * Family name - *

- * @param familyName the familyName to set - */ - void setContactFamilyName (final String familyName); - - /** - * Fax number - *

- * @return the faxNumber - */ - DialableFaxNumber getContactFaxNumber (); - - /** - * Fax number - *

- * @param faxNumber the faxNumber to set - */ - void setContactFaxNumber (final DialableFaxNumber faxNumber); - - /** - * First name - *

- * @return the first name - */ - String getContactFirstName (); - - /** - * First name - *

- * @param firstName the first name to set - */ - void setContactFirstName (final String firstName); - - /** - * Getter for personal title - *

- * @return Personal title - */ - PersonalTitle getContactPersonalTitle (); - - /** - * Setter for personal title - *

- * @param personalTitle Personal title - */ - void setContactPersonalTitle (final PersonalTitle personalTitle); - - /** - * House number - *

- * @return the houseNumber - */ - Short getContactHouseNumber (); - - /** - * House number - *

- * @param houseNumber the houseNumber to set - */ - void setContactHouseNumber (final Short houseNumber); - - /** - * Getter for house number extension, example: 123a 'a' is then the - * extension and 123 is the house number. - *

- * @return House number extension - */ - String getContactHouseNumberExtension (); - - /** - * Setter for house number extension - *

- * @param contactHouseNumberExtension House number extension - */ - void setContactHouseNumberExtension (final String contactHouseNumberExtension); - - /** - * Setter for own contact - *

- * @param ownContact Own contact - */ - void setContactOwnContact (final Boolean ownContact); - - /** - * Getter for phone number - *

- * @return Phone number - */ - DialableLandLineNumber getContactLandLineNumber (); - - /** - * Setter for phone number - *

- * @param phoneNumber Phone number - */ - void setContactLandLineNumber (final DialableLandLineNumber phoneNumber); - - /** - * Street - *

- * @return the street - */ - String getContactStreet (); - - /** - * Street - *

- * @param street the street to set - */ - void setContactStreet (final String street); - - /** - * Getter for contact's title - *

- * @return Contact's title - */ - String getContactTitle (); - - /** - * Setter for contact's title - *

- * @param contactTitle Contact's title - */ - void setContactTitle (final String contactTitle); - - /** - * Getter for "updated" timestamp - *

- * @return "updated" timestamp - */ - Calendar getContactUpdated (); - - /** - * Getter for "updated" timestamp - *

- * @param updated "updated" timestamp - */ - void setContactUpdated (final Calendar updated); - - /** - * ZIP code - *

- * @return the zipCode - */ - Integer getContactZipCode (); - - /** - * ZIP code - *

- * @param zipCode the zipCode to set - */ - void setContactZipCode (final Integer zipCode); - - /** - * Checks whether the contact is user's own data - *

- * @return Own data? - */ - Boolean isOwnContact (); - - /** - * Check if contacts are same or throw an exception - *

- * @param object Other possible contact class - *

- * @return Whether both contacts are same - */ - @Override - boolean equals (final Object object); - - @Override - int hashCode (); - -} diff --git a/src/org/mxchange/jcontacts/contact/ContactUtils.java b/src/org/mxchange/jcontacts/contact/ContactUtils.java deleted file mode 100644 index 7cc6f12..0000000 --- a/src/org/mxchange/jcontacts/contact/ContactUtils.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontacts.contact; - -import java.io.Serializable; -import java.util.Objects; -import org.mxchange.jcountry.data.Country; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.fax.FaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.phonenumbers.mobile.MobileNumber; -import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; - -/** - * Utilities for contacts - *

- * @author Roland Häder - */ -public class ContactUtils implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 26_785_734_719_670L; - - /** - * Copies all attributes from other contact object to this - *

- * @param sourceContact Source instance - * @param targetContact Target instance - */ - public static void copyAll (final Contact sourceContact, final Contact targetContact) { - // Contact should be valid - if (null == sourceContact) { - // Throw NPE - throw new NullPointerException("sourceContact is null"); //NOI18N - } else if (null == targetContact) { - // Throw NPE - throw new NullPointerException("targetContact is null"); //NOI18N - } - - // Copy all: - // - base data - targetContact.setContactPersonalTitle(sourceContact.getContactPersonalTitle()); - targetContact.setContactTitle(sourceContact.getContactTitle()); - targetContact.setContactFirstName(sourceContact.getContactFirstName()); - targetContact.setContactFamilyName(sourceContact.getContactFamilyName()); - targetContact.setContactStreet(sourceContact.getContactStreet()); - targetContact.setContactHouseNumber(sourceContact.getContactHouseNumber()); - targetContact.setContactHouseNumberExtension(sourceContact.getContactHouseNumberExtension()); - targetContact.setContactZipCode(sourceContact.getContactZipCode()); - targetContact.setContactCity(sourceContact.getContactCity()); - targetContact.setContactCountry(sourceContact.getContactCountry()); - - // - phone, fax, email - targetContact.setContactLandLineNumber(sourceContact.getContactLandLineNumber()); - targetContact.setContactFaxNumber(sourceContact.getContactFaxNumber()); - targetContact.setContactMobileNumber(sourceContact.getContactMobileNumber()); - - // - other data - targetContact.setContactBirthday(sourceContact.getContactBirthday()); - targetContact.setContactComment(sourceContact.getContactComment()); - targetContact.setContactCreated(sourceContact.getContactCreated()); - targetContact.setContactUpdated(sourceContact.getContactUpdated()); - } - - /** - * Checks whether both contacts are same, but ignoring id number. If you - * want to include id number in comparison, better use Objects.equals() as - * the equal() method is implemented and checks all fields. - *

- * @param contact Contact one - * @param other Contact two - *

- * @return Whether both are the same - */ - public static boolean isSameContact (final Contact contact, final Contact other) { - // Both should not be null - if (null == contact) { - // First contact is null - throw new NullPointerException("contact is null"); //NOI18N - } else if (null == other) { - // Secondcontact is null - throw new NullPointerException("other is null"); //NOI18N - } - - // Check all data fields, except id number - return ((Objects.equals(contact.getContactBirthday(), other.getContactBirthday())) && - (Objects.equals(contact.getContactCity(), other.getContactCity())) && - (Objects.equals(contact.getContactCountry(), other.getContactCountry())) && - (Objects.equals(contact.getContactEmailAddress(), other.getContactEmailAddress())) && - (Objects.equals(contact.getContactFamilyName(), other.getContactFamilyName())) && - (Objects.equals(contact.getContactFirstName(), other.getContactFirstName())) && - (Objects.equals(contact.getContactPersonalTitle(), other.getContactPersonalTitle())) && - (Objects.equals(contact.getContactHouseNumber(), other.getContactHouseNumber())) && - (Objects.equals(contact.getContactStreet(), other.getContactStreet())) && - (Objects.equals(contact.getContactTitle(), other.getContactTitle())) && - (Objects.equals(contact.getContactZipCode(), other.getContactZipCode()))); - } - - /** - * Updates land-line data in contact instance. This method also removes the - * land-line instance if no country is selected. A bean (mostly EJB) should - * then make sure that the land-line entry is being unlinked from contact - * instance or being removed, if no longer used. - *

- * @param contact Contact instance being updated - * @param faxCountry Updated fax number or null - * @param faxAreaCode Updated fax area code or null - * @param faxNumber Updated fax number - *

- * @return Whether the fax number has been unlinked in contact object - */ - public static boolean updateFaxNumber (final Contact contact, final Country faxCountry, final Integer faxAreaCode, final Long faxNumber) { - // At least contact must be valid - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } - - // Default is not unlinked - boolean isUnlinked = false; - - // Is there a fax instance? - if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { - // Found existing fax number, remove it? - if ((null == faxCountry) || (null == faxAreaCode) || (null == faxNumber)) { - // Remove existing instance - contact.setContactFaxNumber(null); - - // Mark it as being removed - isUnlinked = true; - } else { - // Set all data - contact.getContactFaxNumber().setPhoneCountry(faxCountry); - contact.getContactFaxNumber().setPhoneAreaCode(faxAreaCode); - contact.getContactFaxNumber().setPhoneNumber(faxNumber); - } - } else if ((faxCountry instanceof Country) && (faxAreaCode > 0) && (faxNumber > 0)) { - // Set new land-line number - DialableFaxNumber fax = new FaxNumber(faxCountry, faxAreaCode, faxNumber); - - // Set it in contact - contact.setContactFaxNumber(fax); - } - - // Return status - return isUnlinked; - } - - /** - * Updates land-line data in contact instance. This method also removes the - * land-line instance if no country is selected. A bean (mostly EJB) should - * then make sure that the land-line entry is being unlinked from contact - * instance or being removed, if no longer used. - *

- * @param contact Contact instance being updated - * @param phoneCountry New phone country or old or null - * @param phoneAreaCode New phone's area code (or old) - * @param phoneNumber New phone number (or old) - *

- * @return Whether the land-line number has been unlinked in contact object - */ - public static boolean updateLandLineNumber (final Contact contact, final Country phoneCountry, final Integer phoneAreaCode, final Long phoneNumber) { - // At least contact must be valid - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } - - // Default is not unlinked - boolean isUnlinked = false; - - // Is there a land-line instance? - if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { - // Found existing land-line number, remove it? - if ((null == phoneCountry) || (null == phoneAreaCode) || (null == phoneNumber)) { - // Remove existing instance - contact.setContactLandLineNumber(null); - - // Mark it as being removed - isUnlinked = true; - } else { - // Set all data - contact.getContactLandLineNumber().setPhoneCountry(phoneCountry); - contact.getContactLandLineNumber().setPhoneAreaCode(phoneAreaCode); - contact.getContactLandLineNumber().setPhoneNumber(phoneNumber); - } - } else if ((phoneCountry instanceof Country) && (phoneAreaCode > 0) && (phoneNumber > 0)) { - // Set new land-line number - DialableLandLineNumber landLine = new LandLineNumber(phoneCountry, phoneAreaCode, phoneNumber); - - // Set it in contact - contact.setContactLandLineNumber(landLine); - } - - // Return status - return isUnlinked; - } - - /** - * Updates mobile data in contact instance. This method also removes the - * mobile instance if no provider is selected. A bean (mostly EJB) should - * then make sure that the mobile entry is being unlinked from contact - * instance or being removed, if no longer used. - *

- * @param contact Contact instance to update - * @param mobileProvider New mobile provider (or old) - * @param mobileNumber New mobile number (or old) - *

- * @return Whether the mobile has been unlinked in contact object - */ - public static boolean updateMobileNumber (final Contact contact, final MobileProvider mobileProvider, final Long mobileNumber) { - // At least contact must be valid - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if ((mobileProvider instanceof MobileProvider) && (null == mobileNumber)) { - // Mobile provider given, but no number - throw new NullPointerException("mobileNumber is null"); //NOI18N - } - - // Default is not unlinked - boolean isUnlinked = false; - - // Is there a mobile number? - if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { - // Is provider null? - if ((null == mobileProvider) || (null == mobileNumber) || (mobileNumber == 0)) { - // Remove instance - contact.setContactMobileNumber(null); - - // Mark as unlinked - isUnlinked = true; - } else { - // Yes, then update as well - contact.getContactMobileNumber().setMobileProvider(mobileProvider); - contact.getContactMobileNumber().setPhoneNumber(mobileNumber); - } - } else if ((mobileProvider instanceof MobileProvider) && (mobileNumber > 0)) { - // Create new instance - DialableMobileNumber mobile = new MobileNumber(mobileProvider, mobileNumber); - - // Set it in contact - contact.setContactMobileNumber(mobile); - } - - // Return status - return isUnlinked; - } - - /** - * Private constructor for utilities - */ - private ContactUtils () { - } - -} diff --git a/src/org/mxchange/jcontacts/contact/UserContact.java b/src/org/mxchange/jcontacts/contact/UserContact.java deleted file mode 100644 index 6a61c8b..0000000 --- a/src/org/mxchange/jcontacts/contact/UserContact.java +++ /dev/null @@ -1,518 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontacts.contact; - -import java.util.Calendar; -import java.util.Date; -import java.util.Objects; -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.Lob; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToOne; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import javax.persistence.Transient; -import org.mxchange.jcontacts.contact.title.PersonalTitle; -import org.mxchange.jcountry.data.Country; -import org.mxchange.jcountry.data.CountryData; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.fax.FaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.phonenumbers.mobile.MobileNumber; - -/** - * A general contact class which serves as an entity. - *

- * @author Roland Häder - * @version 0.0 - */ -@Entity (name = "contacts") -@Table ( - name = "contacts", - indexes = { - @Index ( - name = "contact_personal_title", - columnList = "contact_personal_title" - ) - } -) -@NamedQueries ( - { - @NamedQuery (name = "AllContacts", query = "SELECT c FROM contacts AS c ORDER BY c.contactId ASC"), - @NamedQuery (name = "AllContactEmailAddresses", query = "SELECT c.contactEmailAddress FROM contacts AS c ORDER BY c.contactId ASC"), - @NamedQuery (name = "AllContactsByCellphone", query = "SELECT c FROM contacts AS c WHERE c.contactMobileNumber = :mobileNumber ORDER BY c.contactId ASC"), - @NamedQuery (name = "SearchContact", query = "SELECT c FROM contacts AS c WHERE c = :contact"), - @NamedQuery (name = "SearchContactById", query = "SELECT c FROM contacts AS c WHERE c.contactId = :contactId"), - @NamedQuery (name = "SearchContactByEmailAddress", query = "SELECT c FROM contacts AS c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:emailAddress)") - } -) -@SuppressWarnings ("PersistenceUnitPresent") -public class UserContact implements Contact { - - /** - * Serial number - */ - @Transient - private static final long serialVersionUID = 58_744_284_981_863L; - - /** - * Birth day - */ - @Column (name = "contact_birthday") - @Temporal (TemporalType.DATE) - private Date contactBirthday; - - /** - * City - */ - @Column (name = "contact_city", length = 100) - private String contactCity; - - /** - * Optional comments - */ - @Lob - @Column (name = "contact_comment") - private String contactComment; - - /** - * Country code - */ - @JoinColumn (name = "contact_country_id", nullable = false, referencedColumnName = "country_id") - @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false) - private Country contactCountry; - - /** - * When the contact has been created - */ - @Basic (optional = false) - @Temporal (TemporalType.TIMESTAMP) - @Column (name = "contact_created", nullable = false) - private Calendar contactCreated; - - /** - * Email address - */ - @Column (name = "contact_email_address", length = 100, unique = true) - private String contactEmailAddress; - - /** - * Family name - */ - @Basic (optional = false) - @Column (name = "contact_family_name", length = 100, nullable = false) - private String contactFamilyName; - - /** - * Fax number - */ - @JoinColumn (name = "contact_fax_number_id", referencedColumnName = "fax_id", unique = true) - @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL) - private DialableFaxNumber contactFaxNumber; - - /** - * First name - */ - @Basic (optional = false) - @Column (name = "contact_first_name", length = 100, nullable = false) - private String contactFirstName; - - /** - * House number - */ - @Column (name = "contact_house_number") - private Short contactHouseNumber; - - /** - * House number extension - */ - @Column (name = "contact_house_number_extension", length = 5) - private String contactHouseNumberExtension; - - /** - * Id number - */ - @Id - @GeneratedValue (strategy = GenerationType.IDENTITY) - @Column (name = "contact_id", nullable = false, updatable = false) - private Long contactId; - - /** - * Cellphone number - */ - @JoinColumn (name = "contact_mobile_number_id", referencedColumnName = "mobile_id", unique = true) - @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.ALL) - private DialableMobileNumber contactMobileNumber; - - /** - * Flag whether this contact is user's own data - */ - @Basic (optional = false) - @Column (name = "contact_own_contact", nullable = false) - private Boolean contactOwnContact; - - /** - * Contact's personal title (Mr./Mrs.) - */ - @Basic (optional = false) - @Column (name = "contact_personal_title", nullable = false) - @Enumerated (EnumType.STRING) - private PersonalTitle contactPersonalTitle; - - /** - * Phone number - */ - @JoinColumn (name = "contact_landline_number_id", referencedColumnName = "landline_id", unique = true) - @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL) - private DialableLandLineNumber contactPhoneNumber; - - /** - * Street - */ - @Column (name = "contact_street") - private String contactStreet; - - /** - * Title (Doctor, etc) - */ - @Column (name = "contact_title") - private String contactTitle; - - /** - * When the contact has been updated - */ - @Temporal (TemporalType.TIMESTAMP) - @Column (name = "contact_updated") - private Calendar contactUpdated; - - /** - * ZIP code - */ - @Column (name = "contact_zip_code") - private Integer contactZipCode; - - /** - * Default constructor - */ - public UserContact () { - // Default is not user's own contact - this.contactOwnContact = Boolean.FALSE; - } - - /** - * Constructor for title and names - *

- * @param contactTitle Personal title - * @param contactFirstName First name - * @param contactFamilyName Family name - */ - public UserContact (final PersonalTitle contactTitle, final String contactFirstName, final String contactFamilyName) { - // Call default constructor - this(); - - // Set all - this.contactPersonalTitle = contactTitle; - this.contactFirstName = contactFirstName; - this.contactFamilyName = contactFamilyName; - } - - @Override - public boolean equals (final Object object) { - if (this == object) { - return true; - } else if (null == object) { - return false; - } else if (this.getClass() != object.getClass()) { - return false; - } else if (!(object instanceof Contact)) { - // Not correct interface - return false; - } - - final Contact other = (Contact) object; - - if (!Objects.equals(this.getContactId(), other.getContactId())) { - return false; - } else if (!Objects.equals(this.getContactCity(), other.getContactCity())) { - return false; - } else if (!Objects.equals(this.getContactEmailAddress(), other.getContactEmailAddress())) { - return false; - } else if (!Objects.equals(this.getContactFamilyName(), other.getContactFamilyName())) { - return false; - } else if (!Objects.equals(this.getContactFirstName(), other.getContactFirstName())) { - return false; - } else if (!Objects.equals(this.getContactStreet(), other.getContactStreet())) { - return false; - } else if (!Objects.equals(this.getContactTitle(), other.getContactTitle())) { - return false; - } else if (!Objects.equals(this.getContactBirthday(), other.getContactBirthday())) { - return false; - } else if (!Objects.equals(this.getContactCountry(), other.getContactCountry())) { - return false; - } else if (this.getContactPersonalTitle() != other.getContactPersonalTitle()) { - return false; - } else if (!Objects.equals(this.getContactHouseNumber(), other.getContactHouseNumber())) { - return false; - } else if (!Objects.equals(this.getContactHouseNumberExtension(), other.getContactHouseNumberExtension())) { - return false; - } - - return true; - } - - @Override - @SuppressWarnings ("ReturnOfDateField") - public Date getContactBirthday () { - return this.contactBirthday; - } - - @Override - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setContactBirthday (final Date contactBirthday) { - this.contactBirthday = contactBirthday; - } - - @Override - public String getContactCity () { - return this.contactCity; - } - - @Override - public void setContactCity (final String contactCity) { - this.contactCity = contactCity; - } - - @Override - public String getContactComment () { - return this.contactComment; - } - - @Override - public void setContactComment (final String contactComment) { - this.contactComment = contactComment; - } - - @Override - public Country getContactCountry () { - return this.contactCountry; - } - - @Override - public void setContactCountry (final Country contactCountry) { - this.contactCountry = contactCountry; - } - - @Override - @SuppressWarnings ("ReturnOfDateField") - public Calendar getContactCreated () { - return this.contactCreated; - } - - @Override - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setContactCreated (final Calendar contactCreated) { - this.contactCreated = contactCreated; - } - - @Override - public String getContactEmailAddress () { - return this.contactEmailAddress; - } - - @Override - public void setContactEmailAddress (final String contactEmailAddress) { - this.contactEmailAddress = contactEmailAddress; - } - - @Override - public String getContactFamilyName () { - //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!"); - return this.contactFamilyName; - } - - @Override - public void setContactFamilyName (final String contactFamilyName) { - this.contactFamilyName = contactFamilyName; - } - - @Override - public DialableFaxNumber getContactFaxNumber () { - return this.contactFaxNumber; - } - - @Override - public void setContactFaxNumber (final DialableFaxNumber contactFaxNumber) { - this.contactFaxNumber = contactFaxNumber; - } - - @Override - public String getContactFirstName () { - return this.contactFirstName; - } - - @Override - public void setContactFirstName (final String contactFirstName) { - this.contactFirstName = contactFirstName; - } - - @Override - public Short getContactHouseNumber () { - return this.contactHouseNumber; - } - - @Override - public void setContactHouseNumber (final Short contactHouseNumber) { - this.contactHouseNumber = contactHouseNumber; - } - - @Override - public String getContactHouseNumberExtension () { - return this.contactHouseNumberExtension; - } - - @Override - public void setContactHouseNumberExtension (final String contactHouseNumberExtension) { - this.contactHouseNumberExtension = contactHouseNumberExtension; - } - - @Override - public Long getContactId () { - return this.contactId; - } - - @Override - public void setContactId (final Long contactId) { - this.contactId = contactId; - } - - @Override - public DialableLandLineNumber getContactLandLineNumber () { - return this.contactPhoneNumber; - } - - @Override - public void setContactLandLineNumber (final DialableLandLineNumber contactPhoneNumber) { - this.contactPhoneNumber = contactPhoneNumber; - } - - @Override - public DialableMobileNumber getContactMobileNumber () { - return this.contactMobileNumber; - } - - @Override - public void setContactMobileNumber (final DialableMobileNumber contactMobileNumber) { - this.contactMobileNumber = contactMobileNumber; - } - - @Override - public void setContactOwnContact (final Boolean contactOwnContact) { - this.contactOwnContact = contactOwnContact; - } - - @Override - public PersonalTitle getContactPersonalTitle () { - return this.contactPersonalTitle; - } - - @Override - public void setContactPersonalTitle (final PersonalTitle contactPersonalTitle) { - this.contactPersonalTitle = contactPersonalTitle; - } - - @Override - public String getContactStreet () { - return this.contactStreet; - } - - @Override - public void setContactStreet (final String contactStreet) { - this.contactStreet = contactStreet; - } - - @Override - public String getContactTitle () { - return this.contactTitle; - } - - @Override - public void setContactTitle (final String contactTitle) { - this.contactTitle = contactTitle; - } - - @Override - @SuppressWarnings ("ReturnOfDateField") - public Calendar getContactUpdated () { - return this.contactUpdated; - } - - @Override - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setContactUpdated (final Calendar contactUpdated) { - this.contactUpdated = contactUpdated; - } - - @Override - public Integer getContactZipCode () { - return this.contactZipCode; - } - - @Override - public void setContactZipCode (final Integer contactZipCode) { - this.contactZipCode = contactZipCode; - } - - @Override - public int hashCode () { - int hash = 5; - - hash = 29 * hash + Objects.hashCode(this.getContactBirthday()); - hash = 29 * hash + Objects.hashCode(this.getContactCity()); - hash = 29 * hash + Objects.hashCode(this.getContactCountry()); - hash = 29 * hash + Objects.hashCode(this.getContactEmailAddress()); - hash = 29 * hash + Objects.hashCode(this.getContactFamilyName()); - hash = 29 * hash + Objects.hashCode(this.getContactFirstName()); - hash = 29 * hash + Objects.hashCode(this.getContactPersonalTitle()); - hash = 29 * hash + Objects.hashCode(this.getContactHouseNumber()); - hash = 29 * hash + Objects.hashCode(this.getContactHouseNumberExtension()); - hash = 29 * hash + Objects.hashCode(this.getContactId()); - hash = 29 * hash + Objects.hashCode(this.getContactStreet()); - hash = 29 * hash + Objects.hashCode(this.getContactTitle()); - - return hash; - } - - @Override - public Boolean isOwnContact () { - return this.contactOwnContact; - } - -} diff --git a/src/org/mxchange/jcontacts/contact/gender/Gender.java b/src/org/mxchange/jcontacts/contact/gender/Gender.java deleted file mode 100644 index b06b94d..0000000 --- a/src/org/mxchange/jcontacts/contact/gender/Gender.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontacts.contact.gender; - -import java.io.Serializable; - -/** - * An enumeration for genders, sure more need to be added here. If you need - * titles instead, please use the proper enumeration then. - *

- * @author Roland Häder - */ -public enum Gender implements Serializable { - - /** - * Male gender - */ - MALE('M', "GENDER_MALE"), //NOI18N - - /** - * Female gender - */ - FEMALE('F', "GENDER_FEMALE"); //NOI18N - - /** - * Access key being entered by ConsoleClient - */ - private final char accessChar; - - /** - * Output value (for messages) - */ - private final String messageKey; - - /** - * Constructor - *

- * @param accessChar Value being entered by ConsoleClient - * @param messageKey Message key for resource file - */ - private Gender (final char accessChar, final String messageKey) { - // Set both - this.accessChar = accessChar; - this.messageKey = messageKey; - } - - /** - * Access key (console client mostly) - *

- * @return the accessChar - */ - public char getAccessChar () { - return this.accessChar; - } - - /** - * Output value (for messages) - *

- * @return the messageKey - */ - public String getMessageKey () { - return this.messageKey; - } - -} diff --git a/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java b/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java deleted file mode 100644 index 87ec6e8..0000000 --- a/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontacts.contact.gender; - -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.LinkedList; -import java.util.List; - -/** - * Gender utils class - *

- * @author Roland Häder - */ -public class GenderUtils implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 185_683_479_107L; - - /** - * Cache for valid chars - */ - private static char[] validChars; - - /** - * All available genders as a list - *

- * @return Selectable genders (not UNKNOWN) - */ - public static List allGendersAsList () { - // Init list - List list = new LinkedList<>(); - - // Walk through all genders - for (final Gender gender : Gender.values()) { - // Add it and check if it has been added - list.add(gender); - } - - // Return it - return list; - } - - /** - * Getter for Gender enumeration from given character - *

- * @param c Gender character -

- * @return Gender enumeration - */ - public static Gender fromChar (final char c) { - // Init variable - Gender found = null; - - // Loop through all - for (final Gender gender : Gender.values()) { - // Does the char match? - if (c == gender.getAccessChar()) { - // Found it - found = gender; - break; - } - } - - // Still null? - if (null == found) { - // Didn't found a valid one - throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N - } - - // Return it - return found; - } - - /** - * Valid chars (mostly for console client) - *

- * @return Valid chars - */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public static char[] validChars () { - // Is cache set? - if (validChars != null) { - // Return it - return validChars; - } - - // Init array, only 2 are valid. - char[] valid = new char[2]; - - // Get values - int i = 0; - for (final Gender gender : Gender.values()) { - // Get access key as this is also the access - valid[i] = gender.getAccessChar(); - - // Increment index - i++; - } - - // Set it here - validChars = valid; - - // Return finialized array - return valid; - } - - /** - * Private constructor as this is an utility class - */ - private GenderUtils () { - } - -} diff --git a/src/org/mxchange/jcontacts/contact/title/PersonalTitle.java b/src/org/mxchange/jcontacts/contact/title/PersonalTitle.java deleted file mode 100644 index 8a88902..0000000 --- a/src/org/mxchange/jcontacts/contact/title/PersonalTitle.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontacts.contact.title; - -import java.io.Serializable; - -/** - * An enumeration for personal titles. If you need the gender instead, please - * use the other enumeration instead. - *

- * @author Roland Häder - */ -public enum PersonalTitle implements Serializable { - - /** - * Title "Mr." - */ - MR('M', "PERSONAL_TITLE_MR"), //NOI18N - - /** - * Title "Mrs." - */ - MRS('F', "PERSONAL_TITLE_MRS"); //NOI18N - - /** - * Access key being entered by ConsoleClient - */ - private final char accessChar; - - /** - * Output value (for messages) - */ - private final String messageKey; - - /** - * Constructor - *

- * @param accessChar Value being entered by ConsoleClient - * @param messageKey Message key for resource file - */ - private PersonalTitle (final char accessChar, final String messageKey) { - // Set both - this.accessChar = accessChar; - this.messageKey = messageKey; - } - - /** - * Access key (console client mostly) - *

- * @return the accessChar - */ - public char getAccessChar () { - return this.accessChar; - } - - /** - * Output value (for messages) - *

- * @return the messageKey - */ - public String getMessageKey () { - return this.messageKey; - } - -} diff --git a/src/org/mxchange/jcontacts/contact/title/TitleUtils.java b/src/org/mxchange/jcontacts/contact/title/TitleUtils.java deleted file mode 100644 index 492f5ef..0000000 --- a/src/org/mxchange/jcontacts/contact/title/TitleUtils.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontacts.contact.title; - -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.LinkedList; -import java.util.List; - -/** - * Title utilities class - *

- * @author Roland Häder - */ -public class TitleUtils implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 185_683_479_107L; - - /** - * Cache for valid chars - */ - private static char[] validChars; - - /** - * All available personal titles as a list - *

- * @return Selectable personal titles - */ - public static List allPersonalTitlesAsList () { - // Init list - List list = new LinkedList<>(); - - // Walk through all genders - for (final PersonalTitle title : PersonalTitle.values()) { - // Add it and check if it has been added - list.add(title); - } - - // Return it - return list; - } - - /** - * Getter for personal title enumeration from given character - *

- * @param c PersonalTitle character - *

- * @return PersonalTitle enumeration - */ - public static PersonalTitle getPersonalTitleFromChar (final char c) { - // Init variable - PersonalTitle found = null; - - // Loop through all - for (final PersonalTitle title : PersonalTitle.values()) { - // Does the char match? - if (c == title.getAccessChar()) { - // Found it - found = title; - break; - } - } - - // Still null? - if (null == found) { - // Didn't found a valid one - throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N - } - - // Return it - return found; - } - - /** - * Valid chars (mostly for console client) - *

- * @return Valid chars - */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public static char[] validChars () { - // Is cache set? - if (validChars != null) { - // Return it - return validChars; - } - - // Init array, only 2 are valid. - char[] valid = new char[2]; - - // Get values - int i = 0; - for (final PersonalTitle title : PersonalTitle.values()) { - // Get access key as this is also the access - valid[i] = title.getAccessChar(); - - // Increment index - i++; - } - - // Set it here - validChars = valid; - - // Return finialized array - return valid; - } - - /** - * Private constructor as this is an utility class - */ - private TitleUtils () { - } - -} diff --git a/src/org/mxchange/jcontacts/events/contact/add/AdminAddedContactEvent.java b/src/org/mxchange/jcontacts/events/contact/add/AdminAddedContactEvent.java index 1e1dd70..3ec3481 100644 --- a/src/org/mxchange/jcontacts/events/contact/add/AdminAddedContactEvent.java +++ b/src/org/mxchange/jcontacts/events/contact/add/AdminAddedContactEvent.java @@ -17,7 +17,7 @@ package org.mxchange.jcontacts.events.contact.add; import java.text.MessageFormat; -import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.model.contact.Contact; /** * An event being fired when the administrator has added a new user account diff --git a/src/org/mxchange/jcontacts/events/contact/add/ObservableAdminAddedContactEvent.java b/src/org/mxchange/jcontacts/events/contact/add/ObservableAdminAddedContactEvent.java index 8346b31..feef6eb 100644 --- a/src/org/mxchange/jcontacts/events/contact/add/ObservableAdminAddedContactEvent.java +++ b/src/org/mxchange/jcontacts/events/contact/add/ObservableAdminAddedContactEvent.java @@ -17,7 +17,7 @@ package org.mxchange.jcontacts.events.contact.add; import java.io.Serializable; -import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.model.contact.Contact; /** * An interface for events being fired when an administrator added new contact diff --git a/src/org/mxchange/jcontacts/events/contact/created/CreatedContactEvent.java b/src/org/mxchange/jcontacts/events/contact/created/CreatedContactEvent.java index 29d69e1..7f7fb55 100644 --- a/src/org/mxchange/jcontacts/events/contact/created/CreatedContactEvent.java +++ b/src/org/mxchange/jcontacts/events/contact/created/CreatedContactEvent.java @@ -16,7 +16,7 @@ */ package org.mxchange.jcontacts.events.contact.created; -import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.model.contact.Contact; /** * An interface for observable events being fired when a contact instance has diff --git a/src/org/mxchange/jcontacts/events/contact/created/ObservableCreatedContactEvent.java b/src/org/mxchange/jcontacts/events/contact/created/ObservableCreatedContactEvent.java index edda265..777b3ae 100644 --- a/src/org/mxchange/jcontacts/events/contact/created/ObservableCreatedContactEvent.java +++ b/src/org/mxchange/jcontacts/events/contact/created/ObservableCreatedContactEvent.java @@ -17,7 +17,7 @@ package org.mxchange.jcontacts.events.contact.created; import java.io.Serializable; -import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.model.contact.Contact; /** * An interface for observable events being fired when a contact instance has diff --git a/src/org/mxchange/jcontacts/events/contact/deleted/AdminDeletedContactEvent.java b/src/org/mxchange/jcontacts/events/contact/deleted/AdminDeletedContactEvent.java index 3bc3cc2..ff2b5e7 100644 --- a/src/org/mxchange/jcontacts/events/contact/deleted/AdminDeletedContactEvent.java +++ b/src/org/mxchange/jcontacts/events/contact/deleted/AdminDeletedContactEvent.java @@ -17,7 +17,7 @@ package org.mxchange.jcontacts.events.contact.deleted; import java.text.MessageFormat; -import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.model.contact.Contact; /** * An event being fired when the administrator has deleted a contact diff --git a/src/org/mxchange/jcontacts/events/contact/deleted/ObservableAdminDeletedContactEvent.java b/src/org/mxchange/jcontacts/events/contact/deleted/ObservableAdminDeletedContactEvent.java index 0427df9..8b09643 100644 --- a/src/org/mxchange/jcontacts/events/contact/deleted/ObservableAdminDeletedContactEvent.java +++ b/src/org/mxchange/jcontacts/events/contact/deleted/ObservableAdminDeletedContactEvent.java @@ -17,7 +17,7 @@ package org.mxchange.jcontacts.events.contact.deleted; import java.io.Serializable; -import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.model.contact.Contact; /** * An interface for events being fired when an administrator deleted a contact. diff --git a/src/org/mxchange/jcontacts/events/contact/update/AdminUpdatedContactEvent.java b/src/org/mxchange/jcontacts/events/contact/update/AdminUpdatedContactEvent.java index 51e691f..881ff4e 100644 --- a/src/org/mxchange/jcontacts/events/contact/update/AdminUpdatedContactEvent.java +++ b/src/org/mxchange/jcontacts/events/contact/update/AdminUpdatedContactEvent.java @@ -17,7 +17,7 @@ package org.mxchange.jcontacts.events.contact.update; import java.text.MessageFormat; -import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.model.contact.Contact; /** * An event being fired when the administrator has updated a new user account diff --git a/src/org/mxchange/jcontacts/events/contact/update/ObservableAdminUpdatedContactEvent.java b/src/org/mxchange/jcontacts/events/contact/update/ObservableAdminUpdatedContactEvent.java index 845fae8..87182ee 100644 --- a/src/org/mxchange/jcontacts/events/contact/update/ObservableAdminUpdatedContactEvent.java +++ b/src/org/mxchange/jcontacts/events/contact/update/ObservableAdminUpdatedContactEvent.java @@ -17,7 +17,7 @@ package org.mxchange.jcontacts.events.contact.update; import java.io.Serializable; -import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.model.contact.Contact; /** * An interface for events being fired when an administrator updated a new user diff --git a/src/org/mxchange/jcontacts/events/fax/linked/AdminLinkedFaxNumberEvent.java b/src/org/mxchange/jcontacts/events/fax/linked/AdminLinkedFaxNumberEvent.java index 2bd28e2..eb71aac 100644 --- a/src/org/mxchange/jcontacts/events/fax/linked/AdminLinkedFaxNumberEvent.java +++ b/src/org/mxchange/jcontacts/events/fax/linked/AdminLinkedFaxNumberEvent.java @@ -16,8 +16,8 @@ */ package org.mxchange.jcontacts.events.fax.linked; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; /** * An event when a fax number has been linked with a contact diff --git a/src/org/mxchange/jcontacts/events/fax/linked/ObservableAdminLinkedFaxNumberEvent.java b/src/org/mxchange/jcontacts/events/fax/linked/ObservableAdminLinkedFaxNumberEvent.java index 962606d..afc7286 100644 --- a/src/org/mxchange/jcontacts/events/fax/linked/ObservableAdminLinkedFaxNumberEvent.java +++ b/src/org/mxchange/jcontacts/events/fax/linked/ObservableAdminLinkedFaxNumberEvent.java @@ -17,8 +17,8 @@ package org.mxchange.jcontacts.events.fax.linked; import java.io.Serializable; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; /** * An interface for an event when a fax number has been linked with a contact diff --git a/src/org/mxchange/jcontacts/events/fax/unlinked/AdminUnlinkedFaxNumberEvent.java b/src/org/mxchange/jcontacts/events/fax/unlinked/AdminUnlinkedFaxNumberEvent.java index ff1e769..764f5d3 100644 --- a/src/org/mxchange/jcontacts/events/fax/unlinked/AdminUnlinkedFaxNumberEvent.java +++ b/src/org/mxchange/jcontacts/events/fax/unlinked/AdminUnlinkedFaxNumberEvent.java @@ -16,8 +16,8 @@ */ package org.mxchange.jcontacts.events.fax.unlinked; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; /** * An event when a fax number has been unlinked diff --git a/src/org/mxchange/jcontacts/events/fax/unlinked/ObservableAdminUnlinkedFaxNumberEvent.java b/src/org/mxchange/jcontacts/events/fax/unlinked/ObservableAdminUnlinkedFaxNumberEvent.java index d6c9b99..51082d1 100644 --- a/src/org/mxchange/jcontacts/events/fax/unlinked/ObservableAdminUnlinkedFaxNumberEvent.java +++ b/src/org/mxchange/jcontacts/events/fax/unlinked/ObservableAdminUnlinkedFaxNumberEvent.java @@ -17,8 +17,8 @@ package org.mxchange.jcontacts.events.fax.unlinked; import java.io.Serializable; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; /** * An interface for an event when a fax number has been unlinked diff --git a/src/org/mxchange/jcontacts/events/landline/linked/AdminLinkedLandLineNumberEvent.java b/src/org/mxchange/jcontacts/events/landline/linked/AdminLinkedLandLineNumberEvent.java index 89f39f5..01ef3e4 100644 --- a/src/org/mxchange/jcontacts/events/landline/linked/AdminLinkedLandLineNumberEvent.java +++ b/src/org/mxchange/jcontacts/events/landline/linked/AdminLinkedLandLineNumberEvent.java @@ -16,8 +16,8 @@ */ package org.mxchange.jcontacts.events.landline.linked; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; /** * An event when a land-line number has been linked with a contact diff --git a/src/org/mxchange/jcontacts/events/landline/linked/ObservableAdminLinkedLandLineNumberEvent.java b/src/org/mxchange/jcontacts/events/landline/linked/ObservableAdminLinkedLandLineNumberEvent.java index d02597f..c4e04f6 100644 --- a/src/org/mxchange/jcontacts/events/landline/linked/ObservableAdminLinkedLandLineNumberEvent.java +++ b/src/org/mxchange/jcontacts/events/landline/linked/ObservableAdminLinkedLandLineNumberEvent.java @@ -17,8 +17,8 @@ package org.mxchange.jcontacts.events.landline.linked; import java.io.Serializable; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; /** * An interface for an event when a land-line number has been linked with a diff --git a/src/org/mxchange/jcontacts/events/landline/unlinked/AdminUnlinkedLandLineNumberEvent.java b/src/org/mxchange/jcontacts/events/landline/unlinked/AdminUnlinkedLandLineNumberEvent.java index 93efedc..4a46001 100644 --- a/src/org/mxchange/jcontacts/events/landline/unlinked/AdminUnlinkedLandLineNumberEvent.java +++ b/src/org/mxchange/jcontacts/events/landline/unlinked/AdminUnlinkedLandLineNumberEvent.java @@ -16,8 +16,8 @@ */ package org.mxchange.jcontacts.events.landline.unlinked; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; /** * An event when a land-line number has been unlinked diff --git a/src/org/mxchange/jcontacts/events/landline/unlinked/ObservableAdminUnlinkedLandLineNumberEvent.java b/src/org/mxchange/jcontacts/events/landline/unlinked/ObservableAdminUnlinkedLandLineNumberEvent.java index 90f2051..bc6cbc7 100644 --- a/src/org/mxchange/jcontacts/events/landline/unlinked/ObservableAdminUnlinkedLandLineNumberEvent.java +++ b/src/org/mxchange/jcontacts/events/landline/unlinked/ObservableAdminUnlinkedLandLineNumberEvent.java @@ -17,8 +17,8 @@ package org.mxchange.jcontacts.events.landline.unlinked; import java.io.Serializable; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; /** * An interface for an event when a land-line number has been unlinked diff --git a/src/org/mxchange/jcontacts/events/mobile/linked/AdminLinkedMobileNumberEvent.java b/src/org/mxchange/jcontacts/events/mobile/linked/AdminLinkedMobileNumberEvent.java index bda30bf..f681f20 100644 --- a/src/org/mxchange/jcontacts/events/mobile/linked/AdminLinkedMobileNumberEvent.java +++ b/src/org/mxchange/jcontacts/events/mobile/linked/AdminLinkedMobileNumberEvent.java @@ -16,8 +16,8 @@ */ package org.mxchange.jcontacts.events.mobile.linked; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; /** * An event when a mobile number has been linked with a contact diff --git a/src/org/mxchange/jcontacts/events/mobile/linked/ObservableAdminLinkedMobileNumberEvent.java b/src/org/mxchange/jcontacts/events/mobile/linked/ObservableAdminLinkedMobileNumberEvent.java index 8ba8813..580b48a 100644 --- a/src/org/mxchange/jcontacts/events/mobile/linked/ObservableAdminLinkedMobileNumberEvent.java +++ b/src/org/mxchange/jcontacts/events/mobile/linked/ObservableAdminLinkedMobileNumberEvent.java @@ -17,8 +17,8 @@ package org.mxchange.jcontacts.events.mobile.linked; import java.io.Serializable; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; /** * An interface for an event when a mobile number has been linked with a contact diff --git a/src/org/mxchange/jcontacts/events/mobile/unlinked/AdminUnlinkedMobileNumberEvent.java b/src/org/mxchange/jcontacts/events/mobile/unlinked/AdminUnlinkedMobileNumberEvent.java index 03f09b3..b7a9589 100644 --- a/src/org/mxchange/jcontacts/events/mobile/unlinked/AdminUnlinkedMobileNumberEvent.java +++ b/src/org/mxchange/jcontacts/events/mobile/unlinked/AdminUnlinkedMobileNumberEvent.java @@ -16,8 +16,8 @@ */ package org.mxchange.jcontacts.events.mobile.unlinked; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; /** * An event when a mobile number has been unlinked diff --git a/src/org/mxchange/jcontacts/events/mobile/unlinked/ObservableAdminUnlinkedMobileNumberEvent.java b/src/org/mxchange/jcontacts/events/mobile/unlinked/ObservableAdminUnlinkedMobileNumberEvent.java index daa64e1..f85862c 100644 --- a/src/org/mxchange/jcontacts/events/mobile/unlinked/ObservableAdminUnlinkedMobileNumberEvent.java +++ b/src/org/mxchange/jcontacts/events/mobile/unlinked/ObservableAdminUnlinkedMobileNumberEvent.java @@ -17,8 +17,8 @@ package org.mxchange.jcontacts.events.mobile.unlinked; import java.io.Serializable; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; /** * An interface for an event when a mobile number has been unlinked diff --git a/src/org/mxchange/jcontacts/exceptions/ContactAlreadyAddedException.java b/src/org/mxchange/jcontacts/exceptions/ContactAlreadyAddedException.java index 4ccd3ce..062966a 100644 --- a/src/org/mxchange/jcontacts/exceptions/ContactAlreadyAddedException.java +++ b/src/org/mxchange/jcontacts/exceptions/ContactAlreadyAddedException.java @@ -17,7 +17,7 @@ package org.mxchange.jcontacts.exceptions; import java.text.MessageFormat; -import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.model.contact.Contact; /** * Thrown if the given Contact instance is already added diff --git a/src/org/mxchange/jcontacts/model/contact/Contact.java b/src/org/mxchange/jcontacts/model/contact/Contact.java new file mode 100644 index 0000000..4eb2f5a --- /dev/null +++ b/src/org/mxchange/jcontacts/model/contact/Contact.java @@ -0,0 +1,329 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontacts.model.contact; + +import java.io.Serializable; +import java.util.Calendar; +import java.util.Date; +import org.mxchange.jcontacts.model.contact.title.PersonalTitle; +import org.mxchange.jcountry.model.data.Country; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; + +/** + * A general contact POJI + *

+ * @author Roland Häder + */ +public interface Contact extends Serializable { + + /** + * Birth day + *

+ * @return the birthday + */ + Date getContactBirthday (); + + /** + * Birth day + *

+ * @param birthday the birthday to set + */ + void setContactBirthday (final Date birthday); + + /** + * Getter for mobile number + *

+ * @return Mobile number + */ + DialableMobileNumber getContactMobileNumber (); + + /** + * Setter for mobile number + *

+ * @param mobileNumber Mobile number + */ + void setContactMobileNumber (final DialableMobileNumber mobileNumber); + + /** + * City + *

+ * @return the city + */ + String getContactCity (); + + /** + * City + *

+ * @param city the city to set + */ + void setContactCity (final String city); + + /** + * Comments + *

+ * @return the comment + */ + String getContactComment (); + + /** + * Comments + *

+ * @param comment the comment to set + */ + void setContactComment (final String comment); + + /** + * Id number + *

+ * @return the contactId + */ + Long getContactId (); + + /** + * Id number + *

+ * @param id the contactId to set + */ + void setContactId (final Long id); + + /** + * Country code + *

+ * @return the countryCode + */ + Country getContactCountry (); + + /** + * Country code + *

+ * @param contactCountry the countryCode to set + */ + void setContactCountry (final Country contactCountry); + + /** + * Getter for "created" timestamp + *

+ * @return "created" timestamp + */ + Calendar getContactCreated (); + + /** + * Setter for "created" timestamp + *

+ * @param created "created" timestamp + */ + void setContactCreated (final Calendar created); + + /** + * Email address + *

+ * @return the emailAddress + */ + String getContactEmailAddress (); + + /** + * Email address + *

+ * @param emailAddress the emailAddress to set + */ + void setContactEmailAddress (final String emailAddress); + + /** + * Family name + *

+ * @return the familyName + */ + String getContactFamilyName (); + + /** + * Family name + *

+ * @param familyName the familyName to set + */ + void setContactFamilyName (final String familyName); + + /** + * Fax number + *

+ * @return the faxNumber + */ + DialableFaxNumber getContactFaxNumber (); + + /** + * Fax number + *

+ * @param faxNumber the faxNumber to set + */ + void setContactFaxNumber (final DialableFaxNumber faxNumber); + + /** + * First name + *

+ * @return the first name + */ + String getContactFirstName (); + + /** + * First name + *

+ * @param firstName the first name to set + */ + void setContactFirstName (final String firstName); + + /** + * Getter for personal title + *

+ * @return Personal title + */ + PersonalTitle getContactPersonalTitle (); + + /** + * Setter for personal title + *

+ * @param personalTitle Personal title + */ + void setContactPersonalTitle (final PersonalTitle personalTitle); + + /** + * House number + *

+ * @return the houseNumber + */ + Short getContactHouseNumber (); + + /** + * House number + *

+ * @param houseNumber the houseNumber to set + */ + void setContactHouseNumber (final Short houseNumber); + + /** + * Getter for house number extension, example: 123a 'a' is then the + * extension and 123 is the house number. + *

+ * @return House number extension + */ + String getContactHouseNumberExtension (); + + /** + * Setter for house number extension + *

+ * @param contactHouseNumberExtension House number extension + */ + void setContactHouseNumberExtension (final String contactHouseNumberExtension); + + /** + * Setter for own contact + *

+ * @param ownContact Own contact + */ + void setContactOwnContact (final Boolean ownContact); + + /** + * Getter for phone number + *

+ * @return Phone number + */ + DialableLandLineNumber getContactLandLineNumber (); + + /** + * Setter for phone number + *

+ * @param phoneNumber Phone number + */ + void setContactLandLineNumber (final DialableLandLineNumber phoneNumber); + + /** + * Street + *

+ * @return the street + */ + String getContactStreet (); + + /** + * Street + *

+ * @param street the street to set + */ + void setContactStreet (final String street); + + /** + * Getter for contact's title + *

+ * @return Contact's title + */ + String getContactTitle (); + + /** + * Setter for contact's title + *

+ * @param contactTitle Contact's title + */ + void setContactTitle (final String contactTitle); + + /** + * Getter for "updated" timestamp + *

+ * @return "updated" timestamp + */ + Calendar getContactUpdated (); + + /** + * Getter for "updated" timestamp + *

+ * @param updated "updated" timestamp + */ + void setContactUpdated (final Calendar updated); + + /** + * ZIP code + *

+ * @return the zipCode + */ + Integer getContactZipCode (); + + /** + * ZIP code + *

+ * @param zipCode the zipCode to set + */ + void setContactZipCode (final Integer zipCode); + + /** + * Checks whether the contact is user's own data + *

+ * @return Own data? + */ + Boolean isOwnContact (); + + /** + * Check if contacts are same or throw an exception + *

+ * @param object Other possible contact class + *

+ * @return Whether both contacts are same + */ + @Override + boolean equals (final Object object); + + @Override + int hashCode (); + +} diff --git a/src/org/mxchange/jcontacts/model/contact/ContactUtils.java b/src/org/mxchange/jcontacts/model/contact/ContactUtils.java new file mode 100644 index 0000000..8397012 --- /dev/null +++ b/src/org/mxchange/jcontacts/model/contact/ContactUtils.java @@ -0,0 +1,274 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontacts.model.contact; + +import java.io.Serializable; +import java.util.Objects; +import org.mxchange.jcountry.model.data.Country; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; +import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; + +/** + * Utilities for contacts + *

+ * @author Roland Häder + */ +public class ContactUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 26_785_734_719_670L; + + /** + * Copies all attributes from other contact object to this + *

+ * @param sourceContact Source instance + * @param targetContact Target instance + */ + public static void copyAll (final Contact sourceContact, final Contact targetContact) { + // Contact should be valid + if (null == sourceContact) { + // Throw NPE + throw new NullPointerException("sourceContact is null"); //NOI18N + } else if (null == targetContact) { + // Throw NPE + throw new NullPointerException("targetContact is null"); //NOI18N + } + + // Copy all: + // - base data + targetContact.setContactPersonalTitle(sourceContact.getContactPersonalTitle()); + targetContact.setContactTitle(sourceContact.getContactTitle()); + targetContact.setContactFirstName(sourceContact.getContactFirstName()); + targetContact.setContactFamilyName(sourceContact.getContactFamilyName()); + targetContact.setContactStreet(sourceContact.getContactStreet()); + targetContact.setContactHouseNumber(sourceContact.getContactHouseNumber()); + targetContact.setContactHouseNumberExtension(sourceContact.getContactHouseNumberExtension()); + targetContact.setContactZipCode(sourceContact.getContactZipCode()); + targetContact.setContactCity(sourceContact.getContactCity()); + targetContact.setContactCountry(sourceContact.getContactCountry()); + + // - phone, fax, email + targetContact.setContactLandLineNumber(sourceContact.getContactLandLineNumber()); + targetContact.setContactFaxNumber(sourceContact.getContactFaxNumber()); + targetContact.setContactMobileNumber(sourceContact.getContactMobileNumber()); + + // - other data + targetContact.setContactBirthday(sourceContact.getContactBirthday()); + targetContact.setContactComment(sourceContact.getContactComment()); + targetContact.setContactCreated(sourceContact.getContactCreated()); + targetContact.setContactUpdated(sourceContact.getContactUpdated()); + } + + /** + * Checks whether both contacts are same, but ignoring id number. If you + * want to include id number in comparison, better use Objects.equals() as + * the equal() method is implemented and checks all fields. + *

+ * @param contact Contact one + * @param other Contact two + *

+ * @return Whether both are the same + */ + public static boolean isSameContact (final Contact contact, final Contact other) { + // Both should not be null + if (null == contact) { + // First contact is null + throw new NullPointerException("contact is null"); //NOI18N + } else if (null == other) { + // Secondcontact is null + throw new NullPointerException("other is null"); //NOI18N + } + + // Check all data fields, except id number + return ((Objects.equals(contact.getContactBirthday(), other.getContactBirthday())) && + (Objects.equals(contact.getContactCity(), other.getContactCity())) && + (Objects.equals(contact.getContactCountry(), other.getContactCountry())) && + (Objects.equals(contact.getContactEmailAddress(), other.getContactEmailAddress())) && + (Objects.equals(contact.getContactFamilyName(), other.getContactFamilyName())) && + (Objects.equals(contact.getContactFirstName(), other.getContactFirstName())) && + (Objects.equals(contact.getContactPersonalTitle(), other.getContactPersonalTitle())) && + (Objects.equals(contact.getContactHouseNumber(), other.getContactHouseNumber())) && + (Objects.equals(contact.getContactStreet(), other.getContactStreet())) && + (Objects.equals(contact.getContactTitle(), other.getContactTitle())) && + (Objects.equals(contact.getContactZipCode(), other.getContactZipCode()))); + } + + /** + * Updates land-line data in contact instance. This method also removes the + * land-line instance if no country is selected. A bean (mostly EJB) should + * then make sure that the land-line entry is being unlinked from contact + * instance or being removed, if no longer used. + *

+ * @param contact Contact instance being updated + * @param faxCountry Updated fax number or null + * @param faxAreaCode Updated fax area code or null + * @param faxNumber Updated fax number + *

+ * @return Whether the fax number has been unlinked in contact object + */ + public static boolean updateFaxNumber (final Contact contact, final Country faxCountry, final Integer faxAreaCode, final Long faxNumber) { + // At least contact must be valid + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } + + // Default is not unlinked + boolean isUnlinked = false; + + // Is there a fax instance? + if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { + // Found existing fax number, remove it? + if ((null == faxCountry) || (null == faxAreaCode) || (null == faxNumber)) { + // Remove existing instance + contact.setContactFaxNumber(null); + + // Mark it as being removed + isUnlinked = true; + } else { + // Set all data + contact.getContactFaxNumber().setPhoneCountry(faxCountry); + contact.getContactFaxNumber().setPhoneAreaCode(faxAreaCode); + contact.getContactFaxNumber().setPhoneNumber(faxNumber); + } + } else if ((faxCountry instanceof Country) && (faxAreaCode > 0) && (faxNumber > 0)) { + // Set new land-line number + DialableFaxNumber fax = new FaxNumber(faxCountry, faxAreaCode, faxNumber); + + // Set it in contact + contact.setContactFaxNumber(fax); + } + + // Return status + return isUnlinked; + } + + /** + * Updates land-line data in contact instance. This method also removes the + * land-line instance if no country is selected. A bean (mostly EJB) should + * then make sure that the land-line entry is being unlinked from contact + * instance or being removed, if no longer used. + *

+ * @param contact Contact instance being updated + * @param phoneCountry New phone country or old or null + * @param phoneAreaCode New phone's area code (or old) + * @param phoneNumber New phone number (or old) + *

+ * @return Whether the land-line number has been unlinked in contact object + */ + public static boolean updateLandLineNumber (final Contact contact, final Country phoneCountry, final Integer phoneAreaCode, final Long phoneNumber) { + // At least contact must be valid + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } + + // Default is not unlinked + boolean isUnlinked = false; + + // Is there a land-line instance? + if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { + // Found existing land-line number, remove it? + if ((null == phoneCountry) || (null == phoneAreaCode) || (null == phoneNumber)) { + // Remove existing instance + contact.setContactLandLineNumber(null); + + // Mark it as being removed + isUnlinked = true; + } else { + // Set all data + contact.getContactLandLineNumber().setPhoneCountry(phoneCountry); + contact.getContactLandLineNumber().setPhoneAreaCode(phoneAreaCode); + contact.getContactLandLineNumber().setPhoneNumber(phoneNumber); + } + } else if ((phoneCountry instanceof Country) && (phoneAreaCode > 0) && (phoneNumber > 0)) { + // Set new land-line number + DialableLandLineNumber landLine = new LandLineNumber(phoneCountry, phoneAreaCode, phoneNumber); + + // Set it in contact + contact.setContactLandLineNumber(landLine); + } + + // Return status + return isUnlinked; + } + + /** + * Updates mobile data in contact instance. This method also removes the + * mobile instance if no provider is selected. A bean (mostly EJB) should + * then make sure that the mobile entry is being unlinked from contact + * instance or being removed, if no longer used. + *

+ * @param contact Contact instance to update + * @param mobileProvider New mobile provider (or old) + * @param mobileNumber New mobile number (or old) + *

+ * @return Whether the mobile has been unlinked in contact object + */ + public static boolean updateMobileNumber (final Contact contact, final MobileProvider mobileProvider, final Long mobileNumber) { + // At least contact must be valid + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if ((mobileProvider instanceof MobileProvider) && (null == mobileNumber)) { + // Mobile provider given, but no number + throw new NullPointerException("mobileNumber is null"); //NOI18N + } + + // Default is not unlinked + boolean isUnlinked = false; + + // Is there a mobile number? + if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { + // Is provider null? + if ((null == mobileProvider) || (null == mobileNumber) || (mobileNumber == 0)) { + // Remove instance + contact.setContactMobileNumber(null); + + // Mark as unlinked + isUnlinked = true; + } else { + // Yes, then update as well + contact.getContactMobileNumber().setMobileProvider(mobileProvider); + contact.getContactMobileNumber().setPhoneNumber(mobileNumber); + } + } else if ((mobileProvider instanceof MobileProvider) && (mobileNumber > 0)) { + // Create new instance + DialableMobileNumber mobile = new MobileNumber(mobileProvider, mobileNumber); + + // Set it in contact + contact.setContactMobileNumber(mobile); + } + + // Return status + return isUnlinked; + } + + /** + * Private constructor for utilities + */ + private ContactUtils () { + } + +} diff --git a/src/org/mxchange/jcontacts/model/contact/UserContact.java b/src/org/mxchange/jcontacts/model/contact/UserContact.java new file mode 100644 index 0000000..7554f46 --- /dev/null +++ b/src/org/mxchange/jcontacts/model/contact/UserContact.java @@ -0,0 +1,518 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontacts.model.contact; + +import java.util.Calendar; +import java.util.Date; +import java.util.Objects; +import javax.persistence.Basic; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; +import org.mxchange.jcontacts.model.contact.title.PersonalTitle; +import org.mxchange.jcountry.model.data.Country; +import org.mxchange.jcountry.model.data.CountryData; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; + +/** + * A general contact class which serves as an entity. + *

+ * @author Roland Häder + * @version 0.0 + */ +@Entity (name = "contacts") +@Table ( + name = "contacts", + indexes = { + @Index ( + name = "contact_personal_title", + columnList = "contact_personal_title" + ) + } +) +@NamedQueries ( + { + @NamedQuery (name = "AllContacts", query = "SELECT c FROM contacts AS c ORDER BY c.contactId ASC"), + @NamedQuery (name = "AllContactEmailAddresses", query = "SELECT c.contactEmailAddress FROM contacts AS c ORDER BY c.contactId ASC"), + @NamedQuery (name = "AllContactsByCellphone", query = "SELECT c FROM contacts AS c WHERE c.contactMobileNumber = :mobileNumber ORDER BY c.contactId ASC"), + @NamedQuery (name = "SearchContact", query = "SELECT c FROM contacts AS c WHERE c = :contact"), + @NamedQuery (name = "SearchContactById", query = "SELECT c FROM contacts AS c WHERE c.contactId = :contactId"), + @NamedQuery (name = "SearchContactByEmailAddress", query = "SELECT c FROM contacts AS c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:emailAddress)") + } +) +@SuppressWarnings ("PersistenceUnitPresent") +public class UserContact implements Contact { + + /** + * Serial number + */ + @Transient + private static final long serialVersionUID = 58_744_284_981_863L; + + /** + * Birth day + */ + @Column (name = "contact_birthday") + @Temporal (TemporalType.DATE) + private Date contactBirthday; + + /** + * City + */ + @Column (name = "contact_city", length = 100) + private String contactCity; + + /** + * Optional comments + */ + @Lob + @Column (name = "contact_comment") + private String contactComment; + + /** + * Country code + */ + @JoinColumn (name = "contact_country_id", nullable = false, referencedColumnName = "country_id") + @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false) + private Country contactCountry; + + /** + * When the contact has been created + */ + @Basic (optional = false) + @Temporal (TemporalType.TIMESTAMP) + @Column (name = "contact_created", nullable = false) + private Calendar contactCreated; + + /** + * Email address + */ + @Column (name = "contact_email_address", length = 100, unique = true) + private String contactEmailAddress; + + /** + * Family name + */ + @Basic (optional = false) + @Column (name = "contact_family_name", length = 100, nullable = false) + private String contactFamilyName; + + /** + * Fax number + */ + @JoinColumn (name = "contact_fax_number_id", referencedColumnName = "fax_id", unique = true) + @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL) + private DialableFaxNumber contactFaxNumber; + + /** + * First name + */ + @Basic (optional = false) + @Column (name = "contact_first_name", length = 100, nullable = false) + private String contactFirstName; + + /** + * House number + */ + @Column (name = "contact_house_number") + private Short contactHouseNumber; + + /** + * House number extension + */ + @Column (name = "contact_house_number_extension", length = 5) + private String contactHouseNumberExtension; + + /** + * Id number + */ + @Id + @GeneratedValue (strategy = GenerationType.IDENTITY) + @Column (name = "contact_id", nullable = false, updatable = false) + private Long contactId; + + /** + * Cellphone number + */ + @JoinColumn (name = "contact_mobile_number_id", referencedColumnName = "mobile_id", unique = true) + @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.ALL) + private DialableMobileNumber contactMobileNumber; + + /** + * Flag whether this contact is user's own data + */ + @Basic (optional = false) + @Column (name = "contact_own_contact", nullable = false) + private Boolean contactOwnContact; + + /** + * Contact's personal title (Mr./Mrs.) + */ + @Basic (optional = false) + @Column (name = "contact_personal_title", nullable = false) + @Enumerated (EnumType.STRING) + private PersonalTitle contactPersonalTitle; + + /** + * Phone number + */ + @JoinColumn (name = "contact_landline_number_id", referencedColumnName = "landline_id", unique = true) + @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL) + private DialableLandLineNumber contactPhoneNumber; + + /** + * Street + */ + @Column (name = "contact_street") + private String contactStreet; + + /** + * Title (Doctor, etc) + */ + @Column (name = "contact_title") + private String contactTitle; + + /** + * When the contact has been updated + */ + @Temporal (TemporalType.TIMESTAMP) + @Column (name = "contact_updated") + private Calendar contactUpdated; + + /** + * ZIP code + */ + @Column (name = "contact_zip_code") + private Integer contactZipCode; + + /** + * Default constructor + */ + public UserContact () { + // Default is not user's own contact + this.contactOwnContact = Boolean.FALSE; + } + + /** + * Constructor for title and names + *

+ * @param contactTitle Personal title + * @param contactFirstName First name + * @param contactFamilyName Family name + */ + public UserContact (final PersonalTitle contactTitle, final String contactFirstName, final String contactFamilyName) { + // Call default constructor + this(); + + // Set all + this.contactPersonalTitle = contactTitle; + this.contactFirstName = contactFirstName; + this.contactFamilyName = contactFamilyName; + } + + @Override + public boolean equals (final Object object) { + if (this == object) { + return true; + } else if (null == object) { + return false; + } else if (this.getClass() != object.getClass()) { + return false; + } else if (!(object instanceof Contact)) { + // Not correct interface + return false; + } + + final Contact other = (Contact) object; + + if (!Objects.equals(this.getContactId(), other.getContactId())) { + return false; + } else if (!Objects.equals(this.getContactCity(), other.getContactCity())) { + return false; + } else if (!Objects.equals(this.getContactEmailAddress(), other.getContactEmailAddress())) { + return false; + } else if (!Objects.equals(this.getContactFamilyName(), other.getContactFamilyName())) { + return false; + } else if (!Objects.equals(this.getContactFirstName(), other.getContactFirstName())) { + return false; + } else if (!Objects.equals(this.getContactStreet(), other.getContactStreet())) { + return false; + } else if (!Objects.equals(this.getContactTitle(), other.getContactTitle())) { + return false; + } else if (!Objects.equals(this.getContactBirthday(), other.getContactBirthday())) { + return false; + } else if (!Objects.equals(this.getContactCountry(), other.getContactCountry())) { + return false; + } else if (this.getContactPersonalTitle() != other.getContactPersonalTitle()) { + return false; + } else if (!Objects.equals(this.getContactHouseNumber(), other.getContactHouseNumber())) { + return false; + } else if (!Objects.equals(this.getContactHouseNumberExtension(), other.getContactHouseNumberExtension())) { + return false; + } + + return true; + } + + @Override + @SuppressWarnings ("ReturnOfDateField") + public Date getContactBirthday () { + return this.contactBirthday; + } + + @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setContactBirthday (final Date contactBirthday) { + this.contactBirthday = contactBirthday; + } + + @Override + public String getContactCity () { + return this.contactCity; + } + + @Override + public void setContactCity (final String contactCity) { + this.contactCity = contactCity; + } + + @Override + public String getContactComment () { + return this.contactComment; + } + + @Override + public void setContactComment (final String contactComment) { + this.contactComment = contactComment; + } + + @Override + public Country getContactCountry () { + return this.contactCountry; + } + + @Override + public void setContactCountry (final Country contactCountry) { + this.contactCountry = contactCountry; + } + + @Override + @SuppressWarnings ("ReturnOfDateField") + public Calendar getContactCreated () { + return this.contactCreated; + } + + @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setContactCreated (final Calendar contactCreated) { + this.contactCreated = contactCreated; + } + + @Override + public String getContactEmailAddress () { + return this.contactEmailAddress; + } + + @Override + public void setContactEmailAddress (final String contactEmailAddress) { + this.contactEmailAddress = contactEmailAddress; + } + + @Override + public String getContactFamilyName () { + //* NOISY-DEBUG: */ this.getLogger().logTrace("CALLED!"); + return this.contactFamilyName; + } + + @Override + public void setContactFamilyName (final String contactFamilyName) { + this.contactFamilyName = contactFamilyName; + } + + @Override + public DialableFaxNumber getContactFaxNumber () { + return this.contactFaxNumber; + } + + @Override + public void setContactFaxNumber (final DialableFaxNumber contactFaxNumber) { + this.contactFaxNumber = contactFaxNumber; + } + + @Override + public String getContactFirstName () { + return this.contactFirstName; + } + + @Override + public void setContactFirstName (final String contactFirstName) { + this.contactFirstName = contactFirstName; + } + + @Override + public Short getContactHouseNumber () { + return this.contactHouseNumber; + } + + @Override + public void setContactHouseNumber (final Short contactHouseNumber) { + this.contactHouseNumber = contactHouseNumber; + } + + @Override + public String getContactHouseNumberExtension () { + return this.contactHouseNumberExtension; + } + + @Override + public void setContactHouseNumberExtension (final String contactHouseNumberExtension) { + this.contactHouseNumberExtension = contactHouseNumberExtension; + } + + @Override + public Long getContactId () { + return this.contactId; + } + + @Override + public void setContactId (final Long contactId) { + this.contactId = contactId; + } + + @Override + public DialableLandLineNumber getContactLandLineNumber () { + return this.contactPhoneNumber; + } + + @Override + public void setContactLandLineNumber (final DialableLandLineNumber contactPhoneNumber) { + this.contactPhoneNumber = contactPhoneNumber; + } + + @Override + public DialableMobileNumber getContactMobileNumber () { + return this.contactMobileNumber; + } + + @Override + public void setContactMobileNumber (final DialableMobileNumber contactMobileNumber) { + this.contactMobileNumber = contactMobileNumber; + } + + @Override + public void setContactOwnContact (final Boolean contactOwnContact) { + this.contactOwnContact = contactOwnContact; + } + + @Override + public PersonalTitle getContactPersonalTitle () { + return this.contactPersonalTitle; + } + + @Override + public void setContactPersonalTitle (final PersonalTitle contactPersonalTitle) { + this.contactPersonalTitle = contactPersonalTitle; + } + + @Override + public String getContactStreet () { + return this.contactStreet; + } + + @Override + public void setContactStreet (final String contactStreet) { + this.contactStreet = contactStreet; + } + + @Override + public String getContactTitle () { + return this.contactTitle; + } + + @Override + public void setContactTitle (final String contactTitle) { + this.contactTitle = contactTitle; + } + + @Override + @SuppressWarnings ("ReturnOfDateField") + public Calendar getContactUpdated () { + return this.contactUpdated; + } + + @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setContactUpdated (final Calendar contactUpdated) { + this.contactUpdated = contactUpdated; + } + + @Override + public Integer getContactZipCode () { + return this.contactZipCode; + } + + @Override + public void setContactZipCode (final Integer contactZipCode) { + this.contactZipCode = contactZipCode; + } + + @Override + public int hashCode () { + int hash = 5; + + hash = 29 * hash + Objects.hashCode(this.getContactBirthday()); + hash = 29 * hash + Objects.hashCode(this.getContactCity()); + hash = 29 * hash + Objects.hashCode(this.getContactCountry()); + hash = 29 * hash + Objects.hashCode(this.getContactEmailAddress()); + hash = 29 * hash + Objects.hashCode(this.getContactFamilyName()); + hash = 29 * hash + Objects.hashCode(this.getContactFirstName()); + hash = 29 * hash + Objects.hashCode(this.getContactPersonalTitle()); + hash = 29 * hash + Objects.hashCode(this.getContactHouseNumber()); + hash = 29 * hash + Objects.hashCode(this.getContactHouseNumberExtension()); + hash = 29 * hash + Objects.hashCode(this.getContactId()); + hash = 29 * hash + Objects.hashCode(this.getContactStreet()); + hash = 29 * hash + Objects.hashCode(this.getContactTitle()); + + return hash; + } + + @Override + public Boolean isOwnContact () { + return this.contactOwnContact; + } + +} diff --git a/src/org/mxchange/jcontacts/model/contact/gender/Gender.java b/src/org/mxchange/jcontacts/model/contact/gender/Gender.java new file mode 100644 index 0000000..3af0329 --- /dev/null +++ b/src/org/mxchange/jcontacts/model/contact/gender/Gender.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontacts.model.contact.gender; + +import java.io.Serializable; + +/** + * An enumeration for genders, sure more need to be added here. If you need + * titles instead, please use the proper enumeration then. + *

+ * @author Roland Häder + */ +public enum Gender implements Serializable { + + /** + * Male gender + */ + MALE('M', "GENDER_MALE"), //NOI18N + + /** + * Female gender + */ + FEMALE('F', "GENDER_FEMALE"); //NOI18N + + /** + * Access key being entered by ConsoleClient + */ + private final char accessChar; + + /** + * Output value (for messages) + */ + private final String messageKey; + + /** + * Constructor + *

+ * @param accessChar Value being entered by ConsoleClient + * @param messageKey Message key for resource file + */ + private Gender (final char accessChar, final String messageKey) { + // Set both + this.accessChar = accessChar; + this.messageKey = messageKey; + } + + /** + * Access key (console client mostly) + *

+ * @return the accessChar + */ + public char getAccessChar () { + return this.accessChar; + } + + /** + * Output value (for messages) + *

+ * @return the messageKey + */ + public String getMessageKey () { + return this.messageKey; + } + +} diff --git a/src/org/mxchange/jcontacts/model/contact/gender/GenderUtils.java b/src/org/mxchange/jcontacts/model/contact/gender/GenderUtils.java new file mode 100644 index 0000000..5156db7 --- /dev/null +++ b/src/org/mxchange/jcontacts/model/contact/gender/GenderUtils.java @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontacts.model.contact.gender; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.LinkedList; +import java.util.List; + +/** + * Gender utils class + *

+ * @author Roland Häder + */ +public class GenderUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 185_683_479_107L; + + /** + * Cache for valid chars + */ + private static char[] validChars; + + /** + * All available genders as a list + *

+ * @return Selectable genders (not UNKNOWN) + */ + public static List allGendersAsList () { + // Init list + List list = new LinkedList<>(); + + // Walk through all genders + for (final Gender gender : Gender.values()) { + // Add it and check if it has been added + list.add(gender); + } + + // Return it + return list; + } + + /** + * Getter for Gender enumeration from given character + *

+ * @param c Gender character +

+ * @return Gender enumeration + */ + public static Gender fromChar (final char c) { + // Init variable + Gender found = null; + + // Loop through all + for (final Gender gender : Gender.values()) { + // Does the char match? + if (c == gender.getAccessChar()) { + // Found it + found = gender; + break; + } + } + + // Still null? + if (null == found) { + // Didn't found a valid one + throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N + } + + // Return it + return found; + } + + /** + * Valid chars (mostly for console client) + *

+ * @return Valid chars + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public static char[] validChars () { + // Is cache set? + if (validChars != null) { + // Return it + return validChars; + } + + // Init array, only 2 are valid. + char[] valid = new char[2]; + + // Get values + int i = 0; + for (final Gender gender : Gender.values()) { + // Get access key as this is also the access + valid[i] = gender.getAccessChar(); + + // Increment index + i++; + } + + // Set it here + validChars = valid; + + // Return finialized array + return valid; + } + + /** + * Private constructor as this is an utility class + */ + private GenderUtils () { + } + +} diff --git a/src/org/mxchange/jcontacts/model/contact/title/PersonalTitle.java b/src/org/mxchange/jcontacts/model/contact/title/PersonalTitle.java new file mode 100644 index 0000000..ee8c343 --- /dev/null +++ b/src/org/mxchange/jcontacts/model/contact/title/PersonalTitle.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontacts.model.contact.title; + +import java.io.Serializable; + +/** + * An enumeration for personal titles. If you need the gender instead, please + * use the other enumeration instead. + *

+ * @author Roland Häder + */ +public enum PersonalTitle implements Serializable { + + /** + * Title "Mr." + */ + MR('M', "PERSONAL_TITLE_MR"), //NOI18N + + /** + * Title "Mrs." + */ + MRS('F', "PERSONAL_TITLE_MRS"); //NOI18N + + /** + * Access key being entered by ConsoleClient + */ + private final char accessChar; + + /** + * Output value (for messages) + */ + private final String messageKey; + + /** + * Constructor + *

+ * @param accessChar Value being entered by ConsoleClient + * @param messageKey Message key for resource file + */ + private PersonalTitle (final char accessChar, final String messageKey) { + // Set both + this.accessChar = accessChar; + this.messageKey = messageKey; + } + + /** + * Access key (console client mostly) + *

+ * @return the accessChar + */ + public char getAccessChar () { + return this.accessChar; + } + + /** + * Output value (for messages) + *

+ * @return the messageKey + */ + public String getMessageKey () { + return this.messageKey; + } + +} diff --git a/src/org/mxchange/jcontacts/model/contact/title/TitleUtils.java b/src/org/mxchange/jcontacts/model/contact/title/TitleUtils.java new file mode 100644 index 0000000..60b1f56 --- /dev/null +++ b/src/org/mxchange/jcontacts/model/contact/title/TitleUtils.java @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontacts.model.contact.title; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.LinkedList; +import java.util.List; + +/** + * Title utilities class + *

+ * @author Roland Häder + */ +public class TitleUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 185_683_479_107L; + + /** + * Cache for valid chars + */ + private static char[] validChars; + + /** + * All available personal titles as a list + *

+ * @return Selectable personal titles + * @deprecated Arrays.asList() is there + */ + @Deprecated + public static List allPersonalTitlesAsList () { + // Init list + List list = new LinkedList<>(); + + // Walk through all genders + for (final PersonalTitle title : PersonalTitle.values()) { + // Add it and check if it has been added + list.add(title); + } + + // Return it + return list; + } + + /** + * Getter for personal title enumeration from given character + *

+ * @param c PersonalTitle character + *

+ * @return PersonalTitle enumeration + */ + public static PersonalTitle getPersonalTitleFromChar (final char c) { + // Init variable + PersonalTitle found = null; + + // Loop through all + for (final PersonalTitle title : PersonalTitle.values()) { + // Does the char match? + if (c == title.getAccessChar()) { + // Found it + found = title; + break; + } + } + + // Still null? + if (null == found) { + // Didn't found a valid one + throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N + } + + // Return it + return found; + } + + /** + * Valid chars (mostly for console client) + *

+ * @return Valid chars + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public static char[] validChars () { + // Is cache set? + if (validChars != null) { + // Return it + return validChars; + } + + // Init array, only 2 are valid. + char[] valid = new char[2]; + + // Get values + int i = 0; + for (final PersonalTitle title : PersonalTitle.values()) { + // Get access key as this is also the access + valid[i] = title.getAccessChar(); + + // Increment index + i++; + } + + // Set it here + validChars = valid; + + // Return finialized array + return valid; + } + + /** + * Private constructor as this is an utility class + */ + private TitleUtils () { + } + +}