<commit_before>package com.health.input;

import java.io.FileInputStream;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Objects;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

import com.health.Record;
import com.health.Table;

/**
 * Implements a parser for xls input files.
 *
 */
public final class XlsParser implements Parser {

	/**
	 * Given a path to a xls file and an input descriptor, parses the input file
	 * into a {@link Table}.
	 *
	 * @param path
	 *            the path of the input file.
	 * @param config
	 *            the input descriptor.
	 * @return a table representing the parsed input file.
	 * @throws IOException
	 *             if any IO errors occur.
	 * @throws InputException
	 *             if any input errors occur.
	 */

	@Override
	public Table parse(final String path, final InputDescriptor config)
			throws InputException, IOException {
		Objects.requireNonNull(path);
		Objects.requireNonNull(config);

		Table table = config.buildTable();

		FileInputStream io = new FileInputStream(path);
		XSSFWorkbook wb = new XSSFWorkbook(io);

		StartCell startCell = config.getStartCell();
		int rowCount = 0;
		int columnsCount = config.getColumns().size();

		Sheet sheet = wb.getSheetAt(0);
		for (Row row : sheet) {
			// if at start row or beyond
			if (rowCount >= startCell.getStartRow()) {
				Record tableRow = new Record(table);

				int columnCountTableRow = 0;
				for (int i = startCell.getStartColumn() - 1; i < columnsCount
						+ startCell.getStartColumn() - 1; i++) {
					switch (table.getColumn(columnCountTableRow).getType()) {
					case String:
						tableRow.setValue(columnCountTableRow, row.getCell(i)
								.toString());
						break;
					case Number:
						tableRow.setValue(columnCountTableRow,
								Double.parseDouble(row.getCell(i).toString()));
						break;
					case Date:
						if (config.getDateFormat() != null) {
							try {
								DateTimeFormatter formatter = DateTimeFormatter

								.ofPattern(config.getDateFormat());
								LocalDate dateValue = LocalDate.parse(row
										.getCell(i).toString(), formatter);
								tableRow.setValue(columnCountTableRow,
										dateValue);
							} catch (DateTimeParseException e) {
								break;
							}
						}
						break;
					default:
						// The type was null, this should never happen
						assert false;
						throw new InputException(
								"Internal error.",
								new Exception("Column.getType() returned null."));
					}

					columnCountTableRow++;
				}

			}

			rowCount++;
		}

		wb.close();
		return table;

	}
}
<commit_msg>depending on which workbook is needed parser is chosen<commit_after>package com.health.input;

import java.io.FileInputStream;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Objects;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.health.Record;
import com.health.Table;

/**
 * Implements a parser for xls input files.
 *
 */
public final class XlsParser implements Parser {
  public String type = "xls";

  /**
   * Given a path to a xls file and an input descriptor, parses the input file into a {@link Table}.
   *
   * @param path
   *          the path of the input file.
   * @param config
   *          the input descriptor.
   * @return a table representing the parsed input file.
   * @throws IOException
   *           if any IO errors occur.
   * @throws InputException
   *           if any input errors occur.
   */

  @Override
  public Table parse(final String path, final InputDescriptor config) throws InputException,
      IOException {
    Objects.requireNonNull(path);
    Objects.requireNonNull(config);

    Table table = config.buildTable();
    Workbook wb;

    FileInputStream io = new FileInputStream(path);
    if (type == "xls") {
      wb = new XSSFWorkbook(io);
    } else {
      wb = new HSSFWorkbook(io);
    }

    StartCell startCell = config.getStartCell();
    int rowCount = 0;
    int columnsCount = config.getColumns().size();

    Sheet sheet = wb.getSheetAt(0);
    for (Row row : sheet) {
      // if at start row or beyond
      if (rowCount >= startCell.getStartRow()) {
        Record tableRow = new Record(table);

        int columnCountTableRow = 0;
        for (int i = startCell.getStartColumn() - 1; i < columnsCount + startCell.getStartColumn()
            - 1; i++) {
          switch (table.getColumn(columnCountTableRow).getType()) {
          case String:
            tableRow.setValue(columnCountTableRow, row.getCell(i).toString());
            break;
          case Number:
            tableRow.setValue(columnCountTableRow, Double.parseDouble(row.getCell(i).toString()));
            break;
          case Date:
            if (config.getDateFormat() != null) {
              try {
                DateTimeFormatter formatter = DateTimeFormatter

                .ofPattern(config.getDateFormat());
                LocalDate dateValue = LocalDate.parse(row.getCell(i).toString(), formatter);
                tableRow.setValue(columnCountTableRow, dateValue);
              } catch (DateTimeParseException e) {
                break;
              }
            }
            break;
          default:
            // The type was null, this should never happen
            assert false;
            throw new InputException("Internal error.", new Exception(
                "Column.getType() returned null."));
          }

          columnCountTableRow++;
        }

      }

      rowCount++;
    }

    wb.close();
    return table;

  }
}

{'fraction_non_alphanumeric': 0.10305152576288144, 'fraction_numerical': 0.0016675004168751042, 'mean_word_length': 2.524089306698002, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1557922', 'n_tokens_mistral': 1966, 'n_tokens_neox': 1696, 'n_words': 458}