use google guava for hasCode, toString and equals method of group object

This commit is contained in:
Sebastian Sdorra
2012-02-26 19:33:24 +01:00
parent 723b73112c
commit 4ef02e8600

View File

@@ -35,6 +35,8 @@ package sonia.scm.group;
//~--- 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;
@@ -210,48 +212,12 @@ public class Group extends BasicPropertiesAware
final Group other = (Group) obj; final Group other = (Group) obj;
if ((this.creationDate != other.creationDate) return Objects.equal(name, other.name)
&& ((this.creationDate == null) && Objects.equal(description, other.description)
||!this.creationDate.equals(other.creationDate))) && Objects.equal(members, other.members)
{ && Objects.equal(type, other.type)
return false; && Objects.equal(creationDate, other.creationDate)
} && Objects.equal(lastModified, lastModified);
if ((this.description == null)
? (other.description != null)
: !this.description.equals(other.description))
{
return false;
}
if ((this.lastModified != other.lastModified)
&& ((this.lastModified == null)
||!this.lastModified.equals(other.lastModified)))
{
return false;
}
if ((this.members != other.members)
&& ((this.members == null) ||!this.members.equals(other.members)))
{
return false;
}
if ((this.name == null)
? (other.name != null)
: !this.name.equals(other.name))
{
return false;
}
if ((this.type == null)
? (other.type != null)
: !this.type.equals(other.type))
{
return false;
}
return true;
} }
/** /**
@@ -263,28 +229,8 @@ public class Group extends BasicPropertiesAware
@Override @Override
public int hashCode() public int hashCode()
{ {
int hash = 7; return Objects.hashCode(name, description, members, type, creationDate,
lastModified);
hash = 73 * hash + ((this.creationDate != null)
? this.creationDate.hashCode()
: 0);
hash = 73 * hash + ((this.description != null)
? this.description.hashCode()
: 0);
hash = 73 * hash + ((this.lastModified != null)
? this.lastModified.hashCode()
: 0);
hash = 73 * hash + ((this.members != null)
? this.members.hashCode()
: 0);
hash = 73 * hash + ((this.name != null)
? this.name.hashCode()
: 0);
hash = 73 * hash + ((this.type != null)
? this.type.hashCode()
: 0);
return hash;
} }
/** /**
@@ -321,26 +267,16 @@ public class Group extends BasicPropertiesAware
@Override @Override
public String toString() public String toString()
{ {
StringBuilder msg = new StringBuilder(); //J-
return Objects.toStringHelper(this)
msg.append(name).append(" ["); .add("name", name)
.add("description", description)
if (Util.isNotEmpty(members)) .add("members", members)
{ .add("type", type)
Iterator<String> it = members.iterator(); .add("creationDate", creationDate)
.add("lastModified", lastModified)
while (it.hasNext()) .toString();
{ //J+
msg.append(it.next());
if (it.hasNext())
{
msg.append(",");
}
}
}
return msg.append("]").toString();
} }
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------