package net.sf.jasperreports.engine.fill;

import java.math.BigDecimal;

class JRBigDecimalStandardDeviationIncrementer extends JRAbstractExtendedIncrementer {
  private static JRBigDecimalStandardDeviationIncrementer mainInstance = new JRBigDecimalStandardDeviationIncrementer();
  
  public static JRBigDecimalStandardDeviationIncrementer getInstance() {
    return mainInstance;
  }
  
  public Object increment(JRCalculable variable, Object expressionValue, AbstractValueProvider valueProvider) {
    if (expressionValue == null) {
      if (variable.isInitialized())
        return null; 
      return variable.getValue();
    } 
    Number varianceValue = (Number)valueProvider.getValue(variable.getHelperVariable((byte)2));
    return new BigDecimal(Math.sqrt(varianceValue.doubleValue()));
  }
  
  public Object initialValue() {
    return JRBigDecimalIncrementerFactory.ZERO;
  }
}
