]> git.mxchange.org Git - juser-core.git/commitdiff
Continued a bit:
authorRoland Häder <roland@mxchange.org>
Fri, 23 Jun 2017 18:05:50 +0000 (20:05 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 23 Jun 2017 18:05:50 +0000 (20:05 +0200)
- moved copyAll() away from POJO to utils class

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jusercore/model/user/LoginUser.java
src/org/mxchange/jusercore/model/user/User.java
src/org/mxchange/jusercore/model/user/UserUtils.java

index 755b511f3c6cc25b55da21f88750a689d842161b..8de7f6ceb6f1af06e762a87878573e6648b7cb92 100644 (file)
@@ -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) {
index c9f39b6d53923b93801e6a518b515c2031f87719..09e4f337765186f4aac2c8c1459d4b35fd73def1 100644 (file)
@@ -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
-        * <p>
-        * @param userSource Source instance
-        */
-       void copyAll (final User userSource);
-
        /**
         * Getter for account status
         * <p>
index c15b8bcc634f49d61930cadb148a3ac7b1c7e79a..fc6a3fe306763f01d78f1eaf36af2a64b3d7587b 100644 (file)
@@ -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
         * <p>
         * @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
+        * <p>
+        * @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
         * <p>
@@ -458,7 +494,7 @@ public class UserUtils implements Serializable {
         * Checks if direct password the updatedUser's password
         * <p>
         * @param clearTextPassword Clear-text (direct) password
-        * @param updatedUser         Updated user instance from database
+        * @param updatedUser       Updated user instance from database
         * <p>
         * @return Whether the password matches
         */