1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.util.counters.impl; |
8 | |
|
9 | |
import org.mule.util.counters.CounterFactory.Type; |
10 | |
|
11 | |
public class Average extends AggregateCounter |
12 | |
{ |
13 | |
|
14 | 0 | private double sum = 0; |
15 | 0 | private long times = 0; |
16 | |
|
17 | |
public Average(String name, AbstractCounter base) |
18 | |
{ |
19 | 0 | super(name, Type.AVERAGE, base); |
20 | 0 | } |
21 | |
|
22 | |
public double nextValue() |
23 | |
{ |
24 | 0 | return (times > 0) ? sum / times : 0; |
25 | |
} |
26 | |
|
27 | |
public void doCompute() |
28 | |
{ |
29 | 0 | this.sum += getBase().nextValue(); |
30 | 0 | this.times++; |
31 | 0 | } |
32 | |
|
33 | |
} |