package net.sf.jasperreports.engine.fill;

class JRByteStandardDeviationIncrementer extends JRAbstractExtendedIncrementer {
  private static JRByteStandardDeviationIncrementer mainInstance = new JRByteStandardDeviationIncrementer();
  
  public static JRByteStandardDeviationIncrementer 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 Byte((byte)(int)Math.sqrt(varianceValue.doubleValue()));
  }
  
  public Object initialValue() {
    return JRByteIncrementerFactory.ZERO;
  }
}
