]> git.mxchange.org Git - jcore.git/blobdiff - src/org/mxchange/jcore/model/contact/gender/GenderUtils.java
Removed dependency to log4j and commons
[jcore.git] / src / org / mxchange / jcore / model / contact / gender / GenderUtils.java
index f589240ce8835a7e3c893de44df05cecd539e91f..b4d1ec7ef2484d946b5e0b77ea5059b7e6c8d1b7 100644 (file)
@@ -20,13 +20,41 @@ 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
- *
+ * <p>
  * @author Roland Haeder<roland@mxchange.org>
  */
 public class GenderUtils extends BaseFrameworkSystem {
+
+       /**
+        * Translates contact's gender to human-readable
+        * <p>
+        * @param contact Contact instance
+        * @return Translates value (from bundle)
+        */
+       public static String getTranslatedGender (final Contact contact) {
+               // Init instance
+               GenderUtils utils = new GenderUtils();
+
+               // 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();
+
+               // Translate and return it
+               return utils.getMessageStringFromKey(key);
+       }
+
        /**
         * Private contructor as this is an utility class
         */
@@ -35,34 +63,25 @@ public class GenderUtils extends BaseFrameworkSystem {
 
        /**
         * All selectable genders (not UNKNOWN)
-        * 
+        * <p>
         * @return Selectable genders (not UNKNOWN)
         */
        public static List<Gender> selectableGenders () {
-               // Trace message
-               new GenderUtils().getLogger().trace("CALLED!"); //NOI18N
-
                // Init list
                List<Gender> list = new LinkedList<>();
 
                // Walk through all genders
                for (final Gender gender : Gender.values()) {
-                       // Debug log
-                       new GenderUtils().getLogger().debug(MessageFormat.format("gender={0}", gender)); //NOI18N
-
                        // 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
+                               assert (added) : MessageFormat.format("gender {0} not added.", gender); //NOI18N
                        }
                }
 
-               // Trace message
-               new GenderUtils().getLogger().trace(MessageFormat.format("list={0} - EXIT!", list)); //NOI18N
-
                // Return it
                return list;
        }