From: Stephane Gamard Date: Wed, 2 Jul 2014 07:21:33 +0000 (+0200) Subject: fix quality flaws (equals and hashcode methods) X-Git-Tag: 4.4-RC1~22 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e1c887c19b3bb85448b4b693bd572bfe6ea64dd7;p=sonarqube.git fix quality flaws (equals and hashcode methods) --- diff --git a/sonar-server/src/main/java/org/sonar/server/search/FacetValue.java b/sonar-server/src/main/java/org/sonar/server/search/FacetValue.java index cffc5dc9fed..ab447a9db5c 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/FacetValue.java +++ b/sonar-server/src/main/java/org/sonar/server/search/FacetValue.java @@ -79,4 +79,26 @@ public class FacetValue implements Comparable { return this.getValue().compareTo(other.getValue()); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof FacetValue)) return false; + + FacetValue that = (FacetValue) o; + + if (!key.equals(that.key)) return false; + if (subFacets != null ? !subFacets.equals(that.subFacets) : that.subFacets != null) return false; + if (!value.equals(that.value)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = key.hashCode(); + result = 31 * result + value.hashCode(); + result = 31 * result + (subFacets != null ? subFacets.hashCode() : 0); + return result; + } } diff --git a/sonar-server/src/main/java/org/sonar/server/search/Hit.java b/sonar-server/src/main/java/org/sonar/server/search/Hit.java index e31ae2904b5..ef04a7ddd6b 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/Hit.java +++ b/sonar-server/src/main/java/org/sonar/server/search/Hit.java @@ -73,6 +73,28 @@ public class Hit implements Comparable { } } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Hit)) return false; + + Hit hit = (Hit) o; + + if (fields != null ? !fields.equals(hit.fields) : hit.fields != null) return false; + if (rank != null ? !rank.equals(hit.rank) : hit.rank != null) return false; + if (score != null ? !score.equals(hit.score) : hit.score != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = fields != null ? fields.hashCode() : 0; + result = 31 * result + (rank != null ? rank.hashCode() : 0); + result = 31 * result + (score != null ? score.hashCode() : 0); + return result; + } + public static Hit fromMap(Integer rank, Map fieldMap) { return fromMap(rank, new TreeMap(fieldMap)); }