View Javadoc

1   package com.google.code.jetm.maven.internal;
2   
3   import java.util.Collections;
4   import java.util.Map;
5   
6   import org.apache.commons.lang.builder.ToStringBuilder;
7   
8   import etm.core.aggregation.Aggregate;
9   
10  /**
11   * A simple {@link Aggregate} bean implementation.
12   * 
13   * @author jrh3k5
14   * 
15   */
16  
17  public class SimpleAggregate implements Aggregate {
18      private final String name;
19      private final double average;
20      private final double min;
21      private final double max;
22      private final long measurements;
23      private final double total;
24      private final boolean hasChilds;
25      private final Map<?, ?> childs;
26  
27      /**
28       * Create an aggregate.
29       * 
30       * @param name
31       *            The name of the aggregate.
32       * @param average
33       *            The average of the measurements.
34       * @param min
35       *            The lowest measurement.
36       * @param max
37       *            The highest measurement.
38       * @param measurements
39       *            The number of measurements.
40       * @param total
41       *            The total of all measurements collected.
42       */
43      public SimpleAggregate(String name, double average, double min, double max, long measurements, double total) {
44          this.name = name;
45          this.average = average;
46          this.min = min;
47          this.max = max;
48          this.measurements = measurements;
49          this.total = total;
50          this.hasChilds = false;
51          this.childs = Collections.emptyMap();
52      }
53  
54      @Override
55      public boolean equals(Object obj) {
56          if (this == obj)
57              return true;
58  
59          if (!(obj instanceof Aggregate))
60              return false;
61  
62          final Aggregate other = (Aggregate) obj;
63          return getName().equals(other.getName()) && getAverage() == other.getAverage() && getChilds().equals(other.getChilds()) && getMax() == other.getMax()
64                  && getMeasurements() == other.getMeasurements() && getMin() == other.getMin() && getTotal() == other.getTotal() && hasChilds() == other.hasChilds();
65      }
66  
67      /**
68       * {@inheritDoc}
69       */
70      public double getAverage() {
71          return average;
72      }
73  
74      /**
75       * {@inheritDoc}
76       */
77      public Map<?, ?> getChilds() {
78          return childs;
79      }
80  
81      /**
82       * {@inheritDoc}
83       */
84      public double getMax() {
85          return max;
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      public long getMeasurements() {
92          return measurements;
93      }
94  
95      /**
96       * {@inheritDoc}
97       */
98      public double getMin() {
99          return min;
100     }
101 
102     /**
103      * {@inheritDoc}
104      */
105     public String getName() {
106         return name;
107     }
108 
109     /**
110      * {@inheritDoc}
111      */
112     public double getTotal() {
113         return total;
114     }
115 
116     /**
117      * {@inheritDoc}
118      */
119     public boolean hasChilds() {
120         return hasChilds;
121     }
122 
123     @Override
124     public int hashCode() {
125         final int prime = 31;
126         int result = 1;
127         long temp;
128         temp = Double.doubleToLongBits(average);
129         result = prime * result + (int) (temp ^ (temp >>> 32));
130         temp = Double.doubleToLongBits(max);
131         result = prime * result + (int) (temp ^ (temp >>> 32));
132         result = prime * result + (int) (measurements ^ (measurements >>> 32));
133         temp = Double.doubleToLongBits(min);
134         result = prime * result + (int) (temp ^ (temp >>> 32));
135         result = prime * result + ((name == null) ? 0 : name.hashCode());
136         temp = Double.doubleToLongBits(total);
137         result = prime * result + (int) (temp ^ (temp >>> 32));
138         return result;
139     }
140 
141     @Override
142     public String toString() {
143         return ToStringBuilder.reflectionToString(this);
144     }
145 }