]> git.mxchange.org Git - juser-activity-core.git/commitdiff
added new checked exception + equals()/hashCode()
authorRoland Haeder <roland@mxchange.org>
Tue, 13 Oct 2015 07:00:34 +0000 (09:00 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 13 Oct 2015 07:06:46 +0000 (09:06 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/org/mxchange/jusercore/exceptions/UserPasswordMismatchException.java [new file with mode: 0644]
src/org/mxchange/jusercore/model/user/LoginUser.java
src/org/mxchange/jusercore/model/user/User.java

diff --git a/src/org/mxchange/jusercore/exceptions/UserPasswordMismatchException.java b/src/org/mxchange/jusercore/exceptions/UserPasswordMismatchException.java
new file mode 100644 (file)
index 0000000..195f2c5
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jusercore.exceptions;
+
+import java.text.MessageFormat;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * An exception thrown when the entered password did not match the stored
+ * password.
+ * <p>
+ * @author Roland Haeder
+ */
+public class UserPasswordMismatchException extends Exception {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 97_283_567_871_569_401L;
+
+       /**
+        * Creates an exception with given user instance
+        * <p>
+        * @param user User instance
+        */
+       public UserPasswordMismatchException (final User user) {
+               super(MessageFormat.format("Password for user {0} does not match stored password.", user));
+       }
+}
index 1ca353ec0a2dc3d3decc86b2e152cd76ce27ce34..5e9cd65267123fa2edf7943a53c14e948086f23f 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.jusercore.model.user;
 
 import java.util.Calendar;
+import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
@@ -150,6 +151,20 @@ public class LoginUser implements User {
                this.setUserLocked(user.getUserLocked());
        }
 
+       @Override
+       public boolean equals (final Object object) {
+               if (object == null) {
+                       return false;
+               }
+               if (getClass() != object.getClass()) {
+                       return false;
+               }
+
+               final User other = (User) object;
+
+               return Objects.equals(this.getUserName(), other.getUserName());
+       }
+
        @Override
        public UserAccountStatus getUserAccountStatus () {
                return this.userAccountStatus;
@@ -229,4 +244,11 @@ public class LoginUser implements User {
        public void setUserName (final String userName) {
                this.userName = userName;
        }
+
+       @Override
+       public int hashCode () {
+               int hash = 5;
+               hash = 83 * hash + Objects.hashCode(this.getUserName());
+               return hash;
+       }
 }
index 51de6500feebeaadf8760a7f2227bcfb41cd65e1..8c3b1a0958f9cb40957d81a61d223bbd231d670c 100644 (file)
@@ -146,4 +146,22 @@ public interface User extends Serializable {
         * @param customerNumber User number
         */
        public void setUserName (final String customerNumber);
+
+       /**
+        * Checks if object is a User instance and whether it matches with this
+        * object.
+        * <p>
+        * @param object Object to be checked
+        * @return Whether it matches this object
+        */
+       @Override
+       public boolean equals (final Object object);
+
+       /**
+        * Hash code caluclation for this object
+        * <p>
+        * @return Hash code for this object
+        */
+       @Override
+       public int hashCode ();
 }