List of usage examples for org.apache.poi.ss.util CellAddress compareTo
@Override public int compareTo(CellAddress other)
From source file:utilities.SmapSheetXMLHandler.java
License:Apache License
/** * Do a check for, and output, comments in otherwise empty cells. *//*from www . jav a 2 s.c o m*/ private void checkForEmptyCellComments(EmptyCellCommentsCheckType type) { if (commentCellRefs != null && !commentCellRefs.isEmpty()) { // If we've reached the end of the sheet data, output any // comments we haven't yet already handled if (type == EmptyCellCommentsCheckType.END_OF_SHEET_DATA) { while (!commentCellRefs.isEmpty()) { outputEmptyCellComment(commentCellRefs.remove()); } return; } // At the end of a row, handle any comments for "missing" rows before us if (this.cellRef == null) { if (type == EmptyCellCommentsCheckType.END_OF_ROW) { while (!commentCellRefs.isEmpty()) { if (commentCellRefs.peek().getRow() == rowNum) { outputEmptyCellComment(commentCellRefs.remove()); } else { return; } } return; } else { throw new IllegalStateException( "Cell ref should be null only if there are only empty cells in the row; rowNum: " + rowNum); } } CellAddress nextCommentCellRef; do { CellAddress cellRef = new CellAddress(this.cellRef); CellAddress peekCellRef = commentCellRefs.peek(); if (type == EmptyCellCommentsCheckType.CELL && cellRef.equals(peekCellRef)) { // remove the comment cell ref from the list if we're about to handle it alongside the cell content commentCellRefs.remove(); return; } else { // fill in any gaps if there are empty cells with comment mixed in with non-empty cells int comparison = peekCellRef.compareTo(cellRef); if (comparison > 0 && type == EmptyCellCommentsCheckType.END_OF_ROW && peekCellRef.getRow() <= rowNum) { nextCommentCellRef = commentCellRefs.remove(); outputEmptyCellComment(nextCommentCellRef); } else if (comparison < 0 && type == EmptyCellCommentsCheckType.CELL && peekCellRef.getRow() <= rowNum) { nextCommentCellRef = commentCellRefs.remove(); outputEmptyCellComment(nextCommentCellRef); } else { nextCommentCellRef = null; } } } while (nextCommentCellRef != null && !commentCellRefs.isEmpty()); } }