package net.sf.jasperreports.engine.fill;

import java.math.BigDecimal;

class JRBigDecimalDistinctCountIncrementer extends JRAbstractExtendedIncrementer {
  private static JRBigDecimalDistinctCountIncrementer mainInstance = new JRBigDecimalDistinctCountIncrementer();
  
  public static JRBigDecimalDistinctCountIncrementer getInstance() {
    return mainInstance;
  }
  
  public Object increment(JRCalculable variable, Object expressionValue, AbstractValueProvider valueProvider) {
    DistinctCountHolder holder = (DistinctCountHolder)valueProvider.getValue(variable.getHelperVariable((byte)0));
    if (variable.isInitialized())
      holder.init(); 
    return new BigDecimal(holder.getCount());
  }
  
  public Object combine(JRCalculable calculable, JRCalculable calculableValue, AbstractValueProvider valueProvider) {
    DistinctCountHolder holder = (DistinctCountHolder)valueProvider.getValue(calculable.getHelperVariable((byte)0));
    return new BigDecimal(holder.getCount());
  }
  
  public Object initialValue() {
    return JRBigDecimalIncrementerFactory.ZERO;
  }
}
