From 26d87f8871abc377f313917a6424ecb587f0fde3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 18 Mar 2018 17:36:26 +0100 Subject: [PATCH] Continued; - implemented Comparable 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 | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) 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 -- 2.39.5