Coverage Report - org.mule.util.counters.impl.Operator
 
Classes in this File Line Coverage Branch Coverage Complexity
Operator
24%
4/17
0%
0/12
4
 
 1  
 /*
 2  
  * $Id: Operator.java 8077 2007-08-27 20:15:25Z aperepel $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 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  
 public class Operator extends AggregateCounter
 17  
 {
 18  
 
 19  
     private final Counter base2;
 20  
     private double val1;
 21  
     private double val2;
 22  
 
 23  
     public Operator(String name, AbstractCounter base, AbstractCounter base2, Type type)
 24  
     {
 25  4
         super(name, type, base);
 26  4
         this.base2 = base2;
 27  4
         base2.addAggregate(this);
 28  4
     }
 29  
 
 30  
     public double nextValue()
 31  
     {
 32  0
         Type type = this.getType();
 33  
 
 34  0
         if (type == Type.PLUS)
 35  
         {
 36  0
             return val1 + val2;
 37  
         }
 38  0
         else if (type == Type.MINUS)
 39  
         {
 40  0
             return val1 - val2;
 41  
         }
 42  0
         else if (type == Type.MULTIPLY)
 43  
         {
 44  0
             return val1 * val2;
 45  
         }
 46  0
         else if (type == Type.DIVIDE)
 47  
         {
 48  0
             return val2 == 0.0
 49  
                             ? (val1 >= 0 ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY)
 50  
                             : (val1 / val2);
 51  
         }
 52  
         else
 53  
         {
 54  0
             throw new IllegalStateException();
 55  
         }
 56  
     }
 57  
 
 58  
     public void doCompute()
 59  
     {
 60  0
         this.val1 = this.getBase().nextValue();
 61  0
         this.val2 = base2.nextValue();
 62  0
     }
 63  
 
 64  
 }