KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > csdl > jblanket > report > element > MethodSetElement


1 package csdl.jblanket.report.element;
2
3 import java.io.PrintWriter JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.Set JavaDoc;
6 import java.util.TreeSet JavaDoc;
7
8 /**
9  * Provides a wrapper for the 'MethodSet' element in the aggregate XML file. An instance of a
10  * MethodSetElement represents elements in a MethodSet.
11  * <p>
12  * An example of a 'MethodSet' as a MethodSetElement with no methods:
13  * <pre>
14  * &lt;MethodSet class="String" package="java.lang" tested="0" untested="0" oneline="0"
15  * constructor="0" excludedindividual="0" timestamp=""/&gt;
16  * </pre>
17  * <p>
18  * An example of a 'MethodSet' as a MethodSetElement with methods:
19  * <pre>
20  * &lt;MethodSet class="String" package="java.lang" tested="1" untested="0" oneline="0"
21  * constructor="0" timestamp=""&gt;
22  * &lt;tested&gt;
23  * &lt;Method name="indexOf" package="java.lang.String"&gt;
24  * &lt;Parameter type="java.lang.String"/&gt;
25  * &lt;Parameter type="int"/&gt;
26  * &lt;/Method&gt;
27  * &lt;/tested&gt;
28  * &lt;untested/&gt;
29  * &lt;oneline/&gt;
30  * &lt;constructor/&gt;
31  * &lt;ecludedindividual/&gt;
32  * &lt;/MethodSet&gt;
33  * </pre>
34  * <p>
35  * Note that the <code>excluded individual methods</code> take priority over all the other
36  * categories of methods. I.e., if a one-line method was individually excluded by the application,
37  * then it is considered to be an individually excluded methods instead of a one-line method.
38  *
39  * @author Joy M. Agustin
40  * @version $Id: MethodSetElement.java,v 1.2 2004/11/07 08:53:26 timshadel Exp $
41  */

