Author: fanningpj
Date: Sat Nov 20 16:26:55 2021
New Revision: 1895210

URL: http://svn.apache.org/viewvc?rev=1895210&view=rev
Log:
remove comment iterator

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

Modified: 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java?rev=1895210&r1=1895209&r2=1895210&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java 
(original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/Comments.java 
Sat Nov 20 16:26:55 2021
@@ -75,14 +75,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
      * @param clientAnchor the anchor for this comment

Modified: 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java?rev=1895210&r1=1895209&r2=1895210&view=diff
==============================================================================
--- 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java 
(original)
+++ 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java 
Sat Nov 20 16:26:55 2021
@@ -101,38 +101,6 @@ public class CommentsTable extends POIXM
     }
 
     /**
-     * @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
      * @param oldReference the comment to remove from the commentRefs map

Modified: 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1895210&r1=1895209&r2=1895210&view=diff
==============================================================================
--- 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java 
(original)
+++ 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java 
Sat Nov 20 16:26:55 2021
@@ -3112,19 +3112,21 @@ public class XSSFSheet extends POIXMLDoc
 
                 // 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 POIXMLDoc
 
 
         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);
+                    }
                 }
             }
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to