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 private double sum = 0;
15 private long times = 0;
16
17 public Average(String name, AbstractCounter base)
18 {
19 super(name, Type.AVERAGE, base);
20 }
21
22 public double nextValue()
23 {
24 return (times > 0) ? sum / times : 0;
25 }
26
27 public void doCompute()
28 {
29 this.sum += getBase().nextValue();
30 this.times++;
31 }
32
33 }