From 139327cfb193757f4d57bbd6a101c25d0c5cf607 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 17 Sep 2015 08:22:42 +0200 Subject: [PATCH] =?utf8?q?Added=20method=20getTranslatedGender()=20Signed-?= =?utf8?q?off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../model/contact/gender/GenderUtils.java | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/org/mxchange/jcore/model/contact/gender/GenderUtils.java b/src/org/mxchange/jcore/model/contact/gender/GenderUtils.java index f589240..c74b131 100644 --- a/src/org/mxchange/jcore/model/contact/gender/GenderUtils.java +++ b/src/org/mxchange/jcore/model/contact/gender/GenderUtils.java @@ -20,6 +20,7 @@ import java.text.MessageFormat; import java.util.LinkedList; import java.util.List; import org.mxchange.jcore.BaseFrameworkSystem; +import org.mxchange.jcore.model.contact.Contact; /** * Gender utils class @@ -27,6 +28,39 @@ import org.mxchange.jcore.BaseFrameworkSystem; * @author Roland Haeder */ public class GenderUtils extends BaseFrameworkSystem { + + /** + * Translates contact's gender to human-readable + * + * @param contact Contact instance + * @return Translates value (from bundle) + */ + public static String getTranslatedGender (final Contact contact) { + // Init instance + GenderUtils utils = new GenderUtils(); + + // Trace message + utils.getLogger().trace(MessageFormat.format("getTranslatedGender: contact={0} - CALLED!", contact)); + + // contact must be set + if (null == contact) { + // Abort here + throw new NullPointerException("contact is null"); + } else if (contact.getGender() == null) { + // Gender is not set + throw new NullPointerException(MessageFormat.format("contact {0} has no gender set.", contact)); + } + + // Get key from it + String key = contact.getGender().getMessageKey(); + + // Debug message + utils.getLogger().debug(MessageFormat.format("getTranslatedGender: key={0}", key)); + + // Translate and return it + return utils.getMessageStringFromKey(key); + } + /** * Private contructor as this is an utility class */ @@ -35,7 +69,7 @@ public class GenderUtils extends BaseFrameworkSystem { /** * All selectable genders (not UNKNOWN) - * + * * @return Selectable genders (not UNKNOWN) */ public static List selectableGenders () { @@ -56,7 +90,7 @@ public class GenderUtils extends BaseFrameworkSystem { boolean added = list.add(gender); // Has it been added? - assert(added) : MessageFormat.format("gender {0} not added.", gender); //NOI18N + assert (added) : MessageFormat.format("gender {0} not added.", gender); //NOI18N } } -- 2.39.5