
package de.ivu.elect.jee.presentation.dynamictable;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractColumnGroupBuilder<E> extends AbstractColumnBuilder<E> {

  private static final long serialVersionUID = 1L;

  private List<ColumnGroup< ? super E>> columnGroups;

  public AbstractColumnGroupBuilder() {
    super();
  }

  @Override
  protected void init() {
    super.init();

    initColumnGroups();
  }

  protected abstract void initColumnGroups();

  @Override
  protected List<ColumnEntry< ? super E>> getColumnEntriesSorted() {
    List<ColumnEntry< ? super E>> columnEntriesSorted = new ArrayList<>();

    for (ColumnGroup< ? super E> columnGroup : getColumnGroups()) {
      columnEntriesSorted.addAll(columnGroup.getColumns());
    }

    return columnEntriesSorted;
  }

  @Override
  public List<ColumnGroup< ? super E>> getColumnGroups() {
    if (columnGroups == null) {
      initIfNotInitialized();

      columnGroups = getColumnGroupsSorted();
    }
    return columnGroups;
  }

  @Override
  protected void resetState() {
    super.resetState();
    columnGroups = null;
  }

  protected abstract List<ColumnGroup< ? super E>> getColumnGroupsSorted();

  protected ColumnGroup<E> createSingleColumnColumnGroup(ColumnEntry< ? super E> column) {
    ColumnGroup<E> columnGroup = new ColumnGroup<>(null);
    columnGroup.addColumn(column);

    return columnGroup;
  }

  @Override // ELECT-5215
  public boolean isColumnFilterSupported() {
    return false;
  }
}
