package net.sf.jasperreports.engine.fill;

class JRFloatAverageIncrementer extends JRAbstractExtendedIncrementer {
  private static JRFloatAverageIncrementer mainInstance = new JRFloatAverageIncrementer();
  
  public static JRFloatAverageIncrementer getInstance() {
    return mainInstance;
  }
  
  public Object increment(JRCalculable variable, Object expressionValue, AbstractValueProvider valueProvider) {
    if (expressionValue == null) {
      if (variable.isInitialized())
        return null; 
      return variable.getValue();
    } 
    Number countValue = (Number)valueProvider.getValue(variable.getHelperVariable((byte)0));
    Number sumValue = (Number)valueProvider.getValue(variable.getHelperVariable((byte)1));
    return new Float(sumValue.floatValue() / countValue.floatValue());
  }
  
  public Object initialValue() {
    return JRFloatIncrementerFactory.ZERO;
  }
}
