package net.sf.jasperreports.engine.fill;

import java.math.BigDecimal;

public class JRDefaultIncrementerFactory extends JRAbstractExtendedIncrementerFactory {
  private static JRDefaultIncrementerFactory mainInstance = new JRDefaultIncrementerFactory();
  
  public static JRDefaultIncrementerFactory getInstance() {
    return mainInstance;
  }
  
  public JRExtendedIncrementer getExtendedIncrementer(byte calculation) {
    JRExtendedIncrementer incrementer = null;
    switch (calculation) {
      case 8:
        incrementer = JRDefaultSystemIncrementer.getInstance();
        return incrementer;
      case 9:
        incrementer = JRDefaultFirstIncrementer.getInstance();
        return incrementer;
    } 
    incrementer = JRDefaultNothingIncrementer.getInstance();
    return incrementer;
  }
  
  public static JRExtendedIncrementerFactory getFactory(Class valueClass) {
    JRExtendedIncrementerFactory factory;
    if (BigDecimal.class.equals(valueClass)) {
      factory = JRBigDecimalIncrementerFactory.getInstance();
    } else if (Number.class.equals(valueClass) || Double.class.equals(valueClass)) {
      factory = JRDoubleIncrementerFactory.getInstance();
    } else if (Float.class.equals(valueClass)) {
      factory = JRFloatIncrementerFactory.getInstance();
    } else if (Long.class.equals(valueClass)) {
      factory = JRLongIncrementerFactory.getInstance();
    } else if (Integer.class.equals(valueClass)) {
      factory = JRIntegerIncrementerFactory.getInstance();
    } else if (Short.class.equals(valueClass)) {
      factory = JRShortIncrementerFactory.getInstance();
    } else if (Byte.class.equals(valueClass)) {
      factory = JRByteIncrementerFactory.getInstance();
    } else if (Comparable.class.isAssignableFrom(valueClass)) {
      factory = JRComparableIncrementerFactory.getInstance();
    } else {
      factory = getInstance();
    } 
    return factory;
  }
}
