From 05c5116f5f0174581f8a93b8251662c1c61b132c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 10 Jun 2017 14:35:25 +0200 Subject: [PATCH] "Gender" for "Mr." and "Mrs." was plain wrong, let's take "Title" (and later add "Academic title"). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../mxchange/jcontacts/contact/Contact.java | 14 +- .../jcontacts/contact/UserContact.java | 54 ++++---- .../jcontacts/contact/gender/Gender.java | 86 +----------- .../jcontacts/contact/gender/GenderUtils.java | 85 ++++++++++-- .../contact/title/PersonalTitle.java | 79 +++++++++++ .../jcontacts/contact/title/TitleUtils.java | 130 ++++++++++++++++++ .../jcontacts/contact/utils/ContactUtils.java | 2 +- .../ContactAlreadyAddedException.java | 2 +- 8 files changed, 323 insertions(+), 129 deletions(-) create mode 100644 src/org/mxchange/jcontacts/contact/title/PersonalTitle.java create mode 100644 src/org/mxchange/jcontacts/contact/title/TitleUtils.java diff --git a/src/org/mxchange/jcontacts/contact/Contact.java b/src/org/mxchange/jcontacts/contact/Contact.java index 1e5841c..649fd82 100644 --- a/src/org/mxchange/jcontacts/contact/Contact.java +++ b/src/org/mxchange/jcontacts/contact/Contact.java @@ -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 *

- * @return the gender + * @return Personal title */ - Gender getContactGender (); + PersonalTitle getContactPersonalTitle (); /** - * Gender of the contact + * Setter for personal title *

- * @param gender the gender to set + * @param personalTitle Personal title */ - void setContactGender (final Gender gender); + void setContactPersonalTitle (final PersonalTitle personalTitle); /** * House number diff --git a/src/org/mxchange/jcontacts/contact/UserContact.java b/src/org/mxchange/jcontacts/contact/UserContact.java index 4dfe8e4..4b47417 100644 --- a/src/org/mxchange/jcontacts/contact/UserContact.java +++ b/src/org/mxchange/jcontacts/contact/UserContact.java @@ -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 *

- * @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()); diff --git a/src/org/mxchange/jcontacts/contact/gender/Gender.java b/src/org/mxchange/jcontacts/contact/gender/Gender.java index a862388..b06b94d 100644 --- a/src/org/mxchange/jcontacts/contact/gender/Gender.java +++ b/src/org/mxchange/jcontacts/contact/gender/Gender.java @@ -17,30 +17,25 @@ 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. *

* @author Roland Häder */ 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 - *

- * @param c Gender character - *

- * @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) - *

- * @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 *

@@ -135,7 +59,7 @@ public enum Gender implements Serializable { } /** - * Acces key (console client mostly) + * Access key (console client mostly) *

* @return the accessChar */ diff --git a/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java b/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java index ddc6430..87ec6e8 100644 --- a/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java +++ b/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java @@ -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 *

* @return Selectable genders (not UNKNOWN) */ - public static List selectableGenders () { - // Trace message - //* NOISY-DEBUG: */ System.out.println("GenderUtils.selectableGenders: CALLED!"); //NOI18N - + public static List allGendersAsList () { // Init list List 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 + *

+ * @param c Gender character +

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

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

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

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

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

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

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

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

+ * @param c PersonalTitle character + *

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

+ * @return Valid chars + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public static char[] validChars () { + // Is cache set? + if (validChars != null) { + // Return it + return validChars; + } + + // Init array, only 2 are valid. + char[] valid = new char[2]; + + // Get values + int i = 0; + for (final PersonalTitle title : PersonalTitle.values()) { + // Get access key as this is also the access + valid[i] = title.getAccessChar(); + + // Increment index + i++; + } + + // Set it here + validChars = valid; + + // Return finialized array + return valid; + } + + /** + * Private constructor as this is an utility class + */ + private TitleUtils () { + } + +} diff --git a/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java b/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java index d950097..1f4f02e 100644 --- a/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java +++ b/src/org/mxchange/jcontacts/contact/utils/ContactUtils.java @@ -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())) && diff --git a/src/org/mxchange/jcontacts/exceptions/ContactAlreadyAddedException.java b/src/org/mxchange/jcontacts/exceptions/ContactAlreadyAddedException.java index febafd1..cde5b29 100644 --- a/src/org/mxchange/jcontacts/exceptions/ContactAlreadyAddedException.java +++ b/src/org/mxchange/jcontacts/exceptions/ContactAlreadyAddedException.java @@ -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 } /** -- 2.39.5