package net.sf.jasperreports.charts.base;

import net.sf.jasperreports.charts.JRTimePeriodDataset;
import net.sf.jasperreports.charts.JRTimePeriodSeries;
import net.sf.jasperreports.engine.JRChartDataset;
import net.sf.jasperreports.engine.JRExpressionCollector;
import net.sf.jasperreports.engine.base.JRBaseChartDataset;
import net.sf.jasperreports.engine.base.JRBaseObjectFactory;
import net.sf.jasperreports.engine.design.JRVerifier;

public class JRBaseTimePeriodDataset extends JRBaseChartDataset implements JRTimePeriodDataset {
  private static final long serialVersionUID = 10200L;
  
  private JRTimePeriodSeries[] timePeriodSeries = null;
  
  protected JRBaseTimePeriodDataset(JRTimePeriodDataset dataset) {
    super((JRChartDataset)dataset);
  }
  
  public JRBaseTimePeriodDataset(JRTimePeriodDataset dataset, JRBaseObjectFactory factory) {
    super((JRChartDataset)dataset, factory);
    JRTimePeriodSeries[] srcTimePeriodSeries = dataset.getSeries();
    if (srcTimePeriodSeries != null && srcTimePeriodSeries.length > 0) {
      this.timePeriodSeries = new JRTimePeriodSeries[srcTimePeriodSeries.length];
      for (int i = 0; i < this.timePeriodSeries.length; i++)
        this.timePeriodSeries[i] = factory.getTimePeriodSeries(srcTimePeriodSeries[i]); 
    } 
  }
  
  public JRTimePeriodSeries[] getSeries() {
    return this.timePeriodSeries;
  }
  
  public byte getDatasetType() {
    return 5;
  }
  
  public void collectExpressions(JRExpressionCollector collector) {
    collector.collect(this);
  }
  
  public void validate(JRVerifier verifier) {
    verifier.verify(this);
  }
  
  public Object clone() {
    JRBaseTimePeriodDataset clone = (JRBaseTimePeriodDataset)super.clone();
    if (this.timePeriodSeries != null) {
      clone.timePeriodSeries = new JRTimePeriodSeries[this.timePeriodSeries.length];
      for (int i = 0; i < this.timePeriodSeries.length; i++)
        this.timePeriodSeries[i] = (JRTimePeriodSeries)this.timePeriodSeries[i].clone(); 
    } 
    return clone;
  }
}
