1 32 33 package com.jeantessier.dependency; 34 35 import java.util.*; 36 37 public class MetricsGatherer extends VisitorBase { 38 private Collection packages = new LinkedList(); 39 private Collection classes = new LinkedList(); 40 private Collection features = new LinkedList(); 41 42 private long nbOutbound = 0; 43 private long nbInbound = 0; 44 private long nbOutboundPackages = 0; 45 private long nbInboundPackages = 0; 46 private long nbOutboundClasses = 0; 47 private long nbInboundClasses = 0; 48 private long nbOutboundFeatures = 0; 49 private long nbInboundFeatures = 0; 50 51 private Map chartData = new TreeMap(); 52 private int chartMaximum = 0; 53 public static final int CHART_INDEX = 0; 54 public static final int CLASSES_PER_PACKAGE = 1; 55 public static final int FEATURES_PER_CLASS = 2; 56 public static final int INBOUNDS_PER_PACKAGE = 3; 57 public static final int OUTBOUNDS_PER_PACKAGE = 4; 58 public static final int INBOUNDS_PER_CLASS = 5; 59 public static final int OUTBOUNDS_PER_CLASS = 6; 60 public static final int INBOUNDS_PER_FEATURE = 7; 61 public static final int OUTBOUNDS_PER_FEATURE = 8; 62 public static final int NB_CHARTS = 9; 63 64 private static final String [] CHART_NAMES = {"n", 65 "Classes per Package", 66 "Feafures per Class", 67 "Inbounds per Package", 68 "Outbounds per Package", 69 "Inbounds per Class", 70 "Outbounds per Class", 71 "Inbounds per Feature", 72 "Outbounds per Feature"}; 73 74 public static int getNbCharts() { 75 return NB_CHARTS; 76 } 77 78 public static String getChartName(int i) { 79 return CHART_NAMES[i]; 80 } 81 82 public MetricsGatherer() { 83 super(); 84 } 85 86 public MetricsGatherer(TraversalStrategy strategy) { 87 super(strategy); 88 } 89 90 public long[] getChartData(int i) { 91 long[] result = null; 92 93 Integer key = new Integer (i); 94 result = (long[]) chartData.get(key); 95 96 if (result == null) { 97 result = new long[NB_CHARTS]; 98 result[CHART_INDEX] = i; 99 chartData.put(key, result); 100 101 if (chartMaximum < i) { 102 chartMaximum = i; 103 } 104 } 105 106 return result; 107 } 108 109 public int getChartMaximum() { 110 return chartMaximum; 111 } 112 113 public Collection getPackages() { 114 return packages; 115 } 116 117 public Collection getClasses() { 118 return classes; 119 } 120 121 public Collection getFeatures() { 122 return features; 123 } 124 125 public long getNbOutbound() { 126 return nbOutbound; 127 } 128 129 public long getNbInbound() { 130 return nbInbound; 131 } 132 133 public long getNbOutboundPackages() { 134 return nbOutboundPackages; 135 } 136 137 public long getNbInboundPackages() { 138 return nbInboundPackages; 139 } 140 141 public long getNbOutboundClasses() { 142 return nbOutboundClasses; 143 } 144 145 public long getNbInboundClasses() { 146 return nbInboundClasses; 147 } 148 149 public long getNbOutboundFeatures() { 150 return nbOutboundFeatures; 151 } 152 153 public long getNbInboundFeatures() { 154 return nbInboundFeatures; 155 } 156 157 public void preprocessPackageNode(PackageNode node) { 158 super.preprocessPackageNode(node); 159 160 packages.add(node); 161 162 getChartData(node.getClasses().size())[CLASSES_PER_PACKAGE]++; 163 getChartData(node.getInboundDependencies().size())[INBOUNDS_PER_PACKAGE]++; 164 getChartData(node.getOutboundDependencies().size())[OUTBOUNDS_PER_PACKAGE]++; 165 } 166 167 170 public void visitInboundPackageNode(PackageNode node) { 171 if (getStrategy().isInFilter(node)) { 172 nbInbound++; 173 nbOutboundPackages++; 174 } 175 } 176 177 180 public void visitOutboundPackageNode(PackageNode node) { 181 if (getStrategy().isInFilter(node)) { 182 nbOutbound++; 183 nbInboundPackages++; 184 } 185 } 186 187 public void preprocessClassNode(ClassNode node) { 188 super.preprocessClassNode(node); 189 190 classes.add(node); 191 192 getChartData(node.getFeatures().size())[FEATURES_PER_CLASS]++; 193 getChartData(node.getInboundDependencies().size())[INBOUNDS_PER_CLASS]++; 194 getChartData(node.getOutboundDependencies().size())[OUTBOUNDS_PER_CLASS]++; 195 } 196 197 200 public void visitInboundClassNode(ClassNode node) { 201 if (getStrategy().isInFilter(node)) { 202 nbInbound++; 203 nbOutboundClasses++; 204 } 205 } 206 207 210 public void visitOutboundClassNode(ClassNode node) { 211 if (getStrategy().isInFilter(node)) { 212 nbOutbound++; 213 nbInboundClasses++; 214 } 215 } 216 217 public void preprocessFeatureNode(FeatureNode node) { 218 super.preprocessFeatureNode(node); 219 220 features.add(node); 221 222 getChartData(node.getInboundDependencies().size())[INBOUNDS_PER_FEATURE]++; 223 getChartData(node.getOutboundDependencies().size())[OUTBOUNDS_PER_FEATURE]++; 224 } 225 226 229 public void visitInboundFeatureNode(FeatureNode node) { 230 if (getStrategy().isInFilter(node)) { 231 nbInbound++; 232 nbOutboundFeatures++; 233 } 234 } 235 236 239 public void visitOutboundFeatureNode(FeatureNode node) { 240 if (getStrategy().isInFilter(node)) { 241 nbOutbound++; 242 nbInboundFeatures++; 243 } 244 } 245 } 246 | Popular Tags |