
com.poiji.bind.mapping.HSSFStreamIterator Maven / Gradle / Ivy
package com.poiji.bind.mapping;
import com.poiji.option.PoijiOptions;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
public final class HSSFStreamIterator implements Iterator {
private final int limit;
private int internalCount;
private final Iterator iter;
private final HSSFReadMappedFields readMappedFields;
private final PoijiOptions options;
private T next;
public HSSFStreamIterator(
final Iterator rowIterator, final HSSFReadMappedFields readMappedFields, final PoijiOptions options
) {
this.readMappedFields = readMappedFields;
this.iter = rowIterator;
this.options = options;
this.limit = options.getLimit();
}
@Override
public boolean hasNext() {
while (iter.hasNext()){
final Row currentRow = iter.next();
if (!skip(currentRow) && !isRowEmpty(currentRow)) {
internalCount += 1;
if (limit != 0 && internalCount > limit) {
continue;
}
this.next = readMappedFields.parseRow(currentRow);
return true;
}
}
return false;
}
private boolean skip(final Row currentRow) {
return currentRow.getRowNum() < options.getHeaderStart() + options.getHeaderCount();
}
private boolean isRowEmpty(Row row) {
for (int c = row.getFirstCellNum(); c < row.getLastCellNum(); c++) {
Cell cell = row.getCell(c, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
if (cell != null && cell.getCellType() != CellType.BLANK) {
return false;
}
}
return true;
}
@Override
public T next() {
return next;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy