From f67911d2934adfe8a9b5b4f46753a7a24a0dd513 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 3 Jun 2016 09:41:24 +0200 Subject: [PATCH] Thumb of a rule: - don't set default values, let it fail with an NPE if not taken correctly care of. - if a default value is set, the mistake of careless will be spotted very much later (e.g. when the data is already persisted). - if no default value is set (in this case it makes sense not set ...) an NPE is likely be thrown which might be spotted much earlier. - this is good as bugs/bad data are detected (prevented in the end) earlier, too. --- src/org/mxchange/jcontacts/contact/UserContact.java | 3 --- src/org/mxchange/jcontacts/contact/gender/Gender.java | 5 ----- .../mxchange/jcontacts/contact/gender/GenderUtils.java | 10 ++-------- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/org/mxchange/jcontacts/contact/UserContact.java b/src/org/mxchange/jcontacts/contact/UserContact.java index 3312c8f..c4f6ba7 100644 --- a/src/org/mxchange/jcontacts/contact/UserContact.java +++ b/src/org/mxchange/jcontacts/contact/UserContact.java @@ -226,9 +226,6 @@ public class UserContact implements Contact { public UserContact () { // Default is not user's own contact this.contactOwnContact = Boolean.FALSE; - - // Unknown gender - this.contactGender = Gender.UNKNOWN; } /** diff --git a/src/org/mxchange/jcontacts/contact/gender/Gender.java b/src/org/mxchange/jcontacts/contact/gender/Gender.java index 62da233..890eb93 100644 --- a/src/org/mxchange/jcontacts/contact/gender/Gender.java +++ b/src/org/mxchange/jcontacts/contact/gender/Gender.java @@ -26,11 +26,6 @@ import java.text.MessageFormat; */ public enum Gender implements Serializable { - /** - * Unknown enum - */ - UNKNOWN('U', "GENDER_UNKNOWN"), //NOI18N - /** * Male enum */ diff --git a/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java b/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java index ab2fd59..b8ec349 100644 --- a/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java +++ b/src/org/mxchange/jcontacts/contact/gender/GenderUtils.java @@ -44,14 +44,8 @@ public class GenderUtils implements Serializable { // Walk through all genders for (final Gender gender : Gender.values()) { - // Is it not UNKNOWN - if (!gender.equals(Gender.UNKNOWN)) { - // Add it - boolean added = list.add(gender); - - // Has it been added? - assert (added) : MessageFormat.format("gender {0} not added.", gender); //NOI18N - } + // Add it and check if it has been added + assert (list.add(gender)) : MessageFormat.format("gender {0} not added.", gender); //NOI18N } // Return it -- 2.39.5