From ae5bf064b6a59b81263d83a28e9d0462c7e26c65 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Tue, 15 Mar 2011 13:22:37 +0300 Subject: [PATCH] SONAR-2228 Fix equals and hashCode for ActiveRuleParam --- .../org/sonar/api/rules/ActiveRuleParam.java | 24 +++++++++---------- .../java/org/sonar/api/rules/RuleParam.java | 24 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleParam.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleParam.java index 56526ba2e9d..260c854603a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleParam.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleParam.java @@ -19,16 +19,19 @@ */ package org.sonar.api.rules; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; - -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; @Entity @Table(name = "active_rule_parameters") public class ActiveRuleParam implements Cloneable { - @Id @Column(name = "id") @GeneratedValue @@ -112,22 +115,19 @@ public class ActiveRuleParam implements Cloneable { @Override public boolean equals(Object obj) { - if (!(obj instanceof RuleParam)) { + if (!(obj instanceof ActiveRuleParam)) { return false; } if (this == obj) { return true; } - RuleParam other = (RuleParam) obj; - return new EqualsBuilder() - .append(getId(), other.getKey()).isEquals(); + ActiveRuleParam other = (ActiveRuleParam) obj; + return other.getKey().equals(getKey()); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(getId()) - .toHashCode(); + return getKey().hashCode(); } @Override diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleParam.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleParam.java index 5afc350344d..edb6690aef7 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleParam.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleParam.java @@ -20,11 +20,16 @@ package org.sonar.api.rules; import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; @Entity @Table(name = "rules_parameters") @@ -110,14 +115,14 @@ public class RuleParam { } public Boolean getDefaultValueAsBoolean() { - if (defaultValue!=null) { + if (defaultValue != null) { return Boolean.parseBoolean(defaultValue); } return null; } public Integer getDefaultValueAsInteger() { - if (defaultValue!=null) { + if (defaultValue != null) { return Integer.parseInt(defaultValue); } return null; @@ -137,17 +142,12 @@ public class RuleParam { return true; } RuleParam other = (RuleParam) obj; - return new EqualsBuilder() - //.append(rule, other.getRule()) - .append(key, other.getKey()).isEquals(); + return other.key.equals(key); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - //.append(rule) - .append(key) - .toHashCode(); + return key.hashCode(); } @Override -- 2.39.5