PageRenderTime 75ms CodeModel.GetById 19ms RepoModel.GetById 0ms 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
Possible License(s): Apache-2.0
  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. package com.google.test.metric.report;
  17. import java.io.PrintStream;
  18. import com.google.test.metric.ClassCost;
  19. import com.google.test.metric.CostModel;
  20. import com.google.test.metric.report.chart.PieGraph;
  21. public class TextReportGenerator extends SummaryReportModel implements ReportGenerator {
  22. private final PrintStream out;
  23. public TextReportGenerator(PrintStream out, CostModel costModel, int maxExcellentCost, int maxAcceptableCost, int worstOffenderCount) {
  24. super(costModel, maxExcellentCost, maxAcceptableCost, worstOffenderCount);
  25. this.out = out;
  26. }
  27. public TextReportGenerator(PrintStream out, CostModel costModel, ReportOptions options) {
  28. this(out, costModel, options.getMaxExcellentCost(), options.getMaxAcceptableCost(),
  29. options.getWorstOffenderCount());
  30. }
  31. public void printSummary() {
  32. int total = costs.size();
  33. out.printf(" Analyzed classes: %5d%n", total);
  34. out.printf(" Excellent classes (.): %5d %5.1f%%%n", excellentCount, 100f * excellentCount / total);
  35. out.printf(" Good classes (=): %5d %5.1f%%%n", goodCount, 100f * goodCount / total);
  36. out.printf("Needs work classes (@): %5d %5.1f%%%n", needsWorkCount, 100f * needsWorkCount / total);
  37. PieGraph graph = new PieGraph(50, new CharMarker('.', '=', '@'));
  38. String chart = graph.render(excellentCount, goodCount, needsWorkCount);
  39. out.printf(" Breakdown: [%s]%n", chart);
  40. }
  41. public void printDistribution(int rows, int width) {
  42. TextHistogram histogram = new TextHistogram(width, rows, new Marker() {
  43. public char get(int index, float value) {
  44. if (value < maxExcellentCost) {
  45. return '.';
  46. } else if (value < maxAcceptableCost) {
  47. return '=';
  48. } else {
  49. return '@';
  50. }
  51. }
  52. });
  53. float[] values = new float[costs.size()];
  54. int i = 0;
  55. for (int cost : costs) {
  56. values[i++] = cost;
  57. }
  58. for (String graph : histogram.graph(values)) {
  59. out.println(graph);
  60. }
  61. }
  62. public void printWorstOffenders(int worstOffenderCount) {
  63. out.println();
  64. out.println("Highest Cost");
  65. out.println("============");
  66. for (ClassCost cost : worstOffenders) {
  67. out.println(cost);
  68. }
  69. }
  70. /* (non-Javadoc)
  71. * @see com.google.test.metric.report.Report#print()
  72. */
  73. public void printFooter() {
  74. printSummary();
  75. printDistribution(25, 70);
  76. printWorstOffenders(worstOffenderCount);
  77. }
  78. public void printHeader() {
  79. }
  80. }