From 93a0eb5529a0520a3f40d4307b70137766ef7f16 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 19 Apr 2020 06:10:41 +0200 Subject: [PATCH] Continued: - always validate parameter of public/package/protected methods and constructors - renamed i18nKey to messageKey MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../jproduct/model/payment/PaymentType.java | 21 ++++++++++++----- .../model/product/agegroup/AgeGroup.java | 23 +++++++++++++------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/org/mxchange/jproduct/model/payment/PaymentType.java b/src/org/mxchange/jproduct/model/payment/PaymentType.java index 4d9838b..fbb7a8c 100644 --- a/src/org/mxchange/jproduct/model/payment/PaymentType.java +++ b/src/org/mxchange/jproduct/model/payment/PaymentType.java @@ -47,16 +47,25 @@ public enum PaymentType { /** * I18n key */ - private final String i18nKey; + private final String messageKey; /** * Constructor with i18n key *

- * @param i18Key I18n key + * @param messageKey I18n key */ - private PaymentType (final String i18Key) { + private PaymentType (final String messageKey) { + // Validate parameter + if (null == messageKey) { + // Throw NPE + throw new NullPointerException("messageKey is null"); //NOI18N + } else if (messageKey.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("messageKey is empty"); //NOI18N + } + // Set both here - this.i18nKey = i18Key; + this.messageKey = messageKey; } /** @@ -64,8 +73,8 @@ public enum PaymentType { *

* @return I18n key */ - public String getI18nKey () { - return this.i18nKey; + public String getMessageKey () { + return this.messageKey; } } diff --git a/src/org/mxchange/jproduct/model/product/agegroup/AgeGroup.java b/src/org/mxchange/jproduct/model/product/agegroup/AgeGroup.java index 54398c3..c9f9455 100644 --- a/src/org/mxchange/jproduct/model/product/agegroup/AgeGroup.java +++ b/src/org/mxchange/jproduct/model/product/agegroup/AgeGroup.java @@ -46,21 +46,30 @@ public enum AgeGroup { /** * Age group "senior" */ - AGE_GROUP_SENIOR("AGE_GROUP_SENIOR"); //NOI18N + AGE_GROUP_SENIOR("AGE_GROUP_SENIOR"); //NOI18N//NOI18N /** * I18n key for age group/class */ - private final String i18nKey; + private final String messageKey; /** * Constructor with all enumeration fields *

- * @param i18nKey I18n key for age class + * @param messageKey I18n key for age class */ - private AgeGroup (final String i18nKey) { + private AgeGroup (final String messageKey) { + // Validate parameter + if (null == messageKey) { + // Throw NPE + throw new NullPointerException("messageKey is null"); //NOI18N + } else if (messageKey.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("messageKey is empty"); //NOI18N + } + // Set all values - this.i18nKey = i18nKey; + this.messageKey = messageKey; } /** @@ -68,8 +77,8 @@ public enum AgeGroup { *

* @return Age group's i18n key */ - public String getI18nKey () { - return this.i18nKey; + public String getMessageKey () { + return this.messageKey; } } -- 2.39.5