package net.sf.jasperreports.engine.fill;

class JRByteCountIncrementer extends JRAbstractExtendedIncrementer {
  private static JRByteCountIncrementer mainInstance = new JRByteCountIncrementer();
  
  public static JRByteCountIncrementer getInstance() {
    return mainInstance;
  }
  
  public Object increment(JRCalculable variable, Object expressionValue, AbstractValueProvider valueProvider) {
    Number value = (Number)variable.getIncrementedValue();
    if (value == null || variable.isInitialized())
      value = JRByteIncrementerFactory.ZERO; 
    if (expressionValue == null)
      return value; 
    return new Byte((byte)(value.byteValue() + 1));
  }
  
  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 = JRByteIncrementerFactory.ZERO; 
    if (combineValue == null)
      return value; 
    return new Byte((byte)(value.byteValue() + combineValue.byteValue()));
  }
  
  public Object initialValue() {
    return JRByteIncrementerFactory.ZERO;
  }
}
