]> git.mxchange.org Git - juser-core.git/commitdiff
Continued;
authorRoland Häder <roland@mxchange.org>
Sun, 18 Mar 2018 16:36:26 +0000 (17:36 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 18 Mar 2018 16:36:26 +0000 (17:36 +0100)
- implemented Comparable

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

index df3e0203173c341bcc3658b14226bfb66fef3a7b..0e05fd712f380002ae401924c4baaa973f27c17b 100644 (file)
@@ -39,6 +39,7 @@ import javax.persistence.TemporalType;
 import javax.persistence.Transient;
 import org.mxchange.jcontacts.model.contact.Contact;
 import org.mxchange.jcontacts.model.contact.UserContact;
+import org.mxchange.jcoreee.utils.Comparables;
 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
 
@@ -59,8 +60,7 @@ import org.mxchange.jusercore.model.user.status.UserAccountStatus;
                        @NamedQuery (name = "SearchUserByEmailAddress", query = "SELECT u FROM users AS u INNER JOIN contacts AS c ON u.userContact = c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:emailAddress)"),
                        @NamedQuery (name = "SearchUserByConfirmKey", query = "SELECT u FROM users AS u WHERE u.userConfirmKey = :confirmKey"),
                        @NamedQuery (name = "SearchAllUsersExcept", query = "SELECT u FROM users AS u WHERE u != :user ORDER BY u.userId ASC"),
-                       @NamedQuery (name = "AllUsers", query = "SELECT u FROM users AS u ORDER BY u.userId ASC"),
-               }
+                       @NamedQuery (name = "AllUsers", query = "SELECT u FROM users AS u ORDER BY u.userId ASC"),}
 )
 @SuppressWarnings ("PersistenceUnitPresent")
 public class LoginUser implements User {
@@ -178,7 +178,7 @@ public class LoginUser implements User {
         * @param userMustChangePassword Whether user must change password
         * @param userEncryptedPassword  Encrypted password
         * @param userAccountStatus      Account status
-        * @param userContact User's contact data
+        * @param userContact            User's contact data
         */
        public LoginUser (final String userName, final ProfileMode userProfileMode, final Boolean userMustChangePassword, final String userEncryptedPassword, final UserAccountStatus userAccountStatus, final Contact userContact) {
                // Call other constructor first
@@ -231,8 +231,19 @@ public class LoginUser implements User {
                        return 0;
                }
 
-               // There can only be one user per user name
-               return this.getUserName().compareTo(user.getUserName());
+               // Init comparitors
+               final int comparitors[] = {
+                       // First contact
+                       this.getUserContact().compareTo(user.getUserContact()),
+                       // ... then user name
+                       this.getUserName().compareTo(user.getUserName())
+               };
+
+               // Check all values
+               final int comparison = Comparables.checkAll(comparitors);
+
+               // Return value
+               return comparison;
        }
 
        @Override