]> git.mxchange.org Git - jcontacts-core.git/commitdiff
"Gender" for "Mr." and "Mrs." was plain wrong, let's take "Title" (and later
authorRoland Häder <roland@mxchange.org>
Sat, 10 Jun 2017 12:35:25 +0000 (14:35 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 10 Jun 2017 12:35:25 +0000 (14:35 +0200)
add "Academic title").

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jcontacts/contact/Contact.java
src/org/mxchange/jcontacts/contact/UserContact.java
src/org/mxchange/jcontacts/contact/gender/Gender.java
src/org/mxchange/jcontacts/contact/gender/GenderUtils.java
src/org/mxchange/jcontacts/contact/title/PersonalTitle.java [new file with mode: 0644]
src/org/mxchange/jcontacts/contact/title/TitleUtils.java [new file with mode: 0644]
src/org/mxchange/jcontacts/contact/utils/ContactUtils.java
src/org/mxchange/jcontacts/exceptions/ContactAlreadyAddedException.java

index 1e5841cd88e5d23e01d63190efb86201876435ff..649fd82085cf6358f9aae3b3f4da0779f6f73782 100644 (file)
@@ -19,7 +19,7 @@ package org.mxchange.jcontacts.contact;
 import java.io.Serializable;
 import java.util.Calendar;
 import java.util.Date;
