1 10 11 package org.mule.util.counters.impl; 12 13 import org.mule.util.counters.Counter; 14 import org.mule.util.counters.CounterFactory.Type; 15 16 20 public class Operator extends AggregateCounter 21 { 22 23 private Counter base2; 24 private double val1; 25 private double val2; 26 27 public Operator(String name, AbstractCounter base, AbstractCounter base2, Type type) 28 { 29 super(name, type, base); 30 this.base2 = base2; 31 base2.addAggregate(this); 32 } 33 34 public double nextValue() 35 { 36 Type type = getType(); 37 if (type == Type.PLUS) 38 { 39 return val1 + val2; 40 } 41 else if (type == Type.MINUS) 42 { 43 return val1 - val2; 44 } 45 else if (type == Type.MULTIPLY) 46 { 47 return val1 * val2; 48 } 49 else if (type == Type.DIVIDE) 50 { 51 return val2 == 0.0 ? (val1 >= 0 ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY) : val1 52 / val2; 53 } 54 else 55 { 56 throw new IllegalStateException (); 57 } 58 } 59 60 public void doCompute() 61 { 62 this.val1 = getBase().nextValue(); 63 this.val2 = base2.nextValue(); 64 } 65 } 66 | Popular Tags |