001: package csdl.jblanket.report.element;
002:
003: import java.io.PrintWriter;
004: import java.util.Iterator;
005: import java.util.Set;
006: import java.util.TreeSet;
007:
008: /**
009: * Provides a wrapper for the 'MethodSet' element in the aggregate XML file. An instance of a
010: * MethodSetElement represents elements in a MethodSet.
011: * <p>
012: * An example of a 'MethodSet' as a MethodSetElement with no methods:
013: * <pre>
014: * <MethodSet class="String" package="java.lang" tested="0" untested="0" oneline="0"
015: * constructor="0" excludedindividual="0" timestamp=""/>
016: * </pre>
017: * <p>
018: * An example of a 'MethodSet' as a MethodSetElement with methods:
019: * <pre>
020: * <MethodSet class="String" package="java.lang" tested="1" untested="0" oneline="0"
021: * constructor="0" timestamp="">
022: * <tested>
023: * <Method name="indexOf" package="java.lang.String">
024: * <Parameter type="java.lang.String"/>
025: * <Parameter type="int"/>
026: * </Method>
027: * </tested>
028: * <untested/>
029: * <oneline/>
030: * <constructor/>
031: * <ecludedindividual/>
032: * </MethodSet>
033: * </pre>
034: * <p>
035: * Note that the <code>excluded individual methods</code> take priority over all the other
036: * categories of methods. I.e., if a one-line method was individually excluded by the application,
037: * then it is considered to be an individually excluded methods instead of a one-line method.
038: *
039: * @author Joy M. Agustin
040: * @version $Id: MethodSetElement.java,v 1.2 2004/11/07 08:53:26 timshadel Exp $
041: */
042: public class MethodSetElement implements Comparable {
043:
044: /** Name of the class */
045: private String className;
046: /** Name of the package className belongs to */
047: private String packageName;
048:
049: /** Timestamp */
050: private String timeStamp;
051:
052: /** Set of all methods tested */
053: private Set testedMethodSet;
054: /** Set of all methods untested */
055: private Set untestedMethodSet;
056: /** Set of all methods untestable */
057: private Set untestableMethodSet;
058: /** Set of all one-line methods */
059: private Set onelineMethodSet;
060: /** Set of all constructors */
061: private Set constructorMethodSet;
062: /** Set of all individually excluded methods */
063: private Set excludedIndividualMethodSet;
064:
065: /**
066: * Constructs a new MethodSetElement object.
067: *
068: * @param className the name of the class.
069: * @param packageName the name of the package <code>className</code> belongs to.
070: */
071: public MethodSetElement(String packageName, String className) {
072:
073: this .packageName = packageName;
074: this .className = className;
075:
076: this .testedMethodSet = new TreeSet();
077: this .untestedMethodSet = new TreeSet();
078: this .untestableMethodSet = new TreeSet();
079: this .onelineMethodSet = new TreeSet();
080: this .constructorMethodSet = new TreeSet();
081: this .excludedIndividualMethodSet = new TreeSet();
082: }
083:
084: /**
085: * Returns the name of the package of this MethodSetElement object.
086: *
087: * @return the name of the package of this MethodSetElement object.
088: */
089: public String getPackageName() {
090: return this .packageName;
091: }
092:
093: /**
094: * Returns the name of the class of this MethodSetElement object.
095: *
096: * @return the name of the class of this MethodSetElement object.
097: */
098: public String getClassName() {
099: 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 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 toString() {
251: StringBuffer buffer = new StringBuffer();
252: buffer.append(" <MethodSet name=\"" + this .className + "\"");
253: buffer.append(" package=\"" + this .packageName + "\"");
254: buffer
255: .append(" tested=\"" + this .testedMethodSet.size()
256: + "\"");
257: buffer.append(" untested=\"" + this .untestedMethodSet.size()
258: + "\"");
259: buffer.append(" untestable=\""
260: + this .untestableMethodSet.size() + "\"");
261: buffer.append(" oneline=\"" + this .onelineMethodSet.size()
262: + "\"");
263: buffer.append(" constructor=\""
264: + this .constructorMethodSet.size() + "\"");
265: buffer.append(" excludedindividual=\""
266: + this .excludedIndividualMethodSet.size() + "\"");
267: buffer.append(" timestamp=\"" + this .timeStamp + "\" >\n");
268:
269: if (this .testedMethodSet.size() > 0) {
270: buffer.append(" <tested>\n");
271: for (Iterator i = this .testedMethodSet.iterator(); i
272: .hasNext();) {
273: buffer.append("" + i.next() + "\n");
274: }
275: buffer.append(" </tested>\n");
276: } else {
277: buffer.append(" <tested/>\n");
278: }
279:
280: if (this .untestedMethodSet.size() > 0) {
281: buffer.append(" <untested>\n");
282: for (Iterator i = this .untestedMethodSet.iterator(); i
283: .hasNext();) {
284: buffer.append("" + i.next() + "\n");
285: }
286: buffer.append(" </untested>\n");
287: } else {
288: buffer.append(" <untested/>\n");
289: }
290:
291: if (this .untestedMethodSet.size() > 0) {
292: buffer.append(" <untestable>\n");
293: for (Iterator i = this .untestableMethodSet.iterator(); i
294: .hasNext();) {
295: buffer.append("" + i.next() + "\n");
296: }
297: buffer.append(" </untestable>\n");
298: } else {
299: buffer.append(" <untestable/>\n");
300: }
301:
302: if (this .onelineMethodSet.size() > 0) {
303: buffer.append(" <oneline>\n");
304: for (Iterator i = this .onelineMethodSet.iterator(); i
305: .hasNext();) {
306: buffer.append("" + i.next() + "\n");
307: }
308: buffer.append(" </oneline>\n");
309: } else {
310: buffer.append(" <oneline/>\n");
311: }
312:
313: if (this .constructorMethodSet.size() > 0) {
314: buffer.append(" <constructor>\n");
315: for (Iterator i = this .constructorMethodSet.iterator(); i
316: .hasNext();) {
317: buffer.append("" + i.next() + "\n");
318: }
319: buffer.append(" </constructor>\n");
320: } else {
321: buffer.append(" <constructor/>\n");
322: }
323:
324: if (this .excludedIndividualMethodSet.size() > 0) {
325: buffer.append(" <excludedindividual>\n");
326: for (Iterator i = this .excludedIndividualMethodSet
327: .iterator(); i.hasNext();) {
328: buffer.append("" + i.next() + "\n");
329: }
330: buffer.append(" </excludedindividual>\n");
331: } else {
332: buffer.append(" <excludedindividual/>\n");
333: }
334:
335: buffer.append(" </MethodSet>");
336:
337: return buffer.toString();
338: }
339:
340: /**
341: * Writes this MethodSetElement to writer.
342: *
343: * @param writer points to an output file.
344: */
345: public void write(PrintWriter writer) {
346:
347: writer.write(" <MethodSet name=\"" + this .className + "\"");
348: writer.write(" package=\"" + this .packageName + "\"");
349: writer.write(" tested=\"" + this .testedMethodSet.size() + "\"");
350: writer.write(" untested=\"" + this .untestedMethodSet.size()
351: + "\"");
352: writer.write(" untestable=\"" + this .untestableMethodSet.size()
353: + "\"");
354: writer.write(" oneline=\"" + this .onelineMethodSet.size()
355: + "\"");
356: writer.write(" constructor=\""
357: + this .constructorMethodSet.size() + "\"");
358: writer.write(" excludedindividual=\""
359: + this .excludedIndividualMethodSet.size() + "\"");
360: writer.write(" timestamp=\"" + this .timeStamp + "\" >\n");
361:
362: if (this .testedMethodSet.size() > 0) {
363: writer.write(" <tested>\n");
364: for (Iterator i = this .testedMethodSet.iterator(); i
365: .hasNext();) {
366: writer.write("" + i.next() + "\n");
367: }
368: writer.write(" </tested>\n");
369: } else {
370: writer.write(" <tested/>\n");
371: }
372:
373: if (this .untestedMethodSet.size() > 0) {
374: writer.write(" <untested>\n");
375: for (Iterator i = this .untestedMethodSet.iterator(); i
376: .hasNext();) {
377: writer.write("" + i.next() + "\n");
378: }
379: writer.write(" </untested>\n");
380: } else {
381: writer.write(" <untested/>\n");
382: }
383:
384: if (this .untestableMethodSet.size() > 0) {
385: writer.write(" <untestable>\n");
386: for (Iterator i = this .untestableMethodSet.iterator(); i
387: .hasNext();) {
388: writer.write("" + i.next() + "\n");
389: }
390: writer.write(" </untestable>\n");
391: } else {
392: writer.write(" <untestable/>\n");
393: }
394:
395: if (this .onelineMethodSet.size() > 0) {
396: writer.write(" <oneline>\n");
397: for (Iterator i = this .onelineMethodSet.iterator(); i
398: .hasNext();) {
399: writer.write("" + i.next() + "\n");
400: }
401: writer.write(" </oneline>\n");
402: } else {
403: writer.write(" <oneline/>\n");
404: }
405:
406: if (this .constructorMethodSet.size() > 0) {
407: writer.write(" <constructor>\n");
408: for (Iterator i = this .constructorMethodSet.iterator(); i
409: .hasNext();) {
410: writer.write("" + i.next() + "\n");
411: }
412: writer.write(" </constructor>\n");
413: } else {
414: writer.write(" <constructor/>\n");
415: }
416:
417: if (this .excludedIndividualMethodSet.size() > 0) {
418: writer.write(" <excludedindividual>\n");
419: for (Iterator i = this .excludedIndividualMethodSet
420: .iterator(); i.hasNext();) {
421: writer.write("" + i.next() + "\n");
422: }
423: writer.write(" </excludedindividual>\n");
424: } else {
425: writer.write(" <excludedindividual/>\n");
426: }
427:
428: writer.write(" </MethodSet>");
429: }
430:
431: /**
432: * Compares this MethodSetElement object to <code>obj</code>.
433: *
434: * @param obj the MethodSetElement object to compare to.
435: * @return negative integer if this MethodSetElement object comes before <code>obj</code>, zero
436: * if this MethodSetElement object is equal to <code>obj</code>, or positive integer if
437: * <code>obj</code> comes before this MethodSetElement object.
438: */
439: public int compareTo(Object obj) {
440:
441: if (this .packageName.compareTo(((MethodSetElement) obj)
442: .getPackageName()) != 0) {
443: return this .packageName.compareTo(((MethodSetElement) obj)
444: .getPackageName());
445: } else {
446: return this .className.compareTo(((MethodSetElement) obj)
447: .getClassName());
448: }
449: }
450: }
|