Coverage Report - org.perfidix.ouput.AbstractOutput
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractOutput
100%
2/2
N/A
1
 
 1  
 /**
 2  
  * Copyright (c) 2012, University of Konstanz, Distributed Systems Group
 3  
  * All rights reserved.
 4  
  * 
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions are met:
 7  
  * * Redistributions of source code must retain the above copyright
 8  
  * notice, this list of conditions and the following disclaimer.
 9  
  * * Redistributions in binary form must reproduce the above copyright
 10  
  * notice, this list of conditions and the following disclaimer in the
 11  
  * documentation and/or other materials provided with the distribution.
 12  
  * * Neither the name of the University of Konstanz nor the
 13  
  * names of its contributors may be used to endorse or promote products
 14  
  * derived from this software without specific prior written permission.
 15  
  * 
 16  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 17  
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 18  
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 19  
  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 20  
  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 21  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 22  
  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 23  
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 24  
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 25  
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 26  
  */
 27  
 package org.perfidix.ouput;
 28  
 
 29  
 import java.lang.reflect.Method;
 30  
 import java.util.Formatter;
 31  
 import java.util.Locale;
 32  
 
 33  
 import org.perfidix.exceptions.AbstractPerfidixMethodException;
 34  
 import org.perfidix.meter.AbstractMeter;
 35  
 import org.perfidix.result.BenchmarkResult;
 36  
 
 37  
 /**
 38  
  * The ResultVisitor is able to visit and view the results. The idea is that
 39  
  * every implementing class can offer all results as long as they are a {@link BenchmarkResult}. The
 40  
  * implementing class should know how to handle
 41  
  * these results. Additionally to the visitor pattern, all inheriting class have
 42  
  * to implement the listener pattern as well since every output class has to
 43  
  * provide functionality to handle listener events as well.
 44  
  * 
 45  
  * @author Sebastian Graf, University of Konstanz
 46  
  * @author Alexander Onea, neue Couch
 47  
  */
 48  80
 public abstract class AbstractOutput {
 49  
 
 50  
     /**
 51  
      * Constant to offer one fix format to display double-variables.
 52  
      */
 53  
     protected static final String FLOATFORMAT = "%05.2f";
 54  
 
 55  
     /**
 56  
      * Visiting the {@link BenchmarkResult} and do something with the result.
 57  
      * 
 58  
      * @param res
 59  
      *            the {@link BenchmarkResult}
 60  
      */
 61  
     public abstract void visitBenchmark(final BenchmarkResult res);
 62  
 
 63  
     /**
 64  
      * Listening to a resultset and handling the data.
 65  
      * 
 66  
      * @param meth
 67  
      *            the related {@link Method}
 68  
      * @param meter
 69  
      *            the corresponding {@link AbstractMeter} instance where the
 70  
      *            result is related to
 71  
      * @param data
 72  
      *            the related data
 73  
      */
 74  
     public abstract boolean
 75  
         listenToResultSet(final Method meth, final AbstractMeter meter, final double data);
 76  
 
 77  
     /**
 78  
      * Listening to an arised exception.
 79  
      * 
 80  
      * @param exec
 81  
      *            an {@link AbstractPerfidixMethodException} instance
 82  
      */
 83  
     public abstract boolean listenToException(final AbstractPerfidixMethodException exec);
 84  
 
 85  
     /**
 86  
      * Formats a double.
 87  
      * 
 88  
      * @param toFormat
 89  
      *            the number to format
 90  
      * @see java.util.Formatter for the documentation.
 91  
      * @return the formatted string.
 92  
      */
 93  
     protected static final String format(final double toFormat) {
 94  920
         return new Formatter(Locale.US).format(FLOATFORMAT, toFormat).toString();
 95  
     }
 96  
 
 97  
 }