mirror of https://github.com/apache/poi.git
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:
parent
fa703eccfb
commit
1d9948f090
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue