View Javadoc

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  public class AggregateSummary implements Aggregate, Comparable<AggregateSummary> {
16      private double min = Double.MAX_VALUE;
17      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       */
28      public AggregateSummary(String name) {
29          this.name = name;
30      }
31  
32      /**
33       * Add an aggregate to the summary.
34       * 
35       * @param aggregate
36       *            The {@link Aggregate} to be added to the summary.
37       */
38      public void add(Aggregate aggregate) {
39          this.min = Math.min(aggregate.getMin(), getMin());
40          this.max = Math.max(aggregate.getMax(), getMax());
41          this.total += aggregate.getTotal();
42          this.measurements += aggregate.getMeasurements();
43      }
44  
45      /**
46       * {@inheritDoc}
47       */
48      public int compareTo(AggregateSummary o) {
49          return getName().compareTo(o.getName());
50      }
51  
52      /**
53       * {@inheritDoc}
54       */
55      public double getAverage() {
56          return getTotal() / getMeasurements();
57      }
58  
59      /**
60       * {@inheritDoc}
61       */
62      @SuppressWarnings("rawtypes")
63      public Map getChilds() {
64          return Collections.emptyMap();
65      }
66  
67      /**
68       * {@inheritDoc}
69       */
70      public double getMax() {
71          return max;
72      }
73  
74      /**
75       * {@inheritDoc}
76       */
77      public long getMeasurements() {
78          return measurements;
79      }
80  
81      /**
82       * {@inheritDoc}
83       */
84      public double getMin() {
85          return min;
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      public String getName() {
92          return name;
93      }
94  
95      /**
96       * {@inheritDoc}
97       */
98      public double getTotal() {
99          return total;
100     }
101 
102     /**
103      * {@inheritDoc}
104      */
105     public boolean hasChilds() {
106         return false;
107     }
108 }