+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-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
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface Contact extends Serializable {
-
- /**
- * Birth day
- * <p>
- * @return the birthday
- */
- Date getContactBirthday ();
-
- /**
- * Birth day
- * <p>
- * @param birthday the birthday to set
- */
- void setContactBirthday (final Date birthday);
-
- /**
- * Getter for mobile number
- * <p>
- * @return Mobile number
- */
- DialableMobileNumber getContactMobileNumber ();
-
- /**
- * Setter for mobile number
- * <p>
- * @param mobileNumber Mobile number
- */
- void setContactMobileNumber (final DialableMobileNumber mobileNumber);
-
- /**
- * City
- * <p>
- * @return the city
- */
- String getContactCity ();
-
- /**
- * City
- * <p>
- * @param city the city to set
- */
- void setContactCity (final String city);
-
- /**
- * Comments
- * <p>
- * @return the comment
- */
- String getContactComment ();
-
- /**
- * Comments
- * <p>
- * @param comment the comment to set
- */
- void setContactComment (final String comment);
-
- /**
- * Id number
- * <p>
- * @return the contactId
- */
- Long getContactId ();
-
- /**
- * Id number
- * <p>
- * @param id the contactId to set
- */
- void setContactId (final Long id);
-
- /**
- * Country code
- * <p>
- * @return the countryCode
- */
- Country getContactCountry ();
-
- /**
- * Country code
- * <p>
- * @param contactCountry the countryCode to set
- */
- void setContactCountry (final Country contactCountry);
-
- /**
- * Getter for "created" timestamp
- * <p>
- * @return "created" timestamp
- */
- Calendar getContactCreated ();
-
- /**
- * Setter for "created" timestamp
- * <p>
- * @param created "created" timestamp
- */
- void setContactCreated (final Calendar created);
-
- /**
- * Email address
- * <p>
- * @return the emailAddress
- */
- String getContactEmailAddress ();
-
- /**
- * Email address
- * <p>
- * @param emailAddress the emailAddress to set
- */
- void setContactEmailAddress (final String emailAddress);
-
- /**
- * Family name
- * <p>
- * @return the familyName
- */
- String getContactFamilyName ();
-
- /**
- * Family name
- * <p>
- * @param familyName the familyName to set
- */
- void setContactFamilyName (final String familyName);
-
- /**
- * Fax number
- * <p>
- * @return the faxNumber
- */
- DialableFaxNumber getContactFaxNumber ();
-
- /**
- * Fax number
- * <p>
- * @param faxNumber the faxNumber to set
- */
- void setContactFaxNumber (final DialableFaxNumber faxNumber);
-
- /**
- * First name
- * <p>
- * @return the first name
- */
- String getContactFirstName ();
-
- /**
- * First name
- * <p>
- * @param firstName the first name to set
- */
- void setContactFirstName (final String firstName);
-
- /**
- * Getter for personal title
- * <p>
- * @return Personal title
- */
- PersonalTitle getContactPersonalTitle ();
-
- /**
- * Setter for personal title
- * <p>
- * @param personalTitle Personal title
- */
- void setContactPersonalTitle (final PersonalTitle personalTitle);
-
- /**
- * House number
- * <p>
- * @return the houseNumber
- */
- Short getContactHouseNumber ();
-
- /**
- * House number
- * <p>
- * @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.
- * <p>
- * @return House number extension
- */
- String getContactHouseNumberExtension ();
-
- /**
- * Setter for house number extension
- * <p>
- * @param contactHouseNumberExtension House number extension
- */
- void setContactHouseNumberExtension (final String contactHouseNumberExtension);
-
- /**
- * Setter for own contact
- * <p>
- * @param ownContact Own contact
- */
- void setContactOwnContact (final Boolean ownContact);
-
- /**
- * Getter for phone number
- * <p>
- * @return Phone number
- */
- DialableLandLineNumber getContactLandLineNumber ();
-
- /**
- * Setter for phone number
- * <p>
- * @param phoneNumber Phone number
- */
- void setContactLandLineNumber (final DialableLandLineNumber phoneNumber);
-
- /**
- * Street
- * <p>
- * @return the street
- */
- String getContactStreet ();
-
- /**
- * Street
- * <p>
- * @param street the street to set
- */
- void setContactStreet (final String street);
-
- /**
- * Getter for contact's title
- * <p>
- * @return Contact's title
- */
- String getContactTitle ();
-
- /**
- * Setter for contact's title
- * <p>
- * @param contactTitle Contact's title
- */
- void setContactTitle (final String contactTitle);
-
- /**
- * Getter for "updated" timestamp
- * <p>
- * @return "updated" timestamp
- */
- Calendar getContactUpdated ();
-
- /**
- * Getter for "updated" timestamp
- * <p>
- * @param updated "updated" timestamp
- */
- void setContactUpdated (final Calendar updated);
-
- /**
- * ZIP code
- * <p>
- * @return the zipCode
- */
- Integer getContactZipCode ();
-
- /**
- * ZIP code
- * <p>
- * @param zipCode the zipCode to set
- */
- void setContactZipCode (final Integer zipCode);
-
- /**
- * Checks whether the contact is user's own data
- * <p>
- * @return Own data?
- */
- Boolean isOwnContact ();
-
- /**
- * Check if contacts are same or throw an exception
- * <p>
- * @param object Other possible contact class
- * <p>
- * @return Whether both contacts are same
- */
- @Override
- boolean equals (final Object object);
-
- @Override
- int hashCode ();
-
-}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-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
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-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
- * <p>
- * @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.
- * <p>
- * @param contact Contact one
- * @param other Contact two
- * <p>
- * @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.
- * <p>
- * @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
- * <p>
- * @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.
- * <p>
- * @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)
- * <p>
- * @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.
- * <p>
- * @param contact Contact instance to update
- * @param mobileProvider New mobile provider (or old)
- * @param mobileNumber New mobile number (or old)
- * <p>
- * @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 () {
- }
-
-}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-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.
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- * @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
- * <p>
- * @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;
- }
-
-}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-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.
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-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
- * <p>
- * @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)
- * <p>
- * @return the accessChar
- */
- public char getAccessChar () {
- return this.accessChar;
- }
-
- /**
- * Output value (for messages)
- * <p>
- * @return the messageKey
- */
- public String getMessageKey () {
- return this.messageKey;
- }
-
-}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-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
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-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
- * <p>
- * @return Selectable genders (not UNKNOWN)
- */
- public static List<Gender> allGendersAsList () {
- // Init list
- List<Gender> 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
- * <p>
- * @param c Gender character
- <p>
- * @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)
- * <p>
- * @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 () {
- }
-
-}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-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.
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-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
- * <p>
- * @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)
- * <p>
- * @return the accessChar
- */
- public char getAccessChar () {
- return this.accessChar;
- }
-
- /**
- * Output value (for messages)
- * <p>
- * @return the messageKey
- */
- public String getMessageKey () {
- return this.messageKey;
- }
-
-}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-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
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-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
- * <p>
- * @return Selectable personal titles
- */
- public static List<PersonalTitle> allPersonalTitlesAsList () {
- // Init list
- List<PersonalTitle> 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
- * <p>
- * @param c PersonalTitle character
- * <p>
- * @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)
- * <p>
- * @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 () {
- }
-
-}
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
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
*/
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
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
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
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.
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
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
*/
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
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
*/
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
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
*/
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
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
*/
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
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
*/
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
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
*/
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
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
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
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface Contact extends Serializable {
+
+ /**
+ * Birth day
+ * <p>
+ * @return the birthday
+ */
+ Date getContactBirthday ();
+
+ /**
+ * Birth day
+ * <p>
+ * @param birthday the birthday to set
+ */
+ void setContactBirthday (final Date birthday);
+
+ /**
+ * Getter for mobile number
+ * <p>
+ * @return Mobile number
+ */
+ DialableMobileNumber getContactMobileNumber ();
+
+ /**
+ * Setter for mobile number
+ * <p>
+ * @param mobileNumber Mobile number
+ */
+ void setContactMobileNumber (final DialableMobileNumber mobileNumber);
+
+ /**
+ * City
+ * <p>
+ * @return the city
+ */
+ String getContactCity ();
+
+ /**
+ * City
+ * <p>
+ * @param city the city to set
+ */
+ void setContactCity (final String city);
+
+ /**
+ * Comments
+ * <p>
+ * @return the comment
+ */
+ String getContactComment ();
+
+ /**
+ * Comments
+ * <p>
+ * @param comment the comment to set
+ */
+ void setContactComment (final String comment);
+
+ /**
+ * Id number
+ * <p>
+ * @return the contactId
+ */
+ Long getContactId ();
+
+ /**
+ * Id number
+ * <p>
+ * @param id the contactId to set
+ */
+ void setContactId (final Long id);
+
+ /**
+ * Country code
+ * <p>
+ * @return the countryCode
+ */
+ Country getContactCountry ();
+
+ /**
+ * Country code
+ * <p>
+ * @param contactCountry the countryCode to set
+ */
+ void setContactCountry (final Country contactCountry);
+
+ /**
+ * Getter for "created" timestamp
+ * <p>
+ * @return "created" timestamp
+ */
+ Calendar getContactCreated ();
+
+ /**
+ * Setter for "created" timestamp
+ * <p>
+ * @param created "created" timestamp
+ */
+ void setContactCreated (final Calendar created);
+
+ /**
+ * Email address
+ * <p>
+ * @return the emailAddress
+ */
+ String getContactEmailAddress ();
+
+ /**
+ * Email address
+ * <p>
+ * @param emailAddress the emailAddress to set
+ */
+ void setContactEmailAddress (final String emailAddress);
+
+ /**
+ * Family name
+ * <p>
+ * @return the familyName
+ */
+ String getContactFamilyName ();
+
+ /**
+ * Family name
+ * <p>
+ * @param familyName the familyName to set
+ */
+ void setContactFamilyName (final String familyName);
+
+ /**
+ * Fax number
+ * <p>
+ * @return the faxNumber
+ */
+ DialableFaxNumber getContactFaxNumber ();
+
+ /**
+ * Fax number
+ * <p>
+ * @param faxNumber the faxNumber to set
+ */
+ void setContactFaxNumber (final DialableFaxNumber faxNumber);
+
+ /**
+ * First name
+ * <p>
+ * @return the first name
+ */
+ String getContactFirstName ();
+
+ /**
+ * First name
+ * <p>
+ * @param firstName the first name to set
+ */
+ void setContactFirstName (final String firstName);
+
+ /**
+ * Getter for personal title
+ * <p>
+ * @return Personal title
+ */
+ PersonalTitle getContactPersonalTitle ();
+
+ /**
+ * Setter for personal title
+ * <p>
+ * @param personalTitle Personal title
+ */
+ void setContactPersonalTitle (final PersonalTitle personalTitle);
+
+ /**
+ * House number
+ * <p>
+ * @return the houseNumber
+ */
+ Short getContactHouseNumber ();
+
+ /**
+ * House number
+ * <p>
+ * @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.
+ * <p>
+ * @return House number extension
+ */
+ String getContactHouseNumberExtension ();
+
+ /**
+ * Setter for house number extension
+ * <p>
+ * @param contactHouseNumberExtension House number extension
+ */
+ void setContactHouseNumberExtension (final String contactHouseNumberExtension);
+
+ /**
+ * Setter for own contact
+ * <p>
+ * @param ownContact Own contact
+ */
+ void setContactOwnContact (final Boolean ownContact);
+
+ /**
+ * Getter for phone number
+ * <p>
+ * @return Phone number
+ */
+ DialableLandLineNumber getContactLandLineNumber ();
+
+ /**
+ * Setter for phone number
+ * <p>
+ * @param phoneNumber Phone number
+ */
+ void setContactLandLineNumber (final DialableLandLineNumber phoneNumber);
+
+ /**
+ * Street
+ * <p>
+ * @return the street
+ */
+ String getContactStreet ();
+
+ /**
+ * Street
+ * <p>
+ * @param street the street to set
+ */
+ void setContactStreet (final String street);
+
+ /**
+ * Getter for contact's title
+ * <p>
+ * @return Contact's title
+ */
+ String getContactTitle ();
+
+ /**
+ * Setter for contact's title
+ * <p>
+ * @param contactTitle Contact's title
+ */
+ void setContactTitle (final String contactTitle);
+
+ /**
+ * Getter for "updated" timestamp
+ * <p>
+ * @return "updated" timestamp
+ */
+ Calendar getContactUpdated ();
+
+ /**
+ * Getter for "updated" timestamp
+ * <p>
+ * @param updated "updated" timestamp
+ */
+ void setContactUpdated (final Calendar updated);
+
+ /**
+ * ZIP code
+ * <p>
+ * @return the zipCode
+ */
+ Integer getContactZipCode ();
+
+ /**
+ * ZIP code
+ * <p>
+ * @param zipCode the zipCode to set
+ */
+ void setContactZipCode (final Integer zipCode);
+
+ /**
+ * Checks whether the contact is user's own data
+ * <p>
+ * @return Own data?
+ */
+ Boolean isOwnContact ();
+
+ /**
+ * Check if contacts are same or throw an exception
+ * <p>
+ * @param object Other possible contact class
+ * <p>
+ * @return Whether both contacts are same
+ */
+ @Override
+ boolean equals (final Object object);
+
+ @Override
+ int hashCode ();
+
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+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
+ * <p>
+ * @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.
+ * <p>
+ * @param contact Contact one
+ * @param other Contact two
+ * <p>
+ * @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.
+ * <p>
+ * @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
+ * <p>
+ * @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.
+ * <p>
+ * @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)
+ * <p>
+ * @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.
+ * <p>
+ * @param contact Contact instance to update
+ * @param mobileProvider New mobile provider (or old)
+ * @param mobileNumber New mobile number (or old)
+ * <p>
+ * @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 () {
+ }
+
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ * @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
+ * <p>
+ * @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;
+ }
+
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+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
+ * <p>
+ * @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)
+ * <p>
+ * @return the accessChar
+ */
+ public char getAccessChar () {
+ return this.accessChar;
+ }
+
+ /**
+ * Output value (for messages)
+ * <p>
+ * @return the messageKey
+ */
+ public String getMessageKey () {
+ return this.messageKey;
+ }
+
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+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
+ * <p>
+ * @return Selectable genders (not UNKNOWN)
+ */
+ public static List<Gender> allGendersAsList () {
+ // Init list
+ List<Gender> 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
+ * <p>
+ * @param c Gender character
+ <p>
+ * @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)
+ * <p>
+ * @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 () {
+ }
+
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+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
+ * <p>
+ * @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)
+ * <p>
+ * @return the accessChar
+ */
+ public char getAccessChar () {
+ return this.accessChar;
+ }
+
+ /**
+ * Output value (for messages)
+ * <p>
+ * @return the messageKey
+ */
+ public String getMessageKey () {
+ return this.messageKey;
+ }
+
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+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
+ * <p>
+ * @return Selectable personal titles
+ * @deprecated Arrays.asList() is there
+ */
+ @Deprecated
+ public static List<PersonalTitle> allPersonalTitlesAsList () {
+ // Init list
+ List<PersonalTitle> 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
+ * <p>
+ * @param c PersonalTitle character
+ * <p>
+ * @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)
+ * <p>
+ * @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 () {
+ }
+
+}