use google guava for hasCode, toString and equals method of user

This commit is contained in:
Sebastian Sdorra
2012-02-26 19:21:23 +01:00
parent 280b222a0a
commit 723b73112c

View File

@@ -35,6 +35,8 @@ package sonia.scm.user;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Objects;
import sonia.scm.BasicPropertiesAware; import sonia.scm.BasicPropertiesAware;
import sonia.scm.ModelObject; import sonia.scm.ModelObject;
import sonia.scm.util.Util; import sonia.scm.util.Util;
@@ -209,61 +211,14 @@ public class User extends BasicPropertiesAware implements Principal, ModelObject
final User other = (User) obj; final User other = (User) obj;
if (this.admin != other.admin) return Objects.equal(name, other.name)
{ && Objects.equal(displayName, other.displayName)
return false; && Objects.equal(mail, other.mail)
} && Objects.equal(type, other.type)
&& Objects.equal(admin, other.admin)
if ((this.creationDate != other.creationDate) && Objects.equal(password, other.password)
&& ((this.creationDate == null) && Objects.equal(creationDate, other.creationDate)
||!this.creationDate.equals(other.creationDate))) && Objects.equal(lastModified, other.lastModified);
{
return false;
}
if ((this.displayName == null)
? (other.displayName != null)
: !this.displayName.equals(other.displayName))
{
return false;
}
if ((this.lastModified != other.lastModified)
&& ((this.lastModified == null)
||!this.lastModified.equals(other.lastModified)))
{
return false;
}
if ((this.mail == null)
? (other.mail != null)
: !this.mail.equals(other.mail))
{
return false;
}
if ((this.name == null)
? (other.name != null)
: !this.name.equals(other.name))
{
return false;
}
if ((this.password == null)
? (other.password != null)
: !this.password.equals(other.password))
{
return false;
}
if ((this.type == null)
? (other.type != null)
: !this.type.equals(other.type))
{
return false;
}
return true;
} }
/** /**
@@ -275,34 +230,35 @@ public class User extends BasicPropertiesAware implements Principal, ModelObject
@Override @Override
public int hashCode() public int hashCode()
{ {
int hash = 3; return Objects.hashCode(name, displayName, mail, type, admin, password,
creationDate, lastModified);
}
hash = 37 * hash + (this.admin /**
? 1 * Method description
: 0); *
hash = 37 * hash + ((this.creationDate != null) *
? this.creationDate.hashCode() * @return
: 0); */
hash = 37 * hash + ((this.displayName != null) @Override
? this.displayName.hashCode() public String toString()
: 0); {
hash = 37 * hash + ((this.lastModified != null) String pwd = (password != null)
? this.lastModified.hashCode() ? "(is set)"
: 0); : "(not set)";
hash = 37 * hash + ((this.mail != null)
? this.mail.hashCode()
: 0);
hash = 37 * hash + ((this.name != null)
? this.name.hashCode()
: 0);
hash = 37 * hash + ((this.password != null)
? this.password.hashCode()
: 0);
hash = 37 * hash + ((this.type != null)
? this.type.hashCode()
: 0);
return hash; //J-
return Objects.toStringHelper(this)
.add("name", name)
.add("displayName",displayName)
.add("mail", mail)
.add("password", pwd)
.add("admin", admin)
.add("type", type)
.add("creationDate", creationDate)
.add("lastModified", lastModified)
.toString();
//J+
} }
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------