All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sigpwned.tabular4j.model.TabularWorksheetHeaderWriter Maven / Gradle / Ivy

The newest version!
/*-
 * =================================LICENSE_START==================================
 * spreadsheet4j-core
 * ====================================SECTION=====================================
 * Copyright (C) 2022 - 2023 Andy Boothe
 * ====================================SECTION=====================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ==================================LICENSE_END===================================
 */
package com.sigpwned.tabular4j.model;

import static java.util.stream.Collectors.toList;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import com.sigpwned.tabular4j.filter.RectangularWorksheetWriter;

public class TabularWorksheetHeaderWriter {
  private final WorksheetWriter delegate;

  public TabularWorksheetHeaderWriter(WorksheetWriter delegate) {
    this.delegate = new RectangularWorksheetWriter(delegate);
  }

  public int getSheetIndex() {
    return getDelegate().getSheetIndex();
  }

  public String getSheetName() {
    return getDelegate().getSheetName();
  }

  public TabularWorksheetRowWriter writeHeaders(String... headers) throws IOException {
    return writeHeaders(Arrays.asList(headers));
  }

  public TabularWorksheetRowWriter writeHeaders(List headers) throws IOException {
    if (headers == null)
      throw new NullPointerException();
    if (headers.isEmpty())
      throw new IllegalArgumentException("no headers");
    getDelegate()
        .writeRow(headers.stream().map(WorksheetCellDefinition::ofValue).collect(toList()));
    return new TabularWorksheetRowWriter(getDelegate(), headers);
  }

  /**
   * @return the delegate
   */
  private WorksheetWriter getDelegate() {
    return delegate;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy