Coverage Report - org.dishevelled.timer.report.TextTimerReport
 
Classes in this File Line Coverage Branch Coverage Complexity
TextTimerReport
100%
30/30
100%
6/6
2.25
 
 1  
 /*
 2  
 
 3  
     dsh-timer  Timer with nanosecond resolution and summary statistics
 4  
     on recorded elapsed times.
 5  
     Copyright (c) 2004-2013 held jointly by the individual authors.
 6  
 
 7  
     This library is free software; you can redistribute it and/or modify it
 8  
     under the terms of the GNU Lesser General Public License as published
 9  
     by the Free Software Foundation; either version 3 of the License, or (at
 10  
     your option) any later version.
 11  
 
 12  
     This library is distributed in the hope that it will be useful, but WITHOUT
 13  
     ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
 14  
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 15  
     License for more details.
 16  
 
 17  
     You should have received a copy of the GNU Lesser General Public License
 18  
     along with this library;  if not, write to the Free Software Foundation,
 19  
     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
 20  
 
 21  
     > http://www.fsf.org/licensing/licenses/lgpl.html
 22  
     > http://www.opensource.org/licenses/lgpl-license.php
 23  
 
 24  
 */
 25  
 package org.dishevelled.timer.report;
 26  
 
 27  
 import java.io.IOException;
 28  
 
 29  
 import java.text.NumberFormat;
 30  
 
 31  
 import java.util.Map;
 32  
 
 33  
 import org.dishevelled.timer.Timer;
 34  
 
 35  
 /**
 36  
  * Timer report in tab-delimited text format.
 37  
  */
 38  
 public final class TextTimerReport
 39  
     extends AbstractTimerReport
 40  
 {
 41  
     private final NumberFormat numberFormat;
 42  
 
 43  
     public TextTimerReport(final NumberFormat numberFormat)
 44  5
     {
 45  5
         this.numberFormat = numberFormat;
 46  5
     }
 47  
 
 48  
     /** {@inheritDoc} */
 49  
     public <T extends Appendable> T append(final Map<? extends Runnable, Timer> timers, final T appendable)
 50  
         throws IOException
 51  
     {
 52  6
         if (timers == null)
 53  
         {
 54  2
             throw new IllegalArgumentException("timers must not be null");
 55  
         }
 56  4
         if (appendable == null)
 57  
         {
 58  1
             throw new IllegalArgumentException("appendable must not be null");
 59  
         }
 60  3
         append(appendable, "Runnable");
 61  3
         append(appendable, "Size");
 62  3
         append(appendable, "Min (ns)");
 63  3
         append(appendable, "Mean (ns)");
 64  3
         append(appendable, "Max (ns)");
 65  3
         append(appendable, "Standard Deviation (ns)");
 66  3
         appendLast(appendable, "Sum (ns)");
 67  
 
 68  3
         for (Map.Entry<? extends Runnable, Timer> entry : timers.entrySet())
 69  
         {
 70  3
             append(appendable, String.valueOf(entry.getKey()));
 71  3
             append(appendable, numberFormat.format(entry.getValue().size()));
 72  3
             append(appendable, numberFormat.format(entry.getValue().min()));
 73  3
             append(appendable, numberFormat.format(entry.getValue().mean()));
 74  3
             append(appendable, numberFormat.format(entry.getValue().max()));
 75  3
             append(appendable, numberFormat.format(entry.getValue().standardDeviation()));
 76  3
             appendLast(appendable, numberFormat.format(entry.getValue().sum()));
 77  3
         }
 78  3
         return appendable;
 79  
     }
 80  
 
 81  
     private static <T extends Appendable> void append(final T appendable, final String value) throws IOException
 82  
     {
 83  36
         appendable.append(value);
 84  36
         appendable.append("\t");
 85  36
     }
 86  
 
 87  
     private static <T extends Appendable> void appendLast(final T appendable, final String value) throws IOException
 88  
     {
 89  6
         appendable.append(value);
 90  6
         appendable.append("\n");
 91  6
     }
 92  
 }