KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > dependency > MetricsReport


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.dependency;
34
35 import java.io.*;
36 import java.util.*;
37
38 public class MetricsReport {
39     private PrintWriter out;
40
41     boolean listingElements = false;
42     boolean chartingClassesPerPackage = false;
43     boolean chartingFeaturesPerClass = false;
44     boolean chartingInboundsPerPackage = false;
45     boolean chartingOutboundsPerPackage = false;
46     boolean chartingInboundsPerClass = false;
47     boolean chartingOutboundsPerClass = false;
48     boolean chartingInboundsPerFeature = false;
49     boolean chartingOutboundsPerFeature = false;
50
51     public MetricsReport(PrintWriter out) {
52         this.out = out;
53     }
54     
55     public boolean isListingElements() {
56         return listingElements;
57     }
58
59     public void setListingElements(boolean listingElements) {
60         this.listingElements = listingElements;
61     }
62     
63     public boolean isChartingClassesPerPackage() {
64         return chartingClassesPerPackage;
65     }
66
67     public void setChartingClassesPerPackage(boolean chartingClassesPerPackage) {
68         this.chartingClassesPerPackage = chartingClassesPerPackage;
69     }
70     
71     public boolean isChartingFeaturesPerClass() {
72         return chartingFeaturesPerClass;
73     }
74
75     public void setChartingFeaturesPerClass(boolean chartingFeaturesPerClass) {
76         this.chartingFeaturesPerClass = chartingFeaturesPerClass;
77     }
78     
79     public boolean isChartingInboundsPerPackage() {
80         return chartingInboundsPerPackage;
81     }
82
83     public void setChartingInboundsPerPackage(boolean chartingInboundsPerPackage) {
84         this.chartingInboundsPerPackage = chartingInboundsPerPackage;
85     }
86     
87     public boolean isChartingOutboundsPerPackage() {
88         return chartingOutboundsPerPackage;
89     }
90
91     public void setChartingOutboundsPerPackage(boolean chartingOutboundsPerPackage) {
92         this.chartingOutboundsPerPackage = chartingOutboundsPerPackage;
93     }
94     
95     public boolean isChartingInboundsPerClass() {
96         return chartingInboundsPerClass;
97     }
98
99     public void setChartingInboundsPerClass(boolean chartingInboundsPerClass) {
100         this.chartingInboundsPerClass = chartingInboundsPerClass;
101     }
102     
103     public boolean isChartingOutboundsPerClass() {
104         return chartingOutboundsPerClass;
105     }
106
107     public void setChartingOutboundsPerClass(boolean chartingOutboundsPerClass) {
108         this.chartingOutboundsPerClass = chartingOutboundsPerClass;
109     }
110     
111     public boolean isChartingInboundsPerFeature() {
112         return chartingInboundsPerFeature;
113     }
114
115     public void setChartingInboundsPerFeature(boolean chartingInboundsPerFeature) {
116         this.chartingInboundsPerFeature = chartingInboundsPerFeature;
117     }
118     
119     public boolean isChartingOutboundsPerFeature() {
120         return chartingOutboundsPerFeature;
121     }
122
123     public void setChartingOutboundsPerFeature(boolean chartingOutboundsPerFeature) {
124         this.chartingOutboundsPerFeature = chartingOutboundsPerFeature;
125     }
126     
127     public void process(MetricsGatherer metrics) {
128         Iterator j;
129         
130         out.println(metrics.getPackages().size() + " package(s)");
131         if (isListingElements()) {
132             j = metrics.getPackages().iterator();
133             while (j.hasNext()) {
134                 out.println(" " + j.next());
135             }
136         }
137         
138         out.println(metrics.getClasses().size() + " class(es)");
139         if (isListingElements()) {
140             j = metrics.getClasses().iterator();
141             while (j.hasNext()) {
142                 out.println(" " + j.next());
143             }
144         }
145
146         out.println(metrics.getFeatures().size() + " feature(s)");
147         if (isListingElements()) {
148             j = metrics.getFeatures().iterator();
149             while (j.hasNext()) {
150                 out.println(" " + j.next());
151             }
152         }
153
154         out.println();
155
156         out.println(metrics.getNbOutbound() + " outbound link(s)");
157         out.println(" " + metrics.getNbOutboundPackages() + " from package(s) (average " + (metrics.getNbOutboundPackages() / (double) metrics.getPackages().size()) + " per package)");
158         out.println(" " + metrics.getNbOutboundClasses() + " from class(es) (average " + (metrics.getNbOutboundClasses() / (double) metrics.getClasses().size()) + " per class)");
159         out.println(" " + metrics.getNbOutboundFeatures() + " from feature(s) (average " + (metrics.getNbOutboundFeatures() / (double) metrics.getFeatures().size()) + " per feature)");
160
161         out.println(metrics.getNbInbound() + " inbound link(s)");
162         out.println(" " + metrics.getNbInboundPackages() + " to package(s) (average " + (metrics.getNbInboundPackages() / (double) metrics.getPackages().size()) + " per package)");
163         out.println(" " + metrics.getNbInboundClasses() + " to class(es) (average " + (metrics.getNbInboundClasses() / (double) metrics.getClasses().size()) + " per class)");
164         out.println(" " + metrics.getNbInboundFeatures() + " to feature(s) (average " + (metrics.getNbInboundFeatures() / (double) metrics.getFeatures().size()) + " per feature)");
165
166         if (isChartingClassesPerPackage() ||
167             isChartingFeaturesPerClass() ||
168             isChartingInboundsPerPackage() ||
169             isChartingOutboundsPerPackage() ||
170             isChartingInboundsPerClass() ||
171             isChartingOutboundsPerClass() ||
172             isChartingInboundsPerFeature() ||
173             isChartingOutboundsPerFeature()) {
174
175             out.println();
176
177             out.print("n");
178             if (isChartingClassesPerPackage()) {
179                 out.print(", \"classes per package\"");
180             }
181             if (isChartingFeaturesPerClass()) {
182                 out.print(", \"features per class\"");
183             }
184             if (isChartingInboundsPerPackage()) {
185                 out.print(", \"inbounds per package\"");
186             }
187             if (isChartingOutboundsPerPackage()) {
188                 out.print(", \"outbounds per package\"");
189             }
190             if (isChartingInboundsPerClass()) {
191                 out.print(", \"inbounds per class\"");
192             }
193             if (isChartingOutboundsPerClass()) {
194                 out.print(", \"outbounds per class\"");
195             }
196             if (isChartingInboundsPerFeature()) {
197                 out.print(", \"inbounds per feature\"");
198             }
199             if (isChartingOutboundsPerFeature()) {
200                 out.print(", \"outbounds per feature\"");
201             }
202             out.println();
203
204             for (int k=0; k<=metrics.getChartMaximum(); k++) {
205                 long[] dataPoint = metrics.getChartData(k);
206                 
207                 out.print(k);
208                 if (isChartingClassesPerPackage()) {
209                     out.print(", " + dataPoint[MetricsGatherer.CLASSES_PER_PACKAGE]);
210                 }
211                 if (isChartingFeaturesPerClass()) {
212                     out.print(", " + dataPoint[MetricsGatherer.FEATURES_PER_CLASS]);
213                 }
214                 if (isChartingInboundsPerPackage()) {
215                     out.print(", " + dataPoint[MetricsGatherer.INBOUNDS_PER_PACKAGE]);
216                 }
217                 if (isChartingOutboundsPerPackage()) {
218                     out.print(", " + dataPoint[MetricsGatherer.OUTBOUNDS_PER_PACKAGE]);
219                 }
220                 if (isChartingInboundsPerClass()) {
221                     out.print(", " + dataPoint[MetricsGatherer.INBOUNDS_PER_CLASS]);
222                 }
223                 if (isChartingOutboundsPerClass()) {
224                     out.print(", " + dataPoint[MetricsGatherer.OUTBOUNDS_PER_CLASS]);
225                 }
226                 if (isChartingInboundsPerFeature()) {
227                     out.print(", " + dataPoint[MetricsGatherer.INBOUNDS_PER_FEATURE]);
228                 }
229                 if (isChartingOutboundsPerFeature()) {
230                     out.print(", " + dataPoint[MetricsGatherer.OUTBOUNDS_PER_FEATURE]);
231                 }
232                 out.println();
233             }
234         }
235     }
236 }
237
Popular Tags