Clover coverage report - PMD - 3.3
Coverage timestamp: Thu Sep 15 2005 17:59:57 EDT
file stats: LOC: 153   Methods: 13
NCLOC: 76   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RuleSet.java 93.8% 96.9% 100% 96.7%
coverage coverage
 1    /**
 2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 3    */
 4    package net.sourceforge.pmd;
 5   
 6    import java.util.HashSet;
 7    import java.util.Iterator;
 8    import java.util.List;
 9    import java.util.Set;
 10   
 11    /**
 12    * This class represents a Set of rules.
 13    * @see Rule
 14    */
 15    public class RuleSet {
 16   
 17    private Set rules = new HashSet();
 18    private String name = "";
 19    private String description = "";
 20   
 21    /**
 22    * Returns the number of rules in this ruleset
 23    * @return an int representing the number of rules
 24    */
 25  6 public int size() {
 26  6 return rules.size();
 27    }
 28   
 29    /**
 30    * Add a new rule to this ruleset
 31    * @param rule the rule to be added
 32    */
 33  3412 public void addRule(Rule rule) {
 34  3412 if (rule == null) {
 35  0 throw new RuntimeException("Null Rule reference added to a RuleSet; that's a bug somewhere in PMD");
 36    }
 37  3412 rules.add(rule);
 38    }
 39   
 40    /**
 41    * Returns the actual Set of rules in this ruleset
 42    * @return a Set with the rules. All objects are of type {@link Rule}
 43    */
 44  25 public Set getRules() {
 45  25 return rules;
 46    }
 47   
 48    /**
 49    * @return true if any rule in the RuleSet needs the DFA layer
 50    */
 51  755 public boolean usesDFA() {
 52  755 for (Iterator i = rules.iterator(); i.hasNext();) {
 53  755 Rule r = (Rule) i.next();
 54  755 if (r.usesDFA()) {
 55  1 return true;
 56    }
 57    }
 58  754 return false;
 59    }
 60   
 61    /**
 62    * Returns the Rule with the given name
 63    *
 64    * @param ruleName the name of the rule to find
 65    * @return the rule or null if not found
 66    */
 67  180 public Rule getRuleByName(String ruleName) {
 68  180 Rule rule = null;
 69  180 for (Iterator i = rules.iterator(); i.hasNext() && (rule == null);) {
 70  1382 Rule r = (Rule) i.next();
 71  1382 if (r.getName().equals(ruleName)) {
 72  178 rule = r;
 73    }
 74    }
 75  180 return rule;
 76    }
 77   
 78    /**
 79    * Add a whole RuleSet to this RuleSet
 80    *
 81    * @param ruleSet the RuleSet to add
 82    */
 83  1 public void addRuleSet(RuleSet ruleSet) {
 84  1 rules.addAll(ruleSet.getRules());
 85    }
 86   
 87  754 public void apply(List acuList, RuleContext ctx) {
 88  754 Iterator rs = rules.iterator();
 89  754 while (rs.hasNext()) {
 90  753 Rule rule = (Rule) rs.next();
 91  753 rule.apply(acuList, ctx);
 92    }
 93    }
 94   
 95    /**
 96    * Gives the name of this ruleset
 97    *
 98    * @return a String representing the name
 99    */
 100  2621 public String getName() {
 101  2621 return name;
 102    }
 103   
 104    /**
 105    * Set the name of this ruleset
 106    *
 107    * @param name a String representing the name
 108    */
 109  201 public void setName(String name) {
 110  201 this.name = name;
 111    }
 112   
 113    /**
 114    * Gives the description of this ruleset
 115    *
 116    * @return a String representing the description
 117    */
 118  1 public String getDescription() {
 119  1 return description;
 120    }
 121   
 122    /**
 123    * Set the description of this ruleset
 124    *
 125    * @param description a String representing the description
 126    */
 127  194 public void setDescription(String description) {
 128  194 this.description = description;
 129    }
 130   
 131    /**
 132    * @see java.lang.Object#equals(java.lang.Object)
 133    */
 134  6 public boolean equals(Object o) {
 135  6 if ((o == null) || !(o instanceof RuleSet)) {
 136  2 return false; // Trivial
 137    }
 138   
 139  4 if (this == o) {
 140  1 return true; // Basic equality
 141    }
 142   
 143  3 RuleSet ruleSet = (RuleSet) o;
 144  3 return this.getName().equals(ruleSet.getName()) && this.getRules().equals(ruleSet.getRules());
 145    }
 146   
 147    /**
 148    * @see java.lang.Object#hashCode()
 149    */
 150  6 public int hashCode() {
 151  6 return this.getName().hashCode() + 13*this.getRules().hashCode();
 152    }
 153    }