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