1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
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 |
| private boolean listingElements = false; |
42 |
| private boolean chartingClassesPerPackage = false; |
43 |
| private boolean chartingFeaturesPerClass = false; |
44 |
| private boolean chartingInboundsPerPackage = false; |
45 |
| private boolean chartingOutboundsPerPackage = false; |
46 |
| private boolean chartingInboundsPerClass = false; |
47 |
| private boolean chartingOutboundsPerClass = false; |
48 |
| private boolean chartingInboundsPerFeature = false; |
49 |
| private boolean chartingOutboundsPerFeature = false; |
50 |
| |
51 |
2
| public MetricsReport(PrintWriter out) {
|
52 |
2
| this.out = out;
|
53 |
| } |
54 |
| |
55 |
6
| public boolean isListingElements() {
|
56 |
6
| return listingElements;
|
57 |
| } |
58 |
| |
59 |
2
| public void setListingElements(boolean listingElements) {
|
60 |
2
| this.listingElements = listingElements;
|
61 |
| } |
62 |
| |
63 |
2
| public boolean isChartingClassesPerPackage() {
|
64 |
2
| return chartingClassesPerPackage;
|
65 |
| } |
66 |
| |
67 |
0
| public void setChartingClassesPerPackage(boolean chartingClassesPerPackage) {
|
68 |
0
| this.chartingClassesPerPackage = chartingClassesPerPackage;
|
69 |
| } |
70 |
| |
71 |
2
| public boolean isChartingFeaturesPerClass() {
|
72 |
2
| return chartingFeaturesPerClass;
|
73 |
| } |
74 |
| |
75 |
0
| public void setChartingFeaturesPerClass(boolean chartingFeaturesPerClass) {
|
76 |
0
| this.chartingFeaturesPerClass = chartingFeaturesPerClass;
|
77 |
| } |
78 |
| |
79 |
2
| public boolean isChartingInboundsPerPackage() {
|
80 |
2
| return chartingInboundsPerPackage;
|
81 |
| } |
82 |
| |
83 |
0
| public void setChartingInboundsPerPackage(boolean chartingInboundsPerPackage) {
|
84 |
0
| this.chartingInboundsPerPackage = chartingInboundsPerPackage;
|
85 |
| } |
86 |
| |
87 |
2
| public boolean isChartingOutboundsPerPackage() {
|
88 |
2
| return chartingOutboundsPerPackage;
|
89 |
| } |
90 |
| |
91 |
0
| public void setChartingOutboundsPerPackage(boolean chartingOutboundsPerPackage) {
|
92 |
0
| this.chartingOutboundsPerPackage = chartingOutboundsPerPackage;
|
93 |
| } |
94 |
| |
95 |
2
| public boolean isChartingInboundsPerClass() {
|
96 |
2
| return chartingInboundsPerClass;
|
97 |
| } |
98 |
| |
99 |
0
| public void setChartingInboundsPerClass(boolean chartingInboundsPerClass) {
|
100 |
0
| this.chartingInboundsPerClass = chartingInboundsPerClass;
|
101 |
| } |
102 |
| |
103 |
2
| public boolean isChartingOutboundsPerClass() {
|
104 |
2
| return chartingOutboundsPerClass;
|
105 |
| } |
106 |
| |
107 |
0
| public void setChartingOutboundsPerClass(boolean chartingOutboundsPerClass) {
|
108 |
0
| this.chartingOutboundsPerClass = chartingOutboundsPerClass;
|
109 |
| } |
110 |
| |
111 |
2
| public boolean isChartingInboundsPerFeature() {
|
112 |
2
| return chartingInboundsPerFeature;
|
113 |
| } |
114 |
| |
115 |
0
| public void setChartingInboundsPerFeature(boolean chartingInboundsPerFeature) {
|
116 |
0
| this.chartingInboundsPerFeature = chartingInboundsPerFeature;
|
117 |
| } |
118 |
| |
119 |
2
| public boolean isChartingOutboundsPerFeature() {
|
120 |
2
| return chartingOutboundsPerFeature;
|
121 |
| } |
122 |
| |
123 |
0
| public void setChartingOutboundsPerFeature(boolean chartingOutboundsPerFeature) {
|
124 |
0
| this.chartingOutboundsPerFeature = chartingOutboundsPerFeature;
|
125 |
| } |
126 |
| |
127 |
2
| public void process(MetricsGatherer metrics) {
|
128 |
2
| int nbPackages = metrics.getPackages().size();
|
129 |
2
| out.print(nbPackages + " package(s)");
|
130 |
2
| if (nbPackages > 0) {
|
131 |
2
| int nbConfirmedPackages = countConfirmedNodes(metrics.getPackages());
|
132 |
2
| out.print(" (" + nbConfirmedPackages + " confirmed, " + (nbConfirmedPackages / (double) nbPackages) + ")");
|
133 |
| } |
134 |
2
| out.println();
|
135 |
2
| if (isListingElements()) {
|
136 |
0
| for (PackageNode packageNode : metrics.getPackages()) {
|
137 |
0
| out.println(" " + packageNode);
|
138 |
| } |
139 |
| } |
140 |
| |
141 |
2
| int nbClasses = metrics.getClasses().size();
|
142 |
2
| out.print(nbClasses + " class(es)");
|
143 |
2
| if (nbClasses > 0) {
|
144 |
2
| int nbConfirmedClasses = countConfirmedNodes(metrics.getClasses());
|
145 |
2
| out.print(" (" + nbConfirmedClasses + " confirmed, " + (nbConfirmedClasses / (double) nbClasses) + ")");
|
146 |
| } |
147 |
2
| out.println();
|
148 |
2
| if (isListingElements()) {
|
149 |
0
| for (ClassNode classNode : metrics.getClasses()) {
|
150 |
0
| out.println(" " + classNode);
|
151 |
| } |
152 |
| } |
153 |
| |
154 |
2
| int nbFeatures = metrics.getFeatures().size();
|
155 |
2
| out.print(nbFeatures + " feature(s)");
|
156 |
2
| if (nbFeatures > 0) {
|
157 |
2
| int nbConfirmedFeatures = countConfirmedNodes(metrics.getFeatures());
|
158 |
2
| out.print(" (" + nbConfirmedFeatures + " confirmed, " + (nbConfirmedFeatures / (double) nbFeatures) + ")");
|
159 |
| } |
160 |
2
| out.println();
|
161 |
2
| if (isListingElements()) {
|
162 |
0
| for (FeatureNode featureNode : metrics.getFeatures()) {
|
163 |
0
| out.println(" " + featureNode);
|
164 |
| } |
165 |
| } |
166 |
| |
167 |
2
| out.println();
|
168 |
| |
169 |
2
| out.println(metrics.getNbOutbound() + " outbound link(s)");
|
170 |
| |
171 |
2
| long nbOutboundPackages = metrics.getNbOutboundPackages();
|
172 |
2
| out.print(" " + nbOutboundPackages + " from package(s)");
|
173 |
2
| if (nbOutboundPackages > 0 && nbPackages > 0) {
|
174 |
0
| out.print(" (on average " + (nbOutboundPackages / (double) nbPackages) + " per package)");
|
175 |
| } |
176 |
2
| out.println();
|
177 |
| |
178 |
2
| long nbOutboundClasses = metrics.getNbOutboundClasses();
|
179 |
2
| out.print(" " + nbOutboundClasses + " from class(es)");
|
180 |
2
| if (nbOutboundClasses > 0 && nbClasses > 0) {
|
181 |
0
| out.print(" (on average " + (nbOutboundClasses / (double) nbClasses) + " per class)");
|
182 |
| } |
183 |
2
| out.println();
|
184 |
| |
185 |
2
| long nbOutboundFeatures = metrics.getNbOutboundFeatures();
|
186 |
2
| out.print(" " + nbOutboundFeatures + " from feature(s)");
|
187 |
2
| if (nbOutboundFeatures > 0 && nbFeatures > 0) {
|
188 |
2
| out.print(" (on average " + (nbOutboundFeatures / (double) nbFeatures) + " per feature)");
|
189 |
| } |
190 |
2
| out.println();
|
191 |
| |
192 |
2
| out.println(metrics.getNbInbound() + " inbound link(s)");
|
193 |
| |
194 |
2
| long nbInboundPackages = metrics.getNbInboundPackages();
|
195 |
2
| out.print(" " + nbInboundPackages + " to package(s)");
|
196 |
2
| if (nbInboundPackages > 0 && nbPackages > 0) {
|
197 |
0
| out.print(" (on average " + (nbInboundPackages / (double) nbPackages) + " per package)");
|
198 |
| } |
199 |
2
| out.println();
|
200 |
| |
201 |
2
| long nbInboundClasses = metrics.getNbInboundClasses();
|
202 |
2
| out.print(" " + nbInboundClasses + " to class(es)");
|
203 |
2
| if (nbInboundClasses > 0 && nbClasses > 0) {
|
204 |
0
| out.print(" (on average " + (nbInboundClasses / (double) nbClasses) + " per class)");
|
205 |
| } |
206 |
2
| out.println();
|
207 |
| |
208 |
2
| long nbInboundFeatures = metrics.getNbInboundFeatures();
|
209 |
2
| out.print(" " + nbInboundFeatures + " to feature(s)");
|
210 |
2
| if (nbInboundFeatures > 0 && nbFeatures > 0) {
|
211 |
2
| out.print(" (on average " + (nbInboundFeatures / (double) nbFeatures) + " per feature)");
|
212 |
| } |
213 |
2
| out.println();
|
214 |
| |
215 |
2
| if (isChartingClassesPerPackage() ||
|
216 |
| isChartingFeaturesPerClass() || |
217 |
| isChartingInboundsPerPackage() || |
218 |
| isChartingOutboundsPerPackage() || |
219 |
| isChartingInboundsPerClass() || |
220 |
| isChartingOutboundsPerClass() || |
221 |
| isChartingInboundsPerFeature() || |
222 |
| isChartingOutboundsPerFeature()) { |
223 |
| |
224 |
0
| out.println();
|
225 |
| |
226 |
0
| out.print("n");
|
227 |
0
| if (isChartingClassesPerPackage()) {
|
228 |
0
| out.print(", \"classes per package\"");
|
229 |
| } |
230 |
0
| if (isChartingFeaturesPerClass()) {
|
231 |
0
| out.print(", \"features per class\"");
|
232 |
| } |
233 |
0
| if (isChartingInboundsPerPackage()) {
|
234 |
0
| out.print(", \"inbounds per package\"");
|
235 |
| } |
236 |
0
| if (isChartingOutboundsPerPackage()) {
|
237 |
0
| out.print(", \"outbounds per package\"");
|
238 |
| } |
239 |
0
| if (isChartingInboundsPerClass()) {
|
240 |
0
| out.print(", \"inbounds per class\"");
|
241 |
| } |
242 |
0
| if (isChartingOutboundsPerClass()) {
|
243 |
0
| out.print(", \"outbounds per class\"");
|
244 |
| } |
245 |
0
| if (isChartingInboundsPerFeature()) {
|
246 |
0
| out.print(", \"inbounds per feature\"");
|
247 |
| } |
248 |
0
| if (isChartingOutboundsPerFeature()) {
|
249 |
0
| out.print(", \"outbounds per feature\"");
|
250 |
| } |
251 |
0
| out.println();
|
252 |
| |
253 |
0
| for (int k=0; k<=metrics.getChartMaximum(); k++) {
|
254 |
0
| long[] dataPoint = metrics.getChartData(k);
|
255 |
| |
256 |
0
| out.print(k);
|
257 |
0
| if (isChartingClassesPerPackage()) {
|
258 |
0
| out.print(", " + dataPoint[MetricsGatherer.CLASSES_PER_PACKAGE]);
|
259 |
| } |
260 |
0
| if (isChartingFeaturesPerClass()) {
|
261 |
0
| out.print(", " + dataPoint[MetricsGatherer.FEATURES_PER_CLASS]);
|
262 |
| } |
263 |
0
| if (isChartingInboundsPerPackage()) {
|
264 |
0
| out.print(", " + dataPoint[MetricsGatherer.INBOUNDS_PER_PACKAGE]);
|
265 |
| } |
266 |
0
| if (isChartingOutboundsPerPackage()) {
|
267 |
0
| out.print(", " + dataPoint[MetricsGatherer.OUTBOUNDS_PER_PACKAGE]);
|
268 |
| } |
269 |
0
| if (isChartingInboundsPerClass()) {
|
270 |
0
| out.print(", " + dataPoint[MetricsGatherer.INBOUNDS_PER_CLASS]);
|
271 |
| } |
272 |
0
| if (isChartingOutboundsPerClass()) {
|
273 |
0
| out.print(", " + dataPoint[MetricsGatherer.OUTBOUNDS_PER_CLASS]);
|
274 |
| } |
275 |
0
| if (isChartingInboundsPerFeature()) {
|
276 |
0
| out.print(", " + dataPoint[MetricsGatherer.INBOUNDS_PER_FEATURE]);
|
277 |
| } |
278 |
0
| if (isChartingOutboundsPerFeature()) {
|
279 |
0
| out.print(", " + dataPoint[MetricsGatherer.OUTBOUNDS_PER_FEATURE]);
|
280 |
| } |
281 |
0
| out.println();
|
282 |
| } |
283 |
| } |
284 |
| } |
285 |
| |
286 |
6
| private int countConfirmedNodes(Collection<? extends Node> nodes) {
|
287 |
6
| int result = 0;
|
288 |
| |
289 |
6
| for (Node node : nodes) {
|
290 |
30
| if (node.isConfirmed()) {
|
291 |
0
| result++;
|
292 |
| } |
293 |
| } |
294 |
| |
295 |
6
| return result;
|
296 |
| } |
297 |
| } |