]> source.dussan.org Git - poi.git/commitdiff
remove comment iterator
authorPJ Fanning <fanningpj@apache.org>
Sat, 20 Nov 2021 16:26:55 +0000 (16:26 +0000)
committerPJ Fanning <fanningpj@apache.org>
Sat, 20 Nov 2021 16:26:55 +0000 (16:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895210 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java
poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java

index fe4a3ec8b33df30661ae10ab9b5dec08bbeb5b29..6cbf6f6ccccc001293475f7e242348dc3f8862b7 100644 (file)
@@ -74,14 +74,6 @@ public interface Comments {
      */
     Iterator<CellAddress> getCellAddresses();
 
-    /**
-     * @param sheet the sheet to check for comments (used to find drawing/shape data for comments) - set to null
-     *              if you don't need the drawing/shape data
-     * @return iterator of comments
-     * @since POI 5.2.0
-     */
-    Iterator<XSSFComment> commentIterator(Sheet sheet);
-
     /**
      * Create a new comment and add to the CommentTable.
      * @param sheet sheet to add comment to
index d9fbde79361af02076f840ac9505cb5212062d73..3cf33f22cf8d1f2f65823b50e3df9cf8601d0e3d 100644 (file)
@@ -100,38 +100,6 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments {
         }
     }
 
-    /**
-     * @param sheet the sheet to check for comments (used to find drawing/shape data for comments) - set to null
-     *              if you don't need the drawing/shape data
-     * @return iterator of comments
-     * @since POI 5.2.0
-     */
-    @Override
-    public Iterator<XSSFComment> commentIterator(Sheet sheet) {
-        XSSFVMLDrawing vml = getVMLDrawing(sheet, false);
-        final CommentsTable table = this;
-        return new Iterator<XSSFComment>() {
-            private final CTComment[] commentsArray = getCTComments().getCommentList().getCommentArray();
-            private int counter = 0;
-
-            @Override
-            public boolean hasNext() {
-                return counter < commentsArray.length;
-            }
-
-            @Override
-            public XSSFComment next() {
-                CTComment ctComment = commentsArray[counter++];
-                CellAddress cellAddress = new CellAddress(ctComment.getRef());
-                CTShape shape = null;
-                if (vml != null) {
-                    shape = vml.findCommentShape(cellAddress.getRow(), cellAddress.getColumn());
-                }
-                return new XSSFComment(table, ctComment, shape);
-            }
-        };
-    }
-    
     /**
      * Called after the reference is updated, so that
      *  we can reflect that in our cache
index ab9ab51b724af39214ac896871d0a3c864ebabad..66fcbe6499364b22d206e509c04e05b8e2f1c8ae 100644 (file)
@@ -3112,19 +3112,21 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
 
                 // is there a change necessary for the current row?
                 if(newrownum != rownum) {
-                    Iterator<XSSFComment> commentIterator = sheetComments.commentIterator(this);
-                    while (commentIterator.hasNext()) {
-                        XSSFComment oldComment = commentIterator.next();
-                        CellReference ref = new CellReference(oldComment.getRow(), oldComment.getColumn());
+                    Iterator<CellAddress> commentAddressIterator = sheetComments.getCellAddresses();
+                    while (commentAddressIterator.hasNext()) {
+                        CellAddress cellAddress = commentAddressIterator.next();
 
                         // is this comment part of the current row?
-                        if(ref.getRow() == rownum) {
-                            XSSFComment xssfComment = new XSSFComment(sheetComments, oldComment.getCTComment(),
-                                    oldComment.getCTShape());
-
-                            // we should not perform the shifting right here as we would then find
-                            // already shifted comments and would shift them again...
-                            commentsToShift.put(xssfComment, newrownum);
+                        if(cellAddress.getRow() == rownum) {
+                            XSSFComment oldComment = sheetComments.findCellComment(this, cellAddress);
+                            if (oldComment != null) {
+                                XSSFComment xssfComment = new XSSFComment(sheetComments, oldComment.getCTComment(),
+                                        oldComment.getCTShape());
+
+                                // we should not perform the shifting right here as we would then find
+                                // already shifted comments and would shift them again...
+                                commentsToShift.put(xssfComment, newrownum);
+                            }
                         }
                     }
                 }
@@ -3197,17 +3199,19 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
 
 
         if (sheetComments != null) {
-            Iterator<XSSFComment> commentIterator = sheetComments.commentIterator(this);
-            while (commentIterator.hasNext()) {
-                XSSFComment oldComment = commentIterator.next();
-                CellReference ref = new CellReference(oldComment.getRow(), oldComment.getColumn());
+            Iterator<CellAddress> commentAddressIterator = sheetComments.getCellAddresses();
+            while (commentAddressIterator.hasNext()) {
+                CellAddress oldCommentAddress = commentAddressIterator.next();
 
-                int columnIndex =ref.getCol();
+                int columnIndex = oldCommentAddress.getColumn();
                 int newColumnIndex = shiftedRowNum(startColumnIndex, endColumnIndex, n, columnIndex);
-                if(newColumnIndex != columnIndex){
-                    XSSFComment xssfComment = new XSSFComment(sheetComments, oldComment.getCTComment(),
-                            vml == null ? null : vml.findCommentShape(ref.getRow(), columnIndex));
-                    commentsToShift.put(xssfComment, newColumnIndex);
+                if(newColumnIndex != columnIndex) {
+                    XSSFComment oldComment = sheetComments.findCellComment(this, oldCommentAddress);
+                    if (oldComment != null) {
+                        XSSFComment xssfComment = new XSSFComment(sheetComments, oldComment.getCTComment(),
+                                oldComment.getCTShape());
+                        commentsToShift.put(xssfComment, newColumnIndex);
+                    }
                 }
             }
         }