From 39911094330330403be6d8be8e43d1ec541fae3e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 5 Nov 2022 08:53:49 +0100 Subject: [PATCH] Continued: - the prefix "get" is exclusively for getters, you need to find others for non-getter methods - also check if userLocale is set - sorted members --- .../jusercore/model/utils/UserUtils.java | 65 ++++++++++--------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/src/org/mxchange/jusercore/model/utils/UserUtils.java b/src/org/mxchange/jusercore/model/utils/UserUtils.java index 048c3a2..3b86427 100644 --- a/src/org/mxchange/jusercore/model/utils/UserUtils.java +++ b/src/org/mxchange/jusercore/model/utils/UserUtils.java @@ -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 + *

+ * @param user User instance + * @param date Date instance + *

+ * @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 *

@@ -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 - *

- * @param user User instance - * @param date Date instance - *

- * @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 */ -- 2.39.5