PageRenderTime 30ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://testability-explorer.googlecode.com/
Java | 60 lines | 27 code | 9 blank | 24 comment | 0 complexity | bf6162837c862648373c30f77470a215 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.IOException;
  18. import java.io.OutputStream;
  19. import java.util.Properties;
  20. import com.google.test.metric.ClassCost;
  21. import com.google.test.metric.CostModel;
  22. /**
  23. * Write out the classes and their metrics in a Java properties file format.
  24. * @author alexeagle@google.com (Alex Eagle)
  25. *
  26. */
  27. public class PropertiesReportGenerator implements ReportGenerator {
  28. private final Properties properties = new Properties();
  29. private final OutputStream out;
  30. private final CostModel costModel;
  31. /**
  32. * @param out where the report should be written
  33. */
  34. public PropertiesReportGenerator(OutputStream out, CostModel costModel) {
  35. this.out = out;
  36. this.costModel = costModel;
  37. }
  38. public void addClassCost(ClassCost classCost) {
  39. properties.setProperty(classCost.getClassName(), String.valueOf(costModel.computeClass(classCost)));
  40. }
  41. public void printFooter() {
  42. try {
  43. properties.store(out, "Metrics generated by Testability Explorer");
  44. } catch (IOException e) {
  45. throw new RuntimeException(e);
  46. }
  47. }
  48. public void printHeader() {
  49. // Nothing to do
  50. }
  51. }