-import org.mxchange.jcontacts.contact.gender.Gender;
+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;
@@ -194,18 +194,18 @@ public interface Contact extends Serializable {
        void setContactFirstName (final String firstName);
 
        /**
-        * Gender of the contact
+        * Getter for personal title
         * <p>
-        * @return the gender
+        * @return Personal title
         */
-       Gender getContactGender ();
+       PersonalTitle getContactPersonalTitle ();
 
        /**
-        * Gender of the contact
+        * Setter for personal title
         * <p>
-        * @param gender the gender to set
+        * @param personalTitle Personal title
         */
-       void setContactGender (final Gender gender);
+       void setContactPersonalTitle (final PersonalTitle personalTitle);
 
        /**
         * House number
index 4dfe8e46c65afc81ff5362ba10c4e8afdefc42d9..4b47417731291eb89033cfd547bec73b56c12655 100644 (file)
@@ -38,7 +38,7 @@ import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
-import org.mxchange.jcontacts.contact.gender.Gender;
+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;
@@ -145,14 +145,6 @@ public class UserContact implements Contact {
        @Column (name = "contact_first_name", length = 100, nullable = false)
        private String contactFirstName;
 
-       /**
-        * Gender instance
-        */
-       @Basic (optional = false)
-       @Column (name = "contact_gender", nullable = false)
-       @Enumerated (EnumType.STRING)
-       private Gender contactGender;
-
        /**
         * House number
         */
@@ -188,6 +180,14 @@ public class UserContact implements Contact {
        @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
         */
@@ -231,18 +231,18 @@ public class UserContact implements Contact {
        }
 
        /**
-        * Constructor for contactGender and names
+        * Constructor for title and names
         * <p>
-        * @param contactGender Gender instance
-        * @param contactFirstName First name
+        * @param contactTitle      Personal title
+        * @param contactFirstName  First name
         * @param contactFamilyName Family name
         */
-       public UserContact (final Gender contactGender, final String contactFirstName, final String contactFamilyName) {
+       public UserContact (final PersonalTitle contactTitle, final String contactFirstName, final String contactFamilyName) {
                // Call default constructor
                this();
 
                // Set all
-               this.contactGender = contactGender;
+               this.contactPersonalTitle = contactTitle;
                this.contactFirstName = contactFirstName;
                this.contactFamilyName = contactFamilyName;
        }
@@ -257,7 +257,7 @@ public class UserContact implements Contact {
 
                // Copy all:
                // - base data
-               this.setContactGender(contact.getContactGender());
+               this.setContactPersonalTitle(contact.getContactPersonalTitle());
                this.setContactTitle(contact.getContactTitle());
                this.setContactFirstName(contact.getContactFirstName());
                this.setContactFamilyName(contact.getContactFamilyName());
@@ -313,7 +313,7 @@ public class UserContact implements Contact {
                        return false;
                } else if (!Objects.equals(this.getContactCountry(), other.getContactCountry())) {
                        return false;
-               } else if (this.getContactGender() != other.getContactGender()) {
+               } else if (this.getContactPersonalTitle() != other.getContactPersonalTitle()) {
                        return false;
                } else if (!Objects.equals(this.getContactHouseNumber(), other.getContactHouseNumber())) {
                        return false;
@@ -419,16 +419,6 @@ public class UserContact implements Contact {
                this.contactFirstName = contactFirstName;
        }
 
-       @Override
-       public Gender getContactGender () {
-               return this.contactGender;
-       }
-
-       @Override
-       public void setContactGender (final Gender contactGender) {
-               this.contactGender = contactGender;
-       }
-
        @Override
        public Short getContactHouseNumber () {
                return this.contactHouseNumber;
@@ -484,6 +474,16 @@ public class UserContact implements Contact {
                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;
@@ -536,7 +536,7 @@ public class UserContact implements Contact {
                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.getContactGender());
+               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());
index a862388c95049db8c440896009d8ac2bbbca1da4..b06b94dbe6c9d1abfe234bb89e0eff39d3592fcf 100644 (file)
 package org.mxchange.jcontacts.contact.gender;
 
 import java.io.Serializable;
-import java.text.MessageFormat;
 
 /**
- * Gender enum
+ * 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 enum
+        * Male gender
         */
        MALE('M', "GENDER_MALE"), //NOI18N
 
        /**
-        * Female enum
+        * Female gender
         */
        FEMALE('F', "GENDER_FEMALE"); //NOI18N
 
-       /**
-        * Cache for valid chars
-        */
-       private static char[] validChars;
-
        /**
         * Access key being entered by ConsoleClient
         */
@@ -51,77 +46,6 @@ public enum Gender implements Serializable {
         */
        private final String messageKey;
 
-       /**
-        * Getter for Gender enum from given character
-        * <p>
-        * @param c Gender character
-        * <p>
-        * @return Gender enum
-        */
-       public static Gender fromChar (final char c) {
-               // Init variable
-               Gender g = null;
-
-               // Loop through all
-               for (final Gender gender : GenderUtils.selectableGenders()) {
-                       // Does the char match?
-                       if (c == gender.getAccessChar()) {
-                               // Found it
-                               g = gender;
-                               break;
-                       }
-               }
-
-               // Still null?
-               if (null == g) {
-                       // Didn't found a valid one
-                       throw new IllegalArgumentException(MessageFormat.format("Gender {0} is invalid.", c)); //NOI18N
-               }
-
-               // Return it
-               //* NOISY-DEBUG: */ System.out.println("gender=" + g.getClass().getName());
-               return g;
-       }
-
-       /**
-        * 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 3 are valid as 'U' is UNKNOWN and is not valid.
-               char[] valid = new char[3];
-
-               // Get values
-               int i = 0;
-               for (final Gender gender : GenderUtils.selectableGenders()) {
-                       // Debug message
-                       //* NOISY-DEBUG: */ System.out.println("gender=" + gender);
-
-                       // Debug message
-                       //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("gender={0} - adding at pos {1} ...", gender, i));
-
-                       // 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;
-       }
-
        /**
         * Constructor
         * <p>
@@ -135,7 +59,7 @@ public enum Gender implements Serializable {
        }
 
        /**
-        * Acces key (console client mostly)
+        * Access key (console client mostly)
         * <p>
         * @return the accessChar
         */
index ddc643003208faa2bc1a495c96caa851e23f801b..87ec6e8e3ee02d97c58ab9472f0e088a01dff437 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.jcontacts.contact.gender;
 
 import java.io.Serializable;
+import java.text.MessageFormat;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -33,35 +34,95 @@ public class GenderUtils implements Serializable {
        private static final long serialVersionUID = 185_683_479_107L;
 
        /**
-        * All selectable genders (not UNKNOWN)
+        * Cache for valid chars
+        */
+       private static char[] validChars;
+
+       /**
+        * All available genders as a list
         * <p>
         * @return Selectable genders (not UNKNOWN)
         */
-       public static List<Gender> selectableGenders () {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("GenderUtils.selectableGenders: CALLED!"); //NOI18N
-
+       public static List<Gender> allGendersAsList () {
                // Init list
                List<Gender> list = new LinkedList<>();
 
                // Walk through all genders
                for (final Gender gender : Gender.values()) {
-                       // Debug message
-                       //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("GenderUtils.selectableGenders: gender={0}", gender)); //NOI18N
-
                        // Add it and check if it has been added
                        list.add(gender);
                }
 
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("GenderUtils.selectableGenders: list.size()={0} - EXIT!", list.size())); //NOI18N
-
                // Return it
                return list;
        }
 
        /**
-        * Private contructor as this is an utility class
+        * 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 () {
        }
diff --git a/src/org/mxchange/jcontacts/contact/title/PersonalTitle.java b/src/org/mxchange/jcontacts/contact/title/PersonalTitle.java
new file mode 100644 (file)
index 0000000..8a88902
--- /dev/null
@@ -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 <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;
+       }
+
+}
diff --git a/src/org/mxchange/jcontacts/contact/title/TitleUtils.java b/src/org/mxchange/jcontacts/contact/title/TitleUtils.java
new file mode 100644 (file)
index 0000000..492f5ef
--- /dev/null
@@ -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 <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 () {
+       }
+
+}
index d9500970f238cd0e01b2726ced93906769091438..1f4f02ece01f09ddd382b778bb28fdaf3ed8ed46 100644 (file)
@@ -67,7 +67,7 @@ public class ContactUtils implements Serializable {
                                (Objects.equals(contact.getContactEmailAddress(), other.getContactEmailAddress())) &&
                                (Objects.equals(contact.getContactFamilyName(), other.getContactFamilyName())) &&
                                (Objects.equals(contact.getContactFirstName(), other.getContactFirstName())) &&
-                               (Objects.equals(contact.getContactGender(), other.getContactGender())) &&
+                               (Objects.equals(contact.getContactPersonalTitle(), other.getContactPersonalTitle())) &&
                                (Objects.equals(contact.getContactHouseNumber(), other.getContactHouseNumber())) &&
                                (Objects.equals(contact.getContactStreet(), other.getContactStreet())) &&
                                (Objects.equals(contact.getContactTitle(), other.getContactTitle())) &&
index febafd13409fb8bcc9b03ff93082d91be455c981..cde5b29bc3462fe73ee0b931cdd4bcbf30b24160 100644 (file)
@@ -37,7 +37,7 @@ public class ContactAlreadyAddedException extends Exception {
         * @param contact Contact that is already added
         */
        public ContactAlreadyAddedException (final Contact contact) {
-               super(MessageFormat.format("Contact with gender={0}, firstName={1} and familyName={2} already added.", contact.getContactGender(), contact.getContactFirstName(), contact.getContactFamilyName())); //NOI18N
+               super(MessageFormat.format("Contact with gender={0}, firstName={1} and familyName={2} already added.", contact.getContactPersonalTitle(), contact.getContactFirstName(), contact.getContactFamilyName())); //NOI18N
        }
 
        /**