package net.sf.jasperreports.engine.fill;

class JRLongSumIncrementer extends JRAbstractExtendedIncrementer {
  private static JRLongSumIncrementer mainInstance = new JRLongSumIncrementer();
  
  public static JRLongSumIncrementer getInstance() {
    return mainInstance;
  }
  
  public Object increment(JRCalculable variable, Object expressionValue, AbstractValueProvider valueProvider) {
    Number value = (Number)variable.getIncrementedValue();
    Number newValue = (Number)expressionValue;
    if (newValue == null) {
      if (variable.isInitialized())
        return null; 
      return value;
    } 
    if (value == null || variable.isInitialized())
      value = JRLongIncrementerFactory.ZERO; 
    return new Long(value.longValue() + newValue.longValue());
  }
  
  public Object initialValue() {
    return JRLongIncrementerFactory.ZERO;
  }
}
