From ee23861add1ca9053e5e2f0c8e21ae2cd0aef360 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Fri, 4 Jan 2013 20:59:39 +0100 Subject: [PATCH] improve equals, hashCode and toString of plugin information class --- .../sonia/scm/plugin/PluginCondition.java | 60 +++++++ .../sonia/scm/plugin/PluginInformation.java | 165 +++++------------- 2 files changed, 104 insertions(+), 121 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/plugin/PluginCondition.java b/scm-core/src/main/java/sonia/scm/plugin/PluginCondition.java index 1548312a90..8fab066523 100644 --- a/scm-core/src/main/java/sonia/scm/plugin/PluginCondition.java +++ b/scm-core/src/main/java/sonia/scm/plugin/PluginCondition.java @@ -35,6 +35,8 @@ package sonia.scm.plugin; //~--- non-JDK imports -------------------------------------------------------- +import com.google.common.base.Objects; + import sonia.scm.PlatformType; import sonia.scm.SCMContext; import sonia.scm.util.SystemUtil; @@ -111,6 +113,64 @@ public class PluginCondition implements Cloneable, Serializable return clone; } + /** + * Method description + * + * + * @param obj + * + * @return + */ + @Override + public boolean equals(Object obj) + { + if (obj == null) + { + return false; + } + + if (getClass() != obj.getClass()) + { + return false; + } + + final PluginCondition other = (PluginCondition) obj; + + return Objects.equal(arch, other.arch) + && Objects.equal(minVersion, other.minVersion) + && Objects.equal(os, other.os); + } + + /** + * Method description + * + * + * @return + */ + @Override + public int hashCode() + { + return Objects.hashCode(arch, minVersion, os); + } + + /** + * Method description + * + * + * @return + */ + @Override + public String toString() + { + //J- + return Objects.toStringHelper(this) + .add("arch", arch) + .add("minVersion", minVersion) + .add("os", os) + .toString(); + //J+ + } + //~--- get methods ---------------------------------------------------------- /** diff --git a/scm-core/src/main/java/sonia/scm/plugin/PluginInformation.java b/scm-core/src/main/java/sonia/scm/plugin/PluginInformation.java index e67fe65dfb..0ce0bbfcd8 100644 --- a/scm-core/src/main/java/sonia/scm/plugin/PluginInformation.java +++ b/scm-core/src/main/java/sonia/scm/plugin/PluginInformation.java @@ -35,6 +35,8 @@ package sonia.scm.plugin; //~--- non-JDK imports -------------------------------------------------------- +import com.google.common.base.Objects; + import sonia.scm.Validateable; import sonia.scm.util.Util; @@ -127,88 +129,20 @@ public class PluginInformation implements Validateable, Cloneable, Serializable final PluginInformation other = (PluginInformation) obj; - if ((this.artifactId == null) - ? (other.artifactId != null) - : !this.artifactId.equals(other.artifactId)) - { - return false; - } - - if ((this.author == null) - ? (other.author != null) - : !this.author.equals(other.author)) - { - return false; - } - - if ((this.category == null) - ? (other.category != null) - : !this.category.equals(other.category)) - { - return false; - } - - if ((this.condition != other.condition) - && ((this.condition == null) ||!this.condition.equals(other.condition))) - { - return false; - } - - if ((this.description == null) - ? (other.description != null) - : !this.description.equals(other.description)) - { - return false; - } - - if ((this.groupId == null) - ? (other.groupId != null) - : !this.groupId.equals(other.groupId)) - { - return false; - } - - if ((this.name == null) - ? (other.name != null) - : !this.name.equals(other.name)) - { - return false; - } - - if ((this.screenshots != other.screenshots) - && ((this.screenshots == null) - ||!this.screenshots.equals(other.screenshots))) - { - return false; - } - - if (this.state != other.state) - { - return false; - } - - if ((this.url == null) - ? (other.url != null) - : !this.url.equals(other.url)) - { - return false; - } - - if ((this.version == null) - ? (other.version != null) - : !this.version.equals(other.version)) - { - return false; - } - - if ((this.wiki == null) - ? (other.wiki != null) - : !this.wiki.equals(other.wiki)) - { - return false; - } - - return true; + //J- + return Objects.equal(artifactId, other.artifactId) + && Objects.equal(author, other.author) + && Objects.equal(category, other.category) + && Objects.equal(condition, other.condition) + && Objects.equal(description, other.description) + && Objects.equal(groupId, other.groupId) + && Objects.equal(name, other.name) + && Objects.equal(screenshots, other.screenshots) + && Objects.equal(state, other.state) + && Objects.equal(url, other.url) + && Objects.equal(version, other.version) + && Objects.equal(wiki, other.wiki); + //J+ } /** @@ -220,46 +154,35 @@ public class PluginInformation implements Validateable, Cloneable, Serializable @Override public int hashCode() { - int hash = 5; + return Objects.hashCode(artifactId, author, category, condition, + description, groupId, name, screenshots, state, url, version, wiki); + } - hash = 79 * hash + ((this.artifactId != null) - ? this.artifactId.hashCode() - : 0); - hash = 79 * hash + ((this.author != null) - ? this.author.hashCode() - : 0); - hash = 79 * hash + ((this.category != null) - ? this.category.hashCode() - : 0); - hash = 79 * hash + ((this.condition != null) - ? this.condition.hashCode() - : 0); - hash = 79 * hash + ((this.description != null) - ? this.description.hashCode() - : 0); - hash = 79 * hash + ((this.groupId != null) - ? this.groupId.hashCode() - : 0); - hash = 79 * hash + ((this.name != null) - ? this.name.hashCode() - : 0); - hash = 79 * hash + ((this.screenshots != null) - ? this.screenshots.hashCode() - : 0); - hash = 79 * hash + ((this.state != null) - ? this.state.hashCode() - : 0); - hash = 79 * hash + ((this.url != null) - ? this.url.hashCode() - : 0); - hash = 79 * hash + ((this.version != null) - ? this.version.hashCode() - : 0); - hash = 79 * hash + ((this.wiki != null) - ? this.wiki.hashCode() - : 0); - - return hash; + /** + * Method description + * + * + * @return + */ + @Override + public String toString() + { + //J- + return Objects.toStringHelper(this) + .add("artifactId", artifactId) + .add("author", author) + .add("category", category) + .add("condition", condition) + .add("description", description) + .add("groupId", groupId) + .add("name", name) + .add("screenshots", screenshots) + .add("state", state) + .add("url", url) + .add("version", version) + .add("wiki", wiki) + .toString(); + //J+ } //~--- get methods ----------------------------------------------------------