PageRenderTime 27ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://testability-explorer.googlecode.com/
Java | 88 lines | 61 code | 12 blank | 15 comment | 5 complexity | 5b8efb460cb0a27fbd97c922f53c681f 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.util.ArrayList;
  18. import java.util.List;
  19. import java.util.SortedSet;
  20. import java.util.TreeSet;
  21. import com.google.test.metric.ClassCost;
  22. import com.google.test.metric.CostModel;
  23. import com.google.test.metric.WeightedAverage;
  24. public abstract class SummaryReportModel extends ReportModel {
  25. protected final WeightedAverage weightedAverage = new WeightedAverage();
  26. protected SortedSet<ClassCost> worstOffenders;
  27. protected final List<Integer> costs = new ArrayList<Integer>();
  28. public int getExcellentCount() {
  29. return excellentCount;
  30. }
  31. public int getGoodCount() {
  32. return goodCount;
  33. }
  34. public int getNeedsWorkCount() {
  35. return needsWorkCount;
  36. }
  37. protected final int maxExcellentCost;
  38. protected final int maxAcceptableCost;
  39. protected final int worstOffenderCount;
  40. protected int excellentCount = 0;
  41. protected int goodCount = 0;
  42. protected int needsWorkCount = 0;
  43. protected int worstCost = 1;
  44. private final CostModel costModel;
  45. public SummaryReportModel(CostModel costModel, int maxExcellentCost, int maxAcceptableCost, int worstOffenderCount) {
  46. this.costModel = costModel;
  47. this.worstOffenders = new TreeSet<ClassCost>(new ClassCost.CostComparator(costModel));
  48. this.maxExcellentCost = maxExcellentCost;
  49. this.maxAcceptableCost = maxAcceptableCost;
  50. this.worstOffenderCount = worstOffenderCount;
  51. }
  52. @Override
  53. public void addClassCost(ClassCost classCost) {
  54. int cost = costModel.computeClass(classCost);
  55. if (cost < maxExcellentCost) {
  56. excellentCount++;
  57. } else if (cost < maxAcceptableCost) {
  58. goodCount++;
  59. } else {
  60. needsWorkCount++;
  61. }
  62. costs.add(cost);
  63. worstOffenders.add(classCost);
  64. if (worstOffenders.size() > worstOffenderCount) {
  65. worstOffenders.remove(worstOffenders.last());
  66. }
  67. worstCost = Math.max(worstCost, cost);
  68. weightedAverage.addValue(cost);
  69. }
  70. public int getClassCount() {
  71. return costs.size();
  72. }
  73. public int getOverall() {
  74. return (int) weightedAverage.getAverage();
  75. }
  76. }