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

org.sfm.poi.impl.SheetIterator Maven / Gradle / Ivy

package org.sfm.poi.impl;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.sfm.map.Mapper;
import org.sfm.map.MappingContext;

import java.util.Iterator;

public class SheetIterator implements Iterator {

    private final Mapper mapper;
    private final Sheet sheet;
    private final MappingContext mappingContext;

    private int rowNum;

    public SheetIterator(Mapper mapper, int startRow, Sheet sheet, MappingContext mappingContext) {
        this.mapper = mapper;
        this.rowNum = startRow;
        this.sheet = sheet;
        this.mappingContext = mappingContext;
    }

    @Override
    public boolean hasNext() {
        return rowNum <= sheet.getLastRowNum();
    }

    @Override
    public T next() {
        Row row = sheet.getRow(rowNum);
        rowNum++;
        return mapper.map(row, mappingContext);
    }

    @Override
    public void remove() {
        throw new UnsupportedOperationException("remove");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy