PageRenderTime 28ms CodeModel.GetById 14ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/testability-explorer/src/main/java/com/google/test/metric/report/TextReportGenerator.java

http://testability-explorer.googlecode.com/
Java | 93 lines | 62 code | 13 blank | 18 comment | 7 complexity | 1823811304c27da94422465faeda37d4 MD5 | raw file
 1/*
 2 * Copyright 2007 Google Inc.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 5 * use this file except in compliance with the License. You may obtain a copy of
 6 * the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17package com.google.test.metric.report;
18
19import java.io.PrintStream;
20
21import com.google.test.metric.ClassCost;
22import com.google.test.metric.CostModel;
23import com.google.test.metric.report.chart.PieGraph;
24
25
26public class TextReportGenerator extends SummaryReportModel implements ReportGenerator {
27
28  private final PrintStream out;
29  public TextReportGenerator(PrintStream out, CostModel costModel, int maxExcellentCost, int maxAcceptableCost, int worstOffenderCount) {
30    super(costModel, maxExcellentCost, maxAcceptableCost, worstOffenderCount);
31    this.out = out;
32  }
33
34  public TextReportGenerator(PrintStream out, CostModel costModel, ReportOptions options) {
35    this(out, costModel, options.getMaxExcellentCost(), options.getMaxAcceptableCost(),
36            options.getWorstOffenderCount());
37  }
38
39  public void printSummary() {
40    int total = costs.size();
41    out.printf("      Analyzed classes: %5d%n", total);
42    out.printf(" Excellent classes (.): %5d %5.1f%%%n", excellentCount, 100f * excellentCount / total);
43    out.printf("      Good classes (=): %5d %5.1f%%%n", goodCount, 100f * goodCount / total);
44    out.printf("Needs work classes (@): %5d %5.1f%%%n", needsWorkCount, 100f * needsWorkCount / total);
45    PieGraph graph = new PieGraph(50, new CharMarker('.', '=', '@'));
46    String chart = graph.render(excellentCount, goodCount, needsWorkCount);
47    out.printf("             Breakdown: [%s]%n", chart);
48  }
49
50  public void printDistribution(int rows, int width) {
51    TextHistogram histogram = new TextHistogram(width, rows, new Marker() {
52      public char get(int index, float value) {
53        if (value < maxExcellentCost) {
54          return '.';
55        } else if (value < maxAcceptableCost) {
56          return '=';
57        } else {
58          return '@';
59        }
60      }
61    });
62    float[] values = new float[costs.size()];
63    int i = 0;
64    for (int cost : costs) {
65      values[i++] = cost;
66    }
67    for (String graph : histogram.graph(values)) {
68      out.println(graph);
69    }
70  }
71
72  public void printWorstOffenders(int worstOffenderCount) {
73    out.println();
74    out.println("Highest Cost");
75    out.println("============");
76    for (ClassCost cost : worstOffenders) {
77      out.println(cost);
78    }
79  }
80
81  /* (non-Javadoc)
82   * @see com.google.test.metric.report.Report#print()
83   */
84  public void printFooter() {
85    printSummary();
86    printDistribution(25, 70);
87    printWorstOffenders(worstOffenderCount);
88  }
89
90  public void printHeader() {
91  }
92
93}