KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > trove > benchmark > XMLReporter


1 ///////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
3
//
4
// This library is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU Lesser General Public
6
// License as published by the Free Software Foundation; either
7
// version 2.1 of the License, or (at your option) any later version.
8
//
9
// This library is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU Lesser General Public
15
// License along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
///////////////////////////////////////////////////////////////////////////////
18

19 package gnu.trove.benchmark;
20
21 import java.io.*;
22
23 /**
24  *
25  * Created: Thu Nov 22 20:49:24 2001
26  *
27  * @author Eric D. Friedman
28  * @version $Id: XMLReporter.java,v 1.2 2006/11/10 23:27:59 robeden Exp $
29  */

30
31 class XMLReporter implements Reporter {
32     PrintWriter out;
33
34     XMLReporter() {
35         this.out = new PrintWriter(new OutputStreamWriter(System.out),
36                                    true);
37     }
38         
39     XMLReporter(PrintWriter out) {
40         this.out = out;
41     }
42
43     public void report(Result result) {
44         out.println("<result>");
45         out.print("<desc>");
46         out.print(result.getDescription());
47         out.println("</desc>");
48             
49         out.print("<iterations>");
50         out.print(result.getIterations());
51         out.println("</iterations>");
52             
53         out.print("<theirTotal>");
54         out.print(result.getTheirs());
55         out.println("</theirTotal>");
56             
57         out.print("<theirAvg>");
58         out.print(result.getTheirAvg());
59         out.println("</theirAvg>");
60             
61         out.print("<ourTotal>");
62         out.print(result.getOurs());
63         out.println("</ourTotal>");
64             
65         out.print("<ourAvg>");
66         out.print(result.getOurAvg());
67         out.println("</ourAvg>");
68
69         out.println("</result>");
70     }
71
72     public void start() {
73         out.println("<?xml version=\"1.0\" encoding=\"ASCII\" ?>");
74         out.println("<benchmark>");
75         out.print("<env>");
76         for (int i = 0; i < ENV_PROPS.length; i++) {
77             String JavaDoc key = ENV_PROPS[i];
78             out.print(System.getProperty(key));
79             out.print(" ");
80         }
81         out.println("</env>");
82     }
83
84     public void finish() {
85         out.println("</benchmark>");
86     }
87 }
88
Popular Tags