https://bz.apache.org/bugzilla/show_bug.cgi?id=65916

--- Comment #13 from moimoi.chk <moimoi....@gmail.com> ---
package org.apache.poi.xssf.usermodel;
XSSFRow

=====
change
=====
public Iterator<Cell> cellIterator() {
        Iterator<Cell> originalIterator = (Iterator<Cell>)(Iterator<? extends
Cell>)_cells.values().iterator();

        return new Iterator<Cell>() {
            Cell lastNext = null;

            @Override
            public boolean hasNext() {
                return originalIterator.hasNext();
            }

            @Override
            public Cell next() {
                return lastNext = originalIterator.next();
            }

            @Override
            public void remove() {
                removeCellWithoutRemoveFromList(lastNext);
            }
        };
    }

=====
change
=====
    public void removeCell(Cell cell) {
        removeCellWithoutRemoveFromList(cell);
        _cells.remove(cell);
    }

=====
add
=====
private void removeCellWithoutRemoveFromList(Cell cell) {
        if (cell.getRow() != this) {
            throw new IllegalArgumentException("Specified cell does not belong
to this row");
        }
        //noinspection SuspiciousMethodCalls
        if(!_cells.containsValue(cell)) {
            throw new IllegalArgumentException("the row does not contain this
cell");
        }

        XSSFCell xcell = (XSSFCell)cell;
        if(xcell.isPartOfArrayFormulaGroup()) {
            xcell.setCellFormula(null); // to remove the array formula
        }
        if(cell.getCellType() == CellType.FORMULA) {
            _sheet.getWorkbook().onDeleteFormula(xcell);
        }
        // Performance optimization for bug 57840: explicit boxing is slightly
faster than auto-unboxing, though may use more memory
        final Integer colI = Integer.valueOf(cell.getColumnIndex()); // NOSONAR

        // also remove the corresponding CTCell from the _row.cArray,
        // it may not be at the same position right now
        // thus search for it
        int i = 0;
        for (CTCell ctCell : _row.getCArray()) {
            if(ctCell == ((XSSFCell)cell).getCTCell()) {
                _row.removeC(i);
            }
            i++;
        }
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to