From: Roland Häder Date: Sun, 18 Mar 2018 16:36:26 +0000 (+0100) Subject: Continued; X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=26d87f8871abc377f313917a6424ecb587f0fde3;p=juser-core.git Continued; - implemented Comparable Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jusercore/model/user/LoginUser.java b/src/org/mxchange/jusercore/model/user/LoginUser.java index df3e020..0e05fd7 100644 --- a/src/org/mxchange/jusercore/model/user/LoginUser.java +++ b/src/org/mxchange/jusercore/model/user/LoginUser.java @@ -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