com.github.kunalk16.excel.factory.RowFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lightExcelReader Show documentation
Show all versions of lightExcelReader Show documentation
A lightweight Java framework to read .xlsx excel files.
package com.github.kunalk16.excel.factory;
import com.github.kunalk16.excel.factory.extractor.CellByColumnExtractor;
import com.github.kunalk16.excel.factory.extractor.CellRowNumberExtractor;
import com.github.kunalk16.excel.model.factory.ExcelRow;
import com.github.kunalk16.excel.model.jaxb.sharedstrings.SharedStringType;
import com.github.kunalk16.excel.model.jaxb.worksheet.RowType;
import com.github.kunalk16.excel.model.user.Cell;
import com.github.kunalk16.excel.model.user.Row;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
class RowFactory {
static Row create(SharedStringType sharedStrings, RowType row) {
List cells = Optional.ofNullable(getCells(sharedStrings, row))
.orElse(Collections.emptyList());
Map cellByColumn = Optional.of(cells)
.map(new CellByColumnExtractor())
.orElse(Collections.emptyMap());
return new ExcelRow(cellByColumn, new CellRowNumberExtractor(row).apply(cells));
}
private static List getCells(SharedStringType sharedStrings, RowType row) {
return Optional.ofNullable(row)
.map(RowType::getCells)
.orElse(Collections.emptyList())
.stream()
.map(cell -> CellFactory.create(sharedStrings, cell))
.collect(Collectors.toList());
}
}
| |
© 2015 - 2025 Weber Informatics LLC | Privacy Policy