From 17f4c4418978fac1a62fe962edbfbfcf14705a86 Mon Sep 17 00:00:00 2001 From: Philippe Herlin Date: Thu, 9 Jun 2005 22:21:39 +0000 Subject: [PATCH] Harden equality of RuleSet objects git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@3554 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 2 +- pmd/src/net/sourceforge/pmd/RuleSet.java | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index fc6e6bc163..44a64501f4 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -13,7 +13,7 @@ Fixed bug which caused MissingSerialVersionUID to trigger on all interfaces that Modified NullAssignmentRule to catch null assignments in ternary expressions. Added two new node types - ASTCatchStatement and ASTFinallyStatement. Modified rule XML definition; it no longer includes a symboltable attribute. -Harden equality of AbstractRule objects (needed for the Eclipse plugin features) +Harden equality of AbstractRule and RuleSet objects (needed for the Eclipse plugin features) May 10, 2005 - 3.1: New rules: SimplifyStartsWith, UnnecessaryParentheses, CollapsibleIfStatements, UseAssertEqualsInsteadOfAssertTrue, UseAssertSameInsteadOfAssertTrue, UseStringBufferForStringAppends, SimplifyConditional, SingularField diff --git a/pmd/src/net/sourceforge/pmd/RuleSet.java b/pmd/src/net/sourceforge/pmd/RuleSet.java index 780a1af2f6..408558fe60 100644 --- a/pmd/src/net/sourceforge/pmd/RuleSet.java +++ b/pmd/src/net/sourceforge/pmd/RuleSet.java @@ -124,4 +124,27 @@ public class RuleSet { public void setDescription(String description) { this.description = description; } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object o) { + if ((o == null) || !(o instanceof RuleSet)) { + return false; // Trivial + } + + if (this == o) { + return true; // Basic equality + } + + RuleSet ruleSet = (RuleSet) o; + return this.getName().equals(ruleSet.getName()) && this.getRules().equals(ruleSet.getRules()); + } + + /** + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return this.getName().hashCode() + 13*this.getRules().hashCode(); + } }