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
10
11
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
24
25
26
27
28
29
30 public AggregateSummary(String name) {
31 if (name == null)
32 throw new IllegalArgumentException("Name cannot be null.");
33
34 this.name = name;
35 }
36
37
38
39
40
41
42
43 public void add(Aggregate aggregate) {
44 this.min = Math.min(aggregate.getMin(), getMin());
45 this.max = Math.max(aggregate.getMax(), getMax());
46 this.total += aggregate.getTotal();
47 this.measurements += aggregate.getMeasurements();
48 }
49
50
51
52
53 public int compareTo(AggregateSummary o) {
54 return getName().compareTo(o.getName());
55 }
56
57 @Override
58 public boolean equals(Object o) {
59 if (o == this)
60 return true;
61
62 if (!(o instanceof AggregateSummary))
63 return false;
64
65 return getName().equals(((AggregateSummary) o).getName());
66 }
67
68
69
70
71 public double getAverage() {
72 return getTotal() / getMeasurements();
73 }
74
75
76
77
78 @SuppressWarnings("rawtypes")
79 public Map getChilds() {
80 return Collections.emptyMap();
81 }
82
83
84
85
86 public double getMax() {
87 return max;
88 }
89
90
91
92
93 public long getMeasurements() {
94 return measurements;
95 }
96
97
98
99
100 public double getMin() {
101 return min;
102 }
103
104
105
106
107 public String getName() {
108 return name;
109 }
110
111
112
113
114 public double getTotal() {
115 return total;
116 }
117
118
119
120
121 public boolean hasChilds() {
122 return false;
123 }
124
125 @Override
126 public int hashCode() {
127 return getName().hashCode();
128 }
129 }