1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.perfidix.meter;
28
29
30
31
32
33
34
35 public final class CountingMeter extends AbstractMeter {
36
37
38
39
40 private static final String DEFAULTNAME = "CountingMeter";
41
42
43
44
45 private static final String DEFAULTUNIT = "ticks";
46
47
48
49
50 private static final String DEFAULTUNITDESC = "Simple ticks for counting";
51
52
53
54
55 private transient long counter;
56
57
58
59
60 private transient final String name;
61
62
63
64
65 private transient final String unit;
66
67
68
69
70 private transient final String unitDescription;
71
72
73
74
75 public CountingMeter() {
76 this(DEFAULTNAME, DEFAULTUNIT, DEFAULTUNITDESC);
77 }
78
79
80
81
82
83
84
85 public CountingMeter(final String paramName) {
86 this(paramName, DEFAULTUNIT, DEFAULTUNITDESC);
87 }
88
89
90
91
92
93
94
95
96
97 public CountingMeter(final String paramName, final String paramUnit) {
98 this(paramName, paramUnit, DEFAULTUNITDESC);
99 }
100
101
102
103
104
105
106
107
108
109
110
111
112 public CountingMeter(final String paramName, final String paramUnit, final String paramUnitDesc) {
113 super();
114 name = paramName;
115 unit = paramUnit;
116 unitDescription = paramUnitDesc;
117 counter = 0;
118 }
119
120
121
122
123
124
125 @Override
126 public String getName() {
127 return name;
128 }
129
130
131
132
133 public void tick() {
134 counter++;
135 }
136
137
138
139
140
141
142 @Override
143 public double getValue() {
144 return counter;
145 }
146
147
148
149
150
151
152 @Override
153 public String getUnit() {
154 return unit;
155 }
156
157
158
159
160
161
162 @Override
163 public String getUnitDescription() {
164 return unitDescription;
165 }
166
167
168 @Override
169 public int hashCode() {
170 final int prime = 31;
171 int result = prime;
172 if (name == null) {
173 result = prime * result;
174 } else {
175 result = prime * result + name.hashCode();
176 }
177 if (unit == null) {
178 result = prime * result;
179 } else {
180 result = prime * result + unit.hashCode();
181 }
182 if (unitDescription == null) {
183 result = prime * result;
184 } else {
185 result = prime * result + unitDescription.hashCode();
186 }
187 return result;
188 }
189
190
191 @Override
192 public boolean equals(final Object obj) {
193 boolean returnVal = true;
194 if (this == obj) {
195 returnVal = true;
196 }
197 if (getClass() != obj.getClass()) {
198 returnVal = false;
199 }
200 final CountingMeter other = (CountingMeter)obj;
201 if (name == null) {
202 if (other.name != null) {
203 returnVal = false;
204 }
205 } else {
206 if (!name.equals(other.name)) {
207 returnVal = false;
208 }
209 }
210 if (unit == null) {
211 if (other.unit != null) {
212 returnVal = false;
213 }
214 } else if (!unit.equals(other.unit)) {
215 returnVal = false;
216 }
217 if (unitDescription == null) {
218 if (other.unitDescription == null) {
219 if (!unitDescription.equals(other.unitDescription)) {
220 returnVal = false;
221 }
222 } else {
223 returnVal = false;
224 }
225 }
226 return returnVal;
227 }
228
229 }