From 6072297ff0b6712299b60ca556500535b93f385a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 23 Jun 2017 20:05:50 +0200 Subject: [PATCH] Continued a bit: - moved copyAll() away from POJO to utils class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../jusercore/model/user/LoginUser.java | 22 ---------- .../mxchange/jusercore/model/user/User.java | 7 ---- .../jusercore/model/user/UserUtils.java | 42 +++++++++++++++++-- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/org/mxchange/jusercore/model/user/LoginUser.java b/src/org/mxchange/jusercore/model/user/LoginUser.java index 755b511..8de7f6c 100644 --- a/src/org/mxchange/jusercore/model/user/LoginUser.java +++ b/src/org/mxchange/jusercore/model/user/LoginUser.java @@ -174,28 +174,6 @@ public class LoginUser implements User { this.userProfileMode = ProfileMode.INVISIBLE; } - @Override - public void copyAll (final User user) { - // Is contact set? - if (user.getUserContact() instanceof Contact) { - // Copy also contact data - this.getUserContact().copyAll(user.getUserContact()); - } - - // Copy other data - this.setUserConfirmKey(user.getUserConfirmKey()); - this.setUserName(user.getUserName()); - this.setUserEncryptedPassword(user.getUserEncryptedPassword()); - this.setUserAccountStatus(user.getUserAccountStatus()); - this.setUserCreated(user.getUserCreated()); - this.setUserLastLocked(user.getUserLastLocked()); - this.setUserLastLockedReason(user.getUserLastLockedReason()); - this.setUserUpdated(user.getUserUpdated()); - this.setUserProfileMode(user.getUserProfileMode()); - this.setUserLocale(user.getUserLocale()); - this.setUserMustChangePassword(user.getUserMustChangePassword()); - } - @Override public boolean equals (final Object object) { if (null == object) { diff --git a/src/org/mxchange/jusercore/model/user/User.java b/src/org/mxchange/jusercore/model/user/User.java index c9f39b6..09e4f33 100644 --- a/src/org/mxchange/jusercore/model/user/User.java +++ b/src/org/mxchange/jusercore/model/user/User.java @@ -30,13 +30,6 @@ import org.mxchange.jusercore.model.user.status.UserAccountStatus; */ public interface User extends Serializable { - /** - * Copies all attributes from other user object to this - *

- * @param userSource Source instance - */ - void copyAll (final User userSource); - /** * Getter for account status *

diff --git a/src/org/mxchange/jusercore/model/user/UserUtils.java b/src/org/mxchange/jusercore/model/user/UserUtils.java index c15b8bc..fc6a3fe 100644 --- a/src/org/mxchange/jusercore/model/user/UserUtils.java +++ b/src/org/mxchange/jusercore/model/user/UserUtils.java @@ -110,8 +110,8 @@ public class UserUtils implements Serializable { } /** - * Determines given password's strength: 0 = worst, 100 = best. This method is - * based on + * Determines given password's strength: 0 = worst, 100 = best. This method + * is based on * http://stackoverflow.com/questions/1614811/how-do-i-measure-the-strength-of-a-password *

* @param password Clear-text password @@ -176,6 +176,42 @@ public class UserUtils implements Serializable { return score; } + /** + * Copies all attributes from other user object to target + *

+ * @param sourceUser Source instance + * @param targetUser Target instance + */ + public static void copyAll (final User sourceUser, final User targetUser) { + // Check all parameter + if (null == sourceUser) { + // Throw NPE + throw new NullPointerException("sourceUser is null"); //NOI18N + } else if (null == targetUser) { + // Throw NPE + throw new NullPointerException("targetUser is null"); //NOI18N + } + + // Is contact set? + if (sourceUser.getUserContact() instanceof Contact) { + // Copy also contact data + targetUser.getUserContact().copyAll(sourceUser.getUserContact()); + } + + // Copy other data + targetUser.setUserConfirmKey(sourceUser.getUserConfirmKey()); + targetUser.setUserName(sourceUser.getUserName()); + targetUser.setUserEncryptedPassword(sourceUser.getUserEncryptedPassword()); + targetUser.setUserAccountStatus(sourceUser.getUserAccountStatus()); + targetUser.setUserCreated(sourceUser.getUserCreated()); + targetUser.setUserLastLocked(sourceUser.getUserLastLocked()); + targetUser.setUserLastLockedReason(sourceUser.getUserLastLockedReason()); + targetUser.setUserUpdated(sourceUser.getUserUpdated()); + targetUser.setUserProfileMode(sourceUser.getUserProfileMode()); + targetUser.setUserLocale(sourceUser.getUserLocale()); + targetUser.setUserMustChangePassword(sourceUser.getUserMustChangePassword()); + } + /** * Creates a pseudo-random password with given length *

@@ -458,7 +494,7 @@ public class UserUtils implements Serializable { * Checks if direct password the updatedUser's password *

* @param clearTextPassword Clear-text (direct) password - * @param updatedUser Updated user instance from database + * @param updatedUser Updated user instance from database *

* @return Whether the password matches */ -- 2.39.5