001: package csdl.jblanket.report.element;
002:
003: import java.io.PrintWriter;
004: import java.util.Iterator;
005: import java.util.Map;
006: import java.util.TreeMap;
007:
008: /**
009: * Provides a wrapper for the 'MethodSets' element in the aggregate XML file. An instance of a
010: * MethodSetsElement represents elements in a MethodSets.
011: * <p>
012: * An example of a 'MethodSets' as a MethodSetsElement with no 'MethodSet's:
013: * <pre>
014: * <MethodSets tested="0" untested="0" oneline="0" constructor="0" timestamp=""/>
015: * </pre>
016: * <p>
017: * An example of a 'MethodSets' as a MethodSetsElement with 'MethodSet's:
018: * <pre>
019: * <MethodSets tested="1" untested="0" oneline="0">
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: * </MethodSet>
032: * </MethodSets>
033: * </pre>
034: *
035: * @author Joy M. Agustin
036: * @version $Id: MethodSetsElement.java,v 1.1 2004/11/07 00:32:39 timshadel Exp $
037: */
038: public class MethodSetsElement {
039:
040: /** Contains all MethodSet elements; maps className -> MethodSetElement */
041: private Map methodSetMap;
042:
043: /**
044: * Constructs a new MethodSetsElement object.
045: */
046: public MethodSetsElement() {
047: this .methodSetMap = new TreeMap();
048: }
049:
050: /**
051: * Puts a MethodSetElement object into this MethodSetsElement object.
052: *
053: * @param className the name of the class of <code>methodSet</code>.
054: * @param methodSet the MethodSetElement to store.
055: */
056: public void put(String className, MethodSetElement methodSet) {
057: this .methodSetMap.put(className, methodSet);
058: }
059:
060: /**
061: * Gets the MethodSetElement associated with <code>className</code>.
062: *
063: * @param className the name of the class who's MethodSetElement to retrieve.
064: * @return the MethodSetElement for <code>className</code>.
065: */
066: public Object get(String className) {
067: return this .methodSetMap.get(className);
068: }
069:
070: /**
071: * Returns a String representation of this MethodSetsElement as found in an aggregate XML file.
072: *
073: * @return a String representation of this MethodSetsElement.
074: */
075: public String toString() {
076:
077: int tested = 0;
078: int untested = 0;
079: int oneline = 0;
080: int constructor = 0;
081:
082: for (Iterator i = this .methodSetMap.values().iterator(); i
083: .hasNext();) {
084: MethodSetElement methodSet = (MethodSetElement) i.next();
085: tested += methodSet.getTestedSize();
086: untested += methodSet.getUntestedSize();
087: oneline += methodSet.getOnelineSize();
088: constructor += methodSet.getConstructorSize();
089: }
090:
091: StringBuffer buffer = new StringBuffer();
092: buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
093: buffer.append("<MethodSets tested=\"" + tested + "\"");
094: buffer.append(" untested=\"" + untested + "\"");
095: buffer.append(" oneline=\"" + oneline + "\"");
096: buffer.append(" constructor=\"" + constructor + "\">\n");
097: for (Iterator i = this .methodSetMap.values().iterator(); i
098: .hasNext();) {
099: buffer.append((MethodSetElement) i.next());
100: buffer.append("\n");
101: }
102: buffer.append("</MethodSets>");
103:
104: return buffer.toString();
105: }
106:
107: /**
108: * Writes this MethodSetsElement to writer.
109: *
110: * @param writer points to an output file.
111: */
112: public void write(PrintWriter writer) {
113:
114: int tested = 0;
115: int untested = 0;
116: int oneline = 0;
117: int constructor = 0;
118:
119: for (Iterator i = this .methodSetMap.values().iterator(); i
120: .hasNext();) {
121: MethodSetElement methodSet = (MethodSetElement) i.next();
122: tested += methodSet.getTestedSize();
123: untested += methodSet.getUntestedSize();
124: oneline += methodSet.getOnelineSize();
125: constructor += methodSet.getConstructorSize();
126: }
127:
128: writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
129: writer.write("<MethodSets tested=\"" + tested + "\"");
130: writer.write(" untested=\"" + untested + "\"");
131: writer.write(" oneline=\"" + oneline + "\"");
132: writer.write(" constructor=\"" + constructor + "\">\n");
133: for (Iterator i = this .methodSetMap.values().iterator(); i
134: .hasNext();) {
135: ((MethodSetElement) i.next()).write(writer);
136: writer.write("\n");
137: }
138: writer.write("</MethodSets>");
139: }
140: }
|