try to make comments table more extensible

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895113 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-11-17 18:41:16 +00:00
parent fa703eccfb
commit 1d9948f090
2 changed files with 35 additions and 23 deletions

View File

@ -164,6 +164,25 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments {
CTComment ct = getCTComment(cellAddress);
return ct == null ? null : new XSSFComment(this, ct, null);
}
/**
* Finds the cell comment at cellAddress, if one exists
*
* @param sheet the sheet that has the comment
* @param cellAddress the address of the cell to find a comment
* @return cell comment if one exists, otherwise returns null
* @since POI 5.2.0
*/
public XSSFComment findCellComment(XSSFSheet sheet, CellAddress cellAddress) {
CTComment ctComment = getCTComment(cellAddress);
if(ctComment == null) {
return null;
}
XSSFVMLDrawing vml = sheet.getVMLDrawing(false);
return new XSSFComment(this, ctComment,
vml == null ? null : vml.findCommentShape(cellAddress.getRow(), cellAddress.getColumn()));
}
/**
* Get the underlying CTComment xmlbean for a comment located at cellRef, if it exists
@ -221,21 +240,6 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments {
return new XSSFComment(this, newComment(ref), vmlShape);
}
/**
* Refresh Map<CellAddress, CTComment> commentRefs cache,
* Calls that use the commentRefs cache will perform in O(1)
* time rather than O(n) lookup time for List<CTComment> comments.
*/
private void prepareCTCommentCache() {
// Create the cache if needed
if(commentRefs == null) {
commentRefs = new HashMap<>();
for (CTComment comment : comments.getCommentList().getCommentArray()) {
commentRefs.put(new CellAddress(comment.getRef()), comment);
}
}
}
/**
* Create a new comment located at cell address
@ -304,4 +308,19 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments {
public CTComments getCTComments(){
return comments;
}
/**
* Refresh Map<CellAddress, CTComment> commentRefs cache,
* Calls that use the commentRefs cache will perform in O(1)
* time rather than O(n) lookup time for List<CTComment> comments.
*/
private void prepareCTCommentCache() {
// Create the cache if needed
if(commentRefs == null) {
commentRefs = new HashMap<>();
for (CTComment comment : comments.getCommentList().getCommentArray()) {
commentRefs.put(new CellAddress(comment.getRef()), comment);
}
}
}
}

View File

@ -774,14 +774,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
return null;
}
CTComment ctComment = sheetComments.getCTComment(address);
if(ctComment == null) {
return null;
}
XSSFVMLDrawing vml = getVMLDrawing(false);
return new XSSFComment(sheetComments, ctComment,
vml == null ? null : vml.findCommentShape(address.getRow(), address.getColumn()));
return sheetComments.findCellComment(this, address);
}
/**