Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 242   Methods: 26
NCLOC: 152   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MetricsGatherer.java 50% 83.9% 80.8% 77.6%
coverage coverage
 1    /*
 2    * Copyright (c) 2001-2009, 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.util.*;
 36   
 37    public class MetricsGatherer extends VisitorBase {
 38    private Collection<PackageNode> packages = new LinkedList<PackageNode>();
 39    private Collection<ClassNode> classes = new LinkedList<ClassNode>();
 40    private Collection<FeatureNode> features = new LinkedList<FeatureNode>();
 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<Integer, long[]> chartData = new TreeMap<Integer, long[]>();
 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  0 public static int getNbCharts() {
 75  0 return NB_CHARTS;
 76    }
 77   
 78  0 public static String getChartName(int i) {
 79  0 return CHART_NAMES[i];
 80    }
 81   
 82  2 public MetricsGatherer() {
 83  2 super();
 84    }
 85   
 86  2 public MetricsGatherer(TraversalStrategy strategy) {
 87  2 super(strategy);
 88    }
 89   
 90  136 public long[] getChartData(int i) {
 91  136 long[] result = chartData.get(i);
 92   
 93  136 if (result == null) {
 94  11 result = new long[NB_CHARTS];
 95  11 result[CHART_INDEX] = i;
 96  11 chartData.put(i, result);
 97   
 98  11 if (chartMaximum < i) {
 99  7 chartMaximum = i;
 100    }
 101    }
 102   
 103  136 return result;
 104    }
 105   
 106  0 public int getChartMaximum() {
 107  0 return chartMaximum;
 108    }
 109   
 110  5 public Collection<PackageNode> getPackages() {
 111  5 return packages;
 112    }
 113   
 114  5 public Collection<ClassNode> getClasses() {
 115  5 return classes;
 116    }
 117   
 118  5 public Collection<FeatureNode> getFeatures() {
 119  5 return features;
 120    }
 121   
 122  4 public long getNbOutbound() {
 123  4 return nbOutbound;
 124    }
 125   
 126  4 public long getNbInbound() {
 127  4 return nbInbound;
 128    }
 129   
 130  4 public long getNbOutboundPackages() {
 131  4 return nbOutboundPackages;
 132    }
 133   
 134  4 public long getNbInboundPackages() {
 135  4 return nbInboundPackages;
 136    }
 137   
 138  4 public long getNbOutboundClasses() {
 139  4 return nbOutboundClasses;
 140    }
 141   
 142  4 public long getNbInboundClasses() {
 143  4 return nbInboundClasses;
 144    }
 145   
 146  4 public long getNbOutboundFeatures() {
 147  4 return nbOutboundFeatures;
 148    }
 149   
 150  4 public long getNbInboundFeatures() {
 151  4 return nbInboundFeatures;
 152    }
 153   
 154  16 public void preprocessPackageNode(PackageNode node) {
 155  16 super.preprocessPackageNode(node);
 156   
 157  16 packages.add(node);
 158   
 159  16 getChartData(node.getClasses().size())[CLASSES_PER_PACKAGE]++;
 160  16 getChartData(node.getInboundDependencies().size())[INBOUNDS_PER_PACKAGE]++;
 161  16 getChartData(node.getOutboundDependencies().size())[OUTBOUNDS_PER_PACKAGE]++;
 162    }
 163   
 164    /**
 165    * PackageNode --> CurrentNode()
 166    */
 167  0 public void visitInboundPackageNode(PackageNode node) {
 168  0 if (getStrategy().isInFilter(node)) {
 169  0 nbInbound++;
 170  0 nbOutboundPackages++;
 171    }
 172    }
 173   
 174    /**
 175    * CurrentNode() --> PackageNode
 176    */
 177  0 public void visitOutboundPackageNode(PackageNode node) {
 178  0 if (getStrategy().isInFilter(node)) {
 179  0 nbOutbound++;
 180  0 nbInboundPackages++;
 181    }
 182    }
 183   
 184  18 public void preprocessClassNode(ClassNode node) {
 185  18 super.preprocessClassNode(node);
 186   
 187  18 classes.add(node);
 188   
 189  18 getChartData(node.getFeatures().size())[FEATURES_PER_CLASS]++;
 190  18 getChartData(node.getInboundDependencies().size())[INBOUNDS_PER_CLASS]++;
 191  18 getChartData(node.getOutboundDependencies().size())[OUTBOUNDS_PER_CLASS]++;
 192    }
 193   
 194    /**
 195    * ClassNode --> CurrentNode()
 196    */
 197  1 public void visitInboundClassNode(ClassNode node) {
 198  1 if (getStrategy().isInFilter(node)) {
 199  1 nbInbound++;
 200  1 nbOutboundClasses++;
 201    }
 202    }
 203   
 204    /**
 205    * CurrentNode() --> ClassNode
 206    */
 207  5 public void visitOutboundClassNode(ClassNode node) {
 208  5 if (getStrategy().isInFilter(node)) {
 209  5 nbOutbound++;
 210  5 nbInboundClasses++;
 211    }
 212    }
 213   
 214  17 public void preprocessFeatureNode(FeatureNode node) {
 215  17 super.preprocessFeatureNode(node);
 216   
 217  17 features.add(node);
 218   
 219  17 getChartData(node.getInboundDependencies().size())[INBOUNDS_PER_FEATURE]++;
 220  17 getChartData(node.getOutboundDependencies().size())[OUTBOUNDS_PER_FEATURE]++;
 221    }
 222   
 223    /**
 224    * FeatureNode --> CurrentNode()
 225    */
 226  16 public void visitInboundFeatureNode(FeatureNode node) {
 227  16 if (getStrategy().isInFilter(node)) {
 228  16 nbInbound++;
 229  16 nbOutboundFeatures++;
 230    }
 231    }
 232   
 233    /**
 234    * CurrentNode() --> FeatureNode
 235    */
 236  12 public void visitOutboundFeatureNode(FeatureNode node) {
 237  12 if (getStrategy().isInFilter(node)) {
 238  12 nbOutbound++;
 239  12 nbInboundFeatures++;
 240    }
 241    }
 242    }