package net.sf.jasperreports.crosstabs.fill.calculation;

public class HeaderCell {
  private final BucketDefinition.Bucket[] bucketValues;
  
  private final int levelSpan;
  
  private final int depthSpan;
  
  private final boolean isTotal;
  
  public HeaderCell(BucketDefinition.Bucket[] bucketValues, int levelSpan, int depthSpan) {
    this.bucketValues = bucketValues;
    this.levelSpan = levelSpan;
    this.depthSpan = depthSpan;
    boolean foundTotal = false;
    for (int i = 0; i < bucketValues.length; i++) {
      if (bucketValues[i] != null && bucketValues[i].isTotal()) {
        foundTotal = true;
        break;
      } 
    } 
    this.isTotal = foundTotal;
  }
  
  public BucketDefinition.Bucket[] getBucketValues() {
    return this.bucketValues;
  }
  
  public int getLevelSpan() {
    return this.levelSpan;
  }
  
  public int getDepthSpan() {
    return this.depthSpan;
  }
  
  public boolean isTotal() {
    return this.isTotal;
  }
  
  public static HeaderCell createLevelSpanCopy(HeaderCell cell, int newLevelSpan) {
    return new HeaderCell(cell.bucketValues, newLevelSpan, cell.getDepthSpan());
  }
}
