Browse Source

try to speed up SXSSFCell getColumnIndex

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1905937 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_2_4
PJ Fanning 1 year ago
parent
commit
7454a722f0

+ 19
- 2
poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java View File

@@ -52,13 +52,27 @@ public class SXSSFCell extends CellBase {
private CellStyle _style;
private Property _firstProperty;

public SXSSFCell(SXSSFRow row, CellType cellType)
private int _columnIndex = -1;

public SXSSFCell(final SXSSFRow row, final CellType cellType)
{
_row=row;
_row = row;
_value = new BlankValue();
setType(cellType);
}

/**
* @param row the {@link SXSSFRow}
* @param cellType the {@link CellType}
* @param columnIndex the column index (zero based)
* @since POI 5.2.4
*/
public SXSSFCell(final SXSSFRow row, final CellType cellType, final int columnIndex)
{
this(row, cellType);
_columnIndex = columnIndex;
}

/**
* {@inheritDoc}
*/
@@ -75,6 +89,9 @@ public class SXSSFCell extends CellBase {
@Override
public int getColumnIndex()
{
if (_columnIndex >= 0) {
return _columnIndex;
}
return _row.getCellIndex(this);
}


+ 4
- 4
poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFRow.java View File

@@ -113,7 +113,7 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
* The cell that is returned is a {@link CellType#BLANK}. The type can be changed
* either through calling {@code setCellValue} or {@code setCellType}.
*
* @param column - the column number this cell represents
* @param column - the column number this cell represents (zero-based)
* @return Cell a high level representation of the created cell.
* @throws IllegalArgumentException if columnIndex &lt; 0 or greater than the maximum number of supported columns
* (255 for *.xls, 1048576 for *.xlsx)
@@ -130,16 +130,16 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
* The cell that is returned is a {@link CellType#BLANK}. The type can be changed
* either through calling setCellValue or setCellType.
*
* @param column - the column number this cell represents
* @param column - the column number this cell represents (zero-based)
* @return Cell a high level representation of the created cell.
* @throws IllegalArgumentException if columnIndex &lt; 0 or greater than a maximum number of supported columns
* (255 for *.xls, 1048576 for *.xlsx)
*/
@Override
public SXSSFCell createCell(int column, CellType type)
public SXSSFCell createCell(final int column, final CellType type)
{
checkBounds(column);
SXSSFCell cell = new SXSSFCell(this, type);
SXSSFCell cell = new SXSSFCell(this, type, column);
_cells.put(column, cell);
_sheet.trackNewCell(cell);
return cell;

+ 14
- 0
poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFRow.java View File

@@ -23,6 +23,11 @@ import org.apache.poi.ss.tests.usermodel.BaseTestXRow;
import org.apache.poi.xssf.SXSSFITestDataProvider;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Tests for XSSFRow
@@ -51,5 +56,14 @@ public final class TestSXSSFRow extends BaseTestXRow {
// Remove when SXSSFRow.shiftCellsLeft() is implemented.
}

@Test
void testCellColumn() throws IOException {
try (SXSSFWorkbook wb = new SXSSFWorkbook()) {
SXSSFSheet sheet = wb.createSheet();
SXSSFRow row = sheet.createRow(0);
SXSSFCell cell5 = row.createCell(5);
assertEquals(5, cell5.getColumnIndex());
}
}

}

Loading…
Cancel
Save