]> git.mxchange.org Git - juser-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 5 Nov 2022 07:53:49 +0000 (08:53 +0100)
committerRoland Häder <roland@mxchange.org>
Sat, 5 Nov 2022 08:04:33 +0000 (09:04 +0100)
- the prefix "get" is exclusively for getters, you need to find others for
  non-getter methods
- also check if userLocale is set
- sorted members

src/org/mxchange/jusercore/model/utils/UserUtils.java

index 048c3a26ea10416f3cee1f1adeeb7fc8c77b5848..3b864274c5df343139ff0e7c01aa0cdca4eb0ea1 100644 (file)
@@ -150,6 +150,37 @@ public class UserUtils implements Serializable {
                targetUser.setUserMustChangePassword(sourceUser.getUserMustChangePassword());
        }
 
+       /**
+        * Returns a formatted string from given user's locale and Date instance
+        * <p>
+        * @param user User instance
+        * @param date Date instance
+        * <p>
+        * @return A formatted string from Date instance
+        */
+       public static String formatTimestampFromUser (final User user, final Date date) {
+               // Validate parameter
+               if (null == user) {
+                       // Throw NPE
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserLocale() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("user.userLocale is null"); //NOI18N
+               } else if (null == date) {
+                       // Throw NPE
+                       throw new NullPointerException("date is null"); //NOI18N
+               }
+
+               // Get formatter
+               final DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, user.getUserLocale());
+
+               // Now simply format the calendar's Time (not just time) field
+               final String dateTime = format.format(date.getTime());
+
+               // Return it
+               return dateTime;
+       }
+
        /**
         * Generates a pseudo-random user name
         * <p>
@@ -226,9 +257,9 @@ public class UserUtils implements Serializable {
                // - User data
                properties.setProperty("userId", Long.toString(user.getUserId())); //NOI18N
                properties.setProperty("userName", user.getUserName()); //NOI18N
-               properties.setProperty("userCreated", getFormattedTimestampFromUser(user, user.getUserEntryCreated())); //NOI18N
+               properties.setProperty("userCreated", formatTimestampFromUser(user, user.getUserEntryCreated())); //NOI18N
                if (user.getUserEntryUpdated() != null) {
-                       properties.setProperty("userUpdated", getFormattedTimestampFromUser(user, user.getUserEntryUpdated())); //NOI18N
+                       properties.setProperty("userUpdated", formatTimestampFromUser(user, user.getUserEntryUpdated())); //NOI18N
                }
                if (user.getUserConfirmKey() != null) {
                        properties.setProperty("userConfirmKey", user.getUserConfirmKey()); //NOI18N
@@ -237,7 +268,7 @@ public class UserUtils implements Serializable {
                        properties.setProperty("userLastLockedReason", user.getUserLastLockedReason()); //NOI18N
                }
                if (user.getUserLastLocked() != null) {
-                       properties.setProperty("userLastLocked", getFormattedTimestampFromUser(user, user.getUserLastLocked())); //NOI18N
+                       properties.setProperty("userLastLocked", formatTimestampFromUser(user, user.getUserLastLocked())); //NOI18N
                }
                properties.setProperty("userAccountStatus", user.getUserAccountStatus().toString()); //NOI18N
 
@@ -275,34 +306,6 @@ public class UserUtils implements Serializable {
                return properties;
        }
 
-       /**
-        * Returns a formatted string from given user's locale and Date instance
-        * <p>
-        * @param user User instance
-        * @param date Date instance
-        * <p>
-        * @return A formatted string from Date instance
-        */
-       public static String getFormattedTimestampFromUser (final User user, final Date date) {
-               // Validate parameter
-               if (null == user) {
-                       // Throw NPE
-                       throw new NullPointerException("Parameter 'user' is null"); //NOI18N
-               } else if (null == date) {
-                       // Throw NPE
-                       throw new NullPointerException("Parameter 'date' is null"); //NOI18N
-               }
-
-               // Get formatter
-               final DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, user.getUserLocale());
-
-               // Now simply format the calendar's Time (not just time) field
-               final String dateTime = format.format(date.getTime());
-
-               // Return it
-               return dateTime;
-       }
-
        /**
         * No instance from this class
         */