1 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 |