KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > metrics > Printer


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.metrics;
34
35 import java.io.*;
36 import java.util.*;
37
38 public abstract class Printer implements MeasurementVisitor {
39     private PrintWriter out;
40
41     private boolean showEmptyMetrics = false;
42     private boolean showHiddenMeasurements = false;
43     private String JavaDoc indentText = " ";
44     private int indentLevel = 0;
45
46     public Printer(PrintWriter out) {
47         this.out = out;
48     }
49     
50     public String JavaDoc getIndentText() {
51         return indentText;
52     }
53
54     public void setIndentText(String JavaDoc indentText) {
55         this.indentText = indentText;
56     }
57
58     public boolean isShowEmptyMetrics() {
59         return showEmptyMetrics;
60     }
61
62     public void setShowEmptyMetrics(boolean showEmptyMetrics) {
63         this.showEmptyMetrics = showEmptyMetrics;
64     }
65
66     public boolean isShowHiddenMeasurements() {
67         return showHiddenMeasurements;
68     }
69
70     public void setShowHiddenMeasurements(boolean showHiddenMeasurements) {
71         this.showHiddenMeasurements = showHiddenMeasurements;
72     }
73     
74     protected Printer append(boolean b) {
75         out.print(b);
76         return this;
77     }
78
79     protected Printer append(char c) {
80         out.print(c);
81         return this;
82     }
83
84     protected Printer append(char[] s) {
85         out.print(s);
86         return this;
87     }
88
89     protected Printer append(double d) {
90         out.print(d);
91         return this;
92     }
93
94     protected Printer append(float f) {
95         out.print(f);
96         return this;
97     }
98
99     protected Printer append(int i) {
100         out.print(i);
101         return this;
102     }
103
104     protected Printer append(long l) {
105         out.print(l);
106         return this;
107     }
108
109     protected Printer append(Object JavaDoc obj) {
110         out.print(obj);
111         return this;
112     }
113
114     protected Printer append(String JavaDoc s) {
115         out.print(s);
116         return this;
117     }
118
119     protected Printer indent() {
120         for (int i=0; i<indentLevel; i++) {
121             append(getIndentText());
122         }
123
124         return this;
125     }
126
127     protected Printer eol() {
128         out.println();
129         return this;
130     }
131     
132     protected void raiseIndent() {
133         indentLevel++;
134     }
135
136     protected void lowerIndent() {
137         indentLevel--;
138     }
139
140     public void visitMetrics(Collection metrics) {
141         Iterator i = metrics.iterator();
142         while(i.hasNext()) {
143             visitMetrics((Metrics) i.next());
144         }
145     }
146     
147     public abstract void visitMetrics(Metrics metrics);
148     
149     public void visitRatioMeasurement(RatioMeasurement measurement) {
150         visitMeasurement(measurement);
151     }
152     
153     public void visitNbSubMetricsMeasurement(NbSubMetricsMeasurement measurement) {
154         visitMeasurement(measurement);
155     }
156     
157     public void visitCounterMeasurement(CounterMeasurement measurement) {
158         visitMeasurement(measurement);
159     }
160     
161     public void visitContextAccumulatorMeasurement(ContextAccumulatorMeasurement measurement) {
162         visitMeasurement(measurement);
163     }
164         
165     public void visitNameListMeasurement(NameListMeasurement measurement) {
166         visitMeasurement(measurement);
167     }
168     
169     public void visitSubMetricsAccumulatorMeasurement(SubMetricsAccumulatorMeasurement measurement) {
170         visitMeasurement(measurement);
171     }
172
173     public void visitSumMeasurement(SumMeasurement measurement) {
174         visitMeasurement(measurement);
175     }
176
177     protected abstract void visitMeasurement(Measurement measurement);
178 }
179
Popular Tags