Coverage Report - com.google.code.jetm.maven.data.AggregateSummary
 
Classes in this File Line Coverage Branch Coverage Complexity
AggregateSummary
85%
24/28
100%
6/6
1.462
 
 1  
 package com.google.code.jetm.maven.data;
 2  
 
 3  
 import java.util.Collections;
 4  
 import java.util.Map;
 5  
 
 6  
 import etm.core.aggregation.Aggregate;
 7  
 
 8  
 /**
 9  
  * A bean to store summary of aggregate data.
 10  
  * 
 11  
  * @author jrh3k5
 12  
  * 
 13  
  */
 14  
 
 15  0
 public class AggregateSummary implements Aggregate, Comparable<AggregateSummary> {
 16  11
     private double min = Double.MAX_VALUE;
 17  11
     private double max = Double.MIN_VALUE;
 18  
     private double total;
 19  
     private long measurements;
 20  
     private String name;
 21  
 
 22  
     /**
 23  
      * Create a summary.
 24  
      * 
 25  
      * @param name
 26  
      *            The name of the summary.
 27  
      * @throws IllegalArgumentException
 28  
      *             If the given name is {@code null}.
 29  
      */
 30  11
     public AggregateSummary(String name) {
 31  11
         if (name == null)
 32  1
             throw new IllegalArgumentException("Name cannot be null.");
 33  
 
 34  10
         this.name = name;
 35  10
     }
 36  
 
 37  
     /**
 38  
      * Add an aggregate to the summary.
 39  
      * 
 40  
      * @param aggregate
 41  
      *            The {@link Aggregate} to be added to the summary.
 42  
      */
 43  
     public void add(Aggregate aggregate) {
 44  2
         this.min = Math.min(aggregate.getMin(), getMin());
 45  2
         this.max = Math.max(aggregate.getMax(), getMax());
 46  2
         this.total += aggregate.getTotal();
 47  2
         this.measurements += aggregate.getMeasurements();
 48  2
     }
 49  
 
 50  
     /**
 51  
      * {@inheritDoc}
 52  
      */
 53  
     public int compareTo(AggregateSummary o) {
 54  4
         return getName().compareTo(o.getName());
 55  
     }
 56  
 
 57  
     @Override
 58  
     public boolean equals(Object o) {
 59  5
         if (o == this)
 60  1
             return true;
 61  
 
 62  4
         if (!(o instanceof AggregateSummary))
 63  2
             return false;
 64  
 
 65  2
         return getName().equals(((AggregateSummary) o).getName());
 66  
     }
 67  
 
 68  
     /**
 69  
      * {@inheritDoc}
 70  
      */
 71  
     public double getAverage() {
 72  0
         return getTotal() / getMeasurements();
 73  
     }
 74  
 
 75  
     /**
 76  
      * {@inheritDoc}
 77  
      */
 78  
     @SuppressWarnings("rawtypes")
 79  
     public Map getChilds() {
 80  0
         return Collections.emptyMap();
 81  
     }
 82  
 
 83  
     /**
 84  
      * {@inheritDoc}
 85  
      */
 86  
     public double getMax() {
 87  3
         return max;
 88  
     }
 89  
 
 90  
     /**
 91  
      * {@inheritDoc}
 92  
      */
 93  
     public long getMeasurements() {
 94  1
         return measurements;
 95  
     }
 96  
 
 97  
     /**
 98  
      * {@inheritDoc}
 99  
      */
 100  
     public double getMin() {
 101  3
         return min;
 102  
     }
 103  
 
 104  
     /**
 105  
      * {@inheritDoc}
 106  
      */
 107  
     public String getName() {
 108  15
         return name;
 109  
     }
 110  
 
 111  
     /**
 112  
      * {@inheritDoc}
 113  
      */
 114  
     public double getTotal() {
 115  1
         return total;
 116  
     }
 117  
 
 118  
     /**
 119  
      * {@inheritDoc}
 120  
      */
 121  
     public boolean hasChilds() {
 122  0
         return false;
 123  
     }
 124  
 
 125  
     @Override
 126  
     public int hashCode() {
 127  1
         return getName().hashCode();
 128  
     }
 129  
 }