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

com.github.kunalk16.excel.factory.RowFactory Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
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