42 public class MethodSetElement implements Comparable JavaDoc {
43   
44   /** Name of the class */
45   private String JavaDoc className;
46   /** Name of the package className belongs to */
47   private String JavaDoc packageName;
48
49   /** Timestamp */
50   private String JavaDoc timeStamp;
51
52   /** Set of all methods tested */
53   private Set JavaDoc testedMethodSet;
54   /** Set of all methods untested */
55   private Set JavaDoc untestedMethodSet;
56   /** Set of all methods untestable */
57   private Set JavaDoc untestableMethodSet;
58   /** Set of all one-line methods */
59   private Set JavaDoc onelineMethodSet;
60   /** Set of all constructors */
61   private Set JavaDoc constructorMethodSet;
62   /** Set of all individually excluded methods */
63   private Set JavaDoc excludedIndividualMethodSet;
64
65   /**
66    * Constructs a new MethodSetElement object.
67    *
68    * @param className the name of the class.
69    * @param packageName the name of the package <code>className</code> belongs to.
70    */

71   public MethodSetElement(String JavaDoc packageName, String JavaDoc className) {
72
73     this.packageName = packageName;
74     this.className = className;
75
76     this.testedMethodSet = new TreeSet JavaDoc();
77     this.untestedMethodSet = new TreeSet JavaDoc();
78     this.untestableMethodSet = new TreeSet JavaDoc();
79     this.onelineMethodSet = new TreeSet JavaDoc();
80     this.constructorMethodSet = new TreeSet JavaDoc();
81     this.excludedIndividualMethodSet = new TreeSet JavaDoc();
82   }
83
84   /**
85    * Returns the name of the package of this MethodSetElement object.
86    *
87    * @return the name of the package of this MethodSetElement object.
88    */

89   public String JavaDoc getPackageName() {
90     return this.packageName;
91   }
92   
93   /**
94    * Returns the name of the class of this MethodSetElement object.
95    *
96    * @return the name of the class of this MethodSetElement object.
97    */

98   public String JavaDoc getClassName() {
99     return this.className;
100   }
101
102   /**
103    * Returns the number of tested methods.
104    *
105    * @return the number of tested methods.
106    */

107   public int getTestedSize() {
108     return this.testedMethodSet.size();
109   }
110
111   /**
112    * Returns the number of untested methods.
113    *
114    * @return the number of untested methods.
115    */

116   public int getUntestedSize() {
117     return this.untestedMethodSet.size();
118   }
119   
120   /**
121    * Returns the number of untested methods.
122    *
123    * @return the number of untested methods.
124    */

125   public int getUntestableSize() {
126     return this.untestableMethodSet.size();
127   }
128   
129   /**
130    * Returns the number of one-line methods.
131    *
132    * @return the number of one-line methods.
133    */

134   public int getOnelineSize() {
135     return this.onelineMethodSet.size();
136   }
137   
138   /**
139    * Returns the number of constructors.
140    *
141    * @return the number of constructors.
142    */

143   public int getConstructorSize() {
144     return this.constructorMethodSet.size();
145   }
146   
147   /**
148    * Returns the number of individually excluded methods.
149    *
150    * @return the number of individually excluded methods.
151    */

152   public int getExcludedIndividualSize() {
153     return this.excludedIndividualMethodSet.size();
154   }
155
156   /**
157    * Adds the timeStamp from the file this MethodSetElement came from.
158    *
159    * @param timeStamp the timeStamp from the file this MethodSetElement came from.
160    */

161   public void setTimeStamp(String JavaDoc timeStamp) {
162     this.timeStamp = timeStamp;
163   }
164   
165   /**
166    * Adds a method to the set of tested methods.
167    *
168    * @param method the MethodElement representation of a tested method.
169    */

170   public void addTestMethod(MethodElement method) {
171     
172     // need to check if method already added because no control over order of category processing
173
if (!this.excludedIndividualMethodSet.contains(method)) {
174       this.testedMethodSet.add(method);
175     }
176   }
177   
178   /**
179    * Adds a method to the set of untested methods.
180    *
181    * @param method the MethodElement representation of an untested method.
182    */

183   public void addUntestMethod(MethodElement method) {
184
185     // need to check if method already added because no control over order of category processing
186
if (!this.excludedIndividualMethodSet.contains(method)) {
187       this.untestedMethodSet.add(method);
188     }
189   }
190
191   /**
192    * Adds a method to the set of untested methods.
193    *
194    * @param method the MethodElement representation of an untested method.
195    */

196   public void addUntestableMethod(MethodElement method) {
197
198     // need to check if method already added because no control over order of category processing
199
if (!this.excludedIndividualMethodSet.contains(method)) {
200       this.untestableMethodSet.add(method);
201     }
202   }
203
204   /**
205    * Adds a method to the set of one-line methods.
206    *
207    * @param method the MethodElement representation of a one-line method.
208    */

209   public void addOneLineMethod(MethodElement method) {
210
211     // need to check if method already added because no control over order of category processing
212
if (!this.excludedIndividualMethodSet.contains(method)) {
213       this.onelineMethodSet.add(method);
214     }
215   }
216
217   /**
218    * Adds a method to the set of constructors.
219    *
220    * @param method the MethodElement representation of a constructor.
221    */

222   public void addConstructorMethod(MethodElement method) {
223
224     // need to check if method already added because no control over order of category processing
225
if (!this.excludedIndividualMethodSet.contains(method)) {
226       this.constructorMethodSet.add(method);
227     }
228   }
229   
230   /**
231    * Adds a method to the set of constructors.
232    *
233    * @param method the MethodElement representation of a constructor.
234    */

235   public void addExcludedIndividualMethod(MethodElement method) {
236     this.excludedIndividualMethodSet.add(method);
237     
238     // remove collisions with other *MethodSets
239
this.testedMethodSet.remove(method);
240     this.untestedMethodSet.remove(method);
241     this.onelineMethodSet.remove(method);
242     this.constructorMethodSet.remove(method);
243   }
244
245   /**
246    * Returns a String representation of this MethodSetElement as found in an aggregate XML file.
247    *
248    * @return a String representation of this MethodSetElement.
249    */

250   public String JavaDoc toString() {
251     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
252     buffer.append(" <MethodSet name=\"" + this.className + "\"");
253     buffer.append(" package=\"" + this.packageName + "\"");
254     buffer.append(" tested=\"" + this.testedMethodSet.size() + "\"");
255     buffer.append(" untested=\"" + this.untestedMethodSet.size() + "\"");
256     buffer.append(" untestable=\"" + this.untestableMethodSet.size() + "\"");
257     buffer.append(" oneline=\"" + this.onelineMethodSet.size() + "\"");
258     buffer.append(" constructor=\"" + this.constructorMethodSet.size() + "\"");
259     buffer.append(" excludedindividual=\"" + this.excludedIndividualMethodSet.size() + "\"");
260     buffer.append(" timestamp=\"" + this.timeStamp + "\" >\n");
261
262     if (this.testedMethodSet.size() > 0) {
263       buffer.append(" <tested>\n");
264       for (Iterator JavaDoc i = this.testedMethodSet.iterator(); i.hasNext(); ) {
265         buffer.append("" + i.next() + "\n");
266       }
267       buffer.append(" </tested>\n");
268     }
269     else {
270       buffer.append(" <tested/>\n");
271     }
272
273     if (this.untestedMethodSet.size() > 0) {
274       buffer.append(" <untested>\n");
275       for (Iterator JavaDoc i = this.untestedMethodSet.iterator(); i.hasNext(); ) {
276         buffer.append("" + i.next() + "\n");
277       }
278       buffer.append(" </untested>\n");
279     }
280     else {
281       buffer.append(" <untested/>\n");
282     }
283
284     if (this.untestedMethodSet.size() > 0) {
285         buffer.append(" <untestable>\n");
286         for (Iterator JavaDoc i = this.untestableMethodSet.iterator(); i.hasNext(); ) {
287           buffer.append("" + i.next() + "\n");
288         }
289         buffer.append(" </untestable>\n");
290       }
291       else {
292         buffer.append(" <untestable/>\n");
293       }
294
295     if (this.onelineMethodSet.size() > 0) {
296       buffer.append(" <oneline>\n");
297       for (Iterator JavaDoc i = this.onelineMethodSet.iterator(); i.hasNext(); ) {
298         buffer.append("" + i.next() + "\n");
299       }
300       buffer.append(" </oneline>\n");
301     }
302     else {
303       buffer.append(" <oneline/>\n");
304     }
305
306     if (this.constructorMethodSet.size() > 0) {
307       buffer.append(" <constructor>\n");
308       for (Iterator JavaDoc i = this.constructorMethodSet.iterator(); i.hasNext(); ) {
309         buffer.append("" + i.next() + "\n");
310       }
311       buffer.append(" </constructor>\n");
312     }
313     else {
314       buffer.append(" <constructor/>\n");
315     }
316
317     if (this.excludedIndividualMethodSet.size() > 0) {
318       buffer.append(" <excludedindividual>\n");
319       for (Iterator JavaDoc i = this.excludedIndividualMethodSet.iterator(); i.hasNext(); ) {
320         buffer.append("" + i.next() + "\n");
321       }
322       buffer.append(" </excludedindividual>\n");
323     }
324     else {
325       buffer.append(" <excludedindividual/>\n");
326     }
327
328     buffer.append(" </MethodSet>");
329
330     return buffer.toString();
331   }
332
333   /**
334    * Writes this MethodSetElement to writer.
335    *
336    * @param writer points to an output file.
337    */

338   public void write(PrintWriter JavaDoc writer) {
339     
340     writer.write(" <MethodSet name=\"" + this.className + "\"");
341     writer.write(" package=\"" + this.packageName + "\"");
342     writer.write(" tested=\"" + this.testedMethodSet.size() + "\"");
343     writer.write(" untested=\"" + this.untestedMethodSet.size() + "\"");
344     writer.write(" untestable=\"" + this.untestableMethodSet.size() + "\"");
345     writer.write(" oneline=\"" + this.onelineMethodSet.size() + "\"");
346     writer.write(" constructor=\"" + this.constructorMethodSet.size() + "\"");
347     writer.write(" excludedindividual=\"" + this.excludedIndividualMethodSet.size() + "\"");
348     writer.write(" timestamp=\"" + this.timeStamp + "\" >\n");
349
350     if (this.testedMethodSet.size() > 0) {
351       writer.write(" <tested>\n");
352       for (Iterator JavaDoc i = this.testedMethodSet.iterator(); i.hasNext(); ) {
353         writer.write("" + i.next() + "\n");
354       }
355       writer.write(" </tested>\n");
356     }
357     else {
358       writer.write(" <tested/>\n");
359     }
360
361     if (this.untestedMethodSet.size() > 0) {
362       writer.write(" <untested>\n");
363       for (Iterator JavaDoc i = this.untestedMethodSet.iterator(); i.hasNext(); ) {
364         writer.write("" + i.next() + "\n");
365       }
366       writer.write(" </untested>\n");
367     }
368     else {
369       writer.write(" <untested/>\n");
370     }
371
372     if (this.untestableMethodSet.size() > 0) {
373         writer.write(" <untestable>\n");
374         for (Iterator JavaDoc i = this.untestableMethodSet.iterator(); i.hasNext(); ) {
375           writer.write("" + i.next() + "\n");
376         }
377         writer.write(" </untestable>\n");
378       }
379       else {
380         writer.write(" <untestable/>\n");
381       }
382
383     if (this.onelineMethodSet.size() > 0) {
384       writer.write(" <oneline>\n");
385       for (Iterator JavaDoc i = this.onelineMethodSet.iterator(); i.hasNext(); ) {
386         writer.write("" + i.next() + "\n");
387       }
388       writer.write(" </oneline>\n");
389     }
390     else {
391       writer.write(" <oneline/>\n");
392     }
393
394     if (this.constructorMethodSet.size() > 0) {
395       writer.write(" <constructor>\n");
396       for (Iterator JavaDoc i = this.constructorMethodSet.iterator(); i.hasNext(); ) {
397         writer.write("" + i.next() + "\n");
398       }
399       writer.write(" </constructor>\n");
400     }
401     else {
402       writer.write(" <constructor/>\n");
403     }
404
405     if (this.excludedIndividualMethodSet.size() > 0) {
406       writer.write(" <excludedindividual>\n");
407       for (Iterator JavaDoc i = this.excludedIndividualMethodSet.iterator(); i.hasNext(); ) {
408         writer.write("" + i.next() + "\n");
409       }
410       writer.write(" </excludedindividual>\n");
411     }
412     else {
413       writer.write(" <excludedindividual/>\n");
414     }
415
416     writer.write(" </MethodSet>");
417   }
418
419   /**
420    * Compares this MethodSetElement object to <code>obj</code>.
421    *
422    * @param obj the MethodSetElement object to compare to.
423    * @return negative integer if this MethodSetElement object comes before <code>obj</code>, zero
424    * if this MethodSetElement object is equal to <code>obj</code>, or positive integer if
425    * <code>obj</code> comes before this MethodSetElement object.
426    */

427   public int compareTo(Object JavaDoc obj) {
428
429     if (this.packageName.compareTo(((MethodSetElement) obj).getPackageName()) != 0) {
430       return this.packageName.compareTo(((MethodSetElement) obj).getPackageName());
431     }
432     else {
433       return this.className.compareTo(((MethodSetElement) obj).getClassName());
434     }
435   }
436 }
Popular Tags