package net.sf.jasperreports.engine.fill;

class JRLongCountIncrementer extends JRAbstractExtendedIncrementer {
  private static JRLongCountIncrementer mainInstance = new JRLongCountIncrementer();
  
  public static JRLongCountIncrementer getInstance() {
    return mainInstance;
  }
  
  public Object increment(JRCalculable variable, Object expressionValue, AbstractValueProvider valueProvider) {
    Number value = (Number)variable.getIncrementedValue();
    if (value == null || variable.isInitialized())
      value = JRLongIncrementerFactory.ZERO; 
    if (expressionValue == null)
      return value; 
    return new Long(value.longValue() + 1L);
  }
  
  public Object combine(JRCalculable calculable, JRCalculable calculableValue, AbstractValueProvider valueProvider) {
    Number value = (Number)calculable.getIncrementedValue();
    Number combineValue = (Number)calculableValue.getValue();
    if (value == null || calculable.isInitialized())
      value = JRLongIncrementerFactory.ZERO; 
    if (combineValue == null)
      return value; 
    return new Long(value.longValue() + combineValue.longValue());
  }
  
  public Object initialValue() {
    return JRLongIncrementerFactory.ZERO;
  }
}
