From 7df61c55ec0f5d85337e85ae3a9d44d8e6e92e4c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 19 Mar 2018 22:43:49 +0100 Subject: [PATCH] Continued: - renamed UserUtils -> Users to follow common naming-convention - added Users.compare() method to compare two instances of users MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../model/user/{UserUtils.java => Users.java} | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) rename src/org/mxchange/jusercore/model/user/{UserUtils.java => Users.java} (91%) diff --git a/src/org/mxchange/jusercore/model/user/UserUtils.java b/src/org/mxchange/jusercore/model/user/Users.java similarity index 91% rename from src/org/mxchange/jusercore/model/user/UserUtils.java rename to src/org/mxchange/jusercore/model/user/Users.java index dc0e18a..cc1d14a 100644 --- a/src/org/mxchange/jusercore/model/user/UserUtils.java +++ b/src/org/mxchange/jusercore/model/user/Users.java @@ -21,6 +21,7 @@ import java.security.SecureRandom; import java.text.DateFormat; import java.text.MessageFormat; import java.util.Date; +import java.util.Objects; import java.util.Properties; import java.util.Random; import org.mxchange.jcontacts.model.contact.Contact; @@ -31,7 +32,7 @@ import org.mxchange.jcontacts.model.contact.Contacts; *

* @author Roland Häder */ -public class UserUtils implements Serializable { +public class Users implements Serializable { /** * Password alphabet @@ -78,10 +79,36 @@ public class UserUtils implements Serializable { RANDOM_NUMBER_GENERATOR = new SecureRandom(); // Init alphabet - PASSWORD_ALPHABET = UserUtils.PASSWORD_ALPHABET_PARTS[0] + - UserUtils.PASSWORD_ALPHABET_PARTS[1] + - UserUtils.PASSWORD_ALPHABET_PARTS[2] + - UserUtils.PASSWORD_ALPHABET_PARTS[3]; + PASSWORD_ALPHABET = Users.PASSWORD_ALPHABET_PARTS[0] + + Users.PASSWORD_ALPHABET_PARTS[1] + + Users.PASSWORD_ALPHABET_PARTS[2] + + Users.PASSWORD_ALPHABET_PARTS[3]; + } + + /** + * Compares both user instances. This method returns -1 if second + * instance is null. + *

+ * @param user1 User instance 1 + * @param user2 User instance 2 + *

+ * @return Comparison value + */ + public static int compare (final User user1, final User user2) { + // Check euqality, then at least first must be given + if (Objects.equals(user1, user2)) { + // Both are same + return 0; + } else if (null == user1) { + // First is null + return -1; + } else if (null == user2) { + // Second is null + return 1; + } + + // Invoke compare() method + return user1.compareTo(user2); } /** @@ -267,7 +294,7 @@ public class UserUtils implements Serializable { /** * No instance from this class */ - private UserUtils () { + private Users () { } } -- 2.39.5