Clover coverage report - PMD - 3.7
Coverage timestamp: Wed May 31 2006 09:25:59 EDT

file stats: | LOC: | 173 |  | Methods: | 15
| NCLOC: | 83 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

RuleSet.java

93.8%

97.1%

100%

96.9%

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.ArrayList;
7 |  | import java.util.Collection;
8 |  | import java.util.Iterator;
9 |  | import java.util.List;
10 |  |
11 |  |
12 |  | /**
13 |  | * This class represents a collectin of rules.
14 |  | *
15 |  | * @see Rule
16 |  | */
17 |  | public class RuleSet {
18 |  |
19 |  | private List rules = new ArrayList();
20 |  | private String name = "";
21 |  | private String description = "";
22 |  | private Language language;
23 |  |
24 |  | /**
25 |  | * Returns the number of rules in this ruleset
26 |  | *
27 |  | * @return an int representing the number of rules
28 |  | */
29 | 8 | public int size() {
30 | 8 | return rules.size();
31 |  | }
32 |  |
33 |  | /**
34 |  | * Add a new rule to this ruleset
35 |  | *
36 |  | * @param rule the rule to be added
37 |  | */
38 | 5229 | public void addRule(Rule rule) {
39 | 5229 | if (rule == null) {
40 | 0 | throw new RuntimeException("Null Rule reference added to a RuleSet; that's a bug somewhere in PMD");
41 |  | }
42 | 5229 | rules.add(rule);
43 |  | }
44 |  |
45 |  | /**
46 |  | * Returns the actual Collection of rules in this ruleset
47 |  | *
48 |  | * @return a Collection with the rules. All objects are of type {@link Rule}
49 |  | */
50 | 26 | public Collection getRules() {
51 | 26 | return rules;
52 |  | }
53 |  |
54 |  | /**
55 |  | * @return true if any rule in the RuleSet needs the DFA layer
56 |  | */
57 | 1057 | public boolean usesDFA() {
58 | 1057 | for (Iterator i = rules.iterator(); i.hasNext();) {
59 | 1057 | Rule r = (Rule) i.next();
60 | 1057 | if (r.usesDFA()) {
61 | 1 | return true;
62 |  | }
63 |  | }
64 | 1056 | return false;
65 |  | }
66 |  |
67 |  | /**
68 |  | * Returns the Rule with the given name
69 |  | *
70 |  | * @param ruleName the name of the rule to find
71 |  | * @return the rule or null if not found
72 |  | */
73 | 236 | public Rule getRuleByName(String ruleName) {
74 | 236 | Rule rule = null;
75 | 236 | for (Iterator i = rules.iterator(); i.hasNext() && (rule == null);) {
76 | 2049 | Rule r = (Rule) i.next();
77 | 2049 | if (r.getName().equals(ruleName)) {
78 | 234 | rule = r;
79 |  | }
80 |  | }
81 | 236 | return rule;
82 |  | }
83 |  |
84 |  | /**
85 |  | * Add a whole RuleSet to this RuleSet
86 |  | *
87 |  | * @param ruleSet the RuleSet to add
88 |  | */
89 | 2 | public void addRuleSet(RuleSet ruleSet) {
90 | 2 | rules.addAll(rules.size(), ruleSet.getRules());
91 |  | }
92 |  |
93 | 1056 | public void apply(List acuList, RuleContext ctx) {
94 | 1056 | Iterator rs = rules.iterator();
95 | 1056 | while (rs.hasNext()) {
96 | 1055 | Rule rule = (Rule) rs.next();
97 | 1055 | rule.apply(acuList, ctx);
98 |  | }
99 |  | }
100 |  |
101 |  | /**
102 |  | * Gives the name of this ruleset
103 |  | *
104 |  | * @return a String representing the name
105 |  | */
106 | 4131 | public String getName() {
107 | 4131 | return name;
108 |  | }
109 |  |
110 |  | /**
111 |  | * Set the name of this ruleset
112 |  | *
113 |  | * @param name a String representing the name
114 |  | */
115 | 259 | public void setName(String name) {
116 | 259 | this.name = name;
117 |  | }
118 |  |
119 |  | /**
120 |  | * Gives the description of this ruleset
121 |  | *
122 |  | * @return a String representing the description
123 |  | */
124 | 1 | public String getDescription() {
125 | 1 | return description;
126 |  | }
127 |  |
128 |  | /**
129 |  | * Set the description of this ruleset
130 |  | *
131 |  | * @param description a String representing the description
132 |  | */
133 | 251 | public void setDescription(String description) {
134 | 251 | this.description = description;
135 |  | }
136 |  |
137 |  | /**
138 |  | * @see java.lang.Object#equals(java.lang.Object)
139 |  | */
140 | 6 | public boolean equals(Object o) {
141 | 6 | if ((o == null) || !(o instanceof RuleSet)) {
142 | 2 | return false; // Trivial
143 |  | }
144 |  |
145 | 4 | if (this == o) {
146 | 1 | return true; // Basic equality
147 |  | }
148 |  |
149 | 3 | RuleSet ruleSet = (RuleSet) o;
150 | 3 | return this.getName().equals(ruleSet.getName()) && this.getRules().equals(ruleSet.getRules());
151 |  | }
152 |  |
153 |  | /**
154 |  | * @see java.lang.Object#hashCode()
155 |  | */
156 | 6 | public int hashCode() {
157 | 6 | return this.getName().hashCode() + 13 * this.getRules().hashCode();
158 |  | }
159 |  |
160 |  | /**
161 |  | * @return Returns the language.
162 |  | */
163 | 2110 | public Language getLanguage() {
164 | 2110 | return language;
165 |  | }
166 |  |
167 |  | /**
168 |  | * @param language The language to set.
169 |  | */
170 | 1303 | public void setLanguage(Language language) {
171 | 1303 | this.language = language;
172 |  | }
173 |  | }