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