From: Roland Haeder Date: Tue, 13 Oct 2015 07:00:34 +0000 (+0200) Subject: added new checked exception + equals()/hashCode() X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=289e38feca59e38cea1dfd36a81d3ed3052d6934;p=juser-activity-core.git added new checked exception + equals()/hashCode() Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/jusercore/exceptions/UserPasswordMismatchException.java b/src/org/mxchange/jusercore/exceptions/UserPasswordMismatchException.java new file mode 100644 index 0000000..195f2c5 --- /dev/null +++ b/src/org/mxchange/jusercore/exceptions/UserPasswordMismatchException.java @@ -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 . + */ +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. + *

+ * @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 + *

+ * @param user User instance + */ + public UserPasswordMismatchException (final User user) { + super(MessageFormat.format("Password for user {0} does not match stored password.", user)); + } +} diff --git a/src/org/mxchange/jusercore/model/user/LoginUser.java b/src/org/mxchange/jusercore/model/user/LoginUser.java index 1ca353e..5e9cd65 100644 --- a/src/org/mxchange/jusercore/model/user/LoginUser.java +++ b/src/org/mxchange/jusercore/model/user/LoginUser.java @@ -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; + } } diff --git a/src/org/mxchange/jusercore/model/user/User.java b/src/org/mxchange/jusercore/model/user/User.java index 51de650..8c3b1a0 100644 --- a/src/org/mxchange/jusercore/model/user/User.java +++ b/src/org/mxchange/jusercore/model/user/User.java @@ -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. + *

+ * @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 + *

+ * @return Hash code for this object + */ + @Override + public int hashCode (